Ejemplo n.º 1
0
        private void ProcessBlockingQueue(string threadName, ref CBlockingQueue <Action> blockingQueue, int countLimit, bool bOutAlarm, int secRepeatAlarm = 20)
        {
            DateTime lastAlarm = new DateTime(0);

            while (true)
            {
                Action act = blockingQueue.GetElementBlocking();



                if (blockingQueue.Count > countLimit)
                {
                    if ((DateTime.Now - lastAlarm).TotalSeconds > secRepeatAlarm && bOutAlarm)
                    {
                        //2018-04-15 removed to make cleaner alarm list/file
                        //Error(threadName+ "quee more than max skip messages. Count="+blockingQueue.Count);
                        lastAlarm = DateTime.Now;
                    }
                }
                else
                if (GUIDispatcher != null)
                {
                    GUIDispatcher.BeginInvoke(act);
                }
            }
        }
Ejemplo n.º 2
0
        private async void Hyperlink_OnClick(object sender, RoutedEventArgs e)
        {
            MouseEventArgs   m          = e as MouseEventArgs;
            GUIDispatcher    dispatcher = new GUIDispatcher();
            FrameworkElement source     = sender as FrameworkElement;

            switch (source.Name)
            {
            case "grFriends":
            { NavigationService.Navigate(dispatcher.LoadPage("FriendsPage")); break; }

            case "grMessages":
            {
                NavigationService.Navigate(dispatcher.LoadPage("MessagePage")); break;
            }

            case "grAudio":
            {
                NavigationService.Navigate(dispatcher.LoadPage("AudioPage")); break;
            }

            case "grLogin":
            {
                NavigationService.Navigate(dispatcher.LoadPage("LoginPage")); break;
            }

            default:
            {
                break;
            }
            }
        }
Ejemplo n.º 3
0
        protected override void OnGUIBoxPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            CGUIBox GUIBox = (CGUIBox)sender;


            if (e.PropertyName == "IsFORTSOnline")
            {
                FORTSBGColor = GenColorOKOrAlarm(GUIBox.IsFORTSOnline);
            }
            else if (e.PropertyName == "IsSessionActive")
            {
                string status = "";
                if (GUIBox.IsSessionActive == true)
                {
                    status = "Актив";
                }
                else
                {
                    status = "Неактив";
                }
                //TO DO normal
                GUIDispatcher.BeginInvoke(new Action(() => m_mainWindow.SessionTable.SessionStatusText.TextValue = status));
            }
            //   GUIDispatcher.Invoke(new Action(() => m_mainWindow.SessionTable.SessionStatusText.TextBlockLabel.Text = "Act"));
        }
Ejemplo n.º 4
0
 public void FatalError(string message)
 {
     GUIDispatcher.Invoke(new Action(() =>
     {
         AllertWindow win = new AllertWindow(message);
         win.ShowWindowOnCenter();
         //
     }
                                     ));
 }
Ejemplo n.º 5
0
        public void OnClose()
        {
            IsRunning = false;
            GUIDispatcher.BeginInvokeShutdown(System.Windows.Threading.DispatcherPriority.Normal);
            //GUIDispatcher.InvokeShutdown();
            //while (!GUIDispatcher.HasShutdownFinished)
            //Thread.Sleep(100);

            Thread.Sleep(1000);            //wait till all finishable threads ends
            Application.Current.Shutdown();
            Thread.Sleep(1000);
            Process.GetCurrentProcess().Kill();
        }
Ejemplo n.º 6
0
        //This thread not removes
        //deals from queue
        public void ThreadWindowsUpdate()
        {
            while (true)
            {
                Action value = m_bqActions.GetElementBlocking();

                while (GUIDispatcher == null)
                {
                    System.Threading.Thread.Sleep(100);
                }

                GUIDispatcher.BeginInvoke(value, DispatcherPriority.Normal, null);
            }
        }
Ejemplo n.º 7
0
        private void TaskBindAlarm()
        {
            while (IsRunning)
            {
                if (_alarmer != null && _alarmer.AlarmList != null)
                {
                    GUIDispatcher.Invoke(new Action(() => BindAlarm()));
                    return;
                }


                Thread.Sleep(100);
            }
        }
