public PatternManageViewModel(PatternViewModel pattern, IPatternRepository repository, IMappingEngine mappingEngine)
 {
     _repository    = repository;
     _mappingEngine = mappingEngine;
     Pattern        = pattern;
     Children       = new ObservableCollection <CheckablePatternDataViewModel>(pattern.Children.Select(x => x.ToCheckable()));
 }
 public ControlPatternDialog(PatternViewModel patternViewModel)
 {
     InitializeComponent();
     this.PatternViewModel      = patternViewModel ?? throw new ArgumentNullException(nameof(patternViewModel));
     this.Title                 = string.Format(CultureInfo.InvariantCulture, Properties.Resources.ControlPatternDialog_ControlPatternDialog__0__Action, this.PatternViewModel.Name);
     this.tcActions.ItemsSource = this.PatternViewModel.GetActionViewModels();
 }
        public void DataEnabled_IsUpdatedWhenEnabledIsSet()
        {
            var model = new PatternViewModel("");

            model.Enabled.Value = !model.Enabled.Value;
            Assert.Equal(model.Enabled.Value, model.Data.Enabled);
        }
        public void DataRegex_IsUpdatedWhenPatternIsSet()
        {
            var model = new PatternViewModel("");

            model.Pattern.Value = "x";
            Assert.Equal("x", model.Data.Regex.ToString());
        }
        private PatternViewModel CreatePVM(Ticker ticker, List <Candlestick> listOfCandlesticks)
        {
            PatternViewModel pvm = new PatternViewModel();


            var CandlesticksForValidTickers = listOfCandlesticks.FindAll(x => x.Symbol == ticker.Symbol);

            if (CandlesticksForValidTickers.Count > 0)
            {
                pvm.Symbol      = ticker.Symbol;
                pvm.Price       = ticker.Price.ToString();
                pvm.AskPrice    = ticker.AskPrice.ToString();
                pvm.PatternType = "BULLFLAG";
                for (int i = 0; i < CandlesticksForValidTickers.Count; i++)
                {
                    Candlestick candlestick = CandlesticksForValidTickers[i];
                    pvm.Interval = candlestick.Interval;
                    pvm.OpenTimes.Add(Convert.ToDouble(candlestick.OpenTime));
                    pvm.Opens.Add(candlestick.Open);
                    pvm.Highs.Add(candlestick.High);
                    pvm.Lows.Add(candlestick.Low);
                    pvm.Closes.Add(candlestick.Close);
                    pvm.Volumes.Add(candlestick.Volume);
                    pvm.CloseTimes.Add(Convert.ToDouble(candlestick.CloseTime));
                    pvm.QuoteAssetVolumes.Add(candlestick.QuoteAssetVolume);
                    pvm.NumberOfTrades.Add(Convert.ToInt32(candlestick.NumberOfTrades));
                    pvm.TakerBuyBaseAssetVolume.Add(candlestick.TakerBuyBaseAssetVolume);
                    pvm.TakerBuyQuoteAssetVolume.Add(candlestick.TakerBuyQuoteAssetVolume);
                }
                return(pvm);
            }
            return(null);
        }
        public void IsEmpty_IsTrue_IfPatternIsSetToEmpty()
        {
            var model = new PatternViewModel("x");

            model.Pattern.Value = "";

            Assert.True(model.IsEmpty.Value);
        }
        public void IsEmpty_IsFalse_IfPatternIsSetToNonEmpty()
        {
            var model = new PatternViewModel("");

            model.Pattern.Value = "x";

            Assert.False(model.IsEmpty.Value);
        }
        private void _IrPattern()
        {
            PPattern         form    = new PPattern();
            PatternViewModel context = new PatternViewModel();

            form.DataContext = context;

            Pag = form;
        }
Exemplo n.º 9
0
        public PatternDialog(PatternViewModel viewModel, DictionaryEditorViewModel parent)
        {
            _originalHashCode = viewModel.GetHashCode();

            InitializeComponent();
            DataContext = Pattern = viewModel.Clone();
            _parent     = parent;
            Loaded     += PatternDialog_Loaded;
        }
