/// <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();
     });
 }
Beispiel #2
0
        /// <summary>
        /// Execute command by string in quotes.
        /// </summary>
        /// <param name="cc">Console for artificial command executing.</param>
        /// <param name="parameters">Number parameters of loop condition.</param>
        private void ExecuteCommandInQuotes(CyberConsole cc, IList <IParameter> parameters)
        {
            string commandToExecute = Parameters[1].Value;

            Parameters = parameters.ToArray();
            if (IsCorrectSyntax(true))
            {
                int start     = int.Parse(Parameters[0].Value);
                int condition = int.Parse(Parameters[1].Value);
                int iteration = int.Parse(Parameters[2].Value);
                for (int i = start; i < condition; i += iteration)
                {
                    cc.ProcessCommand(commandToExecute);
                }
                Message = string.Empty;
                return;
            }
        }
        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 #4
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);
            });
        }
        public override void Action(string commandLineText, params object[] args)
        {
            Parameters        = (Parser as StandardParser).GetAttributes(this, commandLineText);
            CurrentAttributes = ExtractAttributes(Parameters).ToArray();
            CyberConsole cc = args[0] as CyberConsole;

            if (cc != null && IsCorrectSyntax())
            {
                StartEditingPoint  = cc.TextArea.Caret.Line + 1;
                cc.EnterSymbol     = " > ";
                cc.ConsoleMode     = ConsoleMode.EDITOR_MODE;
                cc.PreviewKeyDown += OnPreviewKeyDown;
                Message            = "Mode is changed to editor.\n";
            }
            else
            {
                Message = GetErrorMessage(commandLineText) + "\n";
            }
        }
        private void OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            CyberConsole cc = sender as CyberConsole;

            if (Keyboard.IsKeyDown(Key.Escape))
            {
                cc.ScrollToEnd();
                if (CurrentAttributes.Contains(StandardAttributes[0]))
                {
                    int    offset      = cc.Document.GetOffset(StartEditingPoint, 0);
                    string editingText = cc.Document.GetText(offset, cc.Document.TextLength - offset);
                    CurrentAttributes[0].Action(new [] { editingText });
                }
                cc.ConsoleMode = ConsoleMode.COMMAND_MODE;
                (cc.TextArea.LeftMargins[0] as NewLineMargin).UpdateLineStates(cc.ConsoleMode);
                cc.Text = cc.Text.Insert(cc.Text.Length, "\nMode is changed to console.\n");
                cc.TextArea.Caret.Line = cc.Document.Lines.Count;
                cc.PreviewKeyDown     -= OnPreviewKeyDown;
            }
        }
Beispiel #7
0
        public override void Action(string commandLineText, params object[] args)
        {
            SetParameters <BracketParameter, string>(commandLineText);
            SetParameters <StringParameter, string>(commandLineText);
            CyberConsole cc = args[0] as CyberConsole;

            if (IsCorrectSyntax(true) && cc != null)
            {
                if (Parameters[0].GetType() == StandardParameters[0].GetType())
                {
                    IList <IParameter> parameters = GetCondtionParameters();
                    if (parameters.Count == 3)      //3 numbers in loop brackets (num;num;num)
                    {
                        if (Parameters.Length == 2) //2 parameters: brackets with condition and command in quotes to repeat.
                        {
                            ExecuteCommandInQuotes(cc, parameters);
                        }
                        else
                        {
                            SetParametersAbsenceError();
                        }
                    }
                    else
                    {
                        Parameters = new IParameter[]
                        {
                            new NumberParameter()
                            {
                                Error = new WrongParametersCountError(" There must be three numbers: start point; condtion; iteration")
                            }
                        }
                    };
                }
                else
                {
                    Parameters[0].Error = new ParameterNotFoundError("with loop conditions");
                }
            }
            Message = GetErrorMessage(commandLineText);
        }
Beispiel #8
0
        public override void Action(string commandLineText, params object[] args)
        {
            CyberConsole cc = args[0] as CyberConsole;

            commandLineText = commandLineText.Replace(" ", "");
            if (IsCorrectSyntax() && cc != null && commandLineText.Length == Spelling.Length)
            {
                cc.Text = string.Empty;
                (cc.TextArea.LeftMargins[0] as NewLineMargin).Clear();
                (cc.TextArea.ReadOnlySectionProvider as TextSegmentReadOnlySectionProvider <TextSegment>).Segments.Clear();
            }
            else if (cc == null)
            {
                Message = new NullArgumentError("CyberConsole").Message;
            }
            else if (commandLineText.Length != Spelling.Length)
            {
                Message = new ParametersExcessError("This command shouldn't have any arguments.").Message;
            }
            else
            {
                Message = new SyntaxError().Message;
            }
        }
Beispiel #9
0
        public override void Action(string commandLineText, params object[] args)
        {
            commandLineText = commandLineText.Replace(" ", "");
            CyberConsole cc = (args[0] as CyberConsole);

            if (commandLineText.Length == Spelling.Length)
            {
                if (cc != null)
                {
                    cc.PreviousCommands.Clear();
                    if (File.Exists(HISTORY_FILE_NAME))
                    {
                        try
                        {
                            FileStream fs = File.Create(HISTORY_FILE_NAME);
                            fs.Close();
                            File.Delete(HISTORY_FILE_NAME);
                        }
                        //The process cannot acess the file.
                        catch (IOException)
                        {
                        }
                    }

                    Message = "History is clear.";
                }
                else
                {
                    Message = "CyberConsole argument was null.";
                }
            }
            else
            {
                Message = "Excess symbols in command.";
            }
        }