Esempio n. 1
0
        public void Test()
        {
            var array = new BetterObservableCollection <string> {
                "Cat", "Dog", "Rat"
            };

            var wrapped = WrappedFilteredCollection.Create(array, s => "Big " + s, s => s.EndsWith("t") || s.EndsWith("e"));
            var second  = WrappedFilteredCollection.Create(wrapped, s => s.Replace("Big", "Small"), s => s.EndsWith("t"));

            array.Add("Mouse");

            Debug.WriteLine(string.Join(", ", array));
            Debug.WriteLine(string.Join(", ", wrapped));
            Debug.WriteLine(string.Join(", ", second));

            Assert.AreEqual("Big Cat", wrapped[0]);
            Assert.AreEqual("Big Rat", wrapped[1]);
            Assert.AreEqual("Big Mouse", wrapped[2]);
            Assert.AreEqual("Small Cat", second[0]);
            Assert.AreEqual("Small Rat", second[1]);
            Assert.AreEqual(3, wrapped.Count);
            Assert.AreEqual(2, second.Count);

            array.Add("Moose");
            Debug.WriteLine(string.Join(", ", array));
            Debug.WriteLine(string.Join(", ", wrapped));
            Debug.WriteLine(string.Join(", ", second));

            Assert.AreEqual("Big Moose", wrapped[3]);
            Assert.AreEqual(2, second.Count);

            /*array.Insert(1, "Mole");
             * Debug.WriteLine(string.Join(", ", array));
             * Debug.WriteLine(string.Join(", ", wrapped));
             * Debug.WriteLine(string.Join(", ", second));
             *
             * Assert.AreEqual("Big Mole", wrapped[1]);
             * Assert.AreEqual("Big Dog", wrapped[2]);
             * Assert.AreEqual("Small Mole", second[1]);
             * Assert.AreEqual("Small Dog", second[2]);
             *
             * array.Remove("Mouse");
             * Assert.AreEqual(5, wrapped.Count);
             * Assert.AreEqual(5, second.Count);
             *
             * array.ReplaceEverythingBy(new[] {
             *  "Human", "Alien"
             * });
             * Assert.AreEqual("Big Human", wrapped[0]);
             * Assert.AreEqual("Big Alien", wrapped[1]);
             * Assert.AreEqual("Small Human", second[0]);
             * Assert.AreEqual("Small Alien", second[1]);*/
        }
Esempio n. 2
0
        public void Test() {
            var array = new BetterObservableCollection<string> {
                "Cat", "Dog", "Rat"
            };

            var wrapped = WrappedCollection.Create(array, s => "Big " + s);
            var second = WrappedCollection.Create(wrapped, s => s.Replace("Big", "Small"));

            array.Add("Mouse");

            Debug.WriteLine(string.Join(", ", array));
            Debug.WriteLine(string.Join(", ", wrapped));
            Debug.WriteLine(string.Join(", ", second));

            Assert.AreEqual("Big Cat", wrapped[0]);
            Assert.AreEqual("Big Rat", wrapped[2]);
            Assert.AreEqual("Small Cat", second[0]);
            Assert.AreEqual("Small Rat", second[2]);
            Assert.AreEqual(4, wrapped.Count);

            array.Add("Moose");
            Debug.WriteLine(string.Join(", ", array));
            Debug.WriteLine(string.Join(", ", wrapped));
            Debug.WriteLine(string.Join(", ", second));

            Assert.AreEqual("Big Moose", wrapped[4]);
            Assert.AreEqual("Small Moose", second[4]);

            array.Insert(1, "Mole");
            Debug.WriteLine(string.Join(", ", array));
            Debug.WriteLine(string.Join(", ", wrapped));
            Debug.WriteLine(string.Join(", ", second));

            Assert.AreEqual("Big Mole", wrapped[1]);
            Assert.AreEqual("Big Dog", wrapped[2]);
            Assert.AreEqual("Small Mole", second[1]);
            Assert.AreEqual("Small Dog", second[2]);

            array.Remove("Mouse");
            Assert.AreEqual(5, wrapped.Count);
            Assert.AreEqual(5, second.Count);

            array.ReplaceEverythingBy(new[] {
                "Human", "Alien"
            });
            Assert.AreEqual("Big Human", wrapped[0]);
            Assert.AreEqual("Big Alien", wrapped[1]);
            Assert.AreEqual("Small Human", second[0]);
            Assert.AreEqual("Small Alien", second[1]);
        }
