private void RenderCodeTypeSelector(CodeGenerationType codeType)
 {
     if (GUILayout.Toggle(Option.CodeType == codeType, codeType.ToString()))
     {
         Option.CodeType = codeType;
     }
 }
        private CodeTypeReference BuildCodeTypeReferenceForOptionSet(
            string attributeName
            , EntityMetadata entityMetadata
            , AttributeMetadata attributeMetadata
            , OptionSetMetadata attributeOptionSet
            , ICodeGenerationServiceProvider iCodeGenerationServiceProvider
            )
        {
            if (iCodeGenerationServiceProvider.CodeWriterFilterService.GenerateOptionSet(attributeOptionSet, attributeMetadata, iCodeGenerationServiceProvider))
            {
                string nameForOptionSet = iCodeGenerationServiceProvider.NamingService.GetNameForOptionSet(entityMetadata, attributeOptionSet, iCodeGenerationServiceProvider);

                CodeGenerationType typeForOptionSet = iCodeGenerationServiceProvider.CodeGenerationService.GetTypeForOptionSet(entityMetadata, attributeOptionSet, iCodeGenerationServiceProvider);

                switch (typeForOptionSet)
                {
                case CodeGenerationType.Class:
                    return(this.TypeRef(nameForOptionSet));

                case CodeGenerationType.Enum:
                case CodeGenerationType.Struct:
                    return(TypeMappingService.TypeRef(typeof(Nullable <>), this.TypeRef(nameForOptionSet)));
                }
            }
            return(TypeMappingService.TypeRef(typeof(object)));
        }
Пример #3
0
        private static string GenerateCode(AssetTypeDefinition typeDefinition, CodeGenerationType type)
        {
            switch (type)
            {
            case CodeGenerationType.Class: return(GenerateCodeAsClass(typeDefinition));

            case CodeGenerationType.Enum: return(GenerateCodeAsEnum(typeDefinition));
            }

            throw new ArgumentException("Unknown enum value", "type");
        }