Exemplo n.º 10
0
        public void Enabled_IsSetFromDataEnabled()
        {
            var model = new PatternViewModel(new PatternData(new Regex(""))
            {
                Enabled = false
            });

            Assert.False(model.Enabled.Value);
        }
        public NumbersForm()
        {
            InitializeComponent();
            _viewModel = new PatternViewModel();
            _viewModel.PropertyChanged += _viewModel_PropertyChanged;

            textBox1.DataBindings.Add("Text", _viewModel, nameof(_viewModel.Liczba1), false, DataSourceUpdateMode.OnPropertyChanged);
            nudLiczba1.DataBindings.Add("Value", _viewModel, nameof(_viewModel.Liczba1), false, DataSourceUpdateMode.OnPropertyChanged);
            doubleInput1.DataBindings.Add("Value", _viewModel, nameof(_viewModel.Liczba1), false, DataSourceUpdateMode.OnPropertyChanged);
            textBox2.DataBindings.Add("Text", _viewModel, nameof(_viewModel.Liczba2), false, DataSourceUpdateMode.OnPropertyChanged);
        }
Exemplo n.º 12
0
        public void PatternChange_AddsItemToData_IfPatternIsSet()
        {
            var data    = new Collection <PatternData>();
            var model   = new PatternCollectionViewModel(data);
            var pattern = new PatternViewModel("");

            model.Values.Add(pattern);

            pattern.Pattern.Value = "x";
            Assert.Equal(new[] { "x" }, data.Select(p => p.Regex.ToString()));
        }
Exemplo n.º 13
0
        public void PatternChange_RemovesItemToData_IfPatternIsNotSet()
        {
            var data    = new Collection <PatternData>();
            var model   = new PatternCollectionViewModel(data);
            var pattern = new PatternViewModel("x");

            model.Values.Add(pattern);

            pattern.Pattern.Value = "";
            Assert.Empty(data);
        }
Exemplo n.º 14
0
        private static PatternViewModel RandomizePattern()
        {
            Random           rand          = new Random();
            int              numColors     = rand.Next(20, 100);
            PatternViewModel randomPattern = new PatternViewModel();

            for (int i = 0; i < numColors; i++)
            {
                randomPattern.Insert(RandomizeColor(rand.Next(0, 10000)));
            }


            return(randomPattern);
        }
Exemplo n.º 15
0
        public PatternPage(string pathForFiles, Measurements measurements)
        {
            InitializeComponent();
            this.SizeChanged += OnSizeChanged;

            this.measurements = measurements;
            this.pathForFiles = pathForFiles;
            showBasePattern   = false;
            readyToDraw       = false;

            BindingContext  = new PatternViewModel();
            patternRenderer = new HoodiePatternRenderer();
            patternRenderer.ProgressStateChanged += PatternRenderer_ProgressStateChanged;
        }
Exemplo n.º 16
0
        public ViewResult Pattern(SearchCandlestickRangeInputViewModel svm)
        {
            //string timeInMilliseconds = new DateTimeOffset(svm.EndTime).ToUnixTimeMilliseconds().ToString();
            //List<Pattern> Patterns = new List<Pattern>();
            var listOfCandlesticks = new List <Candlestick>();
            int counter            = 0;
            List <PatternViewModel> patternViewModels = new List <PatternViewModel>();

            foreach (var ticker in Tickers)
            {
                counter++;
                Ticker tick = GetPrice(ticker);
                listOfCandlesticks.AddRange(GetCandlesticks(ticker, svm.Interval, svm.Limit));
                patternViewModels.Add(CreatePVM(tick, GetCandlesticks(ticker, svm.Interval, svm.Limit)));
                //if (counter > 5)
                //    break;
            }
            List <PatternViewModel> Patterns = new List <PatternViewModel>();

            if (listOfCandlesticks.Count > 0)
            {
                List <Ticker> TickersThatPassedBullFlagTest = new List <Ticker>();
                var           GroupByTicker = listOfCandlesticks.GroupBy(x => x.Symbol).ToList();
                foreach (IEnumerable <Candlestick> ticker in GroupByTicker)
                {
                    Ticker validTicker = CheckIfBullFlagPattern(ticker.ToList <Candlestick>());
                    if (validTicker != null)
                    {
                        TickersThatPassedBullFlagTest.Add(validTicker);
                    }
                }
                if (TickersThatPassedBullFlagTest.Count > 0)
                {
                    //SendEmailForTickersThatPassedBullFlagTest(TickersThatPassedBullFlagTest);
                    foreach (var ticker in TickersThatPassedBullFlagTest)
                    {
                        PatternViewModel pvm = CreatePVM(ticker, listOfCandlesticks);
                        if (pvm != null)
                        {
                            Patterns.Add(pvm);
                        }
                    }
                }
            }
            return(View(Patterns));
        }
