Exemplo n.º 1
0
        public void GenerateCode(FileProjectItem item, CustomToolContext context)
        {
            context.RunAsync(
                () => {
                string fileName = item.FileName;
                var projectNode = item.Project;
                SpecFlowProject specFlowProject = CreateSpecFlowProjectFrom(projectNode);
                var specFlowGenerator           = new SpecFlowGenerator(specFlowProject);

                string outputFile = context.GetOutputFileName(item, ".feature");

                var specFlowFeatureFile = specFlowProject.GetOrCreateFeatureFile(fileName);

                var fileContents = File.ReadAllText(fileName);
                string outputFileContents;
                using (var reader = new StringReader(fileContents)) {
                    using (var writer = new StringWriter(new StringBuilder())) {
                        specFlowGenerator.GenerateTestFile(specFlowFeatureFile, projectNode.LanguageProperties.CodeDomProvider, reader, writer);
                        outputFileContents = writer.ToString();
                    }
                }
                File.WriteAllText(outputFile, outputFileContents);

                WorkbenchSingleton.SafeThreadCall(
                    () => context.EnsureOutputFileIsInProject(item, outputFile));
            });
        }
Exemplo n.º 2
0
 /// <summary>
 /// Invoke the action on the main thread and return after it is done.
 /// WARNING: This may cause a deadlock if the main thread is locked on the current thread!
 /// </summary>
 internal static void Invoke(Action action)
 {
                 #if SD5
     SD.MainThread.Invoke(action);
                 #else
     WorkbenchSingleton.SafeThreadCall(action);
                 #endif
 }
        void btnStartClick(object sender, RoutedEventArgs e)
        {
            try {
                if (!File.Exists(txtExePath.Text))
                {
                    throw new FileNotFoundException("file '" + txtExePath.Text + "' was not found!");
                }
                if (!Directory.Exists(txtWorkingDir.Text))
                {
                    throw new DirectoryNotFoundException("directory '" + txtWorkingDir.Text + "' was not found!");
                }

                string outputName = "Session" + DateTime.Now.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture) + ".sdps";
                string outputPath = "";

                SaveFileDialog sfd = new SaveFileDialog();
                sfd.InitialDirectory = Path.GetDirectoryName(txtExePath.Text);
                sfd.Filter           = StringParser.Parse("${res:AddIns.Profiler.FileExtensionDescription}|*.sdps");
                sfd.FileName         = outputName;
                if (sfd.ShowDialog() == true)
                {
                    outputPath = sfd.FileName;
                }
                else
                {
                    return;
                }

                try {
                    Directory.CreateDirectory(Path.GetDirectoryName(outputPath));

                    var runner = CreateRunner(txtExePath.Text, txtWorkingDir.Text, txtArgs.Text, new ProfilingDataSQLiteWriter(outputPath));

                    if (runner != null)
                    {
                        runner.RunFinished += delegate {
                            WorkbenchSingleton.SafeThreadCall(() => FileService.OpenFile(outputPath));
                        };

                        runner.Run();
                    }

                    this.Close();
                } catch (ProfilerException ex) {
                    MessageService.ShowError(ex.Message);
                }
            } catch (ArgumentNullException) {
                MessageService.ShowError(StringParser.Parse("${res:AddIns.Profiler.ProfileExecutable.ErrorMessage}"));
            } catch (FileNotFoundException ex) {
                MessageService.ShowError(ex.Message);
            } catch (DirectoryNotFoundException ex2) {
                MessageService.ShowError(ex2.Message);
            } catch (UnauthorizedAccessException ex4) {
                MessageService.ShowError(ex4.Message);
            } catch (Exception ex3) {
                MessageService.ShowException(ex3);
            }
        }
Exemplo n.º 4
0
 public void IsSaveRequired()
 {
     if (SDIntegration.Instance.workbenchIsRunning)
     {
         WorkbenchSingleton.SafeThreadCall(IsSaveRequiredInternal);
     }
     else
     {
         StateHolder.Instance.PState = StateHolder.SDAProjectState.ReadyToOpen;
     }
 }