Пример #4
0
        private string ExecuteCrmSvcUtil(CrmProperties props, CodeGenerationType generationType)
        {
            var svcUtilCodeCustomizationParams = "";
            var generatedNameSpace             = "Microsoft.Pfe.Xrm";
            var authProviderType = "";

            var outputFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Gen." + generationType + ".cs");

            if (File.Exists(outputFile))
            {
                File.Delete(outputFile);
            }

            switch (props.AuthenticationProviderType)
            {
            case AuthenticationProviderType.OnlineFederation:
                authProviderType = "Office365";
                break;

            case AuthenticationProviderType.ActiveDirectory:
                authProviderType = "AD";
                break;

            case AuthenticationProviderType.Federation:
                authProviderType = "IFD";
                break;
            }
            if (generationType == CodeGenerationType.Entity)
            {
                LoadMessage = "Generating Entity classes..";
                svcUtilCodeCustomizationParams =
                    "/codeCustomization:\"DLaB.CrmSvcUtilExtensions.Entity.CustomizeCodeDomService,DLaB.CrmSvcUtilExtensions\" /codegenerationservice:\"DLaB.CrmSvcUtilExtensions.Entity.CustomCodeGenerationService,DLaB.CrmSvcUtilExtensions\" /codewriterfilter:\"DLaB.CrmSvcUtilExtensions.Entity.CodeWriterFilterService,DLaB.CrmSvcUtilExtensions\" /namingservice:\"DLaB.CrmSvcUtilExtensions.NamingService,DLaB.CrmSvcUtilExtensions\" /metadataproviderservice:\"DLaB.CrmSvcUtilExtensions.Entity.MetadataProviderService,DLaB.CrmSvcUtilExtensions\"";
                generatedNameSpace = "Microsoft.Pfe.Xrm.Entities";
            }
            else
            {
                LoadMessage = "Generating Optionset enums..";
                svcUtilCodeCustomizationParams =
                    "/codeCustomization:\"DLaB.CrmSvcUtilExtensions.OptionSet.CreateOptionSetEnums,DLaB.CrmSvcUtilExtensions\" /codegenerationservice:\"DLaB.CrmSvcUtilExtensions.OptionSet.CustomCodeGenerationService,DLaB.CrmSvcUtilExtensions\" /codewriterfilter:\"DLaB.CrmSvcUtilExtensions.OptionSet.CodeWriterFilterService,DLaB.CrmSvcUtilExtensions\" /namingservice:\"DLaB.CrmSvcUtilExtensions.NamingService,DLaB.CrmSvcUtilExtensions\" /metadataproviderservice:\"DLaB.CrmSvcUtilExtensions.BaseMetadataProviderService,DLaB.CrmSvcUtilExtensions\"";
            }
            // Create Process
            Process p = new Process();

            p.StartInfo.UseShellExecute = false;
            // Specify CrmSvcUtil.exe as process name.
            p.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CrmSvcUtil.exe");
            // Do not display window
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
            // Assign argumemnt for CrmSvcUtil. This format works for all environment.
            if (props.UserName != string.Empty)
            {
                // For IFD "internal" URLs, we have to append the unique org-name.
                // But not for IFD "external" URLs, or AD urls.
                var orgUri = props.OrgUri;
                if (!orgUri.EndsWith(props.ConnectedOrgUniqueName))
                {
                    orgUri = orgUri.TrimEnd('/') + $"/{props.ConnectedOrgUniqueName}";
                }

                var connStringWithPassword = $"Url={orgUri}; Domain={props.DomainName}; UserName={props.UserName}; Password={props.Password};AuthType={authProviderType}; ";

                var args = $"{svcUtilCodeCustomizationParams} /connectionstring:\"{connStringWithPassword}\"; /out:\"{outputFile}\" /namespace:{generatedNameSpace} /serviceContextName:XrmContext";
                p.StartInfo.Arguments = args;
            }
            else
            {
                p.StartInfo.Arguments =
                    String.Format(
                        "{2} /connectionstring:\"Url={0}; AuthType=AD;\" /out:\"{1}\" /namespace:{3} /serviceContextName:XrmContext",
                        props.OrgUriActual,
                        outputFile,
                        svcUtilCodeCustomizationParams,
                        generatedNameSpace);
            }

            // Execute and wait until it complited.
            p.Start();
            p.WaitForExit();
            // Read generate file and return it.
            return(System.IO.File.ReadAllText(outputFile));
        }
Пример #5
0
        private void ProcessWorkbook(TextWriter outputWriter, string flatFileLocation, CodeGenerationType codeGenerationType)
        {
            Application excelApplication = null;
            Workbook    excelBook        = null;
            Worksheet   excelSheet       = null;

            try
            {
                excelApplication = new Application {
                    Visible = false
                };
                excelBook  = excelApplication.Workbooks.Open(flatFileLocation);
                excelSheet = (Worksheet)excelBook.Sheets[1];
                var lastRow = excelSheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell).Row;

                int totalLength = 0;

                for (var rowIndex = _beginRow; rowIndex <= lastRow; rowIndex++)
                {
                    var cellValues   = (Array)excelSheet.Range["A" + rowIndex, "K" + rowIndex].Cells.Value;
                    var propertyData = cellValues.Cast <object>().Select(v => v == null ? null : v.ToString()).ToArray();
                    totalLength = totalLength + GetFieldLength(propertyData[4]);

                    switch (codeGenerationType)
                    {
                    case CodeGenerationType.Model:
                        ProcessPropertyForCodeGenModel(outputWriter, propertyData);
                        break;

                    case CodeGenerationType.Table:
                        ProcessPropertyForTableSql(outputWriter, propertyData);
                        break;
                    }
                }

                if (codeGenerationType != CodeGenerationType.Model)
                {
                    return;
                }

                outputWriter.WriteLine("         [Write(false)] // dapper attribute specifying not to write this property to the database");
                string fileLengthProperty = @"         public int TotalFileLength { get { return " + totalLength + @"; } }";
                outputWriter.WriteLine(fileLengthProperty);
            }
            finally
            {
                if (excelApplication != null)
                {
                    excelApplication.Quit();
                }
                if (excelSheet != null)
                {
                    Marshal.ReleaseComObject(excelSheet);
                }
                if (excelBook != null)
                {
                    Marshal.ReleaseComObject(excelBook);
                }
                if (excelApplication != null)
                {
                    Marshal.ReleaseComObject(excelApplication);
                }
            }
        }
