A small piece of code

Source: Internet
Author: User

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>


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.