Esempio n. 1
0
 private void btnStart_Click(object sender, EventArgs e)
 {
     btnConnect.Enabled = false;
     if (!thread.IsNull())
     {
         thread.Abort();
     }
     thread = new Thread(threadRun);
     thread.IsBackground = true;
     thread.Start();
 }
Esempio n. 2
0
 public void Abort()
 {
     if (!thread.IsNull())
     {
         thread.Abort();
     }
 }
Esempio n. 3
0
 private void btnStart_Click(object sender, EventArgs e)
 {
     btnStart.Enabled = false;
     openFileDialog1.InitialDirectory = ".\\";
     openFileDialog1.Filter           = "txt files (*.txt)|*.txt|csv files (*.csv)|*.csv|All files (*.*)|*.*";
     openFileDialog1.FilterIndex      = 1;
     openFileDialog1.RestoreDirectory = true;
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         fileName = openFileDialog1.FileName;
         if (!thread.IsNull())
         {
             thread.Abort();
         }
         thread = new Thread(inportEmailList);
         thread.IsBackground = true;
         thread.Start();
     }
 }
Esempio n. 4
0
        private void StartScanThread()
        {
            if (!thread.IsNull())
            {
                resetEvent.Set();
                return;
            }

            lock (this)
            {
                if (thread.IsNull())
                {
                    thread              = new Thread(Scan);
                    thread.Name         = "File_statistic_thread";
                    thread.IsBackground = true;
                    thread.Start();
                }
                resetEvent.Set();
            }
        }
Esempio n. 5
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            btnTest.Enabled = false;

            if (!thread.IsNull())
            {
                thread.Abort();
            }
            thread = new Thread(threadRun);
            thread.IsBackground = true;
            thread.Start();
        }
Esempio n. 6
0
 public void Abort()
 {
     if (this.IsNull())
     {
         return;
     }
     if (mThread.IsNull())
     {
         return;
     }
     mEnd = true;
     mThread.Interrupt();
     Debug.Log("Abort@thread" + mName + " Alive" + mThread.IsAlive);
     mThread = null;
 }
Esempio n. 7
0
        public string DownloadString(string url, int timeout, Regex regex, int maxlength = 0)
        {
            lock(WriteLock)
            {
                try
                {
                    var request = (HttpWebRequest)WebRequest.Create(url);
                    var th = new Thread(() =>
                    {
                        if(timeout > 0)
                            Thread.Sleep(timeout);
                        else
                            Thread.Sleep(13*1000);

                        if(!request.IsNull())
                            request.Abort();
                    });

                    if(timeout > 0)
                    {
                        request.Timeout = timeout;
                        request.ReadWriteTimeout = timeout;
                    }
                    else
                    {
                        request.Timeout = 10*1000;
                        request.ReadWriteTimeout = 10*1000;
                    }

                    request.AllowAutoRedirect = true;
                    request.UserAgent = Consts.SchumixUserAgent;
                    request.Referer = Consts.SchumixReferer;

                    int length = 0;
                    byte[] buf = new byte[1024];
                    var sb = new StringBuilder();

                    using(var response = (HttpWebResponse)request.GetResponse())
                    {
                        using(var stream = response.GetResponseStream())
                        {
                            if(maxlength == 0)
                                maxlength = 10000;

                            while((length = stream.Read(buf, 0, buf.Length)) != 0)
                            {
                                if(regex.Match(sb.ToString()).Success || sb.Length >= maxlength)
                                    break;

                                buf = Encoding.Convert(Encoding.GetEncoding(response.CharacterSet), Encoding.UTF8, buf);
                                sb.Append(Encoding.UTF8.GetString(buf, 0, length));
                            }
                        }
                    }

                    buf = null;

                    if(!th.IsNull())
                    {
                        th.Interrupt();
                        th = null;
                    }

                    return WebUtility.HtmlDecode(sb.ToString());
                }
                catch(Exception e)
                {
                    Log.Debug("Utilities", sLConsole.GetString("Failure details: {0}"), "(DownloadString) " + e.Message);
                    return string.Empty;
                }
            }
        }