Esempio n. 3
0
 public void AddError(IAcError error)
 {
     if (HasError(error.Type) && !IsSeveralAllowed(error.Type))
     {
         return;
     }
     _errors.Add(error);
     if (Errors.Count == 1)
     {
         OnPropertyChanged(nameof(HasErrors));
         CommandManager.InvalidateRequerySuggested();
     }
 }
Esempio n. 4
0
            public async void SetSteamId(string steamId)
            {
                if (steamId == null)
                {
                    return;
                }

                _cancellationTokenSource?.Cancel();

                var existing = SteamProfiles.FirstOrDefault(x => x.SteamId == steamId);

                if (existing != null)
                {
                    SteamProfile = existing;
                    return;
                }

                var profile = new SteamProfile(steamId);

                SteamProfiles.Add(profile);
                SteamProfile = profile;

                profile.ProfileName = await SteamIdHelper.GetSteamName(steamId);
            }
Esempio n. 5
0
        /// <summary>
        /// Start server (all stdout stuff will end up in RunningLog).
        /// </summary>
        /// <exception cref="InformativeException">For some predictable errors.</exception>
        /// <exception cref="Exception">Process starting might cause loads of problems.</exception>
        public async Task RunServer(IProgress <AsyncProgressEntry> progress = null, CancellationToken cancellation = default(CancellationToken))
        {
            StopServer();

            if (!Enabled)
            {
                throw new InformativeException("Can’t run server", "Preset is disabled.");
            }

            if (HasErrors)
            {
                throw new InformativeException("Can’t run server", "Preset has errors.");
            }

            if (TrackId == null)
            {
                throw new InformativeException("Can’t run server", "Track is not specified.");
            }

            var serverExecutable = GetServerExecutableFilename();

            if (!File.Exists(serverExecutable))
            {
                throw new InformativeException("Can’t run server", "Server’s executable not found.");
            }

            if (SettingsHolder.Online.ServerPresetsUpdateDataAutomatically)
            {
                await PrepareServer(progress, cancellation);
            }

            var log = new BetterObservableCollection <string>();

            RunningLog = log;
            try {
                using (var process = new Process {
                    StartInfo =
                    {
                        FileName               = serverExecutable,
                        Arguments              = $"-c presets/{Id}/server_cfg.ini -e presets/{Id}/entry_list.ini",
                        UseShellExecute        = false,
                        WorkingDirectory       = Path.GetDirectoryName(serverExecutable) ?? "",
                        RedirectStandardOutput = true,
                        CreateNoWindow         = true,
                        RedirectStandardError  = true,
                    }
                }) {
                    process.Start();
                    SetRunning(process);
                    ChildProcessTracker.AddProcess(process);

                    progress?.Report(AsyncProgressEntry.Finished);

                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();
                    process.OutputDataReceived += (sender, args) => ActionExtension.InvokeInMainThread(() => log.Add(args.Data));
                    process.ErrorDataReceived  += (sender, args) => ActionExtension.InvokeInMainThread(() => log.Add($@"[color=#ff0000]{args.Data}[/color]"));

                    await process.WaitForExitAsync(cancellation);

                    if (!process.HasExitedSafe())
                    {
                        process.Kill();
                    }

                    log.Add($@"[CM] Stopped: {process.ExitCode}");
                }
            } finally {
                SetRunning(null);
            }
        }
