Ejemplo n.º 1
0
        void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            var list  = client.GetContext(new Catalog.Codes(), 6).Result as List <Catalog.Codes>;
            var stack = new Stack <IStrategics>();
            var array = new IStrategics[]
            {
                new Catalog.TrendsInStockPrices()
            };

            foreach (var strategics in array.OrderBy(o => random.Next(array.Length)))
            {
                foreach (var enumerable in client.GetContext(strategics).Result)
                {
                    stack.Push(enumerable);
                }
            }

            var maximum = list.Count * stack.Count;
            var rate    = 0;
            var po      = new ParallelOptions
            {
                CancellationToken      = Cancel.Token,
                MaxDegreeOfParallelism = (int)(Environment.ProcessorCount * 0.25)
            };

            while (stack.Count > 0)
            {
                try
                {
                    var strategics = stack.Pop();
                    Parallel.ForEach(list.OrderBy(o => Guid.NewGuid()), po, new Action <Catalog.Codes>((w) =>
                    {
                        if (backgroundWorker.CancellationPending)
                        {
                            e.Cancel = true;

                            if (Cancel.IsCancellationRequested)
                            {
                                po.CancellationToken.ThrowIfCancellationRequested();
                            }
                        }
                        else if (IsTheCorrectInformation(w))
                        {
                            var now          = DateTime.Now;
                            HoldingStocks hs = null;

                            switch (strategics)
                            {
                            case Catalog.TrendsInStockPrices ts:
                                if (client.PostContext(new ConfirmStrategics
                                {
                                    Code = w.Code,
                                    Date = now.Hour > 0xF ? now.ToString(format) : now.AddDays(-1).ToString(format),
                                    Strategics = string.Concat("TS.", ts.Short, '.', ts.Long, '.', ts.Trend, '.', (int)(ts.RealizeProfit * 0x2710), '.', (int)(ts.AdditionalPurchase * 0x2710), '.', ts.QuoteUnit, '.', (char)ts.LongShort, '.', (char)ts.TrendType, '.', (char)ts.Setting)
                                }).Result == false)
                                {
                                    ts.Code = w.Code;
                                    hs      = new HoldingStocks(ts)
                                    {
                                        Code = ts.Code
                                    };
                                    hs.SendBalance += OnReceiveAnalysisData;
                                    hs.StartProgress(0D);
                                }
                                break;
                            }
                            if (hs != null)
                            {
                                hs.SendBalance -= OnReceiveAnalysisData;
                            }
                        }
                        Statistical.SetProgressRate(Color.Gold);
                        backgroundWorker.ReportProgress((int)(rate++ *0x64 / (double)maximum));
                    }));
                }
                catch (OperationCanceledException ex)
                {
                    Statistical.SetProgressRate(Color.Ivory);
                    Console.WriteLine("Count_" + rate + "\t" + ex.TargetSite.Name);
                }
            }
