private void MenuItem_Save_Serial(object sender, RoutedEventArgs e) { try { const string filter = "Dat files (*.dat)|*.dat"; string path = AppSettings.PathPattern; SaveFileDialog saveFileDialog = new SaveFileDialog() { InitialDirectory = path, Filter = filter }; if (saveFileDialog.ShowDialog() == true) { List <SettingButton> SettingButtons = new List <SettingButton>(); foreach (UIElement item in CanvasForImage.Children) { var button = (Button)item; SettingButtons.Add(new SettingButton() { Font = hashCodeButtonsOncanvas.FirstOrDefault(x => x.Key == button.GetHashCode()).Value, Name = button.Name, Width = button.Width, Height = button.Height, MarginB = button.Margin.Bottom, MarginL = button.Margin.Left, MarginR = button.Margin.Right, MarginT = button.Margin.Top, }); } DataPattern dataPattern = new DataPattern() { Font = printService.FontCurrent, Image = new Drawing.Bitmap(bitmapImageOriginal), Params = analiticService.PARAMS, SettingButtons = SettingButtons, CalibrationData = printService.CalibrationData, }; Helper.SerializationDataPattern(dataPattern, saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно"); } } catch (Exception ex) { MessageBox.Show("Ошибка при сохранении", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error); throw ex; } }
public static void SerializationDataPattern(DataPattern dataPattern, string path) { if (dataPattern == null) { throw new ArgumentNullException(nameof(dataPattern)); } BinaryFormatter formatter = new BinaryFormatter(); // получаем поток, куда будем записывать сериализованный объект using(FileStream fs = new FileStream(path, FileMode.OpenOrCreate)) { formatter.Serialize(fs, dataPattern); } }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { double result = System.Convert.ToSingle(value); string fieldName = System.Convert.ToString(parameter); Dictionary <string, DataPattern> dic = App.Current.Properties["JhtStock"] as Dictionary <string, DataPattern>; DataPattern dp = dic[fieldName] as DataPattern; if (dp != null) { if (result > GlobalConstants.MinDisplayValue) { if (result > dp.Upper || result < dp.Lower) { return(Brushes.Red); } else { return(Brushes.DarkGreen); } } } return(new SolidColorBrush(Color.FromRgb(0x04, 0x22, 0x71))); }
private void MenuItem_DownloadPattern_Click(object sender, RoutedEventArgs e) { try { const string filter = "Dat files (*.dat)|*.dat"; string path = AppSettings.PathPattern; OpenFileDialog openFileDialog = new OpenFileDialog() { Filter = filter, InitialDirectory = path }; if (openFileDialog.ShowDialog() == true) { hashCodeButtonsOncanvas.Clear(); CanvasForImage.Children.Clear(); DataPattern dataPatternModel = Helper.DeSerializationDataPattern(openFileDialog.FileName); printService.Font(dataPatternModel.Font, isDialog: false, updateFontCurrent: true); printService.CalibrationData = dataPatternModel.CalibrationData; analiticService.PARAMS = dataPatternModel.Params; BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap ( dataPatternModel.Image.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions() ); ImageMainControl.Source = bitmapSource; foreach (SettingButton item in dataPatternModel.SettingButtons) { Button button = new Button() { Name = item.Name, Height = item.Height, Width = item.Width, Content = "**" + item.Name + "**", Margin = new Thickness(item.MarginL, item.MarginT, item.MarginR, item.MarginB) }; button.PreviewMouseDown += new MouseButtonEventHandler(MouseDown); button.PreviewMouseUp += new MouseButtonEventHandler(MouseUp); button.PreviewMouseMove += new MouseEventHandler(MouseMove); button.MouseRightButtonDown += (_sender, _e) => { Button buttonCurrent = _sender as Button; new Views.Button_Calibration(buttonCurrent, hashCodeButtonsOncanvas, printService).ShowDialog(); e.Handled = true; }; Drawing.Font font = item.Font ?? printService.FontCurrent; CanvasForImage.Children.Add(button); hashCodeButtonsOncanvas.Add(button.GetHashCode(), font); } bitmapImageOriginal = new Drawing.Bitmap(dataPatternModel.Image); MessageBox.Show("Загрузка прошла успешно"); } } catch (Exception) { MessageBox.Show("Ошибка при загрузки", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void CheckThatJsonObjectsSuchAsFromCurrencyAndToCurrencyShouldMatchToCodeAndNameValues() { // JPath выражения string jsonFromCurPath = "$...fromCurrency"; string jsonToCurPath = "$...toCurrency"; var datapattern = new DataPattern(); var testdata = new TestData(); var http = new HttpAction(); var response = http.GETRequest(testdata.BaseUrl, testdata.GetResourcePath()["currencyRatesPath"]); var content = response.Content; JObject jsonObj = JObject.Parse(content); IEnumerable <JToken> jsonArrayFromCur = jsonObj.SelectTokens(jsonFromCurPath, true); IEnumerable <JToken> jsonArrayToCur = jsonObj.SelectTokens(jsonToCurPath, true); var rubcode = datapattern.GetCurrencyStuff()["rubcode"]; var rubname = datapattern.GetCurrencyStuff()["rubname"]; var usdcode = datapattern.GetCurrencyStuff()["usdcode"]; var usdname = datapattern.GetCurrencyStuff()["usdname"]; var eurcode = datapattern.GetCurrencyStuff()["eurcode"]; var eurname = datapattern.GetCurrencyStuff()["eurname"]; var gbpcode = datapattern.GetCurrencyStuff()["gbpcode"]; var gbpname = datapattern.GetCurrencyStuff()["gbpname"]; foreach (JToken fromCur in jsonArrayFromCur) { string cutFromCur = fromCur.ToString(). Trim(new char[] { '{', '}' }).Replace(" ", string.Empty); Debug.WriteLine(cutFromCur); if (cutFromCur.Contains(rubcode)) { Assert.That(cutFromCur.Contains(rubcode)); Debug.WriteLine("RUB TRUE"); } else if (cutFromCur.Contains(usdcode)) { Assert.That(cutFromCur.Contains(usdcode)); Debug.WriteLine("USD TRUE"); } else if (cutFromCur.Contains(eurcode)) { Assert.That(cutFromCur.Contains(eurcode)); Debug.WriteLine("EUR TRUE"); } else if (cutFromCur.Contains(gbpcode)) { Assert.That(cutFromCur.Contains(gbpcode)); Debug.WriteLine("GBP TRUE"); } else { throw new Exception( $"Matching CurrencyCode did not happen."); } } foreach (JToken toCur in jsonArrayToCur) { var cutToCur = toCur.ToString(). Trim(new char[] { '{', '}' }).Replace(" ", string.Empty); Debug.WriteLine(cutToCur); if (cutToCur.Contains(rubname)) { Assert.That(cutToCur.Contains(rubname)); Debug.WriteLine("RUB TRUE"); } else if (cutToCur.Contains(usdname)) { Assert.That(cutToCur.Contains(usdname)); Debug.WriteLine("USD TRUE"); } else if (cutToCur.Contains(eurname)) { Assert.That(cutToCur.Contains(eurname)); Debug.WriteLine("EUR TRUE"); } else if (cutToCur.Contains(gbpname)) { Assert.That(cutToCur.Contains(gbpname)); Debug.WriteLine("GBP TRUE"); } else { throw new Exception( $"Matching CurrencyName did not happen."); } } }