Exemplo n.º 1
0
        public ReleaseScheduleViewModel()
        {
            Start = AsyncCommand.Create((parameter, token) =>
            {
                if (!TierControl.TryGetQuota(Release.TasksCount, m_model.Footsite.Type))
                {
                    MessageBoxResult res = MessageBox.Show(
                        "Count of tasks exceeds the count limit of Tasks of your membership. Upgrade memebership?",
                        "Limit", MessageBoxButton.YesNo);

                    if (res == MessageBoxResult.Yes)
                    {
                        Process.Start("https://projectdestroyer.com/product/project-destroyer-sneaker-software-upgrade-beta/");
                    }

                    Task <bool> fakeTask = new Task <bool>(() => true);
                    fakeTask.Start();

                    return(fakeTask);
                }

                if (m_task != null)
                {
                    m_task.SuccessfulCheckout -= OnSuccessfulCheckout;
                }

                if (Release.Footsite.Type == FootsiteType.Footlocker)
                {
                    m_task = new FootlockerBot(m_model);
                }
                else if (Release.Footsite.Type == FootsiteType.SupremeUSA)
                {
                    m_task = new SupremeUSABot(m_model);
                }
                else if (Release.Footsite.Type == FootsiteType.SupremeEurope)
                {
                    m_task = new SupremeEUBot(m_model);
                }
                else if (Release.Footsite.Type == FootsiteType.SupremeJapan)
                {
                    m_task = new SupremeJapanBot(m_model);
                }
                else
                {
                    m_task = new ReleaseTaskBase(m_model);
                }

                m_task.SuccessfulCheckout += OnSuccessfulCheckout;

                ReleaseTask.Model = m_task;

                return(m_task.Start(token));
            });

            Schedule = new DelegateCommand(parameter =>
            {
                IsSchedulingEnabled = false;

                DateTime?startTime = m_model.StartTime;
                DateTime?endTime   = m_model.EndTime;

                ScheduleEditor editor = new ScheduleEditor()
                {
                    DataContext = new ReleaseScheduleEditViewModel()
                    {
                        Model = m_model
                    }
                };

                if (!(editor.ShowDialog() ?? false))
                {
                    m_model.StartTime = startTime;
                    m_model.EndTime   = endTime;
                }

                IsSchedulingEnabled = true;
            },
                                           parameter => ReleaseTask.State != ReleaseTaskState.Working);

            View = new DelegateCommand(parameter =>
            {
                ReleaseTaskViewer viewer = new ReleaseTaskViewer()
                {
                    DataContext = new ReleaseTaskViewModel()
                    {
                        Model = m_task
                    }
                };

                viewer.ShowDialog();
            },
                                       parameter => ReleaseTask.State == ReleaseTaskState.Working);

            Edit = new DelegateCommand(parameter =>
            {
                IsSchedulingEnabled = false;

                ReleaseEditor editor = null;
                Release release      = new Release(m_model);

                editor = new ReleaseEditor()
                {
                    DataContext = new ReleaseEditViewModel()
                    {
                        Model            = release,
                        CheckoutProfiles = CheckoutProfiles,
                        MaxTasksCount    = TierControl.GetRemainder() + Release.TasksCount
                    }
                };

                if (editor.ShowDialog() ?? false)
                {
                    release.CopyTo(m_model);
                }

                IsSchedulingEnabled = true;
            },
                                       parameter => ReleaseTask.State == ReleaseTaskState.Idle);

            OpenCaptchaHarvester = new DelegateCommand(parameter =>
            {
                m_captchaHarvester = new CaptchaHarvester()
                {
                    DataContext = Release.Model.CaptchaHarvester
                };

                m_captchaHarvester.Show();
            },
                                                       parameter => Release.Model.CaptchaHarvester != null && !(m_captchaHarvester?.IsLoaded ?? false));
        }