Ejemplo n.º 1
0
        private void InitializeBindings()
        {
            ViewModel = new VM_Main();

            ViewModel.OnValidation += args => lblErrors.Text = args.ToString();

            chkValidateXSD.DataBindings.Add("Checked", ViewModel, nameof(ViewModel.UseXSD), true, DataSourceUpdateMode.OnPropertyChanged);

            cpXSD.DataBindings.Add(new Binding("Enabled", ViewModel, nameof(ViewModel.UseXSD))
            {
                DataSourceUpdateMode = DataSourceUpdateMode.Never, ControlUpdateMode = ControlUpdateMode.OnPropertyChanged
            });

            cpInputDir.DataBindings.Add("Path", ViewModel, nameof(ViewModel.PathToInputDirectory), true, DataSourceUpdateMode.OnPropertyChanged);
            cpXSD.DataBindings.Add("Path", ViewModel, nameof(ViewModel.PathToXSD), true, DataSourceUpdateMode.OnPropertyChanged);

            lblCount.DataBindings.Add("Text", ViewModel, nameof(ViewModel.LabelCount));

            textXPath.DataBindings.Add("Text", ViewModel, nameof(ViewModel.XPath), true, DataSourceUpdateMode.OnPropertyChanged);

            textSearch.DataBindings.Add("Text", ViewModel, nameof(ViewModel.Search), true, DataSourceUpdateMode.OnPropertyChanged);
            textReplace.DataBindings.Add("Text", ViewModel, nameof(ViewModel.Replace), true, DataSourceUpdateMode.OnPropertyChanged);

            chkRegExp.DataBindings.Add("Checked", ViewModel, nameof(ViewModel.UseRegularExpressions), true, DataSourceUpdateMode.OnPropertyChanged);

            btnReplace.BindCommand(ViewModel.OnReplace);
            btnSearch.BindCommand(ViewModel.OnSearch);

            ViewModel.Update();
        }
Ejemplo n.º 2
0
 public UC_Main(int nodeId = 127)
 {
     if (!DesignerProperties.GetIsInDesignMode(this))
     {
         DataContext = _data_context = new VM_Main(nodeId);
     }
     InitializeComponent();
     IsVisibleChanged += UC_Main_IsVisibleChanged;
     sciChartOsciloscope.oscilloscopeChart.MouseDoubleClick += oscilloscopeChart_MouseDoubleClick;
 }
Ejemplo n.º 3
0
        public MainWindow()
        {
            VM_Main viewmodel = new VM_Main();

            DataContext = viewmodel;
            InitializeComponent();

            DragDrop.AddQueryContinueDragHandler(this, new QueryContinueDragEventHandler((o, a) =>
            {
                viewmodel.Dragging = a.Action == DragAction.Continue && a.KeyStates.HasFlag(DragDropKeyStates.LeftMouseButton) && !a.EscapePressed;
            }));
            viewmodel.ShowWaitCursor = DisplayWaitCursor;
            viewmodel.UpdateTextBox  = UpdateTextBox;
        }
Ejemplo n.º 4
0
        public static void SendCCComand(int ccValue = 60, VM_Main vm_sci = null)
        {
            FrequencyManager.ccValue = (byte)ccValue;

            List <Tuple <VM_Main, uint> > restore =
                Globals.Vm_scis
                .Select(w => new Tuple <VM_Main, uint>(w, w.PlotTime))
                .ToList();

            Frequency = 1 / ((6.0 / ccValue));
            foreach (var tuple in restore)
            {
                tuple.Item1.PlotTime = tuple.Item2;
                tuple.Item1.SynchronizeFrequency(vm_sci);
            }
            CManager.WriteToAll("CC", 0, false, false, (ccValue * 3).ToString());
        }
Ejemplo n.º 5
0
        public async void Convert(VM_Main vmMain, VM_Work vmWork)
        {
            var files = Directory.GetFiles(vmMain.PathToInputDirectory, extension).ToList();

            string outputPath = Path.Combine(vmMain.PathToInputDirectory, outputDirectory);

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            int filesProcessed = 0;

            vmWork.pgBarState.Maximum = files.Count;

            string search = vmMain.Search;

            getAttributeToSearch(ref search, out string attributeToSearch);
            Regex  regex   = vmMain.UseRegularExpressions ? new Regex(search, RegexOptions.Compiled) : null;
            String replace = vmMain.NeedReplace ? (vmMain.Replace ?? "") : null;

            vmWork.Log.TryAdd($"Входная директория: {vmMain.PathToInputDirectory}");
            vmWork.Log.TryAdd($"Выходная директория: {outputPath}");
            if (vmMain.UseXSD)
            {
                vmWork.Log.TryAdd($"XSD схема для проверки: {vmMain.PathToXSD}");
            }
            vmWork.Log.TryAdd(logSearchLine(vmMain.UseRegularExpressions, search, attributeToSearch));
            if (vmMain.NeedReplace)
            {
                vmWork.Log.TryAdd($"Заменять на: {vmMain.Replace}");
            }

            Stopwatch   elapsedTotal = Stopwatch.StartNew();
            List <Task> tasks        = new List <Task>();

            foreach (var file in files)
            {
                var task = Task.Factory.StartNew(() =>
                {
                    string filename   = Path.GetFileName(file) ?? throw new ArgumentException("Can't get short path for: " + file);
                    Stopwatch elapsed = Stopwatch.StartNew();

                    try
                    {
                        XmlDocument xml = new XmlDocument();
                        xml.Load(file);
                        if (vmMain.UseXSD)
                        {
                            xml.Schemas.Add(null, vmMain.PathToXSD);
                        }

                        if (!ValidateXSD(xml))
                        {
                            vmWork.Log.TryAdd("ОШИБКА: Документ не соответствует XSD схеме");
                            goto method_end;
                        }

                        var result = Search(xml, vmMain.XPath, search, regex, attributeToSearch);
                        vmWork.Log.TryAdd($"Найдено {result.Item1} значений в документе");

                        if (vmMain.NeedReplace)
                        {
                            Replace(xml, result.Item2, search, replace, regex);

                            if (!ValidateXSD(xml))
                            {
                                vmWork.Log.TryAdd("ОШИБКА: После замены документ не соответствует XSD схеме");
                                goto method_end;
                            }

                            xml.Save(Path.Combine(outputPath, filename));
                        }

                        method_end:;
                    }
                    catch (XmlException ex)
                    {
                        vmWork.Log.TryAdd($"ОШИБКА: {ex.Message} в документе {filename}");
                    }

                    vmWork.Log.TryAdd($"Документ \"{filename}\" обработан за {elapsed.Elapsed}ms");
                    vmWork.pgBarState.Value = Interlocked.Increment(ref filesProcessed);
                    vmWork.LabelStatus      = $"Обработано документов: {vmWork.pgBarState.Value}/{vmWork.pgBarState.Maximum} (через {TaskScheduler.Current.GetType().Name})";
                });
                tasks.Add(task);
            }

            await Task.WhenAll(tasks.ToArray());

            elapsedTotal.Stop();
            vmWork.Log.TryAdd($"Суммарное время обработки {files.Count} документов: {elapsedTotal.Elapsed}");
        }
Ejemplo n.º 6
0
 public MainWindow()
 {
     InitializeComponent();
     base.DataContext = _main = new VM_Main();
 }
Ejemplo n.º 7
0
        private void Application_Startup(Object sender, StartupEventArgs e)
        {
            ISimulatorModel model = new SimulatorModel(new TelnetClient());

            ViewModel = new VM_Main(model);
        }