Core components of my heart (pluggable AOP) ~ Message Components ~ Perfect article

Source: Internet
Author: User

Back to Catalog

Why do you have to have this article

This article mainly realizes the RTX message producer, and completes the overall design way, before the design time message producer Global use single production mode, namely a project uses the email to use the SMS, this design method and the actual does not match, although is in the performance best (uses the singleton model, Maintenance of a producer, using a strategy model for the implementation of the producer, using the factory model to produce specific producers, the actual project should be able to automatically select the message producer, of course, for the performance of the program, we must also use a singleton model to produce specific producers, this single case, in this procedure, the use of specific types, Specific single example of the method, that is, e-mail to maintain a single case, SMS self-maintenance singleton, so that the program can meet the actual needs, but also improve their performance!

V Message Component

Sixth message Component ~ Cont.

A powerful design

A powerful producer
 // <summary>    ///message producer///the specific message producer is a singleton, such as EMAIL,SMS,RTX, etc./// </summary>     Public classMessagefactory {/// <summary>        ///Message Factory/// </summary>         Public StaticImessagemanager GetService (MessageType MessageType) {Switch(messageType) { CaseMessagetype.email:returnemailmessagemanager.instance;  Casemessagetype.sms:returnsmsmessagemanager.instance;  CaseMessagetype.rtx:returnrtxmessagemanager.instance; default:                    Throw NewNotImplementedException ("message producer not recognized ..."); }        }    }
Implementation of the RTX producer
   /// <summary>    ///RTX Messaging Service/// </summary>    Internal classRtxmessagemanager:imessagemanager {#regionSingletonPrivate Static ObjectLockobj =New Object();  Public StaticRtxmessagemanager Instance; StaticRtxmessagemanager () {Lock(lockobj) {if(Instance = =NULL) Instance=NewRtxmessagemanager (); }        }        PrivateRtxmessagemanager () {}#endregion        Private stringEncodingstring (stringstr) {            returnHttputility.urlencode (str, encoding.getencoding ("GB2312")); }        Private stringRtxurl = system.configuration.configurationmanager.appsettings["Rtxapi"] ??"http://192.168.1.8:8012/sendnotifynew.cgi?"; #regionImessagemanager Members Public voidSend (stringRecipientstringSubjectstringbody) {Send (Newlist<string>{recipient}, subject, body); }         Public voidSend (ienumerable<string> Recipients,stringSubjectstringbody) {            Try            {                varDIC =Newdictionary<string,string>()                       {    {"title", encodingstring (subject)}, {"msg", encodingstring (Body)}, {"receiver", Encodingstring (string. Join (",", recipients)}, {"Delaytime","0"}                 }; StringBuilder Str=NewStringBuilder (); foreach(varIteminchdic) {str. Append (item. Key+"="+ Item. Value +"&"); }                NewHttpClient (). Getasync (Rtxurl +Str. ToString ()).            Wait (); }            Catch(Exception ex) {Logger.Core.LoggerFactory.Instance.Logger_Info (ex).            Message); }        }         Public voidSend (ienumerable<string> Recipients,stringSubjectstringBodyBOOLIsAsync) {            if(IsAsync) Task.run (()={Send (recipients, subject, body);            }); ElseSend (recipients, subject, body); }        #endregion    }

Back to Catalog

Core components of my heart (pluggable AOP) ~ Message Components ~ Perfect article

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.