Ejemplo n.º 8
0
        private void TaskConnectToDatabase()
        {
            try
            {
                //TODO if not connected ????????????
                _dataSource.ConnectToDatabase();

                GUIDispatcher.Invoke(new Action(() =>
                                                _mainWindow.BindDBDataSource()));
            }
            catch (Exception e)
            {
                Error("App.TaskConnectToDatabase", e);
            }
        }
Ejemplo n.º 9
0
        private void TaskCreateInstrumentsTable()
        {
            //changed 2017-05-02



            while (DealingServer == null || DealingServer.GlobalConfig == null || DealingServer.Instruments == null ||
                   !DealingServer.IsGlobalConfigAvail)
            {
                Thread.Sleep(100);
            }


            DealingServer.Instruments.WaitInstrumentsLoaded();

            try
            {
                int ii = 1;


                /*foreach (var r in Plaza2Connector.GlobalConfig.ListIsins)
                 *  GUIDispatcher.Invoke(new Action ( ()=>
                 *                      CreateOneIstrumentsRecord(r, ii++, firstCol))
                 *                      );*/



                foreach (var dbInstrument in DealingServer.Instruments)
                {
                    if (dbInstrument.Is_GUI_monitoring == 1)
                    {
                        GUIDispatcher.Invoke(new Action(() =>
                                                        CreateOneIstrumentsLine(dbInstrument.instrument, dbInstrument.RoundTo, ii++, firstCol)));
                    }
                }
            }
            catch (Exception e)
            {
                DealingServer.Error("TaskCreateInstrumentsTable", e);
            }


            //  CreateOneIstrumentsRecord("RTS-12.15", 1, firstCol);
            //  CreateOneIstrumentsRecord("Si-12.15", 2, firstCol);
            //  CreateOneIstrumentsRecord("SBRF-12.15", 3, firstCol);

            IsButtonsLoaded = true;
        }
