コード例 #1
0
        void PostReq()
        {
            Dbg.Log("Sending connection request.");

            string tmpFile = Path.GetTempFileName();

            m_exHandler = ReqExceptionHandler;

            using (new AutoReleaser(() => File.Delete(tmpFile)))
            {
                var netEngin = new NetEngin(Program.NetworkSettings);

                SetProgressMessage("Envoi des données au serveur...");

                netEngin.Download(tmpFile, Urls.ConnectionReqURL, true);
                List <HubCore.DLG.Message> msgs = DialogEngin.ReadConnectionsReq(tmpFile).ToList();
                m_msgID = msgs.Count == 0 ? 1 : msgs.Max(m => m.ID) + 1;

                var    ms      = new MemoryStream();
                byte[] ciBytes = m_clInfo.GetBytes();
                byte[] ceBytes = GetEnvironment().GetBytes();
                ms.Write(ciBytes, 0, ciBytes.Length);
                ms.Write(ceBytes, 0, ceBytes.Length);

                var msg = new HubCore.DLG.Message(m_msgID, 0, Message_t.NewConnection, ms.ToArray());
                msgs.Add(msg);

                DialogEngin.WriteConnectionsReq(tmpFile, msgs);
                netEngin.Upload(Urls.ConnectionReqURL, tmpFile, true);
                StartTimer();

                SetProgressMessage("Attente de la réponse du serveur...");
            }
        }
コード例 #2
0
        //private:
        void PostReqAsync()
        {
            Action upload = () =>
            {
                var msg = new Message(++m_lastMsgID, 0, Message_t.Resume, BitConverter.GetBytes(m_clientID));
                IEnumerable <Message> msgs = DialogEngin.ReadConnectionsReq(m_cxnReqFile);
                DialogEngin.WriteConnectionsReq(m_cxnReqFile, msgs.Add(msg));

                var netEngin = new NetEngin(Program.NetworkSettings);

                try
                {
                    netEngin.Upload(Urls.ConnectionReqURL, m_cxnReqFile, true);
                    m_timer.Change(TIMER_INTERVALL, TIMER_INTERVALL);
                }
                catch (Exception ex)
                {
                    Dbg.Log(ex.Message);
                    m_callback(Result_t.Error);
                    m_callback = null;
                }
            };

            new Task(upload, TaskCreationOptions.LongRunning).Start();
        }
コード例 #3
0
        public void Start()
        {
            m_cxnReqFile = Path.GetTempFileName();

            //maj du ID req
            Action init = () =>
            {
                var netEngin = new NetEngin(Program.NetworkSettings);
                netEngin.Download(m_cxnReqFile, Urls.ConnectionReqURL, true);

                IEnumerable <Message> msgs = DialogEngin.ReadConnectionsReq(m_cxnReqFile);

                if (msgs.Count() > 0)
                {
                    m_lastMsgID = msgs.Max(msg => msg.ID);
                }
            };

            Action <Task> onErr = t =>
            {
                File.Delete(m_cxnReqFile);

                Dbg.Log(t.Exception.InnerException.Message);
                m_callback(Result_t.Error);
                m_callback = null;
            };


            var task = new Task(init, TaskCreationOptions.LongRunning);

            task.OnSuccess(PostReqAsync);
            task.OnError(onErr);
            task.Start();
        }