Exemplo n.º 17
0
        public static void PostPattern(PatternViewModel pattern)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://url");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = JSONConverter.SerializePattern(pattern);

                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
            }
        }
Exemplo n.º 18
0
        public PatternsViewModel(PatternUserControl patternUserControl)
        {
            patternsListBox      = patternUserControl.Find <ListBox>("PatternsListBox");
            patternTextBox       = patternUserControl.Find <TextBox>("PatternData");
            patternErrorsListBox = patternUserControl.Find <ListBox>("PatternErrors");
            logger = patternUserControl.Find <TextBox>("Logger");

            Dispatcher.UIThread.InvokeAsync(async() =>
            {
                bool error = false;
                if (!string.IsNullOrEmpty(Settings.PatternsFileName))
                {
                    try
                    {
                        PatternsFileName = Settings.PatternsFileName;
                        SelectedPattern  = Patterns.FirstOrDefault(p => p.Key == Settings.SelectedPatternKey) ?? Patterns.FirstOrDefault();
                    }
                    catch (Exception ex)
                    {
                        await MessageBox.ShowDialog(ex.Message);
                        error = true;
                    }
                }

                if (string.IsNullOrEmpty(Settings.PatternsFileName) || error)
                {
                    Settings.PatternsFileName = Settings.DefaultPatternsFileName;
                    SelectedPattern           = Patterns.FirstOrDefault();
                    SavePatterns();
                    Settings.Save();
                }
            });

            patternsListBox.DoubleTapped += (object sender, Avalonia.Interactivity.RoutedEventArgs e) =>
            {
                OpenPatternAction();
            };

            patternErrorsListBox.DoubleTapped += (object sender, Avalonia.Interactivity.RoutedEventArgs e) =>
            {
                GuiHelpers.ProcessErrorOnDoubleClick(patternErrorsListBox, patternTextBox);
            };

            patternLogger = new GuiLogger(PatternErrors)
            {
                LogPatternErrors = true
            };
            patternLogger.LogEvent += PatternLogger_LogEvent;
            dslProcessor.Logger     = patternLogger;

            patternTextBox.GetObservable(TextBox.CaretIndexProperty)
            .Subscribe(UpdatePatternCaretIndex);

            patternTextBox.GetObservable(TextBox.TextProperty)
            .Throttle(TimeSpan.FromMilliseconds(250))
            .Subscribe(str =>
            {
                if (SelectedPattern != null)
                {
                    Value = str;
                }
            });

            OpenPatterns = ReactiveCommand.Create(async() =>
            {
                SavePatterns();
                var openFileDialog = new OpenFileDialog
                {
                    Title = "Select patterns database",
                };
                var fileNames = await openFileDialog.ShowAsync(ServiceLocator.MainWindow);
                if (fileNames != null)
                {
                    try
                    {
                        PatternsFileName = fileNames.First();
                    }
                    catch (Exception ex)
                    {
                        await MessageBox.ShowDialog(ex.Message);
                        Settings.PatternsFileName = Settings.DefaultPatternsFileName;
                        Settings.Save();
                        SelectedPattern = Patterns.FirstOrDefault();
                        ServiceLocator.MainWindowViewModel.ActivateWindow();
                    }
                }
            });

            CreatePattern = ReactiveCommand.Create(() =>
            {
                SavePatterns();
                PatternViewModel newPatternViewMode = CreateNewPattern();
                Patterns.Add(newPatternViewMode);
                SelectedPattern = newPatternViewMode;
                SavePatterns();
            });

            RemovePattern = ReactiveCommand.Create(async() =>
            {
                if (SelectedPattern != null && await MessageBox.ShowDialog($"Do you want to remove {SelectedPattern}?", messageBoxType: MessageBoxType.YesNo))
                {
                    Patterns.Remove(SelectedPattern);
                    SelectedPattern = Patterns.LastOrDefault();
                    SavePatterns();
                }
            });

            OpenPattern = ReactiveCommand.Create(OpenPatternAction);

            SavePattern = ReactiveCommand.Create(() => SavePatterns());

            void OpenPatternAction()
            {
                if (patternsListBox.SelectedItem != null)
                {
                    SelectedPattern = (PatternViewModel)patternsListBox.SelectedItem;
                }
            }
        }
