Ejemplo n.º 1
0
        public LicenseManagerViewModel()
        {
            CheckLicense = AsyncCommand.Create((parameter, token) =>
            {
                IsLicenseValid     = false;
                IsCheckingFinished = false;
                return(Services.LicenseManager.Check(m_model, token));
            });

            CheckLicense.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "Execution" && CheckLicense.Execution != null)
                {
                    CheckLicense.Execution.PropertyChanged += (sender, args) =>
                    {
                        if (args.PropertyName == "IsCompleted")
                        {
                            if (!CheckLicense.Execution.IsCanceled)
                            {
                                LicenseManagerResult?res = CheckLicense.Execution.Result;

                                if (res == LicenseManagerResult.Ok)
                                {
                                    IsLicenseValid = true;
                                }
                                else if (res == LicenseManagerResult.InvalidKey)
                                {
                                    IsLicenseValid = false;
                                }
                                else if (res == LicenseManagerResult.ServerIsUnreachable)
                                {
                                    OnServerUnreachable();
                                    IsLicenseServerReachable = false;
                                }

                                IsCheckingFinished = true;
                            }
                        }
                    };
                }
            };

            ActivateLicense = AsyncCommand.Create((parameter, token) =>
            {
                IsLicenseValid     = false;
                IsCheckingFinished = false;
                return(Services.LicenseManager.Activate(m_model, token));
            });

            ActivateLicense.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "Execution" && CheckLicense.Execution != null)
                {
                    ActivateLicense.Execution.PropertyChanged += (sender, args) =>
                    {
                        if (args.PropertyName == "IsCompleted")
                        {
                            if (!ActivateLicense.Execution.IsCanceled)
                            {
                                LicenseManagerResult?res = ActivateLicense.Execution.Result;

                                if (res == LicenseManagerResult.Ok)
                                {
                                    IsLicenseValid = true;
                                }
                                else if (res == LicenseManagerResult.InvalidKey)
                                {
                                    MessageBox.Show("Invalid key ");
                                }
                                else if (res == LicenseManagerResult.AlreadyActivated)
                                {
                                    MessageBox.Show("This key is already activated for other device");
                                }
                                else if (res == LicenseManagerResult.ServerIsUnreachable)
                                {
                                    OnServerUnreachable();
                                    IsLicenseServerReachable = false;
                                }
                            }
                        }
                    };
                }
            };

            DeactivateLicense = AsyncCommand.Create((parameter, token) =>
            {
                IsDeactivated = false;
                return(Services.LicenseManager.Deactivate(m_model, token));
            });

            DeactivateLicense.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "Execution" && DeactivateLicense.Execution != null)
                {
                    DeactivateLicense.Execution.PropertyChanged += (sender, args) =>
                    {
                        if (args.PropertyName == "IsCompleted")
                        {
                            if (!DeactivateLicense.Execution.IsCanceled)
                            {
                                LicenseManagerResult?res = DeactivateLicense.Execution.Result;

                                if (res == LicenseManagerResult.Ok)
                                {
                                    IsDeactivated = true;
                                }
                                else if (res == LicenseManagerResult.ServerIsUnreachable)
                                {
                                    OnServerUnreachable();
                                    IsLicenseServerReachable = false;
                                }
                                else
                                {
                                    MessageBox.Show("Deactivation is failed. Please try later.");
                                }
                            }
                        }
                    };
                }
            };
        }
Ejemplo n.º 2
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));
        }