Processorhandler:
Using system;
Using system. reflection;
Using system. Collections. Specialized;
Using system. configuration;
Namespace credit. Business
{
/// <Summary>
/// Summary description for processsectionhandler.
/// </Summary>
Public class processorhandler
{
Private Static readonly namevaluecollection s_multiprocessor = configurationsettings. getconfig ("processorsetting") as namevaluecollection;
Public static
Basecreditprocess [] createallinstance ()
{
Basecreditprocess [] processors = new basecreditprocess [s_multiprocesSor. Count];
For (INT I = 0; I <s_multiprocessor.count; ++ I)
{
String [] assemblyinfo = s_multiprocessor [I]. Split (',');
String typename = assemblyinfo [0]. Trim ();
String assemblyname = assemblyinfo [1]. Trim ();
Processors [I] = (basecreditprocess) Assembly. Load (assemblyname). createinstaNCE (typename );
}
Return processors;
}
Public static string getkeyfromclassname (string name)
{
Foreach (string key
In s_multiprocessor.allkeys)
{
If (s_multiprocessor [Key]. startswiTh (name ))
{
Return key;
}
}
Return NULL;
}
Public static basecreditprocess create (string key)
{
String [] assemblyinfo = s_multiprocessor [Key]. Split (',');
String typename = assemblyinfo [0]. Trim ();
String assemblyname = assemblyinfo [1]. Trim ();
Object OBJ = assembly. Load (assemblyname). createinstance(Typename );
Return OBJ as basecreditprocess;
}
Public static basecreditprocess create (string key, Params object [] ARGs)
{
String [] assemblyinfo = s_multiprocessor [Key]. Split (',');
String typename = assemblyinfo [0]. Trim ();
String assemblyname = assemblyinfo [1]. Trim ();
Object OBJ = assembly. Load (assemblyname). createinstance(Typename, false, bindingflags. createinstance, null, argS, null, null );
Return OBJ as basecreditprocess;
}
Public static type build (string key)
{
String [] assemblyinfo = s_multiprocessor [Key]. Split (',');
String typename = assemblyinfo [0]. Trim ();
String assemblyname = assemblyinfo [1]. Trim ();
Return assembly. Load (assemblyname). GetType (typename);
}
}
}
Main:
[Stathread]
Static void main (string [] ARGs)
{
Appdomain. currentdomain. Unhandledexception + = new unhandledexceptioneventhandler(Uepolicy );
Try
{
If (! Processcheck. checkcurrentthreAdfromconfig ())
{
// Logger. Write ("current mode is not allowed of creditforvoidso running again .");
Return;
}
Int currenttime = 0;
While (setting. runtimes <= 0 | currenttime <setting. runtimes)
{
Basecreditprocess [] processors = processorhandler. createallinstaNCE ();
Foreach (basecreditprocess processor in processors)
{
String systemname = processorhandler. getkeyfromclasSname (processor. tostring ());
Processor. Charge ();
Thread. Sleep (timespan. fromseconds (10 ));
}
// Logger. Write (string. Format ("system will sleep {0} minutes.", setting. runinterval ));
++ Currenttime;
If (setting. runtimes <= 0 | currenttime <setting. runtimes)
{
Thread. Sleep (timespan. fromminutes (setting. runinterval ));
}
}
}
Catch (exception ex)
{
Console. writeline ("exception:" + ex. Message );
}
}
App. config:
<Configsections>
<Section name = "processorsetting" type = "system. configuration. namevaluefIlesectionhandler, system, version = 1.0.5000.0, culture = neutral, publickeytoken = b77a5c561934e089"/>
</Configsections>
<Processorsetting>
<!
-- <Add key = "neg_creditsystem" value = "credit. Business. neweggcreditsysTEM, credit. Business "> </Add> -->
<Add key = "abs_creditsystem" value = "credit. Business. abscreditsystem, credit. Business"> </Add>
<Add key = "chv_creditsystem" value = "credit. Business. chiefvaluecrediTsystem, credit. Business "> </Add>
</Processorsetting>