C # converts MSMQ messages into JSON-formatted "optimizations"
Conversion functions:
private string Converttojson (string label, string body) {//todo:convert to JSON string[] La blelist = label. Split (' | '); string[] Bodylist = body. Split (' | '); String jsonstr = "{\" "; NameValueCollection NVC = (NameValueCollection) configurationmanager.getsection ("Lablename"); foreach (String key in NVC. AllKeys) {jsonstr = Jsonstr + Nvc[key] + "\": \ "" + lablelist[convert.toint32 (Key)-1] + "\", \ ""; } NameValueCollection NVD = (NameValueCollection) configurationmanager.getsection ("Bodyname"); foreach (String key in NVD. AllKeys) {jsonstr = Jsonstr + Nvd[key] + "\": \ "" + bodylist[convert.toint32 (Key)-1] + "\", \ "" ; } jsonstr = Jsonstr.remove (jsonstr.length-2, 2) + "}"; Console.WriteLine (JSONSTR); return jsonstr; }
Configuration file:
<?xml version= "1.0" encoding= "Utf-8"?><configuration> <configSections> <section name= " Lablename "type=" System.Configuration.NameValueSectionHandler "/> <!--returns the information in the configuration section as a Namevalue key/pair < Section name= "Bodyname" type= "System.Configuration.NameValueSectionHandler"/> <!-- Returns information in the configuration section as a dictionary dictionary key-value pair </configSections> <startup> <supportedruntime version= "v4.0" Sku= ". netframework,version=v4.5 "/> </startup> <LableName> <add key=" 1 "value=" MessageID "/> <add key= "2" value= "Sendingbasetag"/> <add key= "3" value= "Sendingmachinename"/> <add key= "4" va Lue= "Messagequeuepathname"/> <add key= "5" value= "CustomField1"/> <add key= "6" value= "CustomField2"/& Gt </LableName> <BodyName> <add key= "1" value= "Datamode"/> <add key= "2" value= "Datamodeid"/> <add key= "3" value= "Experimentid"/> <addkey= "4" value= "Basepentype"/> <add key= "5" value= "Basepentypeid"/> <add key= "6" value= "MID"/> < Add key= "7" value= "Stationtag"/> <add key= "8" value= "DateTime"/> <add key= "9" value= "Path1"/> < Add key= "value=" EquipmentID1 "/> <add key=" one "value=" Path2 "/> <add key=" Ten "value=" EquipmentID2 "/> ; </BodyName></configuration>
Thank you!
C # converts MSMQ messages into JSON-formatted "optimizations"