예제 #1
0
 public SolutionLocationComponent(Guid solutionId, string country, string region, string city)
 {
     if (solutionId != Guid.Empty)
     {
         mifnexsoEntities = new MIFNEXSOEntities();
         try
         {
             solutionLocation = mifnexsoEntities.SolutionLocations.FirstOrDefault(a => a.SolutionId == solutionId && a.Country == country &&
                                                                                  a.Region == region && a.City == city);
             if (solutionLocation == null)
             {
                 solutionLocation = new SolutionLocation();
                 solutionLocation.SolutionLocationId = Guid.Empty;
                 solutionLocation.SolutionId         = solutionId;
                 solutionLocation.Country            = country;
                 solutionLocation.City       = city;
                 solutionLocation.Region     = region;
                 solutionLocation.Address    = string.Empty;
                 solutionLocation.PostalCode = string.Empty;
                 solutionLocation.Longitude  = -1;
                 solutionLocation.Latitude   = -1;
                 mifnexsoEntities.SolutionLocations.AddObject(solutionLocation);
             }
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Generates all required classes and documents and returns modified solution.
        /// With that modified solution it is required to call Workspace.ApplyChanges()
        /// </summary>
        /// <param name="solution"></param>
        /// <param name="dtoLocation"></param>
        /// <param name="metadata"></param>
        /// <returns>Modified solution containing changes to apply to workspace</returns>
        public static async Task <Solution> WriteDto(this Solution solution, SolutionLocation dtoLocation, EntityMetadata metadata, bool generateMapper, bool addContractAttrs, bool addDataAnnotations)
        {
            var project = solution.Projects
                          .Where(p => p.Name.Contains(dtoLocation.Project))
                          .OrderBy(p => p.Name) // Due to .NET core project which have more complex project name, cannot use ==
                          .FirstOrDefault();

            var compilation = await project.GetCompilationAsync();

            var existingDtoDocument = compilation.GetDocumentForSymbol(project.Solution, metadata.DtoName);

            SyntaxTree existingSyntaxTree = null;

            if (existingDtoDocument != null)
            {
                existingSyntaxTree = await existingDtoDocument.GetSyntaxTreeAsync();
            }

            var dtoNamespace    = dtoLocation.ToNamespace(project.AssemblyName);
            var mapperNamespace = "unknown";

            var mapperDoc = compilation.GetDocumentForSymbol(project.Solution, "MapperBase");

            if (mapperDoc == null && generateMapper)
            {
                var mapperFolderStructure = dtoLocation.GetFolders().Concat(new[] { "Infrastructure" });
                mapperNamespace = dtoNamespace + ".Infrastructure";

                project = project.AddDocument("MapperBase.cs", DtoBuilder.BuildMapper(mapperNamespace), folders: mapperFolderStructure).Project;
            }
            else if (generateMapper)
            {
                var mapperSyntax = await mapperDoc.GetSyntaxRootAsync();

                mapperNamespace = mapperSyntax.DescendantNodesAndSelf(p => !p.IsKind(CSharp.SyntaxKind.NamespaceDeclaration))
                                  .OfType <NamespaceDeclarationSyntax>()
                                  .Select(p => p.Name.ToString())
                                  .FirstOrDefault();
            }

            var syntaxTree = DtoBuilder.BuildDto(metadata, dtoNamespace: dtoNamespace, existingDto: existingSyntaxTree, mapperNamespace: mapperNamespace, generateMapper: generateMapper, addContractAttrs: addContractAttrs, addDataAnnotations: addDataAnnotations);

            if (existingDtoDocument == null)
            {
                var formatted       = Formatter.Format(syntaxTree.GetRoot(), solution.Workspace);
                var folderStructure = dtoLocation.GetFolders();
                var newDoc          = project.AddDocument(metadata.DtoName + ".cs", formatted, folders: folderStructure);
                return(newDoc.Project.Solution);
            }
            else
            {
                var root = syntaxTree.GetRoot();
                root = Formatter.Format(root, solution.Workspace);

                var newDoc = existingDtoDocument.WithSyntaxRoot(root);
                return(newDoc.Project.Solution);
            }
        }
예제 #3
0
        public static Document GetDocumentByLocation(this Solution solution, SolutionLocation location, string documentName)
        {
            if (!documentName.EndsWith(".cs"))
            {
                documentName += ".cs";
            }

            return(solution.Projects
                   .Where(p => p.Name == location.Project)
                   .SelectMany(p => p.Documents)
                   .Where(p => string.Join("/", p.Folders).ToLower().Trim('/') == location.FolderStructure.ToLower().Trim('/'))
                   .Where(p => p.Name.ToLower() == documentName.ToLower())
                   .FirstOrDefault());
        }
예제 #4
0
 public SolutionLocationComponent(Guid SolutionLocationId)
 {
     if (SolutionLocationId != Guid.Empty)
     {
         mifnexsoEntities = new MIFNEXSOEntities();
         try
         {
             solutionLocation = mifnexsoEntities.SolutionLocations.FirstOrDefault(a => a.SolutionLocationId == SolutionLocationId);
             if (solutionLocation == null)
             {
                 solutionLocation = new SolutionLocation();
                 solutionLocation.SolutionLocationId = Guid.Empty;
                 mifnexsoEntities.SolutionLocations.AddObject(solutionLocation);
             }
         }
         catch (Exception)
         {
             throw;
         }
     }
 }