コード例 #1
0
        private async Task DoOnSolutionReadyOrChange()
        {
            if (!File.Exists(_workspace.CurrentSolution.FilePath))
            {
                LogWarn("Could not find solution.");
                return;
            }

            if (!CurrentSolutionHasBitConfigV1JsonFile())
            {
                LogWarn("Could not find BitConfigV1.json file.");
                return;
            }

            _outputPane.Clear();

            DefaultBitConfigProvider configProvider = new DefaultBitConfigProvider();

            BitConfig config = null;

            try
            {
                config = configProvider.GetConfiguration(_workspace.CurrentSolution, Enumerable.Empty <Project>().ToList());

                foreach (BitCodeGeneratorMapping mapping in config.BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
                {
                    if (!_workspace.CurrentSolution.Projects.Any(p => p.Name == mapping.DestinationProject.Name && p.Language == LanguageNames.CSharp))
                    {
                        throw new InvalidOperationException($"No project found named {mapping.DestinationProject.Name}");
                    }

                    foreach (BitTools.Core.Model.ProjectInfo proj in mapping.SourceProjects)
                    {
                        if (!_workspace.CurrentSolution.Projects.Any(p => p.Name == proj.Name && p.Language == LanguageNames.CSharp))
                        {
                            throw new InvalidOperationException($"No project found named {proj.Name}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogException("Parse BitConfigV1.json failed.", ex);
                return;
            }

            try
            {
                InitHtmlElements(config);
            }
            catch (Exception ex)
            {
                LogException("Init html elements failed.", ex);
            }

            _shouldGeneratedProjects             = new List <Project> {
            };
            generateCodesForTheFirstTimeExecuted = false;
            thereWasAnErrorInBuild = false;
        }
コード例 #2
0
        public virtual IList <BitCodeGeneratorMapping> GetBitCodeGeneratorMappings(Workspace workspace, Solution solution, IList <Project> projects)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            if (solution == null)
            {
                throw new ArgumentNullException(nameof(solution));
            }

            if (projects == null)
            {
                throw new ArgumentNullException(nameof(projects));
            }

            HashSet <BitCodeGeneratorMapping> affectedBitCodeGeneratorMappings = new HashSet <BitCodeGeneratorMapping>();

            BitConfig bitConfig = _configurationProvider.GetConfiguration(workspace, solution, projects);

            foreach (Project vsProject in projects)
            {
                bitConfig.BitCodeGeneratorConfigs
                .BitCodeGeneratorMappings
                .Where(cm => cm.SourceProjects.Any(sp => sp.Name == vsProject.Name))
                .ToList()
                .ForEach((sm) => affectedBitCodeGeneratorMappings.Add(sm));
            }

            return(affectedBitCodeGeneratorMappings.ToList());
        }
コード例 #3
0
        public virtual IList <BitCodeGeneratorMapping> GetBitCodeGeneratorMappings(Workspace workspace, IList <string> projectNames)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            if (projectNames == null)
            {
                throw new ArgumentNullException(nameof(projectNames));
            }

            HashSet <BitCodeGeneratorMapping> affectedBitCodeGeneratorMappings = new HashSet <BitCodeGeneratorMapping>();

            BitConfig bitConfig = _configurationProvider.GetConfiguration(workspace.CurrentSolution.FilePath);

            foreach (string projName in projectNames)
            {
                bitConfig.BitCodeGeneratorConfigs
                .BitCodeGeneratorMappings
                .Where(cm => cm.SourceProjects.Any(sp => sp.Name == projName))
                .ToList()
                .ForEach((sm) => affectedBitCodeGeneratorMappings.Add(sm));
            }

            return(affectedBitCodeGeneratorMappings.ToList());
        }
コード例 #4
0
        public virtual BitConfig GetConfiguration()
        {
            BitConfig bitConfig = JsonConvert
                                  .DeserializeObject <BitConfig>(
                File.ReadAllText(GetBitConfigFilePath()));

            foreach (BitCodeGeneratorMapping mapping in bitConfig.BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
            {
                if (string.IsNullOrEmpty(mapping.DestinationFileName))
                {
                    throw new InvalidOperationException($"{nameof(BitCodeGeneratorMapping.DestinationFileName)} is not provided");
                }

                if (string.IsNullOrEmpty(mapping.DestinationProject?.Name))
                {
                    throw new InvalidOperationException($"{nameof(BitCodeGeneratorMapping.DestinationProject)} is not provided");
                }

                if (mapping.SourceProjects == null || !mapping.SourceProjects.Any() || !mapping.SourceProjects.All(sp => !string.IsNullOrEmpty(sp?.Name)))
                {
                    throw new InvalidOperationException($"No {nameof(BitCodeGeneratorMapping.SourceProjects)} is not provided");
                }

                if (string.IsNullOrEmpty(mapping.Route))
                {
                    throw new InvalidOperationException($"{nameof(BitCodeGeneratorMapping.Route)} is not provided");
                }
            }

            return(bitConfig);
        }
コード例 #5
0
        public virtual Task DeleteCodes(Workspace workspace)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            BitConfig bitConfig = _bitConfigProvider.GetConfiguration(workspace);

            foreach (BitCodeGeneratorMapping proxyGeneratorMapping in bitConfig.BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
            {
                string contextName = proxyGeneratorMapping.DestinationFileName;

                string jsContextExtension = ".js";
                string tsContextExtension = ".d.ts";

                Project destProject = workspace.CurrentSolution.Projects.Where(p => p.Language == LanguageNames.CSharp)
                                      .ExtendedSingle($"Trying to find project with name: {proxyGeneratorMapping.DestinationProject.Name}", p => p.Name == proxyGeneratorMapping.DestinationProject.Name);

                DeleteFiles(contextName, jsContextExtension, destProject);
                DeleteFiles(contextName, tsContextExtension, destProject);
            }

            return(Task.CompletedTask);
        }
コード例 #6
0
        public virtual async Task GenerateCodes(Workspace workspace)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            BitConfig bitConfig = _bitConfigProvider.GetConfiguration();

            foreach (BitCodeGeneratorMapping proxyGeneratorMapping in bitConfig.BitCodeGeneratorConfigs.BitCodeGeneratorMappings.Where(m => m.GenerationType == GenerationType.CSharp))
            {
                string generatedContextName = proxyGeneratorMapping.DestinationFileName;

                StringBuilder generatedCs = new StringBuilder();

                string generatedCSContextExtension = ".cs";

                Project destProject = workspace.CurrentSolution.Projects.Where(p => p.Language == LanguageNames.CSharp)
                                      .ExtendedSingle($"Trying to find project with name: {proxyGeneratorMapping.DestinationProject.Name}", p => proxyGeneratorMapping.DestinationProject.IsThisProject(p));

                IList <Project> involveableProjects = _bitCodeGeneratorOrderedProjectsProvider.GetInvolveableProjects(workspace, workspace.CurrentSolution.Projects.Where(p => p.Language == LanguageNames.CSharp).ToList(), proxyGeneratorMapping);

                List <DtoController> dtoControllers = new List <DtoController>();

                foreach (Project p in involveableProjects)
                {
                    dtoControllers.AddRange(await _dtoControllersProvider.GetProjectDtoControllersWithTheirOperations(p));
                }

                generatedCs.AppendLine(_contextGenerator.GenerateCSharpContext(dtoControllers, proxyGeneratorMapping));

                WriteFiles(generatedCs.ToString(), generatedContextName, generatedCSContextExtension, destProject);
            }
        }
コード例 #7
0
        public virtual BitConfig GetConfiguration(string solutionFilePath)
        {
            DirectoryInfo directoryInfo = Directory.GetParent(solutionFilePath);

            if (directoryInfo == null)
            {
                throw new InvalidOperationException($"Could not find directory of {solutionFilePath}");
            }

            string bitConfigFileName = $"BitConfig{Version}.json";

            FileInfo bitConfigFileInfo =
                directoryInfo.GetFiles(bitConfigFileName)
                .ExtendedSingleOrDefault($"Looking for {bitConfigFileName}");

            if (bitConfigFileInfo == null)
            {
                throw new BitConfigNotFoundException($"No {bitConfigFileName} found in {directoryInfo.FullName}");
            }

            BitConfig bitConfig = JsonConvert
                                  .DeserializeObject <BitConfig>(
                File.ReadAllText(bitConfigFileInfo.FullName));

            foreach (BitCodeGeneratorMapping mapping in bitConfig.BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
            {
                if (string.IsNullOrEmpty(mapping.DestinationFileName))
                {
                    throw new InvalidOperationException($"{nameof(BitCodeGeneratorMapping.DestinationFileName)} is not provided");
                }

                if (string.IsNullOrEmpty(mapping.TypingsPath))
                {
                    throw new InvalidOperationException($"{nameof(BitCodeGeneratorMapping.TypingsPath)} is not provided");
                }

                if (string.IsNullOrEmpty(mapping.DestinationProject?.Name))
                {
                    throw new InvalidOperationException($"{nameof(BitCodeGeneratorMapping.DestinationProject)} is not provided");
                }

                if (mapping.SourceProjects == null || !mapping.SourceProjects.Any() || !mapping.SourceProjects.All(sp => !string.IsNullOrEmpty(sp?.Name)))
                {
                    throw new InvalidOperationException($"No {nameof(BitCodeGeneratorMapping.SourceProjects)} is not provided");
                }

                if (string.IsNullOrEmpty(mapping.Namespace))
                {
                    throw new InvalidOperationException($"{nameof(BitCodeGeneratorMapping.Namespace)} is not provided");
                }

                if (string.IsNullOrEmpty(mapping.Route))
                {
                    throw new InvalidOperationException($"{nameof(BitCodeGeneratorMapping.Route)} is not provided");
                }
            }

            return(bitConfig);
        }
コード例 #8
0
        public virtual async Task GenerateCodes(Workspace workspace)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            BitConfig bitConfig = _bitConfigProvider.GetConfiguration();

            foreach (BitCodeGeneratorMapping proxyGeneratorMapping in bitConfig.BitCodeGeneratorConfigs.BitCodeGeneratorMappings.Where(m => m.GenerationType == GenerationType.TypeScriptJayDataClient))
            {
                string generatedContextName = proxyGeneratorMapping.DestinationFileName;

                StringBuilder generatedJs = new StringBuilder();
                StringBuilder generatedTs = new StringBuilder();

                string generatedJsContextExtension = ".js";
                string generatedTsContextExtension = ".d.ts";

                Project destProject = workspace.CurrentSolution.Projects.Where(p => p.Language == LanguageNames.CSharp)
                                      .ExtendedSingle($"Trying to find project with name: {proxyGeneratorMapping.DestinationProject.Name}", p => proxyGeneratorMapping.DestinationProject == p);

                IList <Project> involveableProjects = _bitCodeGeneratorOrderedProjectsProvider.GetInvolveableProjects(workspace, workspace.CurrentSolution.Projects.Where(p => p.Language == LanguageNames.CSharp).ToList(), proxyGeneratorMapping);

                List <Dto> dtos = new List <Dto>();

                foreach (Project p in involveableProjects)
                {
                    dtos.AddRange(await _dtosProvider.GetProjectDtos(p, involveableProjects).ConfigureAwait(false));
                }

                List <EnumType> enumTypes = new List <EnumType>();

                foreach (Project p in involveableProjects)
                {
                    enumTypes.AddRange(await _projectEnumTypesProvider.GetProjectEnumTypes(p, involveableProjects).ConfigureAwait(false));
                }

                List <DtoController> dtoControllers = new List <DtoController>();

                foreach (Project p in involveableProjects)
                {
                    dtoControllers.AddRange(await _dtoControllersProvider.GetProjectDtoControllersWithTheirOperations(p).ConfigureAwait(false));
                }

                generatedJs.AppendLine(_dtoGenerator.GenerateJavaScriptDtos(dtos, enumTypes));
                generatedJs.AppendLine(_contextGenerator.GenerateJavaScriptContext(dtoControllers, proxyGeneratorMapping));
                generatedTs.AppendLine(_dtoGenerator.GenerateTypeScriptDtos(dtos, enumTypes, proxyGeneratorMapping.TypingsPath));
                generatedTs.AppendLine(_contextGenerator.GenerateTypeScriptContext(dtoControllers, proxyGeneratorMapping));

                WriteFiles(generatedJs.ToString(), generatedContextName, generatedJsContextExtension, destProject);

                WriteFiles(generatedTs.ToString(), generatedContextName, generatedTsContextExtension, destProject);
            }
        }
コード例 #9
0
        private void InitHtmlElements(BitConfig config)
        {
            try
            {
                HtmlElementsContainer.Elements = new List <BitHtmlElement> {
                };

                List <BitHtmlElement> allElements = new List <BitHtmlElement>();

                foreach (string path in config.Schema.HtmlSchemaFiles)
                {
                    List <BitHtmlElement> newElements = JsonConvert.DeserializeObject <List <BitHtmlElement> >(File.ReadAllText(path));

                    foreach (BitHtmlElement newElement in newElements)
                    {
                        newElement.Attributes  = newElement.Attributes ?? new List <HtmlAttribute> {
                        };
                        newElement.Description = newElement.Description ?? "";

                        if (string.IsNullOrEmpty(newElement.Name))
                        {
                            throw new InvalidOperationException("Element must have a name");
                        }

                        newElement.Type = newElement.Type ?? "";

                        BitHtmlElement equivalentHtmlElement = allElements.FirstOrDefault(e => e.Name == newElement.Name);

                        if (equivalentHtmlElement != null)
                        {
                            equivalentHtmlElement.Attributes.AddRange(newElement.Attributes);
                        }
                        else
                        {
                            allElements.Add(newElement);
                        }
                    }
                }

                if (!allElements.Any(element => element.Name == "*"))
                {
                    allElements.Add(new BitHtmlElement {
                        Name = "*", Attributes = new List <HtmlAttribute> {
                        }, Description = "", Type = "existing"
                    });
                }

                HtmlElementsContainer.Elements = allElements;
            }
            catch (Exception ex)
            {
                LogException("Init html elements failed.", ex);
            }
        }
コード例 #10
0
        public override BitConfig GetConfiguration()
        {
            BitConfig bitConfig = base.GetConfiguration();

            bitConfig.BitCodeGeneratorConfigs.BitCodeGeneratorMappings = bitConfig
                                                                         .BitCodeGeneratorConfigs
                                                                         .BitCodeGeneratorMappings
                                                                         .Where(config => config.SourceProjects.Any(sp => sp.Name == _beingCompiledProjectName))
                                                                         .ToArray();

            return(bitConfig);
        }
コード例 #11
0
        static async Task GenerateCodes()
        {
            BitSourceGeneratorBitConfigProvider bitConfigProvider = new BitSourceGeneratorBitConfigProvider(_bitConfigFilePath !, BeingCompiledProjectName);

            BitConfig bitConfig = bitConfigProvider.GetConfiguration();

            using (MSBuildWorkspace workspace = MSBuildWorkspace.Create(new Dictionary <string, string>
            {
                { "TargetFramework", bitConfig.TargetFramework ?? "net5.0" }
            }))
            {
                workspace.SkipUnrecognizedProjects = workspace.LoadMetadataForReferencedProjects = true;

                workspace.WorkspaceFailed += MSBuildWorkspace_WorkspaceFailed;

                foreach (BitCodeGeneratorMapping mapping in bitConfigProvider.GetConfiguration().BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
                {
                    foreach (Bit.Tooling.Core.Model.ProjectInfo proj in mapping.SourceProjects)
                    {
                        if (workspace.CurrentSolution.Projects.Any(p => proj.IsThisProject(p)))
                        {
                            continue; /*It's already loaded*/
                        }
                        string sourceProjetctPath = proj.Name == BeingCompiledProjectName ? ProjectPath : (AllProjectsPaths ?? throw new InvalidOperationException($"There is no solution project and we're unable to find {proj.Name}")).ExtendedSingle($"Trying to find source project {proj.Name}", projPath => Path.GetFileNameWithoutExtension(projPath) == proj.Name);

                        await workspace.OpenProjectAsync(sourceProjetctPath);
                    }

                    if (!workspace.CurrentSolution.Projects.Any(p => mapping.DestinationProject.IsThisProject(p)))
                    {
                        string DestProjetctPath = mapping.DestinationProject.Name == BeingCompiledProjectName ? ProjectPath : (AllProjectsPaths ?? throw new InvalidOperationException($"There is no solution project and we're unable to find {mapping.DestinationProject.Name}")).ExtendedSingle($"Trying to find destination project {mapping.DestinationProject.Name}", projPath => Path.GetFileNameWithoutExtension(projPath) == mapping.DestinationProject.Name);
                        await workspace.OpenProjectAsync(DestProjetctPath);
                    }
                }

                IProjectDtoControllersProvider           controllersProvider = new DefaultProjectDtoControllersProvider();
                IProjectDtosProvider                     dtosProvider        = new DefaultProjectDtosProvider(controllersProvider);
                IBitCodeGeneratorOrderedProjectsProvider bitCodeGeneratorOrderedProjectsProvider = new DefaultBitCodeGeneratorOrderedProjectsProvider();
                IProjectEnumTypesProvider                projectEnumTypesProvider = new DefaultProjectEnumTypesProvider(controllersProvider, dtosProvider);

                DefaultTypeScriptClientProxyGenerator tsGenerator = new DefaultTypeScriptClientProxyGenerator(bitCodeGeneratorOrderedProjectsProvider,
                                                                                                              bitConfigProvider, dtosProvider
                                                                                                              , new DefaultTypeScriptClientProxyDtoGenerator(), new DefaultTypeScriptClientContextGenerator(), controllersProvider, projectEnumTypesProvider);

                await tsGenerator.GenerateCodes(workspace);

                DefaultCSharpClientProxyGenerator csGenerator = new DefaultCSharpClientProxyGenerator(bitCodeGeneratorOrderedProjectsProvider,
                                                                                                      bitConfigProvider, controllersProvider, new DefaultCSharpClientContextGenerator());

                await csGenerator.GenerateCodes(workspace);
            }
        }
コード例 #12
0
        static async Task GenerateCodes(BitConfig bitConfig, BitSourceGeneratorBitConfigProvider bitConfigProvider)
        {
            using (MSBuildWorkspace workspace = MSBuildWorkspace.Create(new Dictionary <string, string>
            {
                { "TargetFramework", bitConfig.TargetFramework ?? "net6.0" }
            }))
            {
                workspace.SkipUnrecognizedProjects = workspace.LoadMetadataForReferencedProjects = true;

                workspace.WorkspaceFailed += MSBuildWorkspace_WorkspaceFailed;

                foreach (BitCodeGeneratorMapping mapping in bitConfig.BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
                {
                    foreach (Bit.Tooling.Core.Model.ProjectInfo proj in mapping.SourceProjects.Union(new[] { mapping.DestinationProject }))
                    {
                        if (workspace.CurrentSolution.Projects.Any(p => proj == p))
                        {
                            continue; /*It's already loaded*/
                        }
                        string sourceProjetctPath = proj.Name == BeingCompiledProjectName ? ProjectPath : (AllProjectsPaths ?? throw new InvalidOperationException($"There is no solution project and we're unable to find {proj.Name}")).ExtendedSingle($"Trying to find project {proj.Name}", projPath => Path.GetFileNameWithoutExtension(projPath) == proj.Name);

                        await workspace.OpenProjectAsync(sourceProjetctPath).ConfigureAwait(false);
                    }
                }

                IProjectDtoControllersProvider           controllersProvider = new DefaultProjectDtoControllersProvider();
                IProjectDtosProvider                     dtosProvider        = new DefaultProjectDtosProvider(controllersProvider);
                IBitCodeGeneratorOrderedProjectsProvider bitCodeGeneratorOrderedProjectsProvider = new DefaultBitCodeGeneratorOrderedProjectsProvider();
                IProjectEnumTypesProvider                projectEnumTypesProvider = new DefaultProjectEnumTypesProvider(controllersProvider, dtosProvider);

                TypeScriptJayDataClientProxyGenerator typeScriptJayDataGeneratedCode = new TypeScriptJayDataClientProxyGenerator(bitCodeGeneratorOrderedProjectsProvider,
                                                                                                                                 bitConfigProvider, dtosProvider
                                                                                                                                 , new TypeScriptJayDataClientProxyDtoGenerator(), new TypeScriptJayDataClientContextGenerator(), controllersProvider, projectEnumTypesProvider);

                await typeScriptJayDataGeneratedCode.GenerateCodes(workspace).ConfigureAwait(false);

                CSharpSimpleODataClientProxyGenerator csharpSimpleODataClientGeneratedCode = new CSharpSimpleODataClientProxyGenerator(bitCodeGeneratorOrderedProjectsProvider,
                                                                                                                                       bitConfigProvider, controllersProvider, new CSharpSimpleODataClientContextGenerator(), new CSharpSimpleODataClientMetadataGenerator(), dtosProvider, projectEnumTypesProvider);

                await csharpSimpleODataClientGeneratedCode.GenerateCodes(workspace).ConfigureAwait(false);

                CSharpHttpClientProxyGenerator csharpHttpClientProxyGenerator = new CSharpHttpClientProxyGenerator(bitCodeGeneratorOrderedProjectsProvider,
                                                                                                                   bitConfigProvider, controllersProvider, new CSharpHttpClientContextGenerator(), dtosProvider, projectEnumTypesProvider);

                await csharpHttpClientProxyGenerator.GenerateCodes(workspace).ConfigureAwait(false);
            }
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: zoha-shobbar/bitframework
        public static async Task Main(string[] args)
        {
            Init(args);

            BitSourceGeneratorBitConfigProvider bitConfigProvider = new BitSourceGeneratorBitConfigProvider(_bitConfigFilePath !, BeingCompiledProjectName);

            BitConfig bitConfig = bitConfigProvider.GetConfiguration();

            Version?bitConfigVSVersion = string.IsNullOrEmpty(bitConfig.VisualStudioBuildToolsVersion) ? null : new Version(bitConfig.VisualStudioBuildToolsVersion);

            VisualStudioInstance?selectedVSInstance = MSBuildLocator.QueryVisualStudioInstances().Where(vs => bitConfigVSVersion == null || vs.Version == bitConfigVSVersion).OrderByDescending(vs => vs.Version).FirstOrDefault() ?? throw new InvalidOperationException("Visual studio could not be found. Please install visual studio build tools.");

            if (!MSBuildLocator.IsRegistered)
            {
                MSBuildLocator.RegisterInstance(selectedVSInstance);
            }

            Console.WriteLine($"{selectedVSInstance.Version} was selected from followings: {string.Join(",", MSBuildLocator.QueryVisualStudioInstances().Select(vs => vs.Version))}");

            await GenerateCodes(bitConfig, bitConfigProvider);
        }
コード例 #14
0
        public virtual BitConfig GetConfiguration(Workspace workspace, Solution solution, IList <Project> projects)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            if (solution == null)
            {
                throw new ArgumentNullException(nameof(solution));
            }

            if (projects == null)
            {
                throw new ArgumentNullException(nameof(projects));
            }

            DirectoryInfo directoryInfo = new FileInfo(solution.FilePath).Directory;

            if (directoryInfo == null)
            {
                throw new InvalidOperationException($"Could not find directory of {solution.FilePath}");
            }

            string bitConfigFileName = $"BitConfig{Version}.json";

            FileInfo bitConfigFileInfo =
                directoryInfo?.GetFiles(bitConfigFileName)
                .SingleOrDefault();

            if (bitConfigFileInfo == null)
            {
                throw new BitConfigNotFoundException($"No {bitConfigFileName} found in {directoryInfo.FullName}");
            }

            BitConfig bitConfig = JsonConvert
                                  .DeserializeObject <BitConfig>(
                File.ReadAllText(bitConfigFileInfo.FullName));

            foreach (BitCodeGeneratorMapping mapping in bitConfig.BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
            {
                if (string.IsNullOrEmpty(mapping.DestinationFileName))
                {
                    throw new InvalidOperationException("DestinationFileName is not provided");
                }

                if (string.IsNullOrEmpty(mapping.TypingsPath))
                {
                    throw new InvalidOperationException("TypingsPath is not provided");
                }

                if (string.IsNullOrEmpty(mapping?.DestinationProject?.Name))
                {
                    throw new InvalidOperationException("DestinationProject is not provided");
                }

                if (mapping.SourceProjects == null || !mapping.SourceProjects.Any() || !mapping.SourceProjects.All(sp => !string.IsNullOrEmpty(sp?.Name)))
                {
                    throw new InvalidOperationException("No | Bad Source Projects is not provided");
                }

                if (string.IsNullOrEmpty(mapping.Namespace))
                {
                    throw new InvalidOperationException("Namespace is not provided");
                }

                if (string.IsNullOrEmpty(mapping.EdmName))
                {
                    throw new InvalidOperationException("EdmName is not provided");
                }
            }

            return(bitConfig);
        }
コード例 #15
0
        public virtual BitConfig GetConfiguration(string solutionFilePath)
        {
            DirectoryInfo directoryInfo = Directory.GetParent(solutionFilePath);

            if (directoryInfo == null)
            {
                throw new InvalidOperationException($"Could not find directory of {solutionFilePath}");
            }

            string bitConfigFileName = $"BitConfig{Version}.json";

            FileInfo bitConfigFileInfo =
                directoryInfo.GetFiles(bitConfigFileName)
                .ExtendedSingleOrDefault($"Looking for {bitConfigFileName}");

            if (bitConfigFileInfo == null)
            {
                throw new BitConfigNotFoundException($"No {bitConfigFileName} found in {directoryInfo.FullName}");
            }

            BitConfig bitConfig = JsonConvert
                                  .DeserializeObject <BitConfig>(
                File.ReadAllText(bitConfigFileInfo.FullName));

            bitConfig.Schema = bitConfig.Schema ?? new Schema {
            };
            bitConfig.Schema.HtmlSchemaFiles = bitConfig.Schema.HtmlSchemaFiles ?? new string[] { };

            for (int index = 0; index < bitConfig.Schema.HtmlSchemaFiles.Length; index++)
            {
                bitConfig.Schema.HtmlSchemaFiles[index] = Path.Combine(directoryInfo.FullName, bitConfig.Schema.HtmlSchemaFiles[index]);
            }

            foreach (BitCodeGeneratorMapping mapping in bitConfig.BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
            {
                if (string.IsNullOrEmpty(mapping.DestinationFileName))
                {
                    throw new InvalidOperationException("DestinationFileName is not provided");
                }

                if (string.IsNullOrEmpty(mapping.TypingsPath))
                {
                    throw new InvalidOperationException("TypingsPath is not provided");
                }

                if (string.IsNullOrEmpty(mapping.DestinationProject?.Name))
                {
                    throw new InvalidOperationException("DestinationProject is not provided");
                }

                if (mapping.SourceProjects == null || !mapping.SourceProjects.Any() || !mapping.SourceProjects.All(sp => !string.IsNullOrEmpty(sp?.Name)))
                {
                    throw new InvalidOperationException("No | Bad Source Projects is not provided");
                }

                if (string.IsNullOrEmpty(mapping.Namespace))
                {
                    throw new InvalidOperationException("Namespace is not provided");
                }

                if (string.IsNullOrEmpty(mapping.EdmName))
                {
                    throw new InvalidOperationException("EdmName is not provided");
                }
            }

            return(bitConfig);
        }
コード例 #16
0
ファイル: BitPackage.cs プロジェクト: Zedfa/bit-framework
        private async void DoOnSolutionReadyOrChange()
        {
            if (!File.Exists(_visualStudioWorkspace.CurrentSolution.FilePath))
            {
                LogWarn("Could not find solution.");
                return;
            }

            if (!WorkspaceHasBitConfigV1JsonFile())
            {
                LogWarn("Could not find BitConfigV1.json file.");
                return;
            }

            _outputPane.Clear();

            DefaultBitConfigProvider configProvider = new DefaultBitConfigProvider();

            BitConfig config = null;

            try
            {
                config = configProvider.GetConfiguration(_visualStudioWorkspace.CurrentSolution.FilePath);

                foreach (BitCodeGeneratorMapping mapping in config.BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
                {
                    if (!_visualStudioWorkspace.CurrentSolution.Projects.Any(p => p.Name == mapping.DestinationProject.Name && p.Language == LanguageNames.CSharp))
                    {
                        LogWarn($"No project found named {mapping.DestinationProject.Name}");
                    }

                    foreach (BitTools.Core.Model.ProjectInfo proj in mapping.SourceProjects)
                    {
                        if (!_visualStudioWorkspace.CurrentSolution.Projects.Any(p => p.Name == proj.Name && p.Language == LanguageNames.CSharp))
                        {
                            LogWarn($"No project found named {proj.Name}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogException("Parse BitConfigV1.json failed.", ex);
                return;
            }

            try
            {
                InitHtmlElements(config);
            }
            catch (Exception ex)
            {
                LogException("Init html elements failed.", ex);
            }

            try
            {
                bitWorkspaceIsPrepared = thereWasAnErrorInLastBuild = lastActionWasClean = false;
                Log("Preparing bit workspace... This includes restoring nuget packages, building your solution and generating codes.");

                using (System.Diagnostics.Process dotnetBuildProcess = new System.Diagnostics.Process())
                {
                    dotnetBuildProcess.StartInfo.UseShellExecute        = false;
                    dotnetBuildProcess.StartInfo.RedirectStandardOutput = true;
                    dotnetBuildProcess.StartInfo.FileName         = @"dotnet";
                    dotnetBuildProcess.StartInfo.Arguments        = "build";
                    dotnetBuildProcess.StartInfo.CreateNoWindow   = true;
                    dotnetBuildProcess.StartInfo.WorkingDirectory = Directory.GetParent(_visualStudioWorkspace.CurrentSolution.FilePath).FullName;
                    dotnetBuildProcess.Start();
                    await dotnetBuildProcess.StandardOutput.ReadToEndAsync();

                    dotnetBuildProcess.WaitForExit();
                }
            }
            catch (Exception ex)
            {
                LogException("Bit workspace preparation failed", ex);
            }
            finally
            {
                bitWorkspaceIsPrepared = true;
                await CallGenerateCodes();

                Log("Bit workspace gets prepared", activatePane: true);
            }
        }
コード例 #17
0
ファイル: BitPackage.cs プロジェクト: mortzi/bit-framework
        private async System.Threading.Tasks.Task DoOnSolutionReadyOrChange()
        {
            if (!File.Exists(_visualStudioWorkspace.CurrentSolution.FilePath))
            {
                LogWarn("Could not find solution.");
                return;
            }

            if (!WorkspaceHasBitConfigV1JsonFile())
            {
                LogWarn("Could not find BitConfigV1.json file.");
                return;
            }

            _outputPane.OutputString("__________----------__________ \n");

            DefaultBitConfigProvider configProvider = new DefaultBitConfigProvider();

            try
            {
                BitConfig config = configProvider.GetConfiguration(_visualStudioWorkspace);

                foreach (BitCodeGeneratorMapping mapping in config.BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
                {
                    if (!_visualStudioWorkspace.CurrentSolution.Projects.Any(p => p.Name == mapping.DestinationProject.Name && p.Language == LanguageNames.CSharp))
                    {
                        LogWarn($"No project found named {mapping.DestinationProject.Name}");
                    }

                    foreach (BitTools.Core.Model.ProjectInfo proj in mapping.SourceProjects)
                    {
                        if (!_visualStudioWorkspace.CurrentSolution.Projects.Any(p => p.Name == proj.Name && p.Language == LanguageNames.CSharp))
                        {
                            LogWarn($"No project found named {proj.Name}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogException("Parse BitConfigV1.json failed.", ex);
                return;
            }

            try
            {
                bitWorkspaceIsPrepared = thereWasAnErrorInLastBuild = lastActionWasClean = false;

                Log("Preparing bit workspace... This includes restoring nuget packages, building your solution and generating codes.");

                _applicationObject.Solution.SolutionBuild.Build(WaitForBuildToFinish: true);
            }
            catch (Exception ex)
            {
                LogException("Bit workspace preparation failed", ex);
            }
            finally
            {
                bitWorkspaceIsPrepared = true;
                await CallGenerateCodes();

                Log("Bit workspace gets prepared", activatePane: true);
            }
        }
コード例 #18
0
 /// <summary>
 /// Инициализация коллекции
 /// </summary>
 private void InitializeBitConfig()
 {
     BitConfig.AddRange(new bool[8] {
         false, false, false, false, false, false, false, false
     });
 }
コード例 #19
0
        private void DoOnSolutionReadyOrChange()
        {
            if (!File.Exists(_visualStudioWorkspace.CurrentSolution.FilePath))
            {
                LogWarn("Could not find solution.");
                return;
            }

            if (!WorkspaceHasBitConfigV1JsonFile())
            {
                LogWarn("Could not find BitConfigV1.json file.");
                return;
            }

            if (Environment.Version < new Version("4.0.30319.42000"))
            {
                ShowInitialLoadProblem("To develop bit projects, you've to install .NET 4.7.1 Developer Pack");
            }

            _outputPane.Clear();

            DefaultBitConfigProvider configProvider = new DefaultBitConfigProvider();

            BitConfig config = null;

            try
            {
                config = configProvider.GetConfiguration(_visualStudioWorkspace.CurrentSolution.FilePath);

                foreach (BitCodeGeneratorMapping mapping in config.BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
                {
                    if (!_visualStudioWorkspace.CurrentSolution.Projects.Any(p => p.Name == mapping.DestinationProject.Name && p.Language == LanguageNames.CSharp))
                    {
                        throw new InvalidOperationException($"No project found named {mapping.DestinationProject.Name}");
                    }

                    foreach (BitTools.Core.Model.ProjectInfo proj in mapping.SourceProjects)
                    {
                        if (!_visualStudioWorkspace.CurrentSolution.Projects.Any(p => p.Name == proj.Name && p.Language == LanguageNames.CSharp))
                        {
                            throw new InvalidOperationException($"No project found named {proj.Name}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogException("Parse BitConfigV1.json failed.", ex);
                return;
            }

            try
            {
                InitHtmlElements(config);
            }
            catch (Exception ex)
            {
                LogException("Init html elements failed.", ex);
            }

            _shouldGeneratedProjectNames = new List <string> {
            };
            needsFirstTimeGenerateCode   = true;
            lastActionWasClean           = false;
            thereWasAnErrorInLastBuild   = false;
        }