public static void Main(string[] args) { //================ JSON Serialization tests ===================== Console.WriteLine("=================TEST: JSON Serialization Started================="); Workspace wks = new Workspace(); wks.Name = "MyWorkspace"; wks.Id = Guid.NewGuid(); Project prj = new Project(); prj.Name = "MyFirstProject"; prj.Id = Guid.NewGuid(); Project prj2 = new Project(); prj.Name = "MySecondProject"; prj.Id = Guid.NewGuid(); wks.AddProject(prj); wks.AddProject(prj2); ProjectItem srcFolder = new ProjectItem(); srcFolder.Name = "Src Folder"; srcFolder.Id = Guid.NewGuid(); prj.AddProjectItem(srcFolder); ProjectItem cfile = new ProjectItem(); cfile.Name = "Program.cs"; cfile.Id = Guid.NewGuid(); srcFolder.AddProjectItem(cfile); LayoutSelector layoutSelector = new LayoutSelector(); NewtonsoftJSONSerializer.Serialize(wks, "Workspace.json"); NewtonsoftJSONSerializer.Serialize(layoutSelector, "DefaultLayout.json"); Console.WriteLine("=================TEST: JSON Serialization Completed================="); //================ LayoutSelector test ======================== Console.WriteLine("=================TEST: LayoutSelector Started================="); foreach (ILayoutElement layout in layoutSelector.Layouts) { Console.WriteLine("Layout: {0}", layout.ToString()); } Console.WriteLine("=================TEST: LayoutSelector Completed================="); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); }
public void TestCreateModels() { wks = new Workspace(); wks.Name = "MyWorkspace"; wks.Id = Guid.NewGuid(); Assert.AreEqual("MyWorkspace", wks.Name); prj = new Project(); prj.Name = "MyFirstProject"; prj.Id = Guid.NewGuid(); Assert.AreEqual("MyFirstProject", prj.Name); wks.AddProject(prj); srcFolder = new ProjectItem(); srcFolder.Name = "Src Folder"; srcFolder.Id = Guid.NewGuid(); Assert.AreEqual("Src Folder", srcFolder.Name); prj.AddProjectItem(srcFolder); cfile = new ProjectItem(); cfile.Name = "Program.cs"; cfile.Id = Guid.NewGuid(); Assert.AreEqual("Program.cs", cfile.Name); srcFolder.AddProjectItem(cfile); }
private void CreateModuleProject() { var refs = CollectReferencedAssemblies(); var moduleProjectName = "RuntimeModule"; var moduleProjectID = ProjectId.CreateNewId(); var versionStamp = VersionStamp.Create(); var projInfo = ProjectInfo.Create(moduleProjectID, versionStamp, moduleProjectName, moduleProjectName, LanguageNames.CSharp, compilationOptions: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); projInfo = projInfo.WithMetadataReferences(refs); Workspace.AddProject(projInfo); //取得所有用户定义的业务类型,并生成文档. var businessObjects = this.objectSpace.GetObjectsQuery <BusinessObjectBase>().Where(x => x.IsRuntimeDefine); CreateAssembyInfoDocument(); CreateRuntimeModule(); Documents.Clear(); foreach (var bo in businessObjects) { CreateDocument(bo); } }
public OmniSharpWorkspaceTestBase() { Workspace = TestOmniSharpWorkspace.Create(); var projectId = ProjectId.CreateNewId(); var projectInfo = ProjectInfo.Create(projectId, VersionStamp.Default, "TestProject", "TestAssembly", LanguageNames.CSharp, filePath: "/path/to/project.csproj"); Workspace.AddProject(projectInfo); Project = Workspace.CurrentSolution.Projects.FirstOrDefault(); }
private void CreateModuleProject() { var refs = CollectReferencedAssemblies(); var moduleProjectName = "RuntimeModule"; var moduleProjectID = ProjectId.CreateNewId(); var versionStamp = VersionStamp.Create(); var projInfo = ProjectInfo.Create(moduleProjectID, versionStamp, moduleProjectName, moduleProjectName, LanguageNames.CSharp, compilationOptions: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); projInfo = projInfo.WithMetadataReferences(refs); Workspace.AddProject(projInfo); //取得所有用户定义的业务类型,并生成文档. var businessObjects = this.objectSpace.GetObjects <BusinessObject>(new BinaryOperator("IsRuntimeDefine", true)); CreateAssembyInfoDocument(); CreateRuntimeModule(); Documents.Clear(); foreach (var bo in businessObjects) { CreateDocument(bo); } var partialLogics = this.objectSpace.GetObjects <BusinessObjectPartialLogic>(null, true); foreach (var logic in partialLogics) { CreateDocument(logic); } var flowactions = this.objectSpace.GetObjects <FlowAction>(null, true); foreach (var flowacion in flowactions) { CreateDocument(flowacion); } var layouts = this.objectSpace.GetObjects <BusinessObjectLayout>(); foreach (var item in layouts) { CreateDocument(item); } var controllers = this.objectSpace.GetObjects <RuntimeController>(null, true); foreach (var item in controllers) { CreateDocument(item); } }
public TestProjectBuilder AddNewProject(string name) { ProjectId projectId = ProjectId.CreateNewId(); VersionStamp vers = VersionStamp.Create(); ProjectInfo projectInfo = ProjectInfo.Create(projectId, vers, name, name, LanguageNames.CSharp); MetadataReference reference = MetadataReference.CreateFromFile(typeof(int).Assembly.Location); projectInfo = projectInfo.WithMetadataReferences(new List <MetadataReference>() { reference }); return(new TestProjectBuilder(Workspace, Workspace.AddProject(projectInfo).Id)); }
/// <summary> /// Adds a project to the workspace. All previous projects remain intact. /// </summary> public ProjectID AddProject(string name) { return(Workspace.AddProject(name, LanguageNames.CSharp).Id); }
/// <summary> /// Each .csx file is to be wrapped in its own project. /// This recursive function does a depth first traversal of the .csx files, following #load references /// </summary> private ProjectInfo CreateCsxProject(string csxPath, IScriptServicesBuilder baseBuilder) { // Circular #load chains are not allowed if (Context.CsxFilesBeingProcessed.Contains(csxPath)) { throw new Exception($"Circular refrences among script files are not allowed: {csxPath} #loads files that end up trying to #load it again."); } // If we already have a project for this path just use that if (Context.CsxFileProjects.ContainsKey(csxPath)) { return(Context.CsxFileProjects[csxPath]); } // Process the file with ScriptCS first Logger.LogInformation($"Processing script {csxPath}..."); Context.CsxFilesBeingProcessed.Add(csxPath); var localScriptServices = baseBuilder.ScriptName(csxPath).Build(); var processResult = localScriptServices.FilePreProcessor.ProcessFile(csxPath); // CSX file usings Context.CsxUsings[csxPath] = processResult.Namespaces.ToList(); var compilationOptions = new CSharpCompilationOptions( outputKind: OutputKind.DynamicallyLinkedLibrary, usings: Context.CommonUsings.Union(Context.CsxUsings[csxPath])); // #r refernces Context.CsxReferences[csxPath] = localScriptServices.MakeMetadataReferences(processResult.References).ToList(); //#load references recursively Context.CsxLoadReferences[csxPath] = processResult .LoadedScripts .Distinct() .Except(new[] { csxPath }) .Select(loadedCsxPath => CreateCsxProject(loadedCsxPath, baseBuilder)) .ToList(); // Create the wrapper project and add it to the workspace Logger.LogDebug($"Creating project for script {csxPath}."); var csxFileName = Path.GetFileName(csxPath); var project = ProjectInfo.Create( id: ProjectId.CreateNewId(Guid.NewGuid().ToString()), version: VersionStamp.Create(), name: csxFileName, assemblyName: $"{csxFileName}.dll", language: LanguageNames.CSharp, compilationOptions: compilationOptions, parseOptions: CsxParseOptions, metadataReferences: Context.CommonReferences.Union(Context.CsxReferences[csxPath]), projectReferences: Context.CsxLoadReferences[csxPath].Select(p => new ProjectReference(p.Id)), isSubmission: true, hostObjectType: typeof(IScriptHost)); Workspace.AddProject(project); AddFile(csxPath, project.Id); //----------LOG ONLY------------ Logger.LogDebug($"All references by {csxFileName}: \n{string.Join("\n", project.MetadataReferences.Select(r => r.Display))}"); Logger.LogDebug($"All #load projects by {csxFileName}: \n{string.Join("\n", Context.CsxLoadReferences[csxPath].Select(p => p.Name))}"); Logger.LogDebug($"All usings in {csxFileName}: \n{string.Join("\n", (project.CompilationOptions as CSharpCompilationOptions)?.Usings ?? new ImmutableArray<string>())}"); //------------------------------ // Traversal administration Context.CsxFileProjects[csxPath] = project; Context.CsxFilesBeingProcessed.Remove(csxPath); return(project); }