Exemplo n.º 1
0
        /// <summary>
        /// Read the compilation/prolint errors of a given execution through its .log file
        /// update the FilesInfo accordingly so the user can see the errors in npp
        /// </summary>
        public Dictionary <string, List <FileError> > LoadErrorLog()
        {
            // we need to correct the files path in the log if needed
            var changePaths = new Dictionary <string, string>(StringComparer.CurrentCultureIgnoreCase);

            foreach (var treatedFile in ListToCompile.Where(treatedFile => !treatedFile.CompInputPath.Equals(treatedFile.InputPath)))
            {
                if (!changePaths.ContainsKey(treatedFile.CompInputPath))
                {
                    changePaths.Add(treatedFile.CompInputPath, treatedFile.InputPath);
                }
            }

            // read the log file
            Dictionary <string, List <FileError> > errorsList;

            if (ExecutionType == ExecutionType.Prolint)
            {
                var treatedFile = ListToCompile.First();
                if (!changePaths.ContainsKey(treatedFile.CompInputPath))
                {
                    changePaths.Add(treatedFile.CompInputPath, treatedFile.InputPath);
                }
                errorsList = FilesInfo.ReadErrorsFromFile(ProlintOutputPath, true, changePaths);
            }
            else
            {
                errorsList = FilesInfo.ReadErrorsFromFile(LogPath, false, changePaths);
            }

            // clear errors on each compiled file
            foreach (var fileToCompile in ListToCompile)
            {
                FilesInfo.ClearAllErrors(fileToCompile.InputPath, true);
            }

            // update the errors
            foreach (var keyValue in errorsList)
            {
                FilesInfo.UpdateFileErrors(keyValue.Key, keyValue.Value);
            }

            return(errorsList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called after the execution of run/compile/check/prolint, clear the current operation from the file
        /// </summary>
        public static void OnSingleExecutionEnd(ProExecution lastExec)
        {
            try {
                var treatedFile = lastExec.ListToCompile.First();
                CurrentOperation currentOperation;
                if (!Enum.TryParse(lastExec.ExecutionType.ToString(), true, out currentOperation))
                {
                    currentOperation = CurrentOperation.Run;
                }

                // Clear flag or we can't do any other actions on this file
                FilesInfo.GetFileInfo(treatedFile.InputPath).CurrentOperation &= ~currentOperation;
                var isCurrentFile = treatedFile.InputPath.EqualsCi(Plug.CurrentFilePath);
                if (isCurrentFile)
                {
                    FilesInfo.UpdateFileStatus();
                }
            } catch (Exception e) {
                ErrorHandler.ShowErrors(e, "Error in OnExecutionEnd");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called after the execution of run/compile/check/prolint, clear the current operation from the file
        /// </summary>
        public static void OnSingleExecutionEnd(ProExecution lastExec)
        {
            try {
                var exec        = (ProExecutionHandleCompilation)lastExec;
                var treatedFile = exec.Files.First();
                CurrentOperation currentOperation;
                if (!Enum.TryParse(exec.ExecutionType.ToString(), true, out currentOperation))
                {
                    currentOperation = CurrentOperation.Run;
                }

                // Clear flag or we can't do any other actions on this file
                FilesInfo.GetFileInfo(treatedFile.SourcePath).CurrentOperation &= ~currentOperation;
                var isCurrentFile = treatedFile.SourcePath.EqualsCi(Npp.CurrentFile.Path);
                if (isCurrentFile)
                {
                    FilesInfo.UpdateFileStatus();
                }

                FilesInfo.CurrentFileInfoObject.ProgressExecution = null;
            } catch (Exception e) {
                ErrorHandler.ShowErrors(e, "Error in OnExecutionEnd");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Called to run/compile/check/prolint the current program
        /// </summary>
        public static void StartProgressExec(ExecutionType executionType)
        {
            CurrentOperation currentOperation;

            if (!Enum.TryParse(executionType.ToString(), true, out currentOperation))
            {
                currentOperation = CurrentOperation.Run;
            }

            // process already running?
            if (Plug.CurrentFileObject.CurrentOperation >= CurrentOperation.Prolint)
            {
                UserCommunication.NotifyUnique("KillExistingProcess", "This file is already being compiled, run or lint-ed.<br>Please wait the end of the previous action,<br>or click the link below to interrupt the previous action :<br><a href='#'>Click to kill the associated prowin process</a>", MessageImg.MsgRip, currentOperation.GetAttribute <CurrentOperationAttr>().Name, "Already being compiled/run", args => {
                    KillCurrentProcess();
                    StartProgressExec(executionType);
                    args.Handled = true;
                }, 5);
                return;
            }
            if (!Abl.IsCurrentProgressFile)
            {
                UserCommunication.Notify("Can only compile and run progress files!", MessageImg.MsgWarning, "Invalid file type", "Progress files only", 10);
                return;
            }
            if (string.IsNullOrEmpty(Plug.CurrentFilePath) || !File.Exists(Plug.CurrentFilePath))
            {
                UserCommunication.Notify("Couldn't find the following file :<br>" + Plug.CurrentFilePath, MessageImg.MsgError, "Execution error", "File not found", 10);
                return;
            }
            if (!Config.Instance.CompileKnownExtension.Split(',').Contains(Path.GetExtension(Plug.CurrentFilePath)))
            {
                UserCommunication.Notify("Sorry, the file extension " + Path.GetExtension(Plug.CurrentFilePath).ProQuoter() + " isn't a valid extension for this action!<br><i>You can change the list of valid extensions in the settings window</i>", MessageImg.MsgWarning, "Invalid file extension", "Not an executable", 10);
                return;
            }

            // update function prototypes
            ProGenerateCode.UpdateFunctionPrototypesIfNeeded(true);

            // prolint? check that the StartProlint.p program is created, or do it
            if (executionType == ExecutionType.Prolint)
            {
                if (!File.Exists(Config.FileStartProlint))
                {
                    if (!Utils.FileWriteAllBytes(Config.FileStartProlint, DataResources.StartProlint))
                    {
                        return;
                    }
                }
            }

            // launch the compile process for the current file
            Plug.CurrentFileObject.ProgressExecution = new ProExecution {
                ListToCompile = new List <FileToCompile> {
                    new FileToCompile(Plug.CurrentFilePath)
                },
                OnExecutionEnd = OnSingleExecutionEnd,
                OnExecutionOk  = OnSingleExecutionOk
            };
            if (!Plug.CurrentFileObject.ProgressExecution.Do(executionType))
            {
                return;
            }

            // change file object current operation, set flag
            Plug.CurrentFileObject.CurrentOperation |= currentOperation;
            FilesInfo.UpdateFileStatus();

            // clear current errors (updates the current file info)
            FilesInfo.ClearAllErrors(Plug.CurrentFilePath, true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Called to run/compile/check/prolint the current program
        /// </summary>
        public static void StartProgressExec(ExecutionType executionType, Action <ProExecutionHandleCompilation> execSetter = null)
        {
            CurrentOperation currentOperation;

            if (!Enum.TryParse(executionType.ToString(), true, out currentOperation))
            {
                currentOperation = CurrentOperation.Run;
            }

            // process already running?
            if (FilesInfo.CurrentFileInfoObject.CurrentOperation >= CurrentOperation.Prolint)
            {
                UserCommunication.NotifyUnique("KillExistingProcess", "This file is already being compiled, run or lint-ed.<br>Please wait the end of the previous action,<br>or click the link below to interrupt the previous action :<br><a href='#'>Click to kill the associated prowin process</a>", MessageImg.MsgRip, currentOperation.GetAttribute <CurrentOperationAttr>().Name, "Already being compiled/run", args => {
                    KillCurrentProcess();
                    StartProgressExec(executionType);
                    args.Handled = true;
                }, 5);
                return;
            }
            if (!Npp.CurrentFile.IsProgress)
            {
                UserCommunication.Notify("Can only compile and run progress files!", MessageImg.MsgWarning, "Invalid file type", "Progress files only", 10);
                return;
            }
            if (string.IsNullOrEmpty(Npp.CurrentFile.Path) || !File.Exists(Npp.CurrentFile.Path))
            {
                UserCommunication.Notify("Couldn't find the following file :<br>" + Npp.CurrentFile.Path, MessageImg.MsgError, "Execution error", "File not found", 10);
                return;
            }
            if (!Npp.CurrentFile.IsCompilable)
            {
                UserCommunication.Notify("Sorry, the file extension " + Path.GetExtension(Npp.CurrentFile.Path).ProQuoter() + " isn't a valid extension for this action!<br><i>You can change the list of valid extensions in the settings window</i>", MessageImg.MsgWarning, "Invalid file extension", "Not an executable", 10);
                return;
            }

            // when running a procedure, check that a .r is not hiding the program, if that's the case we warn the user
            if (executionType == ExecutionType.Run && !_dontWarnAboutRCode)
            {
                if (File.Exists(Path.ChangeExtension(Npp.CurrentFile.Path, ".r")))
                {
                    UserCommunication.NotifyUnique("rcodehide", "Friendly warning, an <b>r-code</b> <i>(i.e. *.r file)</i> is hiding the current program<br>If you modified it since the last compilation you might not have the expected behavior...<br><br><i>" + "stop".ToHtmlLink("Click here to not show this message again for this session") + "</i>", MessageImg.MsgWarning, "Progress execution", "An Rcode hides the program", args => {
                        _dontWarnAboutRCode = true;
                        UserCommunication.CloseUniqueNotif("rcodehide");
                    }, 5);
                }
            }

            // update function prototypes
            ProGenerateCode.Factory.UpdateFunctionPrototypesIfNeeded(true);

            // prolint? check that the StartProlint.p program is created, or do it
            if (executionType == ExecutionType.Prolint)
            {
                if (!File.Exists(Config.FileStartProlint))
                {
                    if (!Utils.FileWriteAllBytes(Config.FileStartProlint, DataResources.StartProlint))
                    {
                        return;
                    }
                }
            }

            // launch the compile process for the current file
            FilesInfo.CurrentFileInfoObject.ProgressExecution       = (ProExecutionHandleCompilation)ProExecution.Factory(executionType);
            FilesInfo.CurrentFileInfoObject.ProgressExecution.Files = new List <FileToCompile> {
                new FileToCompile(Npp.CurrentFile.Path)
            };
            FilesInfo.CurrentFileInfoObject.ProgressExecution.OnExecutionEnd += OnSingleExecutionEnd;
            if (execSetter != null)
            {
                execSetter(FilesInfo.CurrentFileInfoObject.ProgressExecution);
                FilesInfo.CurrentFileInfoObject.ProgressExecution.OnCompilationOk += OnGenerateDebugFileOk;
            }
            else
            {
                FilesInfo.CurrentFileInfoObject.ProgressExecution.OnCompilationOk += OnSingleExecutionOk;
            }
            if (!FilesInfo.CurrentFileInfoObject.ProgressExecution.Start())
            {
                return;
            }

            // change file object current operation, set flag
            FilesInfo.CurrentFileInfoObject.CurrentOperation |= currentOperation;
            FilesInfo.UpdateFileStatus();

            // clear current errors (updates the current file info)
            FilesInfo.ClearAllErrors(Npp.CurrentFile.Path, true);
        }