private static void LoadOneClassProperties <TypeViewModel>(object classWithProps, TypeViewModel marketViewmodel) { classWithProps.GetType().GetProperties().ToList().ForEach( propertyConfig => { try { var valueConfig = propertyConfig.GetValue(classWithProps, null); if (valueConfig != null) { marketViewmodel.GetType().GetProperties().ToList().ForEach( propertyViewMdl => { if (propertyViewMdl.Name == propertyConfig.Name) { //string stVal = val.ToString(); //propertyConfig.SetValue(classWithProps, stVal, null); //propertyViewMdl.SetValue(marketViewmodel, valueConfig, null); CUtilReflex.SetPropertyValue(marketViewmodel, propertyViewMdl, valueConfig); } } ); } } catch (Exception e) { CKernelTerminal.ErrorStatic("LoadOneClassProperties", e); } } ); }
private void TaskSaver() { try { _evDataLoaded.WaitOne(); while (true) { _evSave.WaitOne(); List <CLevelEl> lst = GetCopy(); if (lst != null) { _levelsIO.WriteToFile(lst); } // Thread.Sleep(1000); } } catch (Exception e) { CKernelTerminal.ErrorStatic("CUserLevels.TaskSaver", e); } }
private void IncDecTextBox(IncDec incdecPat, TextBlock txtBlock) { uint num; try { string txt = txtBlock.Text; num = Convert.ToUInt32(txt); } catch (Exception exc) { CKernelTerminal.ErrorStatic("IncDecTextBox", exc); return; } //TODO chek min max values if (incdecPat == IncDec.DoInc) { num++; } else if (incdecPat == IncDec.DoDec) { num--; } num = Math.Max(num, 1); txtBlock.Text = Convert.ToString(num); }
private static void UpdateOneClassProperties <TypeViewModel>(object classWithProps, TypeViewModel marketViewmodel) { classWithProps.GetType().GetProperties().ToList().ForEach( propertyConfig => { try { var value = propertyConfig.GetValue(classWithProps, null); if (value != null) { marketViewmodel.GetType().GetProperties().ToList().ForEach( propertyViewMdl => { if (propertyViewMdl.Name == propertyConfig.Name) { object val = propertyViewMdl.GetValue(marketViewmodel, null); string stVal = val.ToString(); propertyConfig.SetValue(classWithProps, stVal, null); } } ); } } catch (Exception e) { CKernelTerminal.ErrorStatic("UpdateOneClassProperties", e); } } ); }
public void Error(string msg, Exception e) { // if (_alarmer !=null) // _alarmer.Error(msg, e); CKernelTerminal.ErrorStatic(msg, e); }
public T LoadData() { CleanOldData(); T list = new T(); string path = GetFileName(); FileStream serializationStream = null; try { if (File.Exists(path) && CUtil.FileSize(path) != 0) { serializationStream = new FileStream(path, FileMode.Open); } else { //File.Create(path); return(list); } } catch (IOException e) { CKernelTerminal.ErrorStatic("IO Error in LoadData " + _subdir, e); } catch (Exception e) { CKernelTerminal.ErrorStatic("Error in LoadData " + _subdir, e); } if (serializationStream == null) { return(new T()); } try { BinaryFormatter formatter = new BinaryFormatter(); list = (T)formatter.Deserialize(serializationStream); } catch (SerializationException e) { CKernelTerminal.ErrorStatic("Serialization error in LoadData " + _subdir, e); } catch (Exception e) { CKernelTerminal.ErrorStatic("Common error during serialization in LoadData " + _subdir, e); } finally { serializationStream.Close(); } return(list); }
/// <summary> /// Call from MarketViewModel.SetEmptyVewModelInstrParams /// </summary> /// <param name="instrumentConfig"></param> /// <param name="marketViewModel"></param> public static void LoadMarketConfig(CInstrumentConfig instrumentConfig, MarketViewModel marketViewModel) { try { LoadOneClassProperties(instrumentConfig.MarketProperties.StockProperties, marketViewModel); LoadOneClassProperties(instrumentConfig.MarketProperties.DealsProperties, marketViewModel); LoadOneClassProperties(instrumentConfig.MarketProperties.ClusterProperties, marketViewModel); } catch (Exception e) { CKernelTerminal.ErrorStatic("LoadMarketConfig"); } }
private void ControlMarket_PreviewMouseDown(object sender, MouseButtonEventArgs e) { try { if (!base.IsKeyboardFocused) { DoAllFocused(); } } catch (Exception exc) { CKernelTerminal.ErrorStatic("ControlMarket_PreviewMouseDown", exc); } }
private void ColorList_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { CColor cclr = ((CColor)e.AddedItems[0]); Color selectedColor = (Color)ColorConverter.ConvertFromString(cclr.Name); Brush brush = new SolidColorBrush(selectedColor); //Brush selectedColor = (Brush)(e.AddedItems[0] as CColor).GetValue(null, null); rtlfill.Fill = brush; } catch (Exception exc) { CKernelTerminal.ErrorStatic("ColorSelectionWindow.ColorList_SelectionChanged", exc); } }
public static void UpdateTerminalConfig(CTerminalProperties terminalProperties, TerminalViewModel termViewModel) { try { UpdateOneClassProperties(terminalProperties.TerminalCommonProperties, termViewModel); UpdateOneClassProperties(terminalProperties.TerminalStockProperties, termViewModel); UpdateOneClassProperties(terminalProperties.TerminalDealsProperties, termViewModel); UpdateOneClassProperties(terminalProperties.TerminalClustersProperties, termViewModel); UpdateOneClassProperties(terminalProperties.TerminalGlobalProperties, termViewModel); } catch (Exception e) { CKernelTerminal.ErrorStatic("UpdateTerminalConfig", e); } }
private void TaskLoadData() { try { _lstLevels = _levelsIO.LoadData(); } catch (Exception e) { CKernelTerminal.ErrorStatic("UserLevels TaskLoadData", e); } finally { _evDataLoaded.Set(); } }
public void WriteToFile(T dataToSeirilze) { string path = GetFileName(); FileStream fileStream = null; try { //if file exists and valid use it if (File.Exists(path) && CUtil.FileSize(path) > 0) { fileStream = new FileStream(path, FileMode.Create); } //if not create new file else { fileStream = File.Create(path); //serializationStream = new FileStream(path, FileMode.Open); } } catch (IOException e) { CKernelTerminal.ErrorStatic("WriteToFile IO " + _subdir, e); } catch (Exception e) { CKernelTerminal.ErrorStatic("WriteToFile " + _subdir, e); } if (fileStream != null) { BinaryFormatter formatter = new BinaryFormatter(); try { formatter.Serialize(fileStream, dataToSeirilze); } catch (Exception e) { CKernelTerminal.ErrorStatic("WriteToFile Serialize", e); } finally { fileStream.Close(); } } }
public static void SaveMarketConfig(CInstrumentConfig instrumentConfig, MarketViewModel marketViewModel) { try { UpdateOneClassProperties(instrumentConfig.MarketProperties.StockProperties, marketViewModel); UpdateOneClassProperties(instrumentConfig.MarketProperties.DealsProperties, marketViewModel); //2018-08-21 protect against file corruption on file saving when cluster was not loaded yet if (marketViewModel.TimeFrame != null) { UpdateOneClassProperties(instrumentConfig.MarketProperties.ClusterProperties, marketViewModel); } } catch (Exception e) { CKernelTerminal.ErrorStatic("UpdateMarketConfig", e); } }
public void RouteEvent(object sender, ExecutedRoutedEventArgs e) { try { RoutedUICommand cmd = (RoutedUICommand)e.Command; if (!_dictCmdEventHandler.ContainsKey(cmd)) { CKernelTerminal.ErrorStatic("CEventRouterViewModel.RouteEvent command not found"); return; } _dictCmdEventHandler[cmd].Invoke(sender, e); } catch (Exception excp) { CKernelTerminal.ErrorStatic("Error in RouteEvent", excp); } }
public static void BindAllFromViewModel <TypeOfViewModel>(TypeOfViewModel viewModel, DependencyObject dependencyObject) { viewModel.GetType().GetProperties().ToList().ForEach( property => { try { string propertyName = property.Name; string dpName = property.Name + "Property"; PropertyInfo propertyViewModel = viewModel.GetType().GetProperty(propertyName); Type typeDependObj = dependencyObject.GetType(); FieldInfo fieldDP = CUtilReflex.GetDependencyPropertyField(propertyName, typeDependObj); if (fieldDP == null) { throw new ApplicationException("Field " + dpName + " not found in " + typeDependObj.Name); } DependencyProperty dp = (DependencyProperty)fieldDP.GetValue(dependencyObject); /* Bind ViewModel property and DependencyProperty of Control. * If ViewModel property is writable, use two way binding * */ CUtil.SetBinding(viewModel, propertyName, dependencyObject, dp, twoWayBinding: propertyViewModel.CanWrite); } catch (Exception e) { CKernelTerminal.ErrorStatic("BindAllFromViewModel", e); } } ); }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { List <CColor> lstColors = CKernelTerminal.GetKernelTerminalInstance().ColorList.ListColors; ColorList.ItemsSource = lstColors; //PropertyInfo[] props = typeof(Brushes).GetProperties(); string stFill = rtlfill.Fill.ToString(); Color colorSelected = (Color)ColorConverter.ConvertFromString(stFill); string stColor = colorSelected.ToString(); for (int i = 0; i < lstColors.Count; i++) { string colorName = lstColors[i].Name; Color clr = (Color)ColorConverter.ConvertFromString(colorName); if (clr == colorSelected) { ColorList.SelectedItem = ColorList.Items[i]; //ColorList.SelectedIndex = i; ColorList.UpdateLayout(); var listBoxItem = (ListBoxItem)ColorList.ItemContainerGenerator.ContainerFromItem(ColorList.SelectedItem); listBoxItem.Focus(); } } } catch (Exception exc) { CKernelTerminal.ErrorStatic("ColorSelectionWindow.Window_Loaded", exc); } }
/// <summary> /// For each property in property list find property with such name in ViewModel. If value was set use it as initial /// values. Then in control class find dependency property static field with name "PropertyName"Property (also find in parent UserControl class). /// If all OK bind ViewModel property with UserControl dependency property /// </summary> /// <typeparam name="TypeOfViewModel"></typeparam> /// <param name="viewModel"></param> /// <param name="dependencyObject"></param> /// <param name="propertyList">List of strings. Name of fields are name of properties. Values (if it was set) are initial values of properties. </param> public static void BindFromList <TypeOfViewModel>(TypeOfViewModel viewModel, DependencyObject dependencyObject, object propertyList) { propertyList.GetType().GetProperties().ToList().ForEach( propertyConfig => { try { string propertyName = propertyConfig.Name; var p = viewModel.GetType().GetProperty(propertyConfig.Name); PropertyInfo propertyViewModel = viewModel.GetType().GetProperty(propertyName); if (propertyViewModel == null) { string msg = propertyName + " not found in ViewModel"; CKernelTerminal.ErrorStatic(msg); throw new ApplicationException(msg); } //if value was set in config file //set the value to ViewModel property var value = propertyConfig.GetValue(propertyList, null); if (value != null) { //SetValue(marketViewModel, propertyViewModel, value); CUtilReflex.SetPropertyValue(viewModel, propertyViewModel, value); } string dpName = propertyConfig.Name + "Property"; Type type = dependencyObject.GetType(); FieldInfo fieldDP = CUtilReflex.GetDependencyPropertyField(propertyConfig.Name, type); //if not found do find in base FrameWorokElement class if (fieldDP == null) { Type typeFrameWorkElement = type.BaseType.BaseType.BaseType; fieldDP = CUtilReflex.GetField(dpName, typeFrameWorkElement); } //dependency property field must be in Control if (fieldDP != null) //found { DependencyProperty dp = (DependencyProperty)fieldDP.GetValue(dependencyObject); /* Bind ViewModel property and DependencyProperty of Control. * If ViewModel property is writable, use two way binding * */ CUtil.SetBinding(viewModel, propertyName, dependencyObject, dp, twoWayBinding: propertyViewModel.CanWrite); } else //filed == null , field not found, error { string msg = "field not found: " + dpName; CKernelTerminal.ErrorStatic(msg); throw new ApplicationException(msg); } } catch (Exception e) { CKernelTerminal.ErrorStatic("BindFromList error", e); } }); }
//NEED REFACTORING ! remove DP vars public void Draw(DrawingContext drwCntxt, double stringHeight, double x, double highestBidY, double lowestAskY, double widthTextPrice, double widthTotal, Dictionary <double, double> dictPriceY, int decimals) { int profitInSteps = 0; bool isBuy = false; bool isSell = false; bool isProfit = false; bool isActive = false; decimal avPos = 0; _guiDispatcher.Invoke(new Action(() => { profitInSteps = ProfitInSteps; isBuy = IsBuy; isSell = IsSell; isProfit = IsProfit; isActive = IsActive; avPos = AvPos; })); if (!isActive) { return; } try { double price = (double)Math.Round(avPos, decimals); //2017_03_20 removed as client request ///*double price = (double)AvPos; //if (dictPriceY.ContainsKey(price)) // drwCntxt.DrawRectangle(_brushPos, _penPos, new Rect(0.0, dictPriceY[price], widthTotal, stringHeight)); double height = 0; double y = 0; height = stringHeight * (Math.Abs(profitInSteps) + 1); double heightVector = (profitInSteps) * stringHeight; if (isBuy) { if (isProfit) { y = highestBidY; } else { y = highestBidY + heightVector; } } else if (isSell) { if (isProfit) { y = lowestAskY - heightVector; } else { y = lowestAskY; } } Brush brush = Brushes.Black; Pen pen = new Pen(Brushes.Black, 1.0); if (isProfit) { brush = _brushProfit; pen = _penProfit; } else { brush = _brushLoss; pen = _penProfit; } drwCntxt.DrawRectangle(brush, pen, new Rect(x, y, widthTextPrice, height)); } catch (Exception e) { CKernelTerminal.ErrorStatic("CDOUserPos.Draw", e); } }