Пример #1
0
        void LoadModules()
        {
            string moduleFolderPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Modules");

            if (Directory.Exists(moduleFolderPath))
            {
                foreach (string moduleFile in Directory.EnumerateFiles(moduleFolderPath, "*.MagnetoModule.dll"))
                {
                    try
                    {
                        ModuleManager.Register(Assembly.LoadFile(moduleFile));
                    }
                    catch (Exception exception)
                    {
                        if (!SystemUtilities.IsCritical(exception))
                        {
                            TMessageDialog.ShowError(null
                                                     , "Could not load module " + Path.GetFileName(moduleFile) + ":"
                                                     + Environment.NewLine + exception.Message);
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }
Пример #2
0
        private void DisplayLanguageGuide(object sender, EventArgs e)
        {
            string executableFolderPath = Path.GetDirectoryName(SWF.Application.ExecutablePath);
            string languageGuidePath    = Path.Combine(executableFolderPath, "Documentation", "langguide.html");

            try
            {
                if (File.Exists(languageGuidePath))
                {
                    Process.Start(languageGuidePath);
                }
                else
                {
                    ShowError(
                        "The language guide could not be found."
                        + Environment.NewLine + Environment.NewLine
                        + "(langguide.html should be placed in the Documentation sub-folder of the folder where Magneto.exe is placed)");
                }
            }
            catch (Exception exception)
            {
                if (SystemUtilities.IsCritical(exception))
                {
                    throw;
                }
                else
                {
                    ShowError(exception);
                }
            }
        }
Пример #3
0
        private static void StartRunProcess(string executableFilePath, Action <bool> runStateCallback)
        {
            string tempFolderPath = Path.GetDirectoryName(executableFilePath);

            try
            {
                runningProcess = new Process();
                runningProcess.EnableRaisingEvents = true;
                runningProcess.Exited += delegate
                {
                    runningProcess.Dispose();
                    runningProcess = null;
                    CleanupAfterRun(tempFolderPath, runStateCallback);
                };
                runningProcess.StartInfo = new ProcessStartInfo(executableFilePath);
                runningProcess.StartInfo.UseShellExecute  = false;
                runningProcess.StartInfo.WorkingDirectory = tempFolderPath;
                runningProcess.Start();
            }
            catch (Exception ex)
            {
                if (SystemUtilities.IsCritical(ex))
                {
                    throw;
                }
                CleanupAfterRun(tempFolderPath, runStateCallback);
            }
        }
Пример #4
0
 private static void TryDeleteFolder(string folderPath)
 {
     try
     {
         Directory.Delete(folderPath, true);
     }
     catch (Exception ex)
     {
         if (SystemUtilities.IsCritical(ex))
         {
             throw;
         }
     }
 }
Пример #5
0
 void ClearTempFolder()
 {
     if (Directory.Exists(TempFolderPath))
     {
         foreach (string tempSubFolderPath in Directory.EnumerateDirectories(TempFolderPath))
         {
             try { Directory.Delete(tempSubFolderPath, true); }
             catch (Exception exception) { if (SystemUtilities.IsCritical(exception))
                                           {
                                               throw;
                                           }
             }
         }
     }
 }
Пример #6
0
        public static void Run(string sourceCode, Action <bool> runStateCallback, Action <Exception> exceptionHandler)
        {
            runStateCallback?.Invoke(true);

            string tempFolderPath = CreateTempFolder();

            CopyModules(tempFolderPath);

            try
            {
                string executableFilePath = Path.Combine(tempFolderPath, "Temp.exe");
                BuildAssembly(sourceCode, executableFilePath);
                StartRunProcess(executableFilePath, runStateCallback);
            }
            catch (Exception ex)
            {
                if (SystemUtilities.IsCritical(ex))
                {
                    throw;
                }
                exceptionHandler?.Invoke(ex);
                CleanupAfterRun(tempFolderPath, runStateCallback);
            }
        }