예제 #1
0
 public NTransport(Configuration configuration)
 {
     mUserConfiguration = configuration;
 }
예제 #2
0
        public void Login(String username, String password, String url, String path)
        {
            this.mLoggedIn = false;

            if(mConfiguration!=null) mConfiguration=null;

            //Authorize(username, password, type) type=XML
            Hashtable parameters = new Hashtable();
            parameters.Add("username", username);
            parameters.Add("password", password);
            parameters.Add("type", "XML");

            try
            {
                NResultAuthorize resultAuthorize = new NResultAuthorize();
                WebRequest requestAuthorize = WebRequest.Create(url + NTransport.BulildWebRequestQuery("XMLAuthorize", parameters));
                HttpWebResponse responseRequestAuthorize = (HttpWebResponse)requestAuthorize.GetResponse();
                Stream dataStream = responseRequestAuthorize.GetResponseStream();
                XmlSerializer des = new XmlSerializer(typeof(NResultAuthorize));
                resultAuthorize = (NResultAuthorize)des.Deserialize(new System.Xml.XmlTextReader(dataStream));
                dataStream.Close();

                if (resultAuthorize.Success)
                {
                    mStorage.InitializeStorage(path);
                    mConfiguration = new Configuration(path);
                    mConfiguration.Username = username;
                    mConfiguration.Password = password;
                    mConfiguration.LastMessageID = mStorage.InboxIndex.LastMessageId;
#if(DEBUG)                    
                    mConfiguration.Url = url;
#else
                     mConfiguration.Url  = resultAuthorize.WebServiceUrl;
#endif

                    mSettings = new NSettings(path);
                    InitializeViews(mStorage);
                    this.mLoggedIn = true;
                }
                else
                {
                    this.mLoggedIn = false;
                }
            }
            catch (Exception ex)
            {
#if(DEBUG)
                throw;
#endif
            }
        }
예제 #3
0
        public DeliveryWorker(Configuration configuration, NSettings settings, NStorage storage, BackgroundWorker backgroundWorker)
        {
            try
            {
                this.NewMessages = 0;
                int i = 0;
                mConfiguration = configuration;
                mSettings = settings;
                mStorage = storage;
                Boolean updateIndex = false;
                NTransport mTransport = new NTransport(this.mConfiguration);

                backgroundWorker.ReportProgress(0);

                #region RECEIVING
                //Receiving Headers
                List<NMessageHeader> messageHeaders = mTransport.ReciveHeaders();

                if (messageHeaders != null && !mCancel)
                {
                    i = 0;
                    foreach (NMessageHeader messageHeader in messageHeaders)
                    {


                        if (!mStorage.InboxIndex.ExistsID(messageHeader.MsgID) && !mStorage.ArchiveIndex.ExistsID(messageHeader.MsgID)) 
                       {   //skip already downloaded
                            NMessage message = mTransport.ReciveMessage(messageHeader);
                            if(message!=null)  mStorage.SaveInbox(message);
                            updateIndex = true;
                            NewMessages++;
                       }
                        backgroundWorker.ReportProgress(100 * i / (messageHeaders.Count));
                      i++;
                      
                    }
                    
                }

                if (updateIndex)
                {
                    mStorage.UpdateIndex(NStorageFolder.Inbox);
                }
              
                #endregion

                #region SENDING
                //Sending
                updateIndex = false;
                string[] mFileList = Directory.GetFiles(mStorage.OutboxPath, "*.xml");
                i = 1;
                if (mFileList.Length > 0)
                {
                    backgroundWorker.ReportProgress(100 * i / (mFileList.Length + 1));
                    foreach (String file in mFileList)
                    {
                        if (mCancel) break;
                        NMessage message = new NMessage();
                        using (StreamReader sr = new StreamReader(file))
                        {
                            if (File.Exists(file))
                            {
                                XmlSerializer des = new XmlSerializer(typeof(NMessage));
                                message = (NMessage)des.Deserialize(new System.Xml.XmlTextReader(sr));
                                sr.Close();
                            }
                        }

                        if (message != null)
                        {
                            NResultSend resultSend = mTransport.SendMessage(message);
                            if (resultSend.Success)
                            {
                                if (File.Exists(storage.SentPath + file)) File.Delete(storage.SentPath + file);
                                File.Move(file, storage.SentPath + Path.GetFileName(file));
                                updateIndex = true;
                            };
                        }
                        i++;
                        backgroundWorker.ReportProgress(100 * i / (mFileList.Length + 1));
                    }
                    if (updateIndex)
                    {
                        mStorage.UpdateIndex(NStorageFolder.Outbox);
                        mStorage.UpdateIndex(NStorageFolder.Sent);
                    }
                }
                #endregion

            }
            catch (Exception)
            {

#if (DEBUG)
                throw;
#endif
            }
            backgroundWorker.ReportProgress(100);
        }