Ejemplo n.º 2
0
        void OnReceiveTheChangedSize(object sender, SendHoldingStocks e)
        {
            if (sender is Controls.Strategics)
            {
                if (e.Strategics != null)
                {
                    Form          form = null;
                    HoldingStocks hs   = null;

                    switch (e.Strategics)
                    {
                    case Catalog.TrendsInStockPrices ts when string.IsNullOrEmpty(e.Code) == false && uint.TryParse(e.Code, out uint price):
                        hs = new HoldingStocks(ts)
                        {
                            Code = ts.Code
                        };
                        hs.SendBalance += OnReceiveAnalysisData;
                        hs.StartProgress(price);
                        return;

                    case Catalog.Privacies privacies:
                        new SatisfyConditionsAccordingToTrends(privacies, client).PerformClick().ShowDialog();
                        return;

                    case Size size:
                        var height = 0x2DC;

                        switch (size.Height)
                        {
                        case 0xCD:
                            height -= 0x1E;
                            break;

                        case 0x145:
                            height += 0x59;
                            break;

                        case 0x145 - 0x23:
                            height += 0x60;
                            break;
                        }
                        Size = new Size(0x2B9, height);
                        return;

                    case Tuple <int, Catalog.Privacies> tuple when tuple.Item2 is Catalog.Privacies privacy &&
                        (string.IsNullOrEmpty(privacy.Account) || string.IsNullOrEmpty(privacy.SecuritiesAPI) || string.IsNullOrEmpty(privacy.SecurityAPI)) == false:
                        if (tuple.Item1 == 0)
                        {
                            backgroundWorker.RunWorkerAsync();
                        }

                        else if (tuple.Item1 > 0)
                        {
                            backgroundWorker.CancelAsync();
                        }

                        return;

                    case Tuple <Tuple <List <Catalog.ConvertConsensus>, List <Catalog.ConvertConsensus> >, Catalog.ScenarioAccordingToTrend> consensus:
                        hs = new HoldingStocks(consensus.Item2, consensus.Item1, client)
                        {
                            Code = consensus.Item2.Code
                        };
                        form            = new ScenarioAccordingToTrend(hs);
                        hs.SendBalance += OnReceiveAnalysisData;
                        new Task(() => hs.StartProgress(Privacy.Commission)).Start();
                        break;

                    case Catalog.TrendFollowingBasicFutures tf:
                        hs = new HoldingStocks(tf)
                        {
                            Code = tf.Code
                        };
                        form            = new TrendFollowingBasicFutures(hs);
                        hs.SendBalance += OnReceiveAnalysisData;
                        new Task(() => hs.StartProgress(Privacy.Commission)).Start();
                        break;

                    case Catalog.TrendToCashflow tc:
                        hs = new HoldingStocks(tc, client)
                        {
                            Code = tc.Code
                        };
                        form            = new TrendsInStockPrices(hs);
                        hs.SendBalance += OnReceiveAnalysisData;
                        new Task(() => hs.StartProgress(Privacy.Commission)).Start();
                        break;

                    case Catalog.TrendsInValuation tv:
                        hs = new HoldingStocks(tv, client)
                        {
                            Code = tv.Code
                        };
                        form            = new TrendsInStockPrices(hs);
                        hs.SendBalance += OnReceiveAnalysisData;
                        new Task(() => hs.StartProgress(Privacy.Commission)).Start();
                        break;

                    case Catalog.TrendsInStockPrices ts:
                        hs = new HoldingStocks(ts)
                        {
                            Code = ts.Code
                        };
                        form            = new TrendsInStockPrices(hs);
                        hs.SendBalance += OnReceiveAnalysisData;
                        new Task(() => hs.StartProgress(Privacy.Commission)).Start();
                        break;
                    }
                    Cursor      = Cursors.AppStarting;
                    WindowState = FormWindowState.Minimized;

                    if (form.ShowDialog().Equals(DialogResult.Cancel))
                    {
                        hs.SendBalance -= OnReceiveAnalysisData;
                        Cursor          = Cursors.Default;
                        IAsyncResult result = null;

                        switch (e.Strategics)
                        {
                        case Catalog.TrendToCashflow tc:
                            result = Statistical.SetProgressRate(new Catalog.Request.Consensus {
                                Strategics = string.Concat("TC.", tc.AnalysisType)
                            });
                            break;

                        case Catalog.TrendsInValuation tv:
                            result = Statistical.SetProgressRate(new Catalog.Request.Consensus {
                                Strategics = string.Concat("TC.", tv.AnalysisType)
                            });
                            break;

                        case Catalog.TrendFollowingBasicFutures tf:
                            result = Statistical.SetProgressRate(DateTime.Now);
                            break;
                        }
                        if (result != null && result.AsyncWaitHandle.WaitOne(0xED3))
                        {
                            result.AsyncWaitHandle.Close();
                            result.AsyncWaitHandle.Dispose();
                            GC.Collect();
                        }
                        strip.Items.Find(st, false).First(o => o.Name.Equals(st)).PerformClick();
                    }
                }
                else if (string.IsNullOrEmpty(e.Code) == false && e.Color != null)
                {
                    Statistical.SetDataGridView(e.Code, e.Color);
                }
            }
        }
