public void LoadModel(string projectPath)
        {
            _projectPath = projectPath;
            var project = _projectLoader.Load(projectPath);

            _currentProject = project;
            Model           = new SpaceProjectDetails();
            Model.Schemas   = project.Schemas.Values.Select(x => new SchemaDetails {
                Schema = x, SchemaMigrations = project.SchemaMigrations[x.Name]
            }).ToList();
            Model.Queries = project.Queries.Values.Select(x => new QueryDetails {
                Query = x
            }).ToList();
            Model.Forms = project.Forms.Values.Select(x => new FormDetails {
                Form = x
            }).ToList();

            Model.EditWindows = project.Settings.EditWindows.Select(
                s =>
            {
                var obj = FindModelStoreObject(s);
                return(new EditWindowDetails {
                    StoreObject = obj, StoreObjectDetails = FindModelStoreObjectDetails(obj)
                });
            }).ToList();

            Model.EditWindows.ForEach(w => w.Type = GetStoreObjectType(w.StoreObject));
            UpdateFormBuilder();
        }
        public void Run_RunsEntryMethod(string projectDir)
        {
            // Arrange
            string tempDir = $"{_tempDir}{projectDir}";

            _directoryService.Empty(tempDir); // TODO for netstandard2.0 and earlier, AssemblyLoadContexts cannot be unloaded (can't reuse same directory within same process)
            string solutionDir        = Path.GetFullPath(typeof(ProjectHostEndToEndTests).GetTypeInfo().Assembly.Location + "../../../../../../..");
            string projectName        = projectDir;
            string projectAbsSrcDir   = $"{solutionDir}/test/{projectDir}";
            string projectAbsFilePath = $"{tempDir}/{projectName}.csproj";
            string assemblyName       = projectName;
            string className          = $"{projectName}.EntryStubClass";
            int    testExitCode       = 10; // Arbitrary

            string[] stubArgs = new string[] { testExitCode.ToString() };

            _directoryService.Copy(projectAbsSrcDir, tempDir, excludePatterns: new string[] { "^bin$", "^obj$" });

            IServiceCollection services = new ServiceCollection();

            services.AddProjectHost();
            IServiceProvider serviceProvider = services.BuildServiceProvider();
            IProjectLoader   loader          = serviceProvider.GetService <IProjectLoader>();
            IMethodRunner    runner          = serviceProvider.GetService <IMethodRunner>();

            // Act
            Assembly assembly = loader.Load(projectAbsFilePath, assemblyName);
            int      result   = runner.Run(assembly, className, args: stubArgs);

            // Assert
            Assert.Equal(testExitCode, result);
            (serviceProvider as IDisposable).Dispose();
        }
Пример #3
0
        public void Load_BuildsProjectAndLoadsAssembly()
        {
            // Arrange
            // TODO if any tests are added and still using netstandard2.0 and earlier, note that AssemblyLoadContexts cannot be unloaded
            string solutionDir        = Path.GetFullPath(typeof(MethodRunnerIntegrationTests).GetTypeInfo().Assembly.Location + "../../../../../../..");
            string projectDir         = "StubProject.OlderFramework";
            string projectName        = projectDir;
            string projectAbsSrcDir   = $"{solutionDir}/test/{projectDir}";
            string projectAbsFilePath = $"{_tempDir}/{projectName}.csproj";
            string entryAssemblyName  = projectName;
            int    testExitCode       = 10; // Arbitrary

            string[] stubArgs = new string[] { testExitCode.ToString() };

            _directoryService.Copy(projectAbsSrcDir, _tempDir, excludePatterns: new string[] { "^bin$", "^obj$" });

            IServiceCollection services = new ServiceCollection();

            services.AddProjectHost();
            IServiceProvider serviceProvider = services.BuildServiceProvider();
            IProjectLoader   loader          = serviceProvider.GetService <IProjectLoader>();

            // Act
            Assembly result = loader.Load(projectAbsFilePath, entryAssemblyName);

            // Assert
            Assert.Equal(entryAssemblyName, result.GetName().Name);
            (serviceProvider as IDisposable).Dispose();
        }
Пример #4
0
        public bool Execute(int projectId, TimeRegistrationModel timeRegistrationModel)
        {
            var project = projectLoader.Load(projectId);

            if (CanBeSaved(project))
            {
                timeRegistrationSaver.Save(project, timeRegistrationModel);
                return(true);
            }

            return(false);
        }