コード例 #4
0
        void PostSyncMessage()
        {
            Action post = () =>
            {
                var    netEngin = new NetEngin(Program.NetworkSettings);
                string tmpFile  = Path.GetTempFileName();
                var    ms       = new MemoryStream();
                var    writer   = new RawDataWriter(ms, Encoding.UTF8);
                writer.Write(m_clInfo.ClientID);
                writer.Write(m_srvLastMsgID);
                writer.Write(m_clientLastMsgID);
                byte[] msgData = ms.ToArray();

                try
                {
                    netEngin.Download(tmpFile, Urls.ConnectionReqURL);
                    var  seq   = DialogEngin.ReadConnectionsReq(tmpFile);
                    uint msgID = 0;

                    if (seq.Any())
                    {
                        msgID = seq.Max(m => m.ID);
                    }

                    var msg = new Message(msgID + 1, 0, Message_t.Sync, msgData);
                    DialogEngin.AppendConnectionsReq(tmpFile, new Message[] { msg });
                    netEngin.Upload(Urls.ConnectionReqURL, tmpFile);
                }
                catch (Exception ex)
                {
                    Dbg.Log("PostSyncMessage: " + ex.Message);
                }
                finally
                {
                    File.Delete(tmpFile);
                }
            };


            var task = new Task(post, TaskCreationOptions.LongRunning);

            task.Start();
        }
コード例 #5
0
        void PostReq()
        {
            Dbg.Log("Posting start msg...");

            //posting to cnx file
            string tmpFile  = Path.GetTempFileName();
            var    netEngin = new NetEngin(Program.NetworkSettings);

            try
            {
                netEngin.Download(tmpFile, Urls.ConnectionReqURL, true);

                IEnumerable <Message> msgsCnx = DialogEngin.ReadConnectionsReq(tmpFile);

                if (msgsCnx.Any())
                {
                    m_reqID = msgsCnx.Max(m => m.ID);
                }
                else
                {
                    m_reqID = 0;
                }

                Message req = new Message(++m_reqID, 0, Message_t.Start, m_msgData);
                DialogEngin.WriteConnectionsReq(tmpFile, msgsCnx.Add(req));
                netEngin.Upload(Urls.ConnectionReqURL, tmpFile, true);
                m_cnxAttempts = 0;
                Dbg.Log("Posting start msg done.");
            }
            catch (Exception ex)
            {
                Dbg.Log(ex.Message);
            }
            finally
            {
                m_timer.Start();
                File.Delete(tmpFile);
            }
        }
コード例 #6
0
        void ProcessDownloads()
        {
            List <string> files = null;

            lock (m_pendingDownloads)
                if (m_pendingDownloads.Count > 0)
                {
                    files = m_pendingDownloads.ToList();
                    m_pendingDownloads.Clear();
                }

            if (files != null)
            {
                string localDlgFolder = AppPaths.DialogFolderPath;
                string cxnReqFile     = Names.ConnectionReqFile;
                var    netEngin       = new NetEngin(AppContext.Settings.NetworkSettings);

                for (int i = files.Count - 1; i >= 0; --i)
                {
                    string fileName = files[i];
                    string destPath = Path.Combine(localDlgFolder, fileName);
                    string srcURL   = Urls.DialogDirURL + fileName;


                    try
                    {
                        netEngin.Download(destPath, srcURL);
                    }
                    catch (Exception ex)
                    {
                        AppContext.LogManager.LogSysError("Traitement des transferts à partir du serveur: " +
                                                          ex.Message, true);
                        continue;
                    }

                    if (string.Compare(fileName, cxnReqFile, true) == 0)
                    {
                        try
                        {
                            ProcessConnectionReq(DialogEngin.ReadConnectionsReq(AppPaths.ConnectionReqPath));
                        }
                        catch (Exception ex)
                        {
                            TextLogger.Warning(ex.Message);
                        }
                    }
                    else
                    {
                        uint clID = uint.Parse(Path.GetFileNameWithoutExtension(fileName),
                                               System.Globalization.NumberStyles.AllowHexSpecifier);

                        try
                        {
                            ProcessDialog(clID, DialogEngin.ReadHubDialog(Path.Combine(localDlgFolder, fileName), clID));
                        }
                        catch (Exception ex)
                        {
                            AppContext.LogManager.LogSysError("Traitement des transferts à partir du serveur: " +
                                                              ex.Message, true);
                            continue;
                        }
                    }

                    files.RemoveAt(i);
                }


                foreach (string file in files)
                {
                    AddDownload(file);
                }
            }

            //allways need to be downlaoded
            AddDownload(Names.ConnectionReqFile);
        }