Exemplo n.º 5
0
 public void OpenProject(string fileName)
 {
     if (WorkbenchSingleton.InvokeRequired)
     {
         WorkbenchSingleton.SafeThreadCall(OpenProjectInternal, fileName);
     }
     else
     {
         OpenProjectInternal(fileName);
     }
 }
Exemplo n.º 6
0
 public void RemoveProjectItem(IProject project, ProjectItem item)
 {
     if (WorkbenchSingleton.InvokeRequired)
     {
         Action <IProject, ProjectItem> action = RemoveProjectItem;
         WorkbenchSingleton.SafeThreadCall <IProject, ProjectItem>(action, project, item);
     }
     else
     {
         ProjectService.RemoveProjectItem(project, item);
     }
 }
Exemplo n.º 7
0
 public void Save(IProject project)
 {
     if (WorkbenchSingleton.InvokeRequired)
     {
         Action <IProject> action = Save;
         WorkbenchSingleton.SafeThreadCall <IProject>(action, project);
     }
     else
     {
         project.Save();
     }
 }
Exemplo n.º 8
0
 public void Save(Solution solution)
 {
     if (WorkbenchSingleton.InvokeRequired)
     {
         Action <Solution> action = Save;
         WorkbenchSingleton.SafeThreadCall <Solution>(action, solution);
     }
     else
     {
         solution.Save();
     }
 }
        public void Update(Diagnostic[] diagnostics, FileName fileName, IDocument document)
        {
            WorkbenchSingleton.SafeThreadCall(() => {
                ClearTasksForFileName(fileName);

                List <TypeScriptTask> tasks = diagnostics
                                              .Select(diagnostic => TypeScriptTask.Create(fileName, diagnostic, document))
                                              .ToList();

                TaskService.AddRange(tasks);
            });
        }
Exemplo n.º 10
0
 public void RemoveDirectory(string path)
 {
     if (WorkbenchSingleton.InvokeRequired)
     {
         Action <string> action = RemoveDirectory;
         WorkbenchSingleton.SafeThreadCall <string>(action, path);
     }
     else
     {
         FileService.RemoveFile(path, true);
     }
 }
 public void IndentLines(int beginLine, int endLine)
 {
     if (WorkbenchSingleton.InvokeRequired)
     {
         WorkbenchSingleton.SafeThreadCall(() => IndentLines(beginLine, endLine));
     }
     else
     {
         using (IDisposable undoGroup = TextEditor.Document.OpenUndoGroup()) {
             FormattingStrategy.IndentLines(TextEditor, beginLine, endLine);
         }
     }
 }
Exemplo n.º 12
0
        public void GenerateCode(FileProjectItem item, CustomToolContext context)
        {
            context.RunAsync(() =>
            {
                var ideSingleFileGenerator = new IdeSingleFileGenerator();

                string outputFilePath = context.GetOutputFileName(item, ".feature");
                ideSingleFileGenerator.GenerateFile(item.FileName, outputFilePath, () => new SharpDevelop4GeneratorServices(item.Project));

                WorkbenchSingleton.SafeThreadCall(
                    () => context.EnsureOutputFileIsInProject(item, outputFilePath));
            });
        }
Exemplo n.º 13
0
 public void AddNamespace(ICompilationUnit compilationUnit, string newNamespace)
 {
     if (WorkbenchSingleton.InvokeRequired)
     {
         WorkbenchSingleton.SafeThreadCall(() => AddNamespace(compilationUnit, newNamespace));
     }
     else
     {
         IViewContent view       = FileService.OpenFile(compilationUnit.FileName);
         var          textEditor = view as ITextEditorProvider;
         IDocument    document   = textEditor.TextEditor.Document;
         NamespaceRefactoringService.AddUsingDeclaration(compilationUnit, document, newNamespace, false);
     }
 }
Exemplo n.º 14
0
 public void SaveFile(IViewContent view)
 {
     if (WorkbenchSingleton.InvokeRequired)
     {
         Action <IViewContent> action = SaveFile;
         WorkbenchSingleton.SafeThreadCall <IViewContent>(action, view);
     }
     else
     {
         if (view.IsDirty)
         {
             view.Files.ForEach(ICSharpCode.SharpDevelop.Commands.SaveFile.Save);
         }
     }
 }
