/// <summary>
 /// Method for inserting text asynchronously.
 /// </summary>
 /// <param name="cc">CyberConsole parameter (for extension work).</param>
 /// <param name="text">Text to insert.</param>
 /// <param name="start">Start line. (if you have inserted text before async func).</param>
 public static void InsertTextAsync(this CyberConsole cc, string text, int start = -1)
 {
     cc.Dispatcher.Invoke(() =>
     {
         if (start == -1)
         {
             start = cc.Document.LineCount - 1;
         }
         cc.InsertText(text, true);
         int end = cc.Document.LineCount - 1;
         (cc.TextArea.LeftMargins[0] as NewLineMargin).RemoveLines(start, end);
         cc.IsEnabled = true;
         cc.Focus();
     });
 }
        public override async void Action(string commandLineText, params object[] args)
        {
            CyberConsole cc    = (args[0] as CyberConsole);
            int          start = cc.Document.LineCount;

            cc.InsertText("Building . . .");
            cc.IsEnabled = false;
            await Task.Run(() =>
            {
                IAttrib[] attribs = (Parser as StandardParser).GetAttributes(this, commandLineText);
                CurrentAttributes = ExtractAttributes(attribs).ToArray();
                SetParameters <StringParameter, string>(commandLineText);
                SetParameters <QuoteStringParameter, string>(commandLineText);
                if (IsCorrectSyntax(true))
                {
                    if (IsCorrectParameters())
                    {
                        if (CurrentAttributes.Length > 1)
                        {
                            Message = new ParametersExcessError("File attribute must have a single path to .cs file.").Message;
                            return;
                        }
                        else if (CurrentAttributes.Length == 0)
                        {
                            CurrentAttributes = new IAttrib[] { new FileAttribute() }
                        }
                        ;
                        (CurrentAttributes[0] as FileAddAttribute).Action(
                            Parameters.OfType <StringParameter>().Select(p => p.Value).ToArray(),                //Get files.
                            Parameters.FirstOrDefault(p => p.GetType() == typeof(QuoteStringParameter))?.Value); //Get name.
                        Message = CurrentAttributes[0].Message;
                    }
                    else
                    {
                        Message = "Module should contain only one name.";
                    }
                }
                else
                {
                    Message = GetErrorMessage(commandLineText);
                }
                cc.InsertTextAsync(Message, start);
            });
        }
Beispiel #3
0
        public override async void Action(string commandLineText, params object[] args)
        {
            CyberConsole cc    = (args[0] as CyberConsole);
            int          start = cc.Document.LineCount;

            cc.InsertText("Deleting . . .");
            cc.IsEnabled = false;
            await Task.Run(() =>
            {
                IAttrib[] attribs = (Parser as StandardParser).GetAttributes(this, commandLineText);
                CurrentAttributes = ExtractAttributes(attribs).ToArray();
                SetParameters <NumberParameter, short>(commandLineText);
                SetParameters <QuoteStringParameter, string>(commandLineText);
                if (IsCorrectSyntax())
                {
                    if (IsCorrectParameters())
                    {
                        if (attribs.Length > 0)
                        {
                            attribs[0].Action();
                            Message = attribs[0].Message;
                        }
                        else if (Parameters.Length == 0 && CurrentAttributes.Length == 0)
                        {
                            Message = new ParametersAbscenceError(StandardParameters).Message;
                        }
                        else
                        {
                            Message = RemoveModules();
                        }
                    }
                    else
                    {
                        Message = "Parameters must contain only 1 type of module search (search by indexes or search by names);";
                    }
                }
                else
                {
                    Message = GetErrorMessage(commandLineText);
                }
                cc.InsertTextAsync(Message, start);
            });
        }