Exemplo n.º 1
0
        private async Task UpdateProjectReverseAsync(CancellationManager cmSelf)
        {
            try
            {
                while (true)
                {
                    if (cmSelf.Token.IsCancellationRequested)
                    {
                        cmSelf.Token.ThrowIfCancellationRequested();
                    }

                    var proxy = new MonitorRepository();
                    try
                    {
                        await proxy.UpdateProjectReverseAsync();
                    }
                    catch (Exception ex)
                    {
                        LogManager.Instance.Error($"{ex.Message}");
                    }
                    LastUpdate = DateTime.Now;
                    await Task.Delay(FREQ_UPDATE);
                }
            }
            catch (Exception)
            {
                //do nothing
            }
            finally
            {
                cmSelf.Dispose();
            }
        }
        // GET: api/CancellationBooking/5
        public IHttpActionResult Get(string bookingNumber)
        {
            CancellationManager cancellation = new CancellationManager();

            cancellation.CancelForAllProviders(bookingNumber);
            return(Ok(cancellation.cancelData));
        }
Exemplo n.º 3
0
 public virtual void Handle(T item)
 {
     if (Handler != null)
     {
         CancellationManager.CheckForSignal();
         Handler.Handle(item);
     }
 }
Exemplo n.º 4
0
 public CallCollector(CancellationManager cancellationManager)
     : this()
 {
     this.CancellationManager = cancellationManager;
     this.token       = this.CancellationManager.GetToken();
     this.Services    = new ConcurrentDictionary <Type, CallAggregationServiceDescription>();
     this.CallResults = new ConcurrentDictionary <CallAggregationCallDescription, TaskResultDispatcher>();
 }
Exemplo n.º 5
0
        private async Task <bool> LoginBulkAsync(CancellationManager manager)
        {
            try
            {
                var ctrls = new List <UcSettingAccountItem>();
                foreach (Control ctrl in flowAccount.Controls)
                {
                    var ctrlAccount = ctrl as UcSettingAccountItem;
                    if (ctrlAccount != null)
                    {
                        if (!ctrlAccount.IsEnabled)
                        {
                            ctrls.Add(ctrlAccount);
                        }
                    }
                }

                var delayMax = chkLoginProtect.Checked ? 30 : 0;
                var delayMin = chkLoginProtect.Checked ? 5 : 0;
                var rd       = new Random(DateTime.Now.Second);
                ctrls = ctrls.OrderBy(c => rd.Next()).ToList();
                for (var i = 0; i < ctrls.Count; i++)
                {
                    if (!manager.Token.IsCancellationRequested)
                    {
                        var ctrlAccount = ctrls[i];
                        await ctrlAccount.TryLogin();

                        if (i == ctrls.Count - 1)
                        {
                            break;
                        }

                        await Task.Delay(rd.Next(delayMin, delayMax) * 1000);
                    }
                    else
                    {
                        manager.Token.ThrowIfCancellationRequested();
                    }
                }
            }
            catch (Exception)
            {
                //do nothing
            }
            finally
            {
                manager.Dispose();
            }

            return(true);
        }
Exemplo n.º 6
0
    /// <summary>
    /// Instantiates a prompt object. This object can be re-used for multiple invocations of <see cref="ReadLineAsync()"/>.
    /// </summary>
    /// <param name="persistentHistoryFilepath">The filepath of where to store history entries. If null, persistent history is disabled.</param>
    /// <param name="callbacks">A collection of callbacks for modifying and intercepting the prompt's behavior</param>
    /// <param name="console">The implementation of the console to use. This is mainly for ease of unit testing</param>
    /// <param name="configuration">If null, default configuration is used.</param>
    public Prompt(
        string?persistentHistoryFilepath = null,
        PromptCallbacks?callbacks        = null,
        IConsole?console = null,
        PromptConfiguration?configuration = null)
    {
        this.console = console ?? new SystemConsole();
        this.console.InitVirtualTerminalProcessing();

        this.configuration       = configuration ?? new PromptConfiguration();
        this.history             = new HistoryLog(persistentHistoryFilepath, this.configuration.KeyBindings);
        this.cancellationManager = new CancellationManager(this.console);
        this.clipboard           = (console is IConsoleWithClipboard consoleWithClipboard) ? consoleWithClipboard.Clipboard : new Clipboard();

        promptCallbacks  = callbacks ?? new PromptCallbacks();
        this.highlighter = new SyntaxHighlighter(promptCallbacks, PromptConfiguration.HasUserOptedOutFromColor);
    }