Exemplo n.º 15
0
        void AttachToWebWorkerProcessOrStartIISExpress(WebProjectProperties properties, bool withDebugging)
        {
            string processName = WebProjectService.GetWorkerProcessName(properties);

            // try find the worker process directly or using the process monitor callback
            Process[] processes = System.Diagnostics.Process.GetProcesses();
            int       index     = processes.FindIndex(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase));

            if (index > -1)
            {
                if (withDebugging)
                {
                    DebuggerService.CurrentDebugger.Attach(processes[index]);
                }
            }
            else
            {
                if (properties.UseIISExpress)
                {
                    // start IIS express and attach to it
                    if (WebProjectService.IsIISExpressInstalled)
                    {
                        ProcessStartInfo processInfo = IISExpressProcessStartInfo.Create(WebProject);
                        if (withDebugging)
                        {
                            DebuggerService.CurrentDebugger.Start(processInfo);
                        }
                        else
                        {
                            Process.Start(processInfo);
                        }
                    }
                }
                else
                {
                    DisposeProcessMonitor();
                    this.monitor = new ProcessMonitor(processName);
                    this.monitor.ProcessCreated += delegate {
                        WorkbenchSingleton.SafeThreadCall((Action)(() => OnProcessCreated(properties, withDebugging)));
                    };
                    this.monitor.Start();
                }
            }
        }
Exemplo n.º 16
0
        void Start(ProcessStartInfo startInfo, SelectedTests selectedTests)
        {
            LogCommandLine(startInfo);

            string path = selectedTests.Project.GetSessionFileName();

            LoggingService.Info("starting profiler...");

            runner = new ProfilerRunner(startInfo, true, new UnitTestWriter(new ProfilingDataSQLiteWriter(path), GetUnitTestNames(selectedTests).ToArray()));

            runner.RunFinished += delegate {
                WorkbenchSingleton.SafeThreadCall(() => FileService.OpenFile(path));
                AfterFinish(selectedTests, path);
            };

            testResultsMonitor.TestFinished += OnTestFinished;
            testResultsMonitor.Start();
            runner.Run();
        }
Exemplo n.º 17
0
        void DoDiffOperation()
        {
            output = null;
            MemoryStream outStream = new MemoryStream();
            MemoryStream errStream = new MemoryStream();

//			SvnClient.Instance.Client.Diff(new string [] {} ,
//			                               fileName,
//			                               fromRevision,
//			                               fileName,
//			                               toRevision,
//			                               Recurse.None,
//			                               false,
//			                               true,
//			                               outStream,
//			                               errStream);
            output = Encoding.Default.GetString(outStream.ToArray());
            WorkbenchSingleton.SafeThreadCall(SetOutput);
        }
Exemplo n.º 18
0
        public static void AddSessionToProject(this IProject project, string path)
        {
            Action updater = () => {
                if (!File.Exists(path))
                {
                    return;
                }
                FileService.OpenFile(path);
                if (!project.ReadOnly)
                {
                    FileProjectItem file = new FileProjectItem(project, ItemType.Content, "ProfilingSessions\\" + Path.GetFileName(path));
                    ProjectService.AddProjectItem(project, file);
                    ProjectBrowserPad.RefreshViewAsync();
                    project.Save();
                }
            };

            WorkbenchSingleton.SafeThreadCall(updater);
        }
        protected override void RunTests(UnitTestApplicationStartHelper helper)
        {
            TestRunnerCategory.AppendLine(helper.GetCommandLine());

            ProcessStartInfo startInfo = new ProcessStartInfo(helper.UnitTestApplication);

            string path = helper.Project.GetSessionFileName();

            startInfo.Arguments        = helper.GetArguments();
            startInfo.WorkingDirectory = UnitTestApplicationStartHelper.UnitTestApplicationDirectory;
            LoggingService.Info("starting profiler...");

            runner = new ProfilerRunner(startInfo, true, new ProfilingDataSQLiteWriter(path, true, GetUnitTestNames(helper).ToArray()));

            runner.RunFinished += delegate {
                WorkbenchSingleton.SafeThreadCall(() => FileService.OpenFile(path));
                AfterFinish(helper, path);
            };

            runner.Run();
        }
