public virtual IEnumerable <FileName> GenerateFileList() { List <FileName> files = new List <FileName>(); ITextEditor editor; switch (Target) { case SearchTarget.CurrentDocument: case SearchTarget.CurrentSelection: editor = SD.GetActiveViewContentService <ITextEditor>(); if (editor != null) { files.Add(editor.FileName); } break; case SearchTarget.AllOpenFiles: foreach (var vc in SD.Workbench.ViewContentCollection) { editor = vc.GetService <ITextEditor>(); if (editor != null) { files.Add(editor.FileName); } } break; case SearchTarget.WholeProject: if (ProjectService.CurrentProject == null) { break; } foreach (FileProjectItem item in ProjectService.CurrentProject.Items.OfType <FileProjectItem>()) { files.Add(item.FileName); } break; case SearchTarget.WholeSolution: if (ProjectService.OpenSolution == null) { break; } foreach (var item in ProjectService.OpenSolution.AllItems.OfType <ISolutionFileItem>()) { files.Add(item.FileName); } foreach (var item in ProjectService.OpenSolution.Projects.SelectMany(p => p.Items).OfType <FileProjectItem>()) { files.Add(item.FileName); } break; case SearchTarget.Directory: if (!Directory.Exists(BaseDirectory)) { break; } var options = SearchSubdirs ? DirectorySearchOptions.IncludeSubdirectories : DirectorySearchOptions.None; return(SD.FileSystem.GetFiles(DirectoryName.Create(BaseDirectory), Filter, options)); default: throw new Exception("Invalid value for FileListType"); } return(files.Distinct()); }
/// <summary> /// Initializes the application. /// </summary> /// <param name="startupSettings">The settings used for startup of the application.</param> public static void InitializeApplication(StartupSettings startupSettings) { // Initialize the most important services: var container = new AltaxoServiceContainer(); container.AddFallbackProvider(Current.FallbackServiceProvider); container.AddService(typeof(IMessageService), new Altaxo.Main.Services.MessageServiceImpl()); // container.AddService(typeof(ILoggingService), new log4netLoggingService()); Current.Services = container; Current.Log.Info("Initialize application..."); var startup = new CoreStartup(startupSettings.ApplicationName); if (startupSettings.UseExceptionBoxForErrorHandler) { ExceptionBox.RegisterExceptionBoxForUnhandledExceptions(); } string configDirectory = startupSettings.ConfigDirectory; string dataDirectory = startupSettings.DataDirectory; string propertiesName; if (startupSettings.PropertiesName != null) { propertiesName = startupSettings.PropertiesName; } else { propertiesName = startupSettings.ApplicationName + "Properties"; } if (startupSettings.ApplicationRootPath != null) { FileUtility.ApplicationRootPath = startupSettings.ApplicationRootPath; } if (configDirectory == null) { configDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), startupSettings.ApplicationName); } var propertyService = new Altaxo.Main.Services.PropertyService( DirectoryName.Create(configDirectory), DirectoryName.Create(dataDirectory ?? Path.Combine(FileUtility.ApplicationRootPath, "data")), propertiesName); startup.StartCoreServices(propertyService, startupSettings); var exe = Assembly.Load(startupSettings.ResourceAssemblyName); Current.ResourceService.RegisterNeutralStrings(new ResourceManager("Altaxo.Resources.StringResources", exe)); Current.ResourceService.RegisterNeutralImages(new ResourceManager("Altaxo.Resources.BitmapResources", exe)); Current.ResourceService.RegisterNeutralStrings(new ResourceManager("Altaxo.Resources.AltaxoString", exe)); Current.ResourceService.RegisterNeutralImages(new ResourceManager("Altaxo.Resources.AltaxoBitmap", exe)); CommandWrapper.LinkCommandCreator = (link => new LinkCommand(link)); // creation of command for opening web sites CommandWrapper.WellKnownCommandCreator = MenuService.GetKnownCommand; // creation of all other commands CommandWrapper.RegisterConditionRequerySuggestedHandler = (eh => CommandManager.RequerySuggested += eh); // CommandWrapper has to know how to subscribe to the RequerySuggested event of the command manager CommandWrapper.UnregisterConditionRequerySuggestedHandler = (eh => CommandManager.RequerySuggested -= eh); // CommandWrapper must know how to unsubscribe to the RequerySuggested event of the command manager Current.Log.Info("Looking for AddIns..."); foreach (string file in startupSettings._addInFiles) { startup.AddAddInFile(file); } foreach (string dir in startupSettings._addInDirectories) { startup.AddAddInsFromDirectory(dir); } if (startupSettings.AllowAddInConfigurationAndExternalAddIns) { startup.ConfigureExternalAddIns(Path.Combine(configDirectory, "AddIns.xml")); } if (startupSettings.AllowUserAddIns) { startup.ConfigureUserAddIns(Path.Combine(configDirectory, "AddInInstallTemp"), Path.Combine(configDirectory, "AddIns")); } Current.Log.Info("Loading AddInTree..."); startup.RunInitialization(); Current.Log.Info("Init application finished"); }
void CreateTestProject() { testProject = ProjectHelper.CreateTestProject(); testProject.ParentSolution.Stub(s => s.Directory).Return(DirectoryName.Create(@"c:\projects\Test\MyProject")); }
public void TempFolderExists() { Assert.IsTrue(fileSystem.DirectoryExists(DirectoryName.Create(@"c:\temp"))); }
void CreateProject() { if (categoryTreeView.SelectedNode != null) { ICSharpCode.Core.PropertyService.Set("Dialogs.NewProjectDialog.LastSelectedCategory", TreeViewHelper.GetPath(categoryTreeView.SelectedNode)); ICSharpCode.Core.PropertyService.Set("Dialogs.NewProjectDialog.CategoryTreeState", TreeViewHelper.GetViewStateString(categoryTreeView)); ICSharpCode.Core.PropertyService.Set("Dialogs.NewProjectDialog.LargeImages", largeIconsRadioButton.Checked); } string solution = solutionNameTextBox.Text.Trim(); string name = nameTextBox.Text.Trim(); string location = locationTextBox.Text.Trim(); string projectNameError = CheckProjectName(solution, name, location); if (projectNameError != null) { MessageService.ShowError(projectNameError); return; } if (templateListView.SelectedItems.Count == 1 && locationTextBox.Text.Length > 0 && solutionNameTextBox.Text.Length > 0) { TemplateItem item = (TemplateItem)templateListView.SelectedItems[0]; try { System.IO.Directory.CreateDirectory(NewProjectDirectory); } catch (Exception) { MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.CantCreateDirectoryError}"); return; } ProjectTemplateOptions cinfo = new ProjectTemplateOptions(); if (item.Template.SupportedTargetFrameworks.Any()) { cinfo.TargetFramework = (TargetFramework)targetFrameworkComboBox.SelectedItem; ICSharpCode.Core.PropertyService.Set("Dialogs.NewProjectDialog.TargetFramework", cinfo.TargetFramework.TargetFrameworkVersion); } cinfo.ProjectBasePath = DirectoryName.Create(NewProjectDirectory); cinfo.ProjectName = name; if (createNewSolution) { if (!SD.ProjectService.CloseSolution()) { return; } result = item.Template.CreateAndOpenSolution(cinfo, NewSolutionDirectory, solution); } else { cinfo.Solution = SolutionFolder.ParentSolution; cinfo.SolutionFolder = SolutionFolder; result = item.Template.CreateProjects(cinfo); cinfo.Solution.Save(); } if (result != null) { item.Template.RunOpenActions(result); } ProjectBrowserPad.RefreshViewAsync(); DialogResult = DialogResult.OK; } }
public void GetFilesReturnsEmptyArrayForUnknownDirectory() { Assert.AreEqual(new string[0], fileSystem.GetFiles(DirectoryName.Create(@"c:\unknown-dir"), String.Empty)); }
public void UnknownDirectoryDoesNotExist() { Assert.IsFalse(fileSystem.DirectoryExists(DirectoryName.Create(@"c:\unknown-dir"))); }
public void InitSharpDevelopCore(SharpDevelopHost.CallbackHelper callback, StartupSettings properties) { // Initialize the most important services: var container = new SharpDevelopServiceContainer(); container.AddFallbackProvider(ServiceSingleton.FallbackServiceProvider); container.AddService(typeof(IMessageService), new SDMessageService()); container.AddService(typeof(ILoggingService), new log4netLoggingService()); ServiceSingleton.ServiceProvider = container; LoggingService.Info("InitSharpDevelop..."); this.callback = callback; CoreStartup startup = new CoreStartup(properties.ApplicationName); if (properties.UseSharpDevelopErrorHandler) { this.useSharpDevelopErrorHandler = true; ExceptionBox.RegisterExceptionBoxForUnhandledExceptions(); } string configDirectory = properties.ConfigDirectory; string dataDirectory = properties.DataDirectory; string propertiesName; if (properties.PropertiesName != null) { propertiesName = properties.PropertiesName; } else { propertiesName = properties.ApplicationName + "Properties"; } if (properties.ApplicationRootPath != null) { FileUtility.ApplicationRootPath = properties.ApplicationRootPath; } if (configDirectory == null) { configDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), properties.ApplicationName); } var propertyService = new PropertyService( DirectoryName.Create(configDirectory), DirectoryName.Create(dataDirectory ?? Path.Combine(FileUtility.ApplicationRootPath, "data")), propertiesName); startup.StartCoreServices(propertyService); Assembly exe = Assembly.Load(properties.ResourceAssemblyName); SD.ResourceService.RegisterNeutralStrings(new ResourceManager("ICSharpCode.SharpDevelop.Resources.StringResources", exe)); SD.ResourceService.RegisterNeutralImages(new ResourceManager("ICSharpCode.SharpDevelop.Resources.BitmapResources", exe)); CommandWrapper.LinkCommandCreator = (link => new LinkCommand(link)); CommandWrapper.WellKnownCommandCreator = Core.Presentation.MenuService.GetKnownCommand; CommandWrapper.RegisterConditionRequerySuggestedHandler = (eh => CommandManager.RequerySuggested += eh); CommandWrapper.UnregisterConditionRequerySuggestedHandler = (eh => CommandManager.RequerySuggested -= eh); StringParser.RegisterStringTagProvider(new SharpDevelopStringTagProvider()); LoggingService.Info("Looking for AddIns..."); foreach (string file in properties.addInFiles) { startup.AddAddInFile(file); } foreach (string dir in properties.addInDirectories) { startup.AddAddInsFromDirectory(dir); } if (properties.AllowAddInConfigurationAndExternalAddIns) { startup.ConfigureExternalAddIns(Path.Combine(configDirectory, "AddIns.xml")); } if (properties.AllowUserAddIns) { startup.ConfigureUserAddIns(Path.Combine(configDirectory, "AddInInstallTemp"), Path.Combine(configDirectory, "AddIns")); } LoggingService.Info("Loading AddInTree..."); startup.RunInitialization(); ((AssemblyParserService)SD.AssemblyParserService).DomPersistencePath = properties.DomPersistencePath; // Register events to marshal back Project.ProjectService.BuildStarted += delegate { this.callback.StartBuild(); }; Project.ProjectService.BuildFinished += delegate { this.callback.EndBuild(); }; Project.ProjectService.SolutionLoaded += delegate { this.callback.SolutionLoaded(); }; Project.ProjectService.SolutionClosed += delegate { this.callback.SolutionClosed(); }; FileUtility.FileLoaded += delegate(object sender, FileNameEventArgs e) { this.callback.FileLoaded(e.FileName); }; FileUtility.FileSaved += delegate(object sender, FileNameEventArgs e) { this.callback.FileSaved(e.FileName); }; LoggingService.Info("InitSharpDevelop finished"); }
public void GetFilesReturnsFilesSpecifiedInAddDirectoryFilesMethodCall() { Assert.AreEqual(tempDirectoryFiles, fileSystem.GetFiles(DirectoryName.Create(@"c:\temp"), String.Empty).Select(f => f.ToString())); }
bool CreateProject() { if (SelectedCategory != null) { ICSharpCode.Core.PropertyService.Set("Dialogs.NewProjectDialog.LastSelectedCategory", SelectedCategory.Text); ICSharpCode.Core.PropertyService.Set("Dialogs.NewProjectDialog.LargeImages", SelectedIconSizeIndex); } string solution = SolutionName.Trim(); string name = ProjectName.Trim(); string location = ProjectLocationDirectory.Trim(); string projectNameError = CheckProjectName(solution, name, location); if (projectNameError != null) { MessageService.ShowError(projectNameError); return(false); } if (SelectedTemplate != null && ProjectLocationDirectory.Length > 0 && SolutionName.Length > 0) { TemplateItem item = SelectedTemplate; try { System.IO.Directory.CreateDirectory(NewProjectDirectory); } catch (Exception) { MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.CantCreateDirectoryError}"); return(false); } ProjectTemplateOptions cinfo = new ProjectTemplateOptions(); if (item.Template.SupportedTargetFrameworks.Any()) { cinfo.TargetFramework = SelectedTargetFramework; ICSharpCode.Core.PropertyService.Set("Dialogs.NewProjectDialog.TargetFramework", cinfo.TargetFramework.TargetFrameworkVersion); } cinfo.ProjectBasePath = DirectoryName.Create(NewProjectDirectory); cinfo.ProjectName = name; if (CreateNewSolution) { if (!SD.ProjectService.CloseSolution()) { return(false); } _result = item.Template.CreateAndOpenSolution(cinfo, NewSolutionDirectory, solution); } else { cinfo.Solution = SolutionFolder.ParentSolution; cinfo.SolutionFolder = SolutionFolder; _result = item.Template.CreateProjects(cinfo); cinfo.Solution.Save(); } if (_result != null) { item.Template.RunOpenActions(_result); } ProjectBrowserPad.RefreshViewAsync(); return(true); } return(false); }
IEnumerable <FileName> GetMvcViewTemplateFileNamesInFolder(MvcTextTemplateCriteria templateCriteria) { string templatePath = GetMvcViewTemplatePath(templateCriteria); return(fileSystem.GetFiles(DirectoryName.Create(templatePath), "*.tt")); }
void SetProjectDirectory(string directory) { fakeProject.Stub(p => p.Directory).Return(DirectoryName.Create(directory)); }
void CreateDirectoryForCodeCoverageResultsFile(string fileName) { string directory = Path.GetDirectoryName(fileName); fileSystem.CreateDirectory(DirectoryName.Create(directory)); }
void CreateSolution(string fileName) { solution = MockRepository.GenerateStrictMock <ISolution>(); solution.Stub(s => s.FileName).Return(FileName.Create(fileName)); solution.Stub(s => s.Directory).Return(DirectoryName.Create(System.IO.Path.GetDirectoryName(fileName))); }