Esempio n. 8
0
        private void EventStrategy()
        {
            if (checkBoxFGActivate.Checked)
            {
                if (threadStrategy.IsNull() || threadStrategy.ThreadState == ThreadState.Stopped)
                {
                    if (DataTrading.Collection.Count() == 0)
                    {
                        return;
                    }
                    if (FastGapSettings.StepTime == 0)
                    {
                        return;
                    }
                    threadStrategy = MThread.InitThread(() =>
                    {
                        var allStocks = DataTrading.Collection.ToArray();
                        foreach (var elem in allStocks)
                        {
                            if (elem.ListStrategy.Count > 0)
                            {
                                foreach (var stg in elem.ListStrategy)
                                {
                                    if (stg is Strategy.Strategy)
                                    {
                                        var strategy = (Strategy.Strategy)stg;

                                        strategy.StepTime         = FastGapSettings.StepTime;
                                        strategy.TimeFrame        = FastGapSettings.TimeFrame;
                                        strategy.IndexStartCandle = FastGapSettings.IndexStartCandle;
                                        strategy.Option_1         = FastGapSettings.Option_1;
                                        strategy.Option_2         = FastGapSettings.Option_2;
                                        strategy.Option_3         = FastGapSettings.Option_3;

                                        var now = DateTime.Now;
                                        if (strategy.TimeLastAction < now.AddSeconds(strategy.StepTime * -1))
                                        {
                                            var tf            = elem.StorageTF.GetTimeFrame(strategy.TimeFrame);
                                            strategy.Security = elem.Security;
                                            strategy.BeforeAction(() =>
                                            {
                                            });
                                            var log = strategy.ActionCollection(tf.Candles.Collection);
                                            strategy.TimeLastAction = now;
                                            if (!log.Empty())
                                            {
                                                showLog         = true;
                                                this.FastGapLog = log + this.FastGapLog;
                                            }
                                        }
                                    }
                                    Thread.Sleep(1);
                                }
                            }
                        }
                        threadStrategy = null;
                    });
                    if (showLog)
                    {
                        showLog = false;
                        Form_MessageSignal.Show(this.FastGapLog, null);
                        textBoxFGLog.Text = this.FastGapLog;
                    }
                }
            }
        }
Esempio n. 9
0
        /// <summary>Отрисовка всего графика </summary>
        /// <param name="graphic">Полотно</param>
        protected void PaintAll()
        {
            if (!Candels.IssetCollection())
            {
                return;
            }
            GetMinMax();
            //Отрисовка свечей в приоритете
            Candels.PaintCandles();

            RightPrices.Paint(RightPrices.Panel.Params.MaxPrice, RightPrices.Panel.Params.MinPrice);

            if (ActiveCandles.ActiveCandle1.NotIsNull() && ActiveCandles.ActiveCandle2.NotIsNull())
            {
                if (ActiveCandles.ActiveCandle1.dataCandle.Index > ActiveCandles.ActiveCandle2.dataCandle.Index)
                {
                    GHorVolumes.activeCandle1 = ActiveCandles.ActiveCandle1;
                    GHorVolumes.activeCandle2 = ActiveCandles.ActiveCandle2;
                }
                else
                {
                    GHorVolumes.activeCandle1 = ActiveCandles.ActiveCandle2;
                    GHorVolumes.activeCandle2 = ActiveCandles.ActiveCandle1;
                }
                if (TypeHorVolume == 3)
                {
                    GHorVolumes.activeCandle2 = null;
                }
            }

            CandleInfo LastCandle = null;

            Levels.Panel.Clear();
            var leftCandle  = Candels.AllDataPaintedCandle.Last();
            var rightCandle = Candels.AllDataPaintedCandle.First();

            //Паинт
            foreach (var dCandle in Candels.AllDataPaintedCandle.ToArray())
            {
                dCandle.PrevCandleInfo = LastCandle;
                Volumes.PaintByCandle(dCandle);
                GHorVolumes.EachCandle(dCandle);
                Levels.PaintByCandle(dCandle, leftCandle, rightCandle, Candels.AllDataPaintedCandle.Count);
                Indicators.ForEach((ind) =>
                {
                    if (ind is Indicator)
                    {
                        ((Indicator)ind).EachFullCandle(dCandle);
                    }
                });
                LastCandle = dCandle;
            }

            LevelsOrders.Paint();
            Levels.Paint();

            ActualizeActiveCandle();
            if (ThreadPaintHotVol.NotIsNull())
            {
                ThreadPaintHotVol.Abort();
                ThreadPaintHotVol = null;
            }
            if (ThreadPaintHotVol.IsNull())
            {
                ThreadPaintHotVol = MThread.InitThread(() =>
                {
                    GHorVolumes.CollectionCandles = Candels.AllDataPaintedCandle;
                    if (TypeHorVolume == 1)
                    {
                        if (ActiveCandles.ActiveCandle1.NotIsNull())
                        {
                            GHorVolumes.PaintHorVolEachBlock(ActiveCandles.ActiveCandle1.dataCandle.Index + 1);
                        }
                    }
                    else if (TypeHorVolume == 2 || TypeHorVolume == 3)
                    {
                        GHorVolumes.PaintHorVolByPeriodCandleDelta(false, false);
                    }
                    else if (TypeHorVolume == 5)
                    {
                        GHorVolumes.PaintHorVolByPeriodCandleDelta(false, true, limitHorVol);
                    }
                    else if (TypeHorVolume == 4)
                    {
                        GHorVolumes.PaintCollectionHVol();
                    }
                    ThreadPaintHotVol = null;
                });
            }
            ToCanvas();
        }