Exemplo n.º 20
0
        Dictionary <string, object> GetResources(string fileName)
        {
            Stream s = null;

            WorkbenchSingleton.SafeThreadCall(
                delegate {
                OpenedFile file = FileService.GetOpenedFile(fileName);
                if (file != null)
                {
                    s = file.OpenRead();
                }
            });
            if (s == null)
            {
                s = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            }
            using (s) {
                using (IResourceReader reader = ResourceStore.CreateResourceReader(s, ResourceStore.GetResourceType(fileName))) {
                    ResXResourceReader resXReader = reader as ResXResourceReader;
                    if (resXReader != null)
                    {
                        resXReader.BasePath = Path.GetDirectoryName(fileName);
                    }

                    var resources = new Dictionary <string, object>();
                    foreach (System.Collections.DictionaryEntry entry in reader)
                    {
                        if (entry.Value == null)
                        {
                            continue;
                        }
                        if (this.requiredResourceType.IsAssignableFrom(entry.Value.GetType()))
                        {
                            resources.Add((string)entry.Key, entry.Value);
                        }
                    }
                    return(resources);
                }
            }
        }
        protected override string PrepareTempFolderToZip(string selectedPath, string zipFile)
        {
            //create temp folder
            string newScriptName = Path.GetFileNameWithoutExtension(zipFile);
            string tempFolder    = Path.Combine(Path.GetTempPath(), Keywords.VuGen_Keywords_ProductName, newScriptName);

            if (Directory.Exists(tempFolder))
            {
                UttFileSystemUtils.DeleteDirectory(tempFolder);
            }
            UttFileSystemUtils.CreateDirectory(tempFolder);

            //do export
            string loadData = Path.Combine(tempFolder, newScriptName + Keywords.VuGen_Keywords_ScriptExtension);
            UttPersistenceToken newToken = new UttPersistenceToken(loadData, tempFolder);

            WorkbenchSingleton.SafeThreadCall(ExportScript, _script, newToken);

            WorkbenchSingleton.SafeThreadCall(FilterFiles, _script, tempFolder);

            return(tempFolder);
        }
Exemplo n.º 22
0
        public override void Start(bool withDebugging)
        {
            if (!CheckWebProjectStartInfo())
            {
                return;
            }

            try {
                WebProjectProperties properties = WebProject.GetWebProjectProperties();
                string processName = WebProjectService.GetWorkerProcessName(properties);

                // try find the worker process directly or using the process monitor callback
                Process[] processes = System.Diagnostics.Process.GetProcesses();
                int       index     = processes.FindIndex(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase));
                if (index > -1)
                {
                    if (withDebugging)
                    {
                        DebuggerService.CurrentDebugger.Attach(processes[index]);
                    }
                }
                else
                {
                    if (properties.UseIISExpress)
                    {
                        // start IIS express and attach to it
                        if (WebProjectService.IsIISExpressInstalled)
                        {
                            ProcessStartInfo processInfo = IISExpressProcessStartInfo.Create(WebProject);
                            DebuggerService.CurrentDebugger.Start(processInfo);
                        }
                        else
                        {
                            DisposeProcessMonitor();
                            MessageService.ShowError("${res:ICSharpCode.WebProjectOptionsPanel.NoProjectUrlOrProgramAction}");
                            return;
                        }
                    }
                    else
                    {
                        DisposeProcessMonitor();
                        this.monitor = new ProcessMonitor(processName);
                        this.monitor.ProcessCreated += delegate {
                            WorkbenchSingleton.SafeThreadCall((Action)(() => OnProcessCreated(properties, withDebugging)));
                        };
                        this.monitor.Start();
                    }
                }

                // start default application(e.g. browser) or the one specified
                switch (CompilableProject.StartAction)
                {
                case StartAction.Project:
                    if (FileUtility.IsUrl(properties.IISUrl))
                    {
                        Process.Start(properties.IISUrl);
                    }
                    else
                    {
                        MessageService.ShowError("${res:ICSharpCode.WebProjectOptionsPanel.NoProjectUrlOrProgramAction}");
                        DisposeProcessMonitor();
                    }
                    break;

                case StartAction.Program:
                    Process.Start(StartProgram);
                    break;

                case StartAction.StartURL:
                    if (FileUtility.IsUrl(StartUrl))
                    {
                        Process.Start(StartUrl);
                    }
                    else
                    {
                        string url = string.Concat(properties.IISUrl, StartUrl);
                        if (FileUtility.IsUrl(url))
                        {
                            Process.Start(url);
                        }
                        else
                        {
                            MessageService.ShowError("${res:ICSharpCode.WebProjectOptionsPanel.NoProjectUrlOrProgramAction}");
                            DisposeProcessMonitor();
                            return;
                        }
                    }
                    break;

                default:
                    throw new Exception("Invalid value for StartAction");
                }
            } catch (Exception ex) {
                MessageService.ShowError(ex.Message);
                LoggingService.Error(ex.ToString());
                DisposeProcessMonitor();
            }
        }