Пример #5
0
        public static void LoadSolutionOrProject(string fileName)
        {
            IProjectLoader loader = GetProjectLoader(fileName);

            if (loader != null)
            {
                loader.Load(fileName);
            }
            else
            {
                MessageService.ShowError(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.OpenCombine.InvalidProjectOrCombine}", new StringTagPair("FileName", fileName)));
            }
        }
Пример #6
0
 void FileSelected(object sender, EventArgs e)
 {
     foreach (FileList.FileListItem item in filelister.SelectedItems)
     {
         IProjectLoader loader = ProjectService.GetProjectLoader(item.FullName);
         if (loader != null)
         {
             loader.Load(item.FullName);
         }
         else
         {
             FileService.OpenFile(item.FullName);
         }
     }
 }
Пример #7
0
        public Solution LoadFromPath(string pathToSolution)
        {
            pathToSolution = _fileService.GetAbsolutePathBasedOnCurrent(pathToSolution);

            var solution     = new Solution(pathToSolution);
            var projectPaths = _fileService.GetFilesInDirectory(pathToSolution, CsProjectSearchPattern);

            foreach (var projectPath in projectPaths.EmptyIfNull())
            {
                _projectLoader.Load(projectPath);

                var project = GetOrAddProject(solution, projectPath);
                var referencedProjectPaths = _projectLoader.GetReferencedProjectPaths();

                foreach (var referencedProjectPath in referencedProjectPaths.EmptyIfNull())
                {
                    var referencedProject = GetOrAddProject(solution, referencedProjectPath);
                    project.AddReferencedProject(referencedProject);
                }

                var packageReferences = _projectLoader.GetPackageReferences();

                foreach (var(packageName, packageVersion) in packageReferences.EmptyIfNull())
                {
                    if (!solution.TryGetPackage(packageName, packageVersion, out var package))
                    {
                        package = new Package(packageName, packageVersion);
                        solution.AddPackage(package);
                    }

                    project.AddPackage(package);
                }
            }

            return(solution);
        }