Пример #6
0
        private string ExecuteCrmSvcUtil(CrmProperties props, CodeGenerationType generationType)
        {
            var svcUtilCodeCustomizationParams = "";
            var generatedNameSpace             = "Microsoft.Pfe.Xrm";
            var authProviderType = "";

            switch (props.AuthenticationProviderType)
            {
            case AuthenticationProviderType.OnlineFederation:
                authProviderType = "Office365";
                break;

            case AuthenticationProviderType.ActiveDirectory:
                authProviderType = "AD";
                break;

            case AuthenticationProviderType.Federation:
                authProviderType = "IFD";
                break;
            }
            if (generationType == CodeGenerationType.Entity)
            {
                LoadMessage = "Generating Entity classes..";
                svcUtilCodeCustomizationParams =
                    "/codeCustomization:\"DLaB.CrmSvcUtilExtensions.Entity.CustomizeCodeDomService,DLaB.CrmSvcUtilExtensions\" /codegenerationservice:\"DLaB.CrmSvcUtilExtensions.Entity.CustomCodeGenerationService,DLaB.CrmSvcUtilExtensions\" /codewriterfilter:\"DLaB.CrmSvcUtilExtensions.Entity.CodeWriterFilterService,DLaB.CrmSvcUtilExtensions\" /namingservice:\"DLaB.CrmSvcUtilExtensions.NamingService,DLaB.CrmSvcUtilExtensions\" /metadataproviderservice:\"DLaB.CrmSvcUtilExtensions.Entity.MetadataProviderService,DLaB.CrmSvcUtilExtensions\"";
                generatedNameSpace = "Microsoft.Pfe.Xrm.Entities";
            }
            else
            {
                LoadMessage = "Generating Optionset enums..";
                svcUtilCodeCustomizationParams =
                    "/codeCustomization:\"DLaB.CrmSvcUtilExtensions.OptionSet.CreateOptionSetEnums,DLaB.CrmSvcUtilExtensions\" /codegenerationservice:\"DLaB.CrmSvcUtilExtensions.OptionSet.CustomCodeGenerationService,DLaB.CrmSvcUtilExtensions\" /codewriterfilter:\"DLaB.CrmSvcUtilExtensions.OptionSet.CodeWriterFilterService,DLaB.CrmSvcUtilExtensions\" /namingservice:\"DLaB.CrmSvcUtilExtensions.NamingService,DLaB.CrmSvcUtilExtensions\" /metadataproviderservice:\"DLaB.CrmSvcUtilExtensions.BaseMetadataProviderService,DLaB.CrmSvcUtilExtensions\"";
            }
            // Create Process
            Process p = new Process();

            p.StartInfo.UseShellExecute = false;
            // Specify CrmSvcUtil.exe as process name.
            p.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CrmSvcUtil.exe");
            // Do not display window
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
            // Assign argumemnt for CrmSvcUtil. This format works for all environment.
            if (props.UserName != string.Empty)
            {
                p.StartInfo.Arguments =
                    String.Format(
                        "{4} /connectionstring:\"AuthType={5}; Url={0}{7}; UserName={1}; Password={2}; Domain={8}\"; /out:\"{3}\" /namespace:{6} /serviceContextName:XrmContext",
                        props.OrgUri,
                        props.UserName,
                        props.Password,
                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, generationType + ".cs"),
                        svcUtilCodeCustomizationParams,
                        authProviderType,
                        generatedNameSpace,
                        props.ConnectedOrgUniqueName,
                        props.DomainName);
            }
            else
            {
                p.StartInfo.Arguments =
                    String.Format(
                        "{2} /connectionstring:\"Url={0}; AuthType=AD;\" /out:\"{1}\" /namespace:{3} /serviceContextName:XrmContext",
                        props.OrgUriActual,
                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, generationType + ".cs"),
                        svcUtilCodeCustomizationParams,
                        generatedNameSpace);
            }

            // Execute and wait until it complited.
            p.Start();
            p.WaitForExit();
            // Read generate file and return it.
            return(System.IO.File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, generationType + ".cs")));
        }