using System;
using System.Collections.Generic;
using System.Reflection;
namespace Neo.Afx.Services
{
///
/// Provides the base for a worker instance.
///
public abstract class Worker : IWorker
{
protected readonly object PropertyLock = new object();
#region UserID
long _userID;
///
/// Gets or sets the user ID.
///
public long UserID
{
get
{
lock(PropertyLock)
{
return _userID;
}
}
set
{
lock(PropertyLock)
{
_userID = value;
}
}
}
#endregion
#region UserName
string _userEmail;
///
/// Gets or sets the user name.
///
public string UserEmail
{
get
{
lock(PropertyLock)
{
return _userEmail;
}
}
set
{
lock(PropertyLock)
{
_userEmail = value;
}
}
}
#endregion
#region Settings
Dictionary _settings;
///
/// Gets or sets the configuration settings.
///
public Dictionary Settings
{
get
{
lock(PropertyLock)
{
return _settings;
}
}
set
{
lock(PropertyLock)
{
_settings = value;
}
}
}
#endregion
#region TraceInfo
string _traceInfo;
///
/// Gets or sets the trace information, if any.
///
public string TraceInfo
{
get
{
lock(PropertyLock)
{
return _traceInfo;
}
}
set
{
lock(PropertyLock)
{
_traceInfo = value;
}
}
}
#endregion
#region Create
///
/// Creates an instance of the given type.
///
/// The assembly-qualified name of the type.
/// The ID of the user running the .
/// The email address of the user running the .
/// The key-value pair settings for the .
///
/// The instance that was created, otherwise null.
///
public static IWorker Create(string typeName, long userID, string userEmail, Dictionary settings)
{
var objectType = Type.GetType(typeName);
var workerObject = Activator.CreateInstance(objectType);
var worker = (IWorker)workerObject;
worker.UserID = userID;
worker.UserEmail = userEmail;
worker.Settings = settings;
return worker;
}
public static IWorker Create(IWorker worker, long userID, string userEmail, Dictionary settings)
{
worker.UserID = userID;
worker.UserEmail = userEmail;
worker.Settings = settings;
return worker;
}
#endregion
}
}