async void HandleGameSetChanged(Game x)
 {
     _settings.Ready = false;
     _settings.GameOptions.RecentGameSet = x == null ? null : new RecentGameSet(x);
     OnPropertyChanged(nameof(ActiveGame));
     await
     TaskExt.StartLongRunningTask(() => TryActiveGameChanged(x))
     .ConfigureAwait(false);
 }
Example #2
0
 Task RunInstaller() => TaskExt.StartLongRunningTask(() => {
     using (var p = Process.Start(_tmpFile, "-install")) {
         //  /vREINSTALL=ALL /vREINSTALLMODE=vomus /v/qb
         p.WaitForExit();
     }
     if (!IsInstalled())
     {
         throw new InstallationFailed();
     }
 });
Example #3
0
        async Task PerformUnpack()
        {
            _statusRepo.Action = RepoStatus.Unpacking;
            _progress.Reset(RepoStatus.Unpacking);
            await _restarter.TryWithUacFallback(TaskExt.StartLongRunningTask(
                                                    () => Tools.Compression.Unpack(_sourceFile, _destination, true)),
                                                "files").ConfigureAwait(false);

            _progress.Update(null, 100);
            _statusRepo.UpdateProgress(90);
        }
        public override Task Start(uint appId, Uri uri)
        {
            _uri = uri;
            var t2 = TaskExt.StartLongRunningTask(async() => {
                using (var drainer = new Drainer(uri)) {
                    await drainer.Drain().ConfigureAwait(false);
                }
            });

            // TODO: Test the connection?
            return(TaskExt.Default);
        }
Example #5
0
 protected override void OnStartup(StartupEventArgs e)
 {
     base.OnStartup(e);
     _bootstrapper = new WpfAppBootstrapper(Environment.GetCommandLineArgs().Skip(1).ToArray(),
                                            Assembly.GetEntryAssembly().Location.ToAbsoluteFilePath().ParentDirectoryPath);
     _bootstrapper.Configure();
     if (_bootstrapper.CommandMode)
     {
         HandleSingleInstance();
     }
     _cmBs = new CMBootstrapper <string>(_bootstrapper);
     TaskExt.StartLongRunningTask(StartupInternal).WaitSpecial();
 }
Example #6
0
        public virtual Task Run(IPEndPoint http, IPEndPoint https, CancellationToken cancelToken)
        {
            var urls = BuildUrls(http, https);

            var hostBuilder = new WebHostBuilder();

            //        .UseContentRoot(Directory.GetCurrentDirectory())
            ConfigureBuilder(hostBuilder);
            hostBuilder.UseUrls(urls.ToArray());
            var webHost = hostBuilder.Build();

            return(TaskExt.StartLongRunningTask(() => webHost.Run(cancelToken), cancelToken));
        }
Example #7
0
        public static Task RunningQueue <T>(this BlockingCollection <T> block, int maxThreads, Action <T> act)
        {
            var tasks = Enumerable.Range(1, maxThreads > 0
                    ? maxThreads
                    : 1)
                        .Select(x => TaskExt.StartLongRunningTask(() => {
                foreach (var item in block.GetConsumingEnumerable())
                {
                    act(item);
                }
            }));

            return(Task.WhenAll(tasks));
        }
Example #8
0
        private static async Task <int> HandleNative(ISteamSessionLocator locator, bool inclRules,
                                                     List <Tuple <string, string> > filter, Action <ArmaServerInfoModel> act)
        {
            var api = new SteamApi(locator);

            var degreeOfParallelism = inclRules ? 30 : 1;

            using (var bc = new BlockingCollection <ArmaServerInfoModel>()) {
                // TODO: better MT model
                var bcT = TaskExt.StartLongRunningTask(async() => {
                    await Task.WhenAll(Enumerable.Range(1, degreeOfParallelism).Select(_ =>
                                                                                       Task.Run(async() => {
                        foreach (var s in bc.GetConsumingEnumerable())
                        {
                            await UpdateServerInfo(s, api, inclRules).ConfigureAwait(false);
                            act(s);
                        }
                    })
                                                                                       ));
                });
                var c2 = await api.GetServerInfo(locator.Session.AppId, x => {
                    try {
                        var ip        = x.m_NetAdr.GetQueryAddressString().Split(':').First();
                        var ipAddress = IPAddress.Parse(ip);
                        var map       = x.GetMap();
                        var s         = new ArmaServerInfoModel(new IPEndPoint(ipAddress, x.m_NetAdr.GetQueryPort()))
                        {
                            ConnectionEndPoint = new IPEndPoint(ipAddress, x.m_NetAdr.GetConnectionPort()),
                            Name            = x.GetServerName(),
                            Tags            = x.GetGameTags(),
                            Mission         = string.IsNullOrEmpty(map) ? null : x.GetGameDescription(),
                            Map             = map,
                            Ping            = x.m_nPing,
                            MaxPlayers      = x.m_nMaxPlayers,
                            CurrentPlayers  = x.m_nPlayers,
                            RequirePassword = x.m_bPassword,
                            IsVacEnabled    = x.m_bSecure,
                            ServerVersion   = x.m_nServerVersion
                        };
                        bc.Add(s);
                    } catch (Exception ex) {
                        Console.WriteLine(ex);
                    }
                }, filter);

                bc.CompleteAdding();
                await bcT;
                return(c2);
            }
        }
Example #9
0
        public static async Task SimpleRunningQueue <T>(this IEnumerable <T> items, int maxThreads,
                                                        Action <BlockingCollection <T> > mainAct, Action <T> act)
        {
            var queue = new ConcurrentQueue <T>(items);

            using (var blockingCollection = new BlockingCollection <T>(queue)) {
                var syncTask    = TaskExt.StartLongRunningTask(() => mainAct(blockingCollection));
                var monitorTask = blockingCollection.RunningQueue(maxThreads, act);

                await syncTask.ConfigureAwait(false);

                blockingCollection.CompleteAdding();
                await monitorTask.ConfigureAwait(false);
            }
        }