Esempio n. 6
0
        private async Task ShootCar([NotNull] ToUpdatePreview toUpdate, string filterId, bool manualMode, bool applyImmediately, CancellationToken cancellation)
        {
            if (toUpdate == null)
            {
                throw new ArgumentNullException(nameof(toUpdate));
            }

            try {
                _currentCar      = toUpdate.Car;
                _resultDirectory = await Showroom.ShotAsync(new Showroom.ShotProperties {
                    AcRoot                = AcRootDirectory.Instance.Value,
                    CarId                 = toUpdate.Car.Id,
                    ShowroomId            = SelectedShowroom.Id,
                    SkinIds               = toUpdate.Skins?.Select(x => x.Id).ToArray(),
                    Filter                = filterId,
                    Fxaa                  = EnableFxaa,
                    SpecialResolution     = UseSpecialResolution,
                    MaximizeVideoSettings = MaximizeVideoSettings,
                    Mode                  = manualMode ? Showroom.ShotMode.ClassicManual : Showroom.ShotMode.Fixed,
                    UseBmp                = true,
                    DisableWatermark      = DisableWatermark,
                    DisableSweetFx        = DisableSweetFx,
                    ClassicCameraDx       = 0.0,
                    ClassicCameraDy       = 0.0,
                    ClassicCameraDistance = 5.5,
                    FixedCameraPosition   = CameraPosition,
                    FixedCameraLookAt     = CameraLookAt,
                    FixedCameraFov        = CameraFov,
                    FixedCameraExposure   = CameraExposure ?? 0d,
                }, this, cancellation);

                if (cancellation.IsCancellationRequested)
                {
                    return;
                }
            } catch (ProcessExitedException e) when(applyImmediately)
            {
                Errors.Add(new UpdatePreviewError(toUpdate, e.Message, AcLogHelper.TryToDetermineWhatsGoingOn()));
                return;
            }

            if (applyImmediately)
            {
                if (_resultDirectory == null)
                {
                    Errors.Add(new UpdatePreviewError(toUpdate, AppStrings.CarPreviews_SomethingWentWrong, AcLogHelper.TryToDetermineWhatsGoingOn()));
                }
                else
                {
                    Progress = AsyncProgressEntry.Indetermitate;
                    await ImageUtils.ApplyPreviewsAsync(AcRootDirectory.Instance.RequireValue, toUpdate.Car.Id, _resultDirectory, ResizePreviews,
                                                        new AcPreviewImageInformation {
                        Name  = toUpdate.Car.DisplayName,
                        Style = Path.GetFileNameWithoutExtension(UserPresetsControl.SelectedPresetFilename)
                    }, new Progress <Tuple <string, double?> >(t => {
                        Progress = new AsyncProgressEntry($"Applying freshly made previews ({t.Item1})…", t.Item2);
                    }), cancellation);
                }
            }
            else
            {
                if (_resultDirectory == null)
                {
                    SelectPhase(Phase.Error, AppStrings.CarPreviews_SomethingWentWrong, AcLogHelper.TryToDetermineWhatsGoingOn());
                    return;
                }

                ResultPreviewComparisons = new ObservableCollection <ResultPreviewComparison>(
                    Directory.GetFiles(_resultDirectory, "*.*").Select(x => {
                    var id = (Path.GetFileNameWithoutExtension(x) ?? "").ToLower();
                    return(new ResultPreviewComparison {
                        Name = toUpdate.Car.GetSkinById(id)?.DisplayName ?? id,

                        /* custom paths, because theoretically skin might no longer exist at this point */
                        LiveryImage = Path.Combine(toUpdate.Car.Location, @"skins", id, @"livery.png"),
                        OriginalImage = Path.Combine(toUpdate.Car.Location, @"skins", id, @"preview.jpg"),
                        UpdatedImage = x
                    });
                }));
            }
        }
Esempio n. 7
0
 private void InnerWrite(string message, string color = null, int level = 0, bool extraHalf = false)
 {
     _destination.Add($@"{@"  ".RepeatString(level * 2 + (extraHalf ? 1 : 0))}{
             (color != null ? $@"[color=#{color}]" : "")}{BbCodeBlock.Encode(message)}{(color != null ? @"[/color]" : "")}");
 }