Пример #8
0
        public void Run(IList <string> fileList)
        {
            //WorkbenchSingleton.MainForm.Show();

            bool didLoadSolutionOrFile = false;

            NavigationService.SuspendLogging();

            foreach (string file in fileList)
            {
                LoggingService.Info("Open file " + file);
                didLoadSolutionOrFile = true;
                try {
                    string fullFileName = Path.GetFullPath(file);

                    IProjectLoader loader = ProjectService.GetProjectLoader(fullFileName);
                    if (loader != null)
                    {
                        loader.Load(fullFileName);
                    }
                    else
                    {
                        FileService.OpenFile(fullFileName);
                    }
                } catch (Exception e) {
                    MessageService.ShowError(e, "unable to open file " + file);
                }
            }

            // load previous solution
            if (!didLoadSolutionOrFile && PropertyService.Get("SharpDevelop.LoadPrevProjectOnStartup", false))
            {
                if (FileService.RecentOpen.RecentProject.Count > 0)
                {
                    ProjectService.LoadSolution(FileService.RecentOpen.RecentProject[0].ToString());
                    didLoadSolutionOrFile = true;
                }
            }

            if (!didLoadSolutionOrFile)
            {
                foreach (ICommand command in AddInTree.BuildItems <ICommand>("/Workspace/AutostartNothingLoaded", null, false))
                {
                    try {
                        command.Run();
                    } catch (Exception ex) {
                        MessageService.ShowError(ex);
                    }
                }
            }

            NavigationService.ResumeLogging();

            //WorkbenchSingleton.MainForm.Focus(); // windows.forms focus workaround

            ParserService.StartParserThread();

            // finally run the workbench window ...
            Application.AddMessageFilter(new FormKeyHandler());
            Application.Run(WorkbenchSingleton.MainForm);

            // save the workbench memento in the ide properties
            try {
                PropertyService.Set(workbenchMemento, WorkbenchSingleton.Workbench.CreateMemento());
            } catch (Exception e) {
                MessageService.ShowError(e, "Exception while saving workbench state.");
            }
        }
        public override bool Execute()
        {
            if (string.Compare(Platform, "Web", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                // Trigger JSIL provider download if needed.
                string jsilDirectory, jsilCompilerFile;
                if (!m_JSILProvider.GetJSIL(out jsilDirectory, out jsilCompilerFile))
                {
                    return(false);
                }
            }

            var module = ModuleInfo.Load(Path.Combine(RootPath, "Build", "Module.xml"));

            LogMessage(
                "Starting generation of projects for " + Platform);

            var definitions    = module.GetDefinitionsRecursively(Platform).ToArray();
            var loadedProjects = new List <LoadedDefinitionInfo>();

            if (_hostPlatformDetector.DetectPlatform() == "Windows")
            {
                var concurrentProjects = new ConcurrentBag <LoadedDefinitionInfo>();

                Parallel.ForEach(definitions, definition =>
                {
                    LogMessage("Loading: " + definition.Name);
                    concurrentProjects.Add(
                        m_ProjectLoader.Load(
                            Platform,
                            module,
                            definition));
                });

                // Do this so we maintain order with the original definitions list.
                foreach (var definition in definitions)
                {
                    var loadedProject = concurrentProjects.FirstOrDefault(x => x.Definition == definition);
                    if (loadedProject != null)
                    {
                        loadedProjects.Add(loadedProject);
                    }
                }
            }
            else
            {
                foreach (var definition in definitions)
                {
                    LogMessage("Loading: " + definition.Name);
                    loadedProjects.Add(
                        m_ProjectLoader.Load(
                            Platform,
                            module,
                            definition));
                }
            }

            var                  serviceManager = new ServiceManager(Platform);
            List <Service>       services;
            TemporaryServiceSpec serviceSpecPath;

            if (ServiceSpecPath == null)
            {
                serviceManager.SetRootDefinitions(module.GetDefinitions());

                if (EnableServices == null)
                {
                    EnableServices = new string[0];
                }

                if (DisableServices == null)
                {
                    DisableServices = new string[0];
                }

                foreach (var service in EnableServices)
                {
                    serviceManager.EnableService(service);
                }

                foreach (var service in DisableServices)
                {
                    serviceManager.DisableService(service);
                }

                if (DebugServiceResolution)
                {
                    serviceManager.EnableDebugInformation();
                }

                try
                {
                    services = serviceManager.CalculateDependencyGraph(loadedProjects.Select(x => x.Project).ToList());
                }
                catch (InvalidOperationException ex)
                {
                    RedirectableConsole.WriteLine("Error during service resolution: " + ex.Message);
                    return(false);
                }

                serviceSpecPath = serviceManager.SaveServiceSpec(services);

                foreach (var service in services)
                {
                    if (service.ServiceName != null)
                    {
                        LogMessage("Enabled service: " + service.FullName);
                    }
                }
            }
            else
            {
                services        = serviceManager.LoadServiceSpec(ServiceSpecPath);
                serviceSpecPath = new TemporaryServiceSpec(ServiceSpecPath, true);
            }

            using (serviceSpecPath)
            {
                var submodulesToProcess = new List <ModuleInfo>();
                var allSubmodules       = module.GetSubmodules(Platform);

                if (_hostPlatformDetector.DetectPlatform() == "Windows")
                {
                    var concurrentSubmodulesToProcess = new ConcurrentBag <ModuleInfo>();

                    Parallel.ForEach(allSubmodules, submodule =>
                    {
                        if (_featureManager.IsFeatureEnabledInSubmodule(module, submodule,
                                                                        Feature.OptimizationSkipInvocationOnNoStandardProjects))
                        {
                            if (submodule.GetDefinitionsRecursively(Platform).All(x => !x.IsStandardProject))
                            {
                                // Do not invoke this submodule.
                                LogMessage(
                                    "Skipping submodule generation for " + submodule.Name +
                                    " (there are no projects to generate)");
                            }
                            else
                            {
                                concurrentSubmodulesToProcess.Add(submodule);
                            }
                        }
                    });

                    // Do this so we maintain order with the original GetSubmodules list.
                    foreach (var submodule in allSubmodules)
                    {
                        if (concurrentSubmodulesToProcess.Contains(submodule))
                        {
                            submodulesToProcess.Add(submodule);
                        }
                    }
                }
                else
                {
                    foreach (var submodule in module.GetSubmodules(Platform))
                    {
                        if (_featureManager.IsFeatureEnabledInSubmodule(module, submodule,
                                                                        Feature.OptimizationSkipInvocationOnNoStandardProjects))
                        {
                            if (submodule.GetDefinitionsRecursively(Platform).All(x => !x.IsStandardProject))
                            {
                                // Do not invoke this submodule.
                                LogMessage(
                                    "Skipping submodule generation for " + submodule.Name +
                                    " (there are no projects to generate)");
                            }
                            else
                            {
                                submodulesToProcess.Add(submodule);
                            }
                        }
                    }
                }

                // Run Protobuild in batch mode in each of the submodules
                // where it is present.
                foreach (var submodule in submodulesToProcess)
                {
                    LogMessage(
                        "Invoking submodule generation for " + submodule.Name);
                    var noResolve = _featureManager.IsFeatureEnabledInSubmodule(module, submodule,
                                                                                Feature.PackageManagementNoResolve)
                        ? " -no-resolve"
                        : string.Empty;
                    var noHostPlatform = DisableHostPlatformGeneration &&
                                         _featureManager.IsFeatureEnabledInSubmodule(module, submodule,
                                                                                     Feature.NoHostGenerate)
                        ? " -no-host-generate"
                        : string.Empty;
                    _moduleExecution.RunProtobuild(
                        submodule,
                        _featureManager.GetFeatureArgumentToPassToSubmodule(module, submodule) +
                        "-generate " + Platform +
                        " -spec " + serviceSpecPath +
                        " " + m_PackageRedirector.GetRedirectionArguments() +
                        noResolve + noHostPlatform);
                    LogMessage(
                        "Finished submodule generation for " + submodule.Name);
                }

                var repositoryPaths = new List <string>();

                if (_hostPlatformDetector.DetectPlatform() == "Windows")
                {
                    var concurrentRepositoryPaths = new ConcurrentBag <string>();

                    Parallel.ForEach(definitions.Where(x => x.ModulePath == module.Path), definition =>
                    {
                        if (definition.PostBuildHook && RequiresHostPlatform != null)
                        {
                            // We require the host platform projects at this point.
                            RequiresHostPlatform();
                        }

                        string repositoryPath;
                        var definitionCopy = definition;
                        m_ProjectGenerator.Generate(
                            definition,
                            loadedProjects,
                            WorkingDirectory,
                            RootPath,
                            definition.Name,
                            Platform,
                            services,
                            out repositoryPath,
                            () => LogMessage("Generating: " + definitionCopy.Name),
                            DebugProjectGeneration);

                        // Only add repository paths if they should be generated.
                        if (module.GenerateNuGetRepositories && !string.IsNullOrEmpty(repositoryPath))
                        {
                            concurrentRepositoryPaths.Add(repositoryPath);
                        }
                    });

                    repositoryPaths = concurrentRepositoryPaths.ToList();
                }
                else
                {
                    foreach (var definition in definitions.Where(x => x.ModulePath == module.Path))
                    {
                        if (definition.PostBuildHook && RequiresHostPlatform != null)
                        {
                            // We require the host platform projects at this point.
                            RequiresHostPlatform();
                        }

                        string repositoryPath;
                        var    definitionCopy = definition;
                        m_ProjectGenerator.Generate(
                            definition,
                            loadedProjects,
                            WorkingDirectory,
                            RootPath,
                            definition.Name,
                            Platform,
                            services,
                            out repositoryPath,
                            () => LogMessage("Generating: " + definitionCopy.Name),
                            DebugProjectGeneration);

                        // Only add repository paths if they should be generated.
                        if (module.GenerateNuGetRepositories && !string.IsNullOrEmpty(repositoryPath))
                        {
                            repositoryPaths.Add(repositoryPath);
                        }
                    }
                }

                var solution = Path.Combine(
                    RootPath,
                    ModuleName + "." + Platform + ".sln");
                LogMessage("Generating: (solution)");
                m_SolutionGenerator.Generate(
                    WorkingDirectory,
                    module,
                    loadedProjects.Select(x => x.Project).ToList(),
                    Platform,
                    solution,
                    services,
                    repositoryPaths,
                    DebugProjectGeneration);

                // Only save the specification cache if we allow synchronisation
                if (module.DisableSynchronisation == null || !module.DisableSynchronisation.Value)
                {
                    var serviceCache = Path.Combine(RootPath, ModuleName + "." + Platform + ".speccache");
                    LogMessage("Saving service specification");
                    File.Copy(serviceSpecPath.Path, serviceCache, true);
                }

                LogMessage(
                    "Generation complete.");
            }

            return(true);
        }