Exemplo n.º 19
0
 public static string SerializePattern(PatternViewModel pat)
 {
     return(Newtonsoft.Json.JsonConvert.SerializeObject(pat));
 }
Exemplo n.º 20
0
        public PatternsViewModel(PatternUserControl patternUserControl)
        {
            patternsListBox      = patternUserControl.Find <ListBox>("PatternsListBox");
            patternTextBox       = patternUserControl.Find <TextEditor>("PatternData");
            patternErrorsListBox = patternUserControl.Find <ListBox>("PatternErrors");
            logger = patternUserControl.Find <TextBox>("Logger");

            Dispatcher.UIThread.InvokeAsync(async() =>
            {
                bool error = false;
                if (!string.IsNullOrEmpty(Settings.PatternsFileName))
                {
                    try
                    {
                        PatternsFileName = Settings.PatternsFileName;
                        SelectedPattern  = Patterns.FirstOrDefault(p => p.Key == Settings.SelectedPatternKey) ?? Patterns.FirstOrDefault();
                    }
                    catch (Exception ex)
                    {
                        await MessageBox.ShowDialog(ex.Message);
                        error = true;
                    }
                }

                if (string.IsNullOrEmpty(Settings.PatternsFileName) || error)
                {
                    Settings.PatternsFileName = Settings.DefaultPatternsFileName;
                    SelectedPattern           = Patterns.FirstOrDefault();
                    SavePatterns();
                    Settings.Save();
                }
            });

            patternsListBox.DoubleTapped += (sender, e) =>
            {
                OpenPatternAction();
            };

            patternErrorsListBox.DoubleTapped += (sender, e) =>
            {
                GuiUtils.ProcessErrorOnDoubleClick(patternErrorsListBox, patternTextBox);
            };

            patternLogger           = GuiLogger.CreatePatternLogger(PatternErrors);
            patternLogger.LogEvent += PatternLogger_LogEvent;
            dslProcessor.Logger     = patternLogger;

            Observable.Timer(TimeSpan.Zero, TimeSpan.FromMilliseconds(200), RxApp.MainThreadScheduler)
            .Subscribe(_ => UpdatePatternCaretIndex());

            var patternTextBoxObserable = Observable.FromEventPattern <EventHandler, EventArgs>(
                h => patternTextBox.TextChanged += h,
                h => patternTextBox.TextChanged -= h);

            patternTextBoxObserable
            .Throttle(TimeSpan.FromMilliseconds(250))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(str =>
            {
                if (SelectedPattern != null)
                {
                    Value = patternTextBox.Text;
                }
            });

            OpenPatterns = ReactiveCommand.Create(async() =>
            {
                SavePatterns();
                var openFileDialog = new OpenFileDialog
                {
                    Title = "Select patterns database",
                };
                var fileNames = await openFileDialog.ShowAsync(ServiceLocator.MainWindow);
                if (fileNames != null)
                {
                    try
                    {
                        PatternsFileName = fileNames.First();
                    }
                    catch (Exception ex)
                    {
                        await MessageBox.ShowDialog(ex.Message);
                        Settings.PatternsFileName = Settings.DefaultPatternsFileName;
                        Settings.Save();
                        SelectedPattern = Patterns.FirstOrDefault();
                        ServiceLocator.MainWindowViewModel.ActivateWindow();
                    }
                }
            });

            CreatePattern = ReactiveCommand.Create(() =>
            {
                SavePatterns();
                PatternViewModel newPatternViewMode = CreateNewPattern();
                Patterns.Add(newPatternViewMode);
                SelectedPattern = newPatternViewMode;
                SavePatterns();
            });

            RemovePattern = ReactiveCommand.Create(async() =>
            {
                if (SelectedPattern != null && await MessageBox.ShowDialog($"Do you want to remove {SelectedPattern}?", messageBoxType: MessageBoxType.YesNo))
                {
                    Patterns.Remove(SelectedPattern);
                    SelectedPattern = Patterns.LastOrDefault();
                    SavePatterns();
                }
            });

            OpenPattern = ReactiveCommand.Create(OpenPatternAction);

            SavePattern = ReactiveCommand.Create(() => SavePatterns());

            void OpenPatternAction()
            {
                if (patternsListBox.SelectedItem != null)
                {
                    SelectedPattern = (PatternViewModel)patternsListBox.SelectedItem;
                }
            }
        }