Exemplo n.º 7
0
        /// <summary>
        /// Ported from void global_scope_t::report_error(const std::exception& err)
        /// </summary>
        public void ReportError(Exception ex)
        {
            VirtualConsole.Output.Flush();   // first display anything that was pending

            if (!CancellationManager.IsCancellationRequested)
            {
                // Display any pending error context information
                string context = ErrorContext.Current.GetContext();
                if (!String.IsNullOrWhiteSpace(context))
                {
                    VirtualConsole.Error.WriteLine(context);
                }

                VirtualConsole.Error.WriteLine(String.Format("Error: {0}", ex.Message));
            }
            else
            {
                CancellationManager.DiscardCancellationRequest();
            }
        }
Exemplo n.º 8
0
 private async Task RefreshAsync(CancellationManager cmSelf)
 {
     try
     {
         while (true)
         {
             if (cmSelf.Token.IsCancellationRequested)
             {
                 cmSelf.Token.ThrowIfCancellationRequested();
             }
             BindMessage();
             await Task.Delay(FREQ_REFRESH);
         }
     }
     catch (Exception)
     {
         //do nothing
     }
     finally
     {
         cmSelf.Dispose();
     }
 }
Exemplo n.º 9
0
 public void CancellationManager_DiscardCancellationRequest_RestoresDefaultSignalValue()
 {
     MainApplicationContext.Current.CancellationSignal = CaughtSignalEnum.INTERRUPTED;
     CancellationManager.DiscardCancellationRequest();
     Assert.Equal(CaughtSignalEnum.NONE_CAUGHT, MainApplicationContext.Current.CancellationSignal);
 }
Exemplo n.º 10
0
 public void CancellationManager_CheckForSignal_RaisesRTEIfSomethingCaught()
 {
     MainApplicationContext.Current.CancellationSignal = CaughtSignalEnum.INTERRUPTED;
     Assert.Throws <RuntimeError>(() => CancellationManager.CheckForSignal());
 }
Exemplo n.º 11
0
 public void CancellationManager_CheckForSignal_DoesNothingIfNoneCaught()
 {
     MainApplicationContext.Current.CancellationSignal = CaughtSignalEnum.NONE_CAUGHT;
     CancellationManager.CheckForSignal();
 }
Exemplo n.º 12
0
        public int Execute(string argString)
        {
            using (MainApplicationContext.AcquireCurrentThread())
            {
                var envp = VirtualEnvironment.GetEnvironmentVariables();
                var args = CommandLine.PreprocessSingleQuotes(argString);

                int status = 1;

                // The very first thing we do is handle some very special command-line
                // options, since they affect how the environment is setup:
                //
                //   --verify            ; turns on memory tracing
                //   --verbose           ; turns on logging
                //   --debug CATEGORY    ; turns on debug logging
                //   --trace LEVEL       ; turns on trace logging
                //   --memory            ; turns on memory usage tracing
                //   --init-file         ; directs ledger to use a different init file
                GlobalScope.HandleDebugOptions(args);
                // initialize_memory_tracing - [DM] #memory-tracing
                Logger.Current.Info(() => LedgerStarting);
                // ::textdomain("ledger"); - [DM] #localization
                GlobalScope globalScope = null;
                try
                {
                    // Create the session object, which maintains nearly all state relating to
                    // this invocation of Ledger; and register all known journal parsers.
                    globalScope = new GlobalScope(envp);
                    globalScope.Session.FlushOnNextDataFile = true;

                    // Look for options and a command verb in the command-line arguments
                    BindScope boundScope = new BindScope(globalScope, globalScope.Report);
                    args = globalScope.ReadCommandArguments(boundScope, args);

                    if (globalScope.ScriptHandler.Handled)
                    {
                        // Ledger is being invoked as a script command interpreter
                        globalScope.Session.ReadJournalFiles();

                        status = 0;

                        using (StreamReader sr = FileSystem.GetStreamReader(globalScope.ScriptHandler.Str()))
                        {
                            while (status == 0 && !sr.EndOfStream)
                            {
                                string line = sr.ReadLine().Trim();
                                if (!line.StartsWith("#"))
                                {
                                    status = globalScope.ExecuteCommandWrapper(StringExtensions.SplitArguments(line), true);
                                }
                            }
                        }
                    }
                    else if (args.Any())
                    {
                        // User has invoke a verb at the interactive command-line
                        status = globalScope.ExecuteCommandWrapper(args, false);
                    }
                    else
                    {
                        // Commence the REPL by displaying the current Ledger version
                        VirtualConsole.Output.WriteLine(globalScope.ShowVersionInfo());

                        globalScope.Session.ReadJournalFiles();

                        bool exitLoop = false;

                        VirtualConsole.ReadLineName = "Ledger";

                        string p;
                        while ((p = VirtualConsole.ReadLine(globalScope.PromptString())) != null)
                        {
                            string expansion = null;
                            int    result    = VirtualConsole.HistoryExpand(p.Trim(), ref expansion);

                            if (result < 0 || result == 2)
                            {
                                throw new LogicError(String.Format(LogicError.ErrorMessageFailedToExpandHistoryReference, p));
                            }
                            else if (expansion != null)
                            {
                                VirtualConsole.AddHistory(expansion);
                            }

                            CancellationManager.CheckForSignal();

                            if (!String.IsNullOrWhiteSpace(p) && p != "#")
                            {
                                if (String.Compare(p, "quit", true) == 0)
                                {
                                    exitLoop = true;
                                }
                                else
                                {
                                    globalScope.ExecuteCommandWrapper(StringExtensions.SplitArguments(p), true);
                                }
                            }

                            if (exitLoop)
                            {
                                break;
                            }
                        }
                        status = 0;    // report success
                    }
                }
                catch (CountError errors)
                {
                    // used for a "quick" exit, and is used only if help text (such as
                    // --help) was displayed
                    status = errors.Count;
                }
                catch (Exception err)
                {
                    if (globalScope != null)
                    {
                        globalScope.ReportError(err);
                    }
                    else
                    {
                        VirtualConsole.Error.WriteLine(String.Format(ExceptionDuringInitialization, err.Message));
                    }
                }

                if (globalScope != null)
                {
                    globalScope.QuickClose();
                    globalScope.Dispose();              // {DM] It is the most appropriate place to call Dispose for the global scope.
                }
                Logger.Current.Info(() => LedgerEnded); // let global_scope leak!

                // Return the final status to the operating system, either 1 for error or 0
                // for a successful completion.
                return(status);
            }
        }
