Esempio n. 1
0
        private void HandleCompilePackageListStatusComplete(Action action)
        {
            IsWorking.SetValue(false);
            Operation.SetValue(null);

            PackageListStatus.SetValue((PackageListStatus)action.Payload);
        }
Esempio n. 2
0
        private void HandlePackageInstallationStarted(Action action)
        {
            var args = (InstallPackageArgs)action.Payload;

            IsWorking.SetValue(true);
            Operation.SetValue("Installing " + args.PackageName + "...");
        }
Esempio n. 3
0
        private async Task <bool> WorkAsync(Func <ProfileItem, Task <bool> > perform, Func <ProfileItem, bool> judge, ProfileItem targetProfile = null)
        {
            var targetProfileCopy = targetProfile ?? Profiles.FirstOrDefault(x => x.IsTarget);

            if (targetProfileCopy == null)
            {
                return(false);
            }

            IsWorking.TurnOn();
            try
            {
                var timeoutTime = DateTime.Now.Add(_workingTimeoutDuration);

                if (!await perform(targetProfileCopy))
                {
                    return(false);
                }

                await Task.Delay(_workingFirstInterval);

                using (var cts = new CancellationTokenSource())
                {
                    while (timeoutTime > DateTime.Now)
                    {
                        try
                        {
                            await Task.WhenAll(
                                Task.Run(async() =>
                            {
                                await LoadProfilesAsync(false);

                                if (judge(targetProfileCopy))
                                {
                                    cts.Cancel();
                                }
                            }),
                                Task.Delay(_workingSecondInterval, cts.Token));
                        }
                        catch (TaskCanceledException)
                        {
                        }

                        if (cts.IsCancellationRequested)
                        {
                            return(true);
                        }
                    }
                    return(false);
                }
            }
            finally
            {
                IsWorking.TurnOff();
            }
        }
Esempio n. 4
0
 private void ShowWorkingTime()
 {
     IsWorking
     .Select(x => new { Value = x, DateTime.Now.Ticks })
     .Pairwise()
     .Where(x => x.OldItem.Value && !x.NewItem.Value)
     .Select(x => (x.NewItem.Ticks - x.OldItem.Ticks) / TimeSpan.TicksPerMillisecond)
     .Subscribe(x => Debug.WriteLine($"Working Time: {x}"))
     .AddTo(this.Subscription);
 }
Esempio n. 5
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = RecoveriesLeft.GetHashCode();
         hashCode = (hashCode * 397) ^ (Module != null ? Module.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ IsWorking.GetHashCode();
         return(hashCode);
     }
 }
Esempio n. 6
0
        private void HandlePackageInstallationComplete(Action action)
        {
            var args = (InstallPackageArgs)action.Payload;

            var installedPackages = InstalledPackages.Value;

            installedPackages.Packages.Add(new InstalledPackage(args.PackageName, args.Version, args.GitUrl));

            InstalledPackages.SetValue(installedPackages);
            IsWorking.SetValue(false);
            Operation.SetValue(null);

            WritePackagesJson();
        }
Esempio n. 7
0
        private void HandleRemovePackageComplete(Action action)
        {
            var package = (AvailablePackage)action.Payload;

            IsWorking.SetValue(false);
            Operation.SetValue(null);

            var installedPackages = InstalledPackages.Value;

            installedPackages.Packages.RemoveAll(p => p.Name == package.Name);
            InstalledPackages.SetValue(installedPackages);

            WritePackagesJson();
        }
Esempio n. 8
0
        private void HandleSwitchPackageVersionComplete(Action action)
        {
            var args = (SwitchPackageArgs)action.Payload;

            var installedPackages = InstalledPackages.Value;
            var package           = installedPackages.Packages.FirstOrDefault(p => p.Name == args.Package.Name);

            package.Version = args.Version;

            InstalledPackages.SetValue(installedPackages);

            WritePackagesJson();

            IsWorking.SetValue(false);
            Operation.SetValue(null);
        }
Esempio n. 9
0
        private async Task <bool> WorkAsync(ProfileItem targetProfile, Func <ProfileItem, Task <bool> > perform)
        {
            try
            {
                Interlocked.Increment(ref _workCount);
                IsWorking.TurnOn();

                return(await perform.Invoke(targetProfile));
            }
            finally
            {
                if (Interlocked.Decrement(ref _workCount) == 0)
                {
                    IsWorking.TurnOff();
                }
            }
        }
Esempio n. 10
0
 private void HandleCompilePackageListStatusStarted(Action action)
 {
     PackageListStatus.SetValue(null);
     IsWorking.SetValue(true);
     Operation.SetValue("Compiling status of each package");
 }
Esempio n. 11
0
 private void HandleSwitchPackageVersionStarted(Action action)
 {
     IsWorking.SetValue(true);
     Operation.SetValue("Switching package version");
 }
Esempio n. 12
0
 private void HandleRemovePackageStarted(Action action)
 {
     IsWorking.SetValue(true);
     Operation.SetValue("Removing " + ((AvailablePackage)action.Payload).Name + "...");
 }
Esempio n. 13
0
 public override string ToString()
 {
     IsWorking?.Invoke(WorkingStatus());
     return(base.ToString() + "Number Of Cows = " + NumberOfCows + '\n' + "Number Of Chickens = " + NumberOfChickens + '\n' + "Meat per month = " + MeatPerMonth() + '\n');
 }
Esempio n. 14
0
 public override string ToString()
 {
     IsWorking?.Invoke(WorkingStatus());
     return(base.ToString() + "Number Of Cows = " + NumberOfCows + '\n' + "Milk per day = " + MilkPerDay() + '\n');
 }