Exemplo n.º 21
0
 public Pattern2Command(PatternViewModel viewModel)
 {
     _viewModel = viewModel;
 }
Exemplo n.º 22
0
        public ActionResult Pattern(DesignerKey designerKey, string categoryKey, string reference, int p = 1)
        {
            // Modèle.
            var pagedList = _patternService.ListPreviews(designerKey, categoryKey, p, PreviewsPageSize_);

            if (pagedList == null)
            {
                return(new HttpNotFoundResult());
            }

            var views = _patternService.GetPatternViews(designerKey, categoryKey, reference);

            if (views.Count() == 0)
            {
                return(new HttpNotFoundResult());
            }

            var designer = GetDesigner_(designerKey, categoryKey);
            var category = (from _ in designer.Categories where _.Key == categoryKey select _).Single();

            var model = new PatternViewModel {
                Category     = category,
                Designer     = designer,
                PatternViews = from _ in views select PatternViewItem.Of(_, designer.DisplayName),
                Reference    = reference,
                IsFirstPage  = pagedList.IsFirstPage,
                IsLastPage   = pagedList.IsLastPage,
                PageCount    = pagedList.PageCount,
                PageIndex    = pagedList.PageIndex,
                Previews     = from _ in pagedList.Previews select PatternViewItem.Of(_, designer.DisplayName)
            };

            // Ontologie.
            Ontology.Title = String.Format(
                CultureInfo.CurrentUICulture,
                Strings.Designer_Pattern_TitleFormat,
                reference,
                model.Designer.DisplayName);
            Ontology.Description = String.Format(
                CultureInfo.CurrentUICulture,
                Strings.Designer_Pattern_DescriptionFormat,
                reference,
                model.Designer.DisplayName,
                category.DisplayName);
            //Ontology.SchemaOrg.ItemType = SchemaOrgType.ItemPage;
            Ontology.Relationships.CanonicalUrl = SiteMap.DesignerPattern(designerKey, categoryKey, reference, p);

            var image = views.First();

            SetOpenGraphImage_(designerKey, image.Reference, image.Variant);

            // LayoutViewModel.
            LayoutViewModel.AddAlternateUrls(Environment.Language, _ => _.DesignerPattern(designerKey, categoryKey, reference, p));
            LayoutViewModel.DesignerMenuCssClass = ViewUtility.DesignerClass(designerKey);
            LayoutViewModel.MainHeading          = String.Format(
                CultureInfo.CurrentUICulture,
                Strings.Designer_Pattern_MainHeadingFormat,
                category.DisplayName,
                reference.ToUpperInvariant());

            return(View(Constants.ViewName.Designer.Pattern, model));
        }
 public SaveCommand(PatternViewModel viewModel)
 {
     _viewModel        = viewModel;
     _przeliczServices = Di.DiContainer.Container.Resolve <ISaveServices>();
 }
Exemplo n.º 24
0
        public void Pattern_IsSetFromDataRegex()
        {
            var model = new PatternViewModel(new PatternData(new Regex("x")));

            Assert.Equal("x", model.Pattern.Value);
        }
Exemplo n.º 25
0
        private void SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var listbox = sender as ListBox;
            if (listbox == null) return;

            var selected_categories = listbox.SelectedItems.OfType<CategoryViewModel>();
            if (selected_categories.Any())
            {
                SelectedCategoryViewModel = selected_categories.Last();
                return;
            }

            var selected_patterns = listbox.SelectedItems.OfType<PatternViewModel>();
            if (selected_patterns.Any())
            {
                SelectedPatternViewModel = selected_patterns.Last();
                return;
            }
        }