Ejemplo n.º 10
0
        private void TaskConnectToDealingServers()
        {
            try
            {
                GUIDispatcher.Invoke(new Action(() =>
                                                _mainWindow.BindTCPDataSource()));

                _dataSource.ConnectToDealingServers();
            }

            catch (Exception e)

            {
                Error("App.TaskConnectToDealingServers", e);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Wait till it it possible to bind (using specifig delegate) than call BindTextPath
        /// Call from CreateControlTextBlock
        /// </summary>
        /// <param name="textBlock"></param>
        /// <param name="path"></param>
        /// <param name="delToWait">Delegate for wait till it will be possible to binf</param>
        /// <param name="delToWaitPar">Parameter for delToWait</param>
        /// <param name="delBindSourse">Delegate retrieves Bind data source</param>
        /// <param name="delBindSourcePar">Parameter for delBindSourse</param>
        /// <param name="format">String format for output</param>
        private void TaskBindControlTextBlock(TextBlock textBlock, string path, DelegateWait delToWait, object delPar, DeleagateBindingSource delBindSource, object delBindSourcePar, string format)
        {
            try
            {
                while (delToWait(delPar))
                {
                    System.Threading.Thread.Sleep(1000);
                }



                GUIDispatcher.Invoke(new Action(() => BindTextPath(textBlock, path, delBindSource, delBindSourcePar, format)));
            }
            catch (Exception e)
            {// TODO throw exception !
                string st = "";
                if (e != null)
                {
                    Thread.Sleep(0);
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Call from:
        ///
        /// ThreadDataReciever
        /// </summary>
        private void ProcessStocks()
        {
            var dictStockClass = _dataReciever.OutpStockClass[_tickerName];


            if (dictStockClass.LstStockConf == null)
            {
                return; //get out
            }
            lock (_lstStockConf)
            {
                _lstStockConf.Clear();
                dictStockClass.LstStockConf.ForEach(el => _lstStockConf.Add(el));
            }


            var stockConf = dictStockClass.LstStockConf.Find(el => el.MinStep == (decimal)Step);

            if (stockConf == null)
            {
                return; //get out
            }
            int prec = stockConf.PrecissionNum;


            //process stocks
            if (dictStockClass.StockListAsks != null && dictStockClass.StockListBids != null)
            {
                lock (_dataReciever.OutpStockClass)
                {
                    lock (dictStockClass.Locker)
                    {
                        try
                        {
                            bool bStockChanged = false;

                            if (dictStockClass.StockListAsks.ContainsKey(prec))
                            {
                                List <CStock> asks = dictStockClass.StockListAsks[prec];

                                if (asks != null)
                                {
                                    for (int i = 0; i < Asks.Length; i++)
                                    {
                                        if (i >= asks.Count)
                                        {
                                            Asks[i].Price  = 0;
                                            Asks[i].Amount = 0;
                                            continue;
                                        }


                                        if (Asks[i].Price != (double)asks[i].Price ||
                                            Asks[i].Amount != (int)asks[i].Volume

                                            )
                                        {
                                            Asks[i].Price  = (double)asks[i].Price;
                                            Asks[i].Amount = (int)asks[i].Volume;

                                            bStockChanged = true;

                                            //debugging
                                            // if (Bids[0].Price!=0 &&Asks[i].Price <= Bids[0].Price)
                                            //   Thread.Sleep(0);
                                        }
                                    }
                                    //2018-07-09
                                }
                            }

                            if (dictStockClass.StockListBids.ContainsKey(prec))
                            {
                                List <CStock> bids = dictStockClass.StockListBids[prec];

                                if (bids != null)
                                {
                                    for (int i = 0; i < Bids.Length; i++)
                                    {
                                        if (i >= bids.Count)
                                        {
                                            Bids[i].Price  = 0;
                                            Bids[i].Amount = 0;
                                            continue;
                                        }


                                        if (Bids[i].Price != (double)bids[i].Price ||
                                            Bids[i].Amount != (int)bids[i].Volume)
                                        {
                                            Bids[i].Price  = (double)bids[i].Price;
                                            Bids[i].Amount = (int)bids[i].Volume;

                                            bStockChanged = true;

                                            //if (Asks[0].Price!=0 && Bids[i].Price >= Asks[0].Price)
                                            //  Thread.Sleep(0);
                                        }
                                    }
                                }
                            }

                            /*
                             * for (int k = 0; k < Asks.Length; k++)
                             * {
                             *
                             *
                             *   if (Bids[0].Price!=0 && Asks[k].Price!=0 &&  Asks[k].Price <= Bids[0].Price)
                             *         Thread.Sleep(0);
                             * }
                             *
                             * for (int j = 0; j < Bids.Length; j++)
                             * {
                             *
                             *
                             *   if ((Asks[0].Price != 0)  && (Bids[j].Price >= Asks[0].Price))
                             *      Thread.Sleep(0);
                             * }
                             */



                            if (bStockChanged)
                            {
                                _vmUserPos.Recalc((double)Bids[0].Price, (double)Asks[0].Price, Step, Decimals);
                                ForceRepaintControlStock();

                                GUIDispatcher.BeginInvoke(new Action(() =>
                                {
                                    try
                                    {
                                        //note: put it here because of synchronizing problems (pforit calc on graphics is faster !)
                                    }
                                    catch (Exception e)
                                    {
                                        Error("MarketViewModel process stocks GUI", e);
                                    }
                                }
                                                                     ));
                            }
                        }
                        catch (Exception e)
                        {
                            Error("", e);
                        }

                        // else
                        //  Thread.Sleep(0);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public static TaskCompletionSource <Tuple <XElement, string> > ConvertInput(Input input)
        {
            var promise = new TaskCompletionSource <Tuple <XElement, string> >();

            var tempDirectory = NewTempDirectory;

            var outputFileName = input.PartName + ".xml";

            var process = new Process()
            {
                StartInfo = new ProcessStartInfo()
                {
                    FileName               = ApplicationData.ConverterExeName,
                    Arguments              = string.Format("\"{0}\" -TxJT2cojt -extIdMod 3 {1} -dest \"{2}\" -output \"{3}\"", new object[] { input.JTPath, input.PartClass ? "" : "-emsClass defaultResource", tempDirectory, outputFileName }),
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                },
                EnableRaisingEvents = true
            };

            if (process.Start())
            {
                void processOutputDataReceived(object sender, DataReceivedEventArgs dataReceivedEventArgs) => Console.WriteLine(dataReceivedEventArgs.Data);

                void processErrorDataReceived(object processObject, DataReceivedEventArgs dataReceivedEventArgs) => Console.Error.WriteLine(dataReceivedEventArgs.Data);

                void processExited(object processObject, EventArgs exitedEventArguments)
                {
                    try
                    {
                        process.OutputDataReceived -= processOutputDataReceived;
                        process.ErrorDataReceived  -= processErrorDataReceived;
                        process.Exited             -= processExited;

                        var pathToXMLDocument = Path.Combine(tempDirectory, outputFileName);

                        if (File.Exists(pathToXMLDocument))
                        {
                            var xmlDocument      = XElement.Load(pathToXMLDocument);
                            var fileNameElements = xmlDocument.Descendants("fileName").ToArray();

                            for (int i = 0, c = fileNameElements.Length; i < c; ++i)
                            {
                                var fileNameElement = fileNameElements[i];

                                var existingPath = fileNameElement.Value.TrimStart(new char[] { '#' });

                                var existingFileName = Path.GetFileNameWithoutExtension(existingPath);
                                var newFileName      = i.ToString() + ".cojt";

                                var newPath = Path.Combine(GetPathRelativeTo(input.OutputDirectory, ApplicationData.Service.SysRootPath).TrimStart(new char[] { Path.DirectorySeparatorChar }), newFileName);

                                fileNameElement.SetValue("#" + newPath);

                                var outputCOJTDirectory = Path.Combine(input.OutputDirectory, newFileName);

                                try
                                {
                                    Directory.CreateDirectory(outputCOJTDirectory);
                                }

                                catch (Exception e)
                                {
                                    GUIDispatcher.Invoke(() =>
                                    {
                                        ApplicationData.Service.Errors.Add(new TranslationError()
                                        {
                                            Timestamp   = DateTime.Now,
                                            JTPath      = outputCOJTDirectory,
                                            Description = e.Message
                                        });
                                    });

                                    throw new Exception();
                                }

                                var existingJTFilePath = Path.Combine(existingPath, existingFileName + ".jt");

                                if (!File.Exists(existingJTFilePath))
                                {
                                    var existingJTFilePathTmp = Path.Combine(existingPath + ".tmp", existingFileName + ".jt");

                                    if (!File.Exists(existingJTFilePathTmp))
                                    {
                                        GUIDispatcher.Invoke(() =>
                                        {
                                            ApplicationData.Service.Errors.Add(new TranslationError()
                                            {
                                                Timestamp   = DateTime.Now,
                                                JTPath      = input.JTPath,
                                                Description = String.Format("Conversion error: '{0}' not found.", existingJTFilePath)
                                            });
                                        });

                                        continue;
                                    }

                                    else
                                    {
                                        existingJTFilePath = existingJTFilePathTmp;
                                    }
                                }

                                var newJTFilePath = Path.Combine(outputCOJTDirectory, i.ToString() + ".jt");

                                try
                                {
                                    File.Copy(existingJTFilePath, newJTFilePath, true);
                                }

                                catch (Exception e)
                                {
                                    GUIDispatcher.Invoke(() =>
                                    {
                                        ApplicationData.Service.Errors.Add(new TranslationError()
                                        {
                                            Timestamp   = DateTime.Now,
                                            JTPath      = existingJTFilePath,
                                            Description = e.Message
                                        });
                                    });
                                }
                            }

                            promise.TrySetResult(new Tuple <XElement, string>(xmlDocument, outputFileName));
                        }

                        else
                        {
                            GUIDispatcher.Invoke(() =>
                            {
                                ApplicationData.Service.Errors.Add(new TranslationError()
                                {
                                    Timestamp   = DateTime.Now,
                                    JTPath      = input.JTPath,
                                    Description = "Conversion failed: XML file was not created."
                                });
                            });

                            throw new Exception();
                        }
                    }

                    catch (Exception)
                    {
                        /*GUIDispatcher.Invoke(() =>
                         * {
                         *  ApplicationData.Service.Errors.Add(new TranslationError()
                         *  {
                         *      Timestamp = DateTime.Now,
                         *      Description = exception.Message
                         *  });
                         * });*/

                        promise.TrySetResult(null);
                    }

                    finally
                    {
                        if (Directory.Exists(tempDirectory))
                        {
                            try { Directory.Delete(tempDirectory, true); }
                            catch (Exception) { }
                        }
                    }
                }

                process.OutputDataReceived += processOutputDataReceived;
                process.ErrorDataReceived  += processErrorDataReceived;
                process.Exited             += processExited;

                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
            }

            return(promise);
        }