Ejemplo n.º 3
0
        void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            var list  = client.GetContext(new Catalog.Codes(), 6).Result as List <Catalog.Codes>;
            var stack = new Stack <IStrategics>();

            foreach (var strategics in new IStrategics[]
            {
                new Catalog.TrendsInStockPrices(),
                new Catalog.ScenarioAccordingToTrend(),
                new Catalog.TrendToCashflow()
            })
            {
                foreach (var enumerable in client.GetContext(strategics).Result)
                {
                    stack.Push(enumerable);
                }
            }

            ulong maximum = (ulong)(list.Count * stack.Count), rate = 0;

            while (stack.Count > 0)
            {
                try
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Cancel = true;
                        SendMessage(string.Concat(rate, '/', maximum));

                        break;
                    }
                    else
                    {
                        var strategics = stack.Pop();

                        foreach (var w in list.OrderBy(o => Guid.NewGuid()))
                        {
                            if (backgroundWorker.CancellationPending)
                            {
                                e.Cancel = true;
                                SendMessage((rate / (double)maximum).ToString("P5"));

                                break;
                            }
                            else if (IsTheCorrectInformation(w))
                            {
                                var           now = DateTime.Now;
                                HoldingStocks hs  = null;

                                switch (strategics)
                                {
                                case Catalog.ScenarioAccordingToTrend st:
                                    var consensus = client.GetContext(new Catalog.ConvertConsensus {
                                        Code = w.Code
                                    }).Result;

                                    if (consensus != null && consensus.Any(o => o.Date.EndsWith("(E)") && o.Date.StartsWith(now.AddYears(2).ToString("yy"))) &&
                                        client.PostContext(new ConfirmStrategics
                                    {
                                        Code = w.Code,
                                        Date = now.Hour > 0xF ? now.ToString(format) : now.AddDays(-1).ToString(format),
                                        Strategics = string.Concat("ST.", st.Calendar, '.', st.Trend, '.', st.CheckSales.ToString().Substring(0, 1), '.', (uint)(st.Sales * 0x64), '.', st.CheckOperatingProfit.ToString().Substring(0, 1), '.', (uint)(st.OperatingProfit * 0x64), '.', st.CheckNetIncome.ToString().Substring(0, 1), '.', (uint)(st.NetIncome * 0x64))
                                    }).Result == false)
                                    {
                                        st.Code = w.Code;
                                        hs      = new HoldingStocks(st, new Catalog.ConvertConsensus().PresumeToConsensus(consensus), client)
                                        {
                                            Code = st.Code
                                        };
                                        hs.SendBalance += OnReceiveAnalysisData;
                                        hs.StartProgress(0D);
                                    }
                                    break;

                                case Catalog.TrendToCashflow tc:
                                    if (client.PostContext(new ConfirmStrategics
                                    {
                                        Code = w.Code,
                                        Date = now.Hour > 0xF ? now.ToString(format) : now.AddDays(-1).ToString(format),
                                        Strategics = string.Concat("TC.", tc.AnalysisType)
                                    }).Result == false)
                                    {
                                        tc.Code = w.Code;
                                        hs      = new HoldingStocks(tc, client)
                                        {
                                            Code = tc.Code
                                        };
                                        hs.SendBalance += OnReceiveAnalysisData;
                                        hs.StartProgress(0D);
                                    }
                                    break;

                                case Catalog.TrendsInStockPrices ts:
                                    if (client.PostContext(new ConfirmStrategics
                                    {
                                        Code = w.Code,
                                        Date = now.Hour > 0xF ? now.ToString(format) : now.AddDays(-1).ToString(format),
                                        Strategics = string.Concat("TS.", ts.Short, '.', ts.Long, '.', ts.Trend, '.', (int)(ts.RealizeProfit * 0x2710), '.', (int)(ts.AdditionalPurchase * 0x2710), '.', ts.QuoteUnit, '.', (char)ts.LongShort, '.', (char)ts.TrendType, '.', (char)ts.Setting)
                                    }).Result == false)
                                    {
                                        ts.Code = w.Code;
                                        hs      = new HoldingStocks(ts)
                                        {
                                            Code = ts.Code
                                        };
                                        hs.SendBalance += OnReceiveAnalysisData;
                                        hs.StartProgress(0D);
                                    }
                                    break;
                                }
                                if (hs != null)
                                {
                                    hs.SendBalance -= OnReceiveAnalysisData;
                                }
                            }
                            Statistical.SetProgressRate(Color.Gold);
                            backgroundWorker.ReportProgress((int)(rate++ *1e+2 / maximum));
                        }
                    }
                }
                catch (Exception ex)
                {
                    e.Cancel = true;
                    SendMessage(ex.StackTrace);

                    break;
                }
            }
            e.Result = rate == maximum || rate - 1 == maximum;
        }
