示例#1
0
            public static string runTest()
            {
                StringBuilder sb = new StringBuilder();

                //test deserialisation of license xml file
                sb.Append("\r\n### test deserialisation of license xml file ###\r\n");
                string     testFile   = utils.helpers.getAppPath() + "LicenseXMLFileSample.xml";
                LicenseXML licensexml = LicenseXML.Deserialize(utils.helpers.getAppPath() + "LicenseXMLFileSample.xml");

                sb.Append("\r\n### testing xml file read ###\r\n");
                foreach (license l in licensexml.licenses)
                {
                    sb.Append(l.dumpData());
                }

                //test deserialization of memory stream
                sb.Append("\r\n### testing deserialization of xml stream ###\r\n");
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                //read file into memorystream
                using (System.IO.FileStream file = new System.IO.FileStream(testFile, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    byte[] bytes = new byte[file.Length];
                    file.Read(bytes, 0, (int)file.Length);
                    ms.Write(bytes, 0, (int)file.Length);
                    ms.Flush();
                    ms.WriteTo(new System.IO.FileStream(testFile + "_cpy", System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite));
                    sb.Append("\r\nmemory stream copy saved to" + testFile + "_out" + "\r\n");
                }

                LicenseXML xmlStreamed = LicenseXML.Deserialize(ms);

                if (xmlStreamed != null)
                {
                    foreach (license l in xmlStreamed.licenses)
                    {
                        sb.Append(l.dumpData());
                    }
                    //now test serialization of license data
                    LicenseXML.serialize(xmlStreamed, testFile + "_out");
                    sb.Append("\r\ndeserilized stream object serialization test saved to" + testFile + "_out" + "\r\n");
                }
                else
                {
                    sb.Append("\r\nstream read FAILED");
                }
                return(sb.ToString());
            }
示例#2
0
        public int processAttachement(Attachement att, LicenseMailBodyData data, IMailMessage mail)
        {
            int        iCount  = 0;
            LicenseXML xmlData = LicenseXML.Deserialize(att.data);

            foreach (license ldata in xmlData.licenses)
            {
                utils.helpers.addLog("processAttachement: new LicenseData...\r\n");
                LicenseData licenseData = new LicenseData(ldata.id, ldata.user, ldata.key, data.OrderNumber, data.OrderDate, data.yourPOnumber, data.EndCustomer, data.Product, data.Quantity, mail.User, mail.timestamp);
                //if (_licenseDataBase.addQueued(licenseData))
                utils.helpers.addLog("firing license_mail event\r\n");
                OnStateChanged(new StatusEventArgs(StatusType.license_mail, licenseData));
                iCount++;
                //if (_licenseDataBase.add(ldata.id, ldata.user, ldata.key, data.OrderNumber, data.OrderDate, data.yourPOnumber, data.EndCustomer, data.Product, data.Quantity, mail.User, mail.timestamp))
                //    iCount++;
                //utils.helpers.addLog("start _licenseDataBase.add() done\r\n");
            }
            #region alternative_code

            /*
             * // Request all the attachments on the email message. This results in a GetItem operation call to EWS.
             * m.Load(new Microsoft.Exchange.WebServices.Data.PropertySet(Microsoft.Exchange.WebServices.Data.EmailMessageSchema.Attachments));
             * foreach (Microsoft.Exchange.WebServices.Data.Attachment att in m.Attachments)
             * {
             *  if (att is Microsoft.Exchange.WebServices.Data.FileAttachment)
             *  {
             *      Microsoft.Exchange.WebServices.Data.FileAttachment fileAttachment = att as Microsoft.Exchange.WebServices.Data.FileAttachment;
             *
             *      //get a temp file name
             *      string fname = System.IO.Path.GetTempFileName(); //utils.helpers.getAppPath() + fileAttachment.Id.ToString() + "_" + fileAttachment.Name
             *
             *      // Load the file attachment into memory. This gives you access to the attachment content, which
             *      // is a byte array that you can use to attach this file to another item. This results in a GetAttachment operation
             *      // call to EWS.
             *      fileAttachment.Load();
             *
             *      // Load attachment contents into a file. This results in a GetAttachment operation call to EWS.
             *      fileAttachment.Load(fname);
             *      addLog("Attachement file saved to: " + fname);
             *
             *      // Put attachment contents into a stream.
             *      using (System.IO.FileStream theStream =
             *          new System.IO.FileStream(utils.helpers.getAppPath() + fileAttachment.Id.ToString() + "_" + fileAttachment.Name, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite))
             *      {
             *          //This results in a GetAttachment operation call to EWS.
             *          fileAttachment.Load(theStream);
             *      }
             *
             *      //load into memory stream, seems the only stream supported
             *      using (System.IO.MemoryStream ms = new System.IO.MemoryStream(att.Size))
             *      {
             *          fileAttachment.Load(ms);
             *          using (System.IO.FileStream fs = new System.IO.FileStream(fname, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite))
             *          {
             *              ms.CopyTo(fs);
             *              fs.Flush();
             *          }
             *      }
             *      addLog("saved attachement: " + fname);
             *      iRet++;
             *  }
             * }
             */
            #endregion
            return(iCount);
        }