Example #10
0
        public static Task RunningQueue(this BlockingCollection <Action> block, int maxThreads,
                                        CancellationToken token = default(CancellationToken))
        {
            var tasks = Enumerable.Range(1, maxThreads > 0
                    ? maxThreads
                    : 1)
                        .Select(x => TaskExt.StartLongRunningTask(() => {
                foreach (var item in block.GetConsumingEnumerable(token))
                {
                    item();
                }
            }, token));

            return(Task.WhenAll(tasks));
        }
Example #11
0
        public static Task SimpleQueue <T>(this IEnumerable <T> items, int maxThreads, Action <T> act)
        {
            var queue = new ConcurrentQueue <T>(items);

            var tasks = Enumerable.Range(1, maxThreads > 0
                    ? Math.Min(maxThreads, queue.Count)
                    : 1)
                        .Select(x => TaskExt.StartLongRunningTask(() => {
                T item;
                while (queue.TryDequeue(out item))
                {
                    act(item);
                }
            }));

            return(Task.WhenAll(tasks));
        }
Example #12
0
                private async Task OnlyCopyIfHashMisMatch(IAbsoluteFilePath source, IAbsoluteFilePath destination,
                                                          ITProgress status)
                {
                    if (
                        await
                        TaskExt.StartLongRunningTask(
                            () => HashEncryption.MD5FileHash(source) != HashEncryption.MD5FileHash(destination))
                        .ConfigureAwait(false))
                    {
                        await CopyAsyncInternal(source, destination, true, status).ConfigureAwait(false);

                        return;
                    }
                    this.Logger()
                    .Info("Source and destination files equal. Source: {0}, Destination: {1}", source,
                          destination);
                }
Example #13
0
        public static void Main(string[] args)
        {
            var entryAssembly = typeof(Program).GetTypeInfo().Assembly;

            MainLog.logManager = new Lazy <ILogManager>(() => new DummyLogManager());
            var rootPath = entryAssembly.Location.ToAbsoluteFilePath().ParentDirectoryPath;

            CommonBase.AssemblyLoader = new AssemblyLoader(entryAssembly, null, rootPath);
            Common.Flags = new Common.StartupFlags(args, true);

            var bs = new CoreAppBootstrapper(args, rootPath);

            bs.Configure();

            TaskExt.StartLongRunningTask(() => Start(bs)).WaitAndUnwrapException();

            Console.WriteLine("Hello world!");
            Console.ReadLine();
        }
Example #14
0
 private void HandleUpdateStateInBackground()
 => TaskExt.StartLongRunningTask(Container.GetInstance <SelfUpdateHandler>().HandleUpdateState);
Example #15
0
 protected override Task ScanForLocalContentImpl()
 => TaskExt.StartLongRunningTask(() => ScanForLocalContentInternal());
Example #16
0
 public Task CleanAsync(IAbsoluteDirectoryPath workingDirectory,
                        IReadOnlyCollection <IRelativePath> exclusions, IEnumerable <string> fileTypes,
                        IAbsoluteDirectoryPath backupPath)
 => TaskExt.StartLongRunningTask(() => Clean(workingDirectory, exclusions, fileTypes, backupPath));
Example #17
0
 public Task CheckoutAsync(ProgressLeaf progressLeaf, bool confirmChecksums = true)
 => TaskExt.StartLongRunningTask(() => Checkout(progressLeaf, confirmChecksums));
Example #18
0
 private void TryHandleFirefoxInBackground()
 => BackgroundTasks.RegisterTask(TaskExt.StartLongRunningTask(() => TryHandleFirefox()));
Example #19
0
 public Task ReadLoop() => TaskExt.StartLongRunningTask(ReadLoopInternal, _token);
Example #20
0
 GetMissionsToDownload(
     IEnumerable <Mission> missions,
     IAbsoluteDirectoryPath destination, StatusRepo repo)
 => TaskExt.StartLongRunningTask(() => SumMissions(destination, missions.ToDictionary(x => x,
                                                                                      x => (ITransferStatus) new Status(x.FileName, repo))));
Example #21
0
 private void TryInstallFlashInBackground() => TaskExt.StartLongRunningTask(InstallFlash);
 static Task RestartExplorer() => TaskExt.StartLongRunningTask(() => RestartExplorerInternal());
Example #23
0
 public Task Run(CancellationToken token)
 => TaskExt.StartLongRunningTask(() => RunInternal(token), token);
Example #24
0
 private void InstallToolsInBackground() => TaskExt.StartLongRunningTask(InstallTools);
Example #25
0
 public Task CheckoutWithoutRemovalAsync(ProgressLeaf progressLeaf)
 => TaskExt.StartLongRunningTask(() => CheckoutWithoutRemoval(progressLeaf));
 public Task <string> ProcessUserconfig(IAbsoluteDirectoryPath modPath, IAbsoluteDirectoryPath gamePath,
                                        string exisitingChecksum, bool force = true)
 =>
 TaskExt.StartLongRunningTask(() => ProcessUserconfigInternal(modPath, gamePath, exisitingChecksum, force));
Example #27
0
 protected Task End() => TaskExt.StartLongRunningTask(EndInternal);
Example #28
0
 public Task Run() => TaskExt.StartLongRunningTask(RunInternal);
Example #29
0
 public Task <bool> ScanForGames() => TaskExt.StartLongRunningTask(() => ScanAllDrives());