Exemplo n.º 23
0
        public void Start(ProcessStartInfo processStartInfo)
        {
            if (IsDebugging)
            {
                MessageService.ShowMessage(errorDebugging);
                return;
            }
            if (!ServiceInitialized)
            {
                InitializeService();
            }

            if (FileUtility.IsUrl(processStartInfo.FileName))
            {
                if (!CheckWebProjectStartInfo())
                {
                    return;
                }

                var project = ProjectService.OpenSolution.Preferences.StartupProject as CompilableProject;
                var options = WebProjectsOptions.Instance.GetWebProjectOptions(project.Name);
                System.Diagnostics.Process defaultAppProcess = null;

                if (options.Data.WebServer != WebServer.None)
                {
                    string processName = WebProjectService.WorkerProcessName;

                    // try find the worker process directly or using the process monitor callback
                    var processes = System.Diagnostics.Process.GetProcesses();
                    int index     = processes.FindIndex(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase));
                    if (index > -1)
                    {
                        Attach(processes[index]);
                    }
                    else
                    {
                        try {
                            this.monitor = new ProcessMonitor(processName);
                            this.monitor.ProcessCreated += delegate {
                                WorkbenchSingleton.SafeThreadCall((Action)(() => OnProcessCreated(defaultAppProcess, options)));
                            };
                            this.monitor.Start();
                        }
                        catch (System.Exception ex) {
                            LoggingService.ErrorFormatted("Process Monitor exception: {0}", ex.Message);
                        }
                    }

                    if (options.Data.WebServer == WebServer.IISExpress)
                    {
                        // start IIS express and attach to it
                        if (WebProjectService.IISVersion == IISVersion.IISExpress)
                        {
                            System.Diagnostics.Process.Start(WebProjectService.IISExpressProcessLocation);
                        }
                        else
                        {
                            MessageService.ShowError("${res:ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction}");
                            return;
                        }
                    }
                }

                // start default application(e.g. browser)
                if (project.StartAction == StartAction.StartURL)
                {
                    defaultAppProcess = System.Diagnostics.Process.Start(project.StartUrl);
                }
                else
                {
                    if (!string.IsNullOrEmpty(options.Data.ProjectUrl) && options.Data.WebServer == WebServer.IIS)
                    {
                        defaultAppProcess = System.Diagnostics.Process.Start(options.Data.ProjectUrl);
                    }
                    else
                    {
                        if (options.Data.WebServer == WebServer.IISExpress)
                        {
                            defaultAppProcess = System.Diagnostics.Process.Start(options.Data.ProjectUrl);
                        }
                    }
                }
            }
            else
            {
                string version = debugger.GetProgramVersion(processStartInfo.FileName);

                if (version.StartsWith("v1.0"))
                {
                    MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}");
                }
                else if (version.StartsWith("v1.1"))
                {
                    MessageService.ShowMessage(StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}").Replace("1.0", "1.1"));
//					} else if (string.IsNullOrEmpty(version)) {
//					// Not a managed assembly
//					MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.BadAssembly}");
                }
                else if (debugger.IsKernelDebuggerEnabled)
                {
                    MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.KernelDebuggerEnabled}");
                }
                else
                {
                    attached = false;
                    if (DebugStarting != null)
                    {
                        DebugStarting(this, EventArgs.Empty);
                    }

                    try {
                        Process process = debugger.Start(processStartInfo.FileName,
                                                         processStartInfo.WorkingDirectory,
                                                         processStartInfo.Arguments);
                        SelectProcess(process);
                    } catch (System.Exception e) {
                        // COMException: The request is not supported. (Exception from HRESULT: 0x80070032)
                        // COMException: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail. (Exception from HRESULT: 0x800736B1)
                        // COMException: The requested operation requires elevation. (Exception from HRESULT: 0x800702E4)
                        // COMException: The directory name is invalid. (Exception from HRESULT: 0x8007010B)
                        // BadImageFormatException:  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
                        // UnauthorizedAccessException: Отказано в доступе. (Исключение из HRESULT: 0x80070005 (E_ACCESSDENIED))
                        if (e is COMException || e is BadImageFormatException || e is UnauthorizedAccessException)
                        {
                            string msg = StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.CannotStartProcess}");
                            msg += " " + e.Message;
                            // TODO: Remove
                            if (e is COMException && ((uint)((COMException)e).ErrorCode == 0x80070032))
                            {
                                msg += Environment.NewLine + Environment.NewLine;
                                msg += "64-bit debugging is not supported.  Please set Project -> Project Options... -> Compiling -> Target CPU to 32bit.";
                            }
                            MessageService.ShowMessage(msg);

                            if (DebugStopped != null)
                            {
                                DebugStopped(this, EventArgs.Empty);
                            }
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }
Exemplo n.º 24
0
        static void ParserUpdateStep()
        {
            IViewContent activeViewContent = null;
            string       fileName          = null;
            bool         isUntitled        = false;

            try {
                WorkbenchSingleton.SafeThreadCall(
                    delegate {
                    try {
                        activeViewContent = WorkbenchSingleton.Workbench.ActiveViewContent;
                        if (activeViewContent != null && activeViewContent.PrimaryFile != null)
                        {
                            fileName   = activeViewContent.PrimaryFileName;
                            isUntitled = activeViewContent.PrimaryFile.IsUntitled;
                        }
                    } catch (Exception ex) {
                        MessageService.ShowError(ex.ToString());
                    }
                });
            } catch (InvalidOperationException ex) {             // includes ObjectDisposedException
                // maybe workbench has been disposed while waiting for the SafeThreadCall
                // can occur after workbench unload or after aborting SharpDevelop with
                // Application.Exit()
                LoggingService.Warn("InvalidOperationException while trying to invoke GetActiveViewContent() " + ex);
                return;                 // abort this thread
            }
            IEditable editable = activeViewContent as IEditable;

            if (editable != null)
            {
                string text = null;

                if (!(fileName == null || fileName.Length == 0))
                {
                    ParseInformation parseInformation = null;
                    bool             updated          = false;
                    if (text == null)
                    {
                        text = editable.Text;
                        if (text == null)
                        {
                            return;
                        }
                    }
                    int hash = text.GetHashCode();
                    if (!lastUpdateHash.ContainsKey(fileName) || lastUpdateHash[fileName] != hash)
                    {
                        parseInformation         = ParseFile(fileName, text, !isUntitled);
                        lastUpdateHash[fileName] = hash;
                        updated = true;
                    }
                    if (updated)
                    {
                        if (parseInformation != null && editable is IParseInformationListener)
                        {
                            ((IParseInformationListener)editable).ParseInformationUpdated(parseInformation);
                        }
                    }
                    OnParserUpdateStepFinished(new ParserUpdateStepEventArgs(fileName, text, updated, parseInformation));
                }
            }
        }