Example #1
0
        public void WaitForResponse(int timeout, TickTime.Unit unit = TickTime.Unit.ms)
        {
            TickTime start = TickTime.Now;

            while (!TickTime.Timeout(start, timeout, unit) && !Compleated)
            {
                Thread.Sleep(100);
            }
        }
Example #2
0
        /// <summary>
        /// This is synchronised TCP Recive method, received data will be only written into buffer if received bytes contains End Of Message string.
        /// </summary>
        /// <param name="iTimeout">Determines, how long in [ms] method can be executed, if iTimeout is lower then 0, method will not be terminated. </param>
        private void Receive(int timeout = -1)
        {
            DateTime DTStart    = DateTime.Now;
            TickTime TTStart    = TickTime.Now;
            bool     bTimeout   = false;
            bool     bDataFound = false;

            byte[] baData;

            string sData           = sDataBuffer;
            string sMessage        = null;
            string sMessageResidue = null;
            int    iRecivedCount;

            while (!bTimeout && !bDataFound)
            {
                if (timeout > 0 && TickTime.Timeout(TTStart, timeout, TickTime.Unit.ms))
                {
                    bTimeout = true;
                }

                baData        = new byte[1024];
                iRecivedCount = SLClient.Receive(baData);
                sData        += Encoding.ASCII.GetString(baData, 0, iRecivedCount);


                sMessage = sData.ExtractTag(TcpAsyncCommon.SOM, TcpAsyncCommon.EOM, out sMessageResidue);

                if (sMessage == null)
                {
                    continue;
                }
                else
                {
                    bDataFound = true;
                }
            }

            if (!bDataFound)
            {
                sDataBuffer = sData;
                return;
            }

            sDataBuffer = sMessageResidue;
            sData       = sMessage;

            //sData.Replace(TcpAsyncClient.SOM, "");
            //sData.Replace(TcpAsyncClient.EOM, "");
            sData.Replace(@"\\", @"\");

            DBReceive.Set(sData);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="text"></param>
        /// <param name="color"></param>
        /// <param name="maxLines"></param>
        /// <param name="deleteMultiplayer">Reduces flicker of scrollbar</param>
        /// <param name="timeout"></param>
        public void AppendTextToStart(string text, Color color, int maxLines, double deleteMultiplayer = 2, int timeout = 1000)
        {
            try
            {
                bool readonlystate = this.ReadOnly;
                this.ReadOnly = false;

                TickTime start = TickTime.Now;



                this.SelectionStart  = 0;
                this.SelectionLength = 0;// text.Length - 1;
                this.ScrollToCaret();
                this.SelectionColor = color;
                this.SelectedText   = text;

                if (this.Lines.Length >= maxLines)
                {
                    while (this.Lines.Length >= (maxLines * deleteMultiplayer) && !TickTime.Timeout(start, timeout, TickTime.Unit.ms))
                    {
                        string rtext = this.Text;
                        int    last1 = rtext.IndexOfByCount('\n', -1);
                        int    last2 = rtext.IndexOfByCount('\n', -2);

                        if (last1 < 0 || last2 < 0)
                        {
                            Asmodat.Debugging.Output.WriteLine("Not managed outcom in  RichTextBox Abbreviate class !");
                            return;
                        }

                        this.SelectionStart  = (int)last2 + 1;
                        this.SelectionLength = ((int)last1 - (int)last2) + 1;
                        this.SelectedText    = "";
                    }
                }


                this.ScrollTop();

                if (TickTime.Timeout(start, timeout, TickTime.Unit.ms))
                {
                    Asmodat.Debugging.Output.WriteLine("Rtbx timeout.");
                }

                this.ReadOnly = readonlystate;
            }
            catch (Exception ex)
            {
                Asmodat.Debugging.Output.WriteException(ex);
            }
        }
Example #4
0
        public static void AppendTextToStart(RichTextBox RTBox, string text, Color color, int maxLines, int timeout = 1000)
        {
            RTBox.Invoke((MethodInvoker)(() =>
            {
                bool readonlystate = RTBox.ReadOnly;

                try
                {
                    RTBox.ReadOnly = false;
                    RTBox.SelectionStart = 0;
                    RTBox.SelectionLength = 0;// text.Length - 1;
                    RTBox.ScrollToCaret();
                    RTBox.SelectionColor = color;
                    RTBox.SelectedText = text;

                    TickTime start = TickTime.Now;
                    while (RTBox.Lines.Length >= maxLines && !TickTime.Timeout(start, timeout, TickTime.Unit.ms))
                    {
                        string rtext = RTBox.Text;
                        int last1 = rtext.IndexOfByCount('\n', -1);
                        int last2 = rtext.IndexOfByCount('\n', -2);

                        if (last1 < 0 || last2 < 0)
                        {
                            Asmodat.Debugging.Output.WriteLine("Not managed outcom in  RichTextBox Abbreviate class !");
                            return;
                        }
                        // throw new Exception("TODO: finish");

                        RTBox.SelectionStart = (int)last2 + 1;
                        RTBox.SelectionLength = ((int)last1 - (int)last2) + 1;
                        RTBox.SelectedText = "";
                    }

                    RTBox.SelectionStart = 0;
                    RTBox.SelectionLength = 0;
                    RTBox.ScrollToCaret();

                    if (TickTime.Timeout(start, timeout, TickTime.Unit.ms))
                    {
                        Asmodat.Debugging.Output.WriteLine("Rtbx timeout.");
                    }
                }
                catch (Exception ex)
                {
                    Asmodat.Debugging.Output.WriteException(ex);
                }

                RTBox.ReadOnly = readonlystate;
            }));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitializeTrackingNumber(true);
            }

            if (SManager != null && SManager.ExchangeOrder != null)
            {
                if (!SManager.ExchangeOrder.TimeoutWarningsExecute.IsDefault && TickTime.Timeout(SManager.ExchangeOrder.TimeoutWarningsExecute, 5, TickTime.Unit.s))
                {
                    SManager.ExchangeOrder.TimeoutWarningsExecute = TickTime.Default;
                    AlertsControlExecute.HideWarning();
                }
            }
        }
Example #6
0
        public static void AppendText(RichTextBox RTBox, string text, Color color, int maxLines, bool scroll = false, int timeout = 1000)
        {
            RTBox.Invoke((MethodInvoker)(() =>
            {
                bool readonlystate = RTBox.ReadOnly;
                try
                {
                    RTBox.ReadOnly = false;
                    RTBox.SelectionStart = RTBox.TextLength;
                    RTBox.SelectionLength = 0;
                    RTBox.SelectionColor = color;
                    RTBox.AppendText(text);
                    RTBox.SelectionColor = RTBox.ForeColor;

                    int iSelectionSave = RTBox.SelectionStart;
                    TickTime start = TickTime.Now;
                    while (RTBox.Lines.Length > maxLines && !TickTime.Timeout(start, timeout, TickTime.Unit.ms))
                    {
                        RTBox.SelectionStart = 0;
                        RTBox.SelectionLength = RTBox.Text.IndexOf("\n", 0) + 1;
                        RTBox.SelectedText = "";
                    }

                    if (scroll && RTBox.Text != null)
                    {
                        RTBox.SelectionStart = RTBox.Text.Length;
                        RTBox.ScrollToCaret();
                    }

                    if (TickTime.Timeout(start, timeout, TickTime.Unit.ms))
                    {
                        Asmodat.Debugging.Output.WriteLine("Rtbx timeout.");
                    }
                }
                catch (Exception ex)
                {
                    Asmodat.Debugging.Output.WriteException(ex);
                }

                RTBox.ReadOnly = readonlystate;
            }));
        }