Ejemplo n.º 4
0
        void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            var list  = client.GetContext(new Catalog.Codes(), 6).Result as List <Catalog.Codes>;
            var stack = new Stack <IStrategics>();

            foreach (var strategics in new IStrategics[]
            {
                new Catalog.TrendsInStockPrices(),
                new Catalog.ScenarioAccordingToTrend(),
                new Catalog.TrendToCashflow()
            })
            {
                foreach (var enumerable in client.GetContext(strategics).Result)
                {
                    stack.Push(enumerable);
                }
            }

            ulong maximum = (ulong)(list.Count * stack.Count), rate = 0;
            var   po = new ParallelOptions
            {
                CancellationToken      = Cancel.Token,
                MaxDegreeOfParallelism = (int)(Environment.ProcessorCount * 0.25)
            };

            while (stack.Count > 0)
            {
                try
                {
                    var strategics = stack.Pop();
                    Parallel.ForEach(list.OrderBy(o => Guid.NewGuid()), po, new Action <Catalog.Codes>((w) =>
                    {
                        if (backgroundWorker.CancellationPending)
                        {
                            e.Cancel = true;

                            if (Cancel.IsCancellationRequested)
                            {
                                po.CancellationToken.ThrowIfCancellationRequested();
                            }
                        }
                        else if (IsTheCorrectInformation(w))
                        {
                            var now          = DateTime.Now;
                            HoldingStocks hs = null;

                            switch (strategics)
                            {
                            case Catalog.ScenarioAccordingToTrend st:
                                var consensus = client.GetContext(new Catalog.ConvertConsensus {
                                    Code = w.Code
                                }).Result;

                                if (consensus != null && consensus.Any(o => o.Date.EndsWith("(E)") && o.Date.StartsWith(now.AddYears(2).ToString("yy"))) && client.PostContext(new ConfirmStrategics
                                {
                                    Code = w.Code,
                                    Date = now.Hour > 0xF ? now.ToString(format) : now.AddDays(-1).ToString(format),
                                    Strategics = string.Concat("ST.", st.Calendar, '.', st.Trend, '.', st.CheckSales.ToString().Substring(0, 1), '.', (uint)(st.Sales * 0x64), '.', st.CheckOperatingProfit.ToString().Substring(0, 1), '.', (uint)(st.OperatingProfit * 0x64), '.', st.CheckNetIncome.ToString().Substring(0, 1), '.', (uint)(st.NetIncome * 0x64))
                                }).Result == false)
                                {
                                    st.Code = w.Code;
                                    hs      = new HoldingStocks(st, new Catalog.ConvertConsensus().PresumeToConsensus(consensus), client)
                                    {
                                        Code = st.Code
                                    };
                                    hs.SendBalance += OnReceiveAnalysisData;
                                    hs.StartProgress(0D);
                                }
                                break;

                            case Catalog.TrendToCashflow tc:
                                if (client.PostContext(new ConfirmStrategics
                                {
                                    Code = w.Code,
                                    Date = now.Hour > 0xF ? now.ToString(format) : now.AddDays(-1).ToString(format),
                                    Strategics = string.Concat("TC.", tc.AnalysisType)
                                }).Result == false)
                                {
                                    tc.Code = w.Code;
                                    hs      = new HoldingStocks(tc, client)
                                    {
                                        Code = tc.Code
                                    };
                                    hs.SendBalance += OnReceiveAnalysisData;
                                    hs.StartProgress(0D);
                                }
                                break;

                            case Catalog.TrendsInStockPrices ts:
                                if (client.PostContext(new ConfirmStrategics
                                {
                                    Code = w.Code,
                                    Date = now.Hour > 0xF ? now.ToString(format) : now.AddDays(-1).ToString(format),
                                    Strategics = string.Concat("TS.", ts.Short, '.', ts.Long, '.', ts.Trend, '.', (int)(ts.RealizeProfit * 0x2710), '.', (int)(ts.AdditionalPurchase * 0x2710), '.', ts.QuoteUnit, '.', (char)ts.LongShort, '.', (char)ts.TrendType, '.', (char)ts.Setting)
                                }).Result == false)
                                {
                                    ts.Code = w.Code;
                                    hs      = new HoldingStocks(ts)
                                    {
                                        Code = ts.Code
                                    };
                                    hs.SendBalance += OnReceiveAnalysisData;
                                    hs.StartProgress(0D);
                                }
                                break;
                            }
                            if (hs != null)
                            {
                                hs.SendBalance -= OnReceiveAnalysisData;
                            }
                        }
                        Statistical.SetProgressRate(Color.Gold);
                        backgroundWorker.ReportProgress((int)(rate++ *1e+2 / maximum));
                    }));
                }
                catch (OperationCanceledException ex)
                {
                    Statistical.SetProgressRate(Color.Ivory);
                    Cancel.Dispose();
                    Console.WriteLine("Count_" + rate + "\t" + ex.TargetSite.Name);
                }
            }