Exemplo n.º 13
0
 public void CancellationManager_CheckForSignal_RaisesRTEIfSomethingCaught()
 {
     MainApplicationContext.Current.CancellationSignal = CaughtSignalEnum.INTERRUPTED;
     CancellationManager.CheckForSignal();
 }
Exemplo n.º 14
0
        private void PerformSearching(CancellationManager manager)
        {
            Task.Factory.StartNew(() => {
                var settingInfo = BusinessCache.Settings;
                var rd          = new Random();
                var proxySearch = new ProxySearch();
                try
                {
                    while (!manager.Token.IsCancellationRequested)
                    {
                        var delay = (rd.Next(0, settingInfo.DelayTransfer));

                        var searchProxy = BusinessCache.UserProxies.GetRandomProxy(settingInfo.PageDiff);
                        if (searchProxy != null)
                        {
                            try
                            {
                                var list = new List <ClientPortionTransferItem>();
                                for (var i = 0; i < settingInfo.SearchingKeywords.Count; i++)
                                {
                                    var searchingKey = settingInfo.SearchingKeywords[i];
                                    for (var j = settingInfo.PageFrom; j <= settingInfo.PageTo; j++)
                                    {
                                        var subList = proxySearch.SearchAsync(searchProxy.TokenOffical, ProxySearch.Parameter.Create(searchingKey, j)).Result;
                                        if (subList != null && subList.Count > 0)
                                        {
                                            list.AddRange(subList.rowSet);
                                        }
                                        if (j < settingInfo.PageTo)
                                        {
                                            Task.Delay(1000);
                                        }
                                    }
                                    if (i < settingInfo.SearchingKeywords.Count - 1)
                                    {
                                        Task.Delay(1000);
                                    }
                                }

                                BusinessCache.PoolTranser.Clear();
                                BusinessCache.PoolTranser.AddRange(list);
                                BusinessCache.PoolTranser.UpdateFromPayment(BusinessCache.ProjectPayments);
                            }
                            catch (Exception ex)
                            {
                                LogManager.Instance.Error($"{ex.Message}");
                            }

                            var msg = $"{BusinessCache.PoolTranser.TopItem.GetProjectInformation()} {searchProxy.UserName} {settingInfo.FreqTransfer}s+{delay}s";
                            LogManager.Instance.Message(msg);
                        }
                        else
                        {
                            throw new Exception("no proxy found");
                        }

                        Task.Delay((settingInfo.FreqTransfer + delay) * 1000).Wait(manager.Token);
                    }
                    ;
                    manager.Token.ThrowIfCancellationRequested();
                }
                catch (Exception ex)
                {
                    LogManager.Instance.Error($"{ex.Message}");
                }
                finally
                {
                    manager.Dispose();
                }
            }, manager.Token);
        }
Exemplo n.º 15
0
 public KeepAliveChannelProxy()
 {
     this.cancellationManager = new CancellationManager();
 }
Exemplo n.º 16
0
 public CallCollector(CancellationManager cancellationManager, bool measureDuration)
     : this(cancellationManager)
 {
     this.MeasureDuration = measureDuration;
 }