Beispiel #1
0
        private void ExecuteCrmSvcUtil(CrmProperties props)
        {
            var generatedNameSpace = "Microsoft.Pfe.Xrm";
            // Create Process
            Process p = new Process();

            p.StartInfo.UseShellExecute = false;
            // Specify CrmSvcUtil.exe as process name.
            p.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XrmContext", "XrmContext.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 =
                    $"/ap:{props.AuthenticationProviderType} /url:{props.OrgUri}/XrmServices/2011/Organization.svc /username:{props.UserName} /password:{props.Password} /domain:{props.DomainName} /out:\"{AppDomain.CurrentDomain.BaseDirectory}\" /namespace:{generatedNameSpace} /servicecontextname:XrmContext";
            }
            else
            {
                p.StartInfo.Arguments =
                    $"/url:{props.OrgUriActual} /authtype:ActiveDirectory /out:\"{AppDomain.CurrentDomain.BaseDirectory}\" /namespace:{generatedNameSpace} /servicecontextname:XrmContext";
            }

            // Execute and wait until it complited.
            p.Start();
            p.WaitForExit();
        }
 /// <summary>
 /// Generate context for LinqPad by using CrmSvcUtil.exe. In this example, we generate CrmOrganizationServiceContext
 /// so that context has all common methods from OrganizationService. However if you prefer to have just Linq capabilities,
 /// you are also able to generate OrganizationServiceContext only. Please refer to https://msdn.microsoft.com/en-us/library/gg695792.aspx
 /// for more detail about CrmSvcUtil too.
 /// </summary>
 /// <param name="props">CRM Properties</param>
 /// <returns>Generate code</returns>
 private string[] GenerateCode(CrmProperties props)
 {
     return(new []
     {
         ExecuteCrmSvcUtil(props, CodeGenerationType.OptionSet),
         ExecuteCrmSvcUtil(props, CodeGenerationType.Entity)
     });
 }
Beispiel #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        public MainWindowViewModel(IConnectionInfo cxInfo, bool isNewConnection)
        {
            // Display message depending on isNewConnection
            Message = isNewConnection ? "Click Login button to Login." : "Click Reload Data to update Schema";

            IsLoaded        = false;
            props           = new CrmProperties(cxInfo);
            IsNewConnection = isNewConnection;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public MainWindowViewModel(IConnectionInfo cxInfo, bool isNewConnection)
        {
            // Display message depending on isNewConnection
            Message = isNewConnection ? "Click Login button to Login." : "Click Reload Data to update Schema";

            IsLoaded = false;
            props = new CrmProperties(cxInfo);
            IsNewConnection = isNewConnection;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public MainWindowViewModel(IConnectionInfo cxInfo, bool isNewConnection)
        {
            this.cxInfo     = cxInfo;
            IsNewConnection = isNewConnection;
            // Display message depending on isNewConnection
            Message = IsNewConnection ? "Click Login to CRM." : "Click to download latest metadata";

            IsAutoRegister = true;
            useCurrentUser = true;

            // Change button visibility depending on if this is New Connection or not.
            if (IsNewConnection)
            {
                IsLoginVisible = true;
            }

            props = new CrmProperties(cxInfo);
        }
Beispiel #6
0
 /// <summary>
 /// Generate context for LinqPad by using CrmSvcUtil.exe. In this example, we generate CrmOrganizationServiceContext
 /// so that context has all common methods from OrganizationService. However if you prefer to have just Linq capabilities,
 /// you are also able to generate OrganizationServiceContext only. Please refer to https://msdn.microsoft.com/en-us/library/gg695792.aspx
 /// for more detail about CrmSvcUtil too.
 /// </summary>
 /// <param name="props">CRM Properties</param>
 /// <returns>Generate code</returns>
 private void GenerateCode(CrmProperties props)
 {
     ExecuteCrmSvcUtil(props);
 }
        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));
        }
        /// <summary>
        /// Generate context for LinqPad by using CrmSvcUtil.exe. In this example, we generate CrmOrganizationServiceContext
        /// so that context has all common methods from OrganizationService. However if you prefer to have just Linq capabilities, 
        /// you are also able to generate OrganizationServiceContext only. Please refer to https://msdn.microsoft.com/en-us/library/gg695792.aspx
        /// for more detail about CrmSvcUtil too.
        /// </summary>
        /// <param name="props">CRM Properties</param>
        /// <returns>Generate code</returns>
        private string GenerateCode(CrmProperties props)
        {
            // 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.
            p.StartInfo.Arguments =
                String.Format("/codeCustomization:\"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration\" /url:{0} /username:{1} /password:{2} /out:\"{3}\" /namespace:Microsoft.Pfe.Xrm /serviceContextName:XrmContext",
                props.OrgUriActual,
                props.UserName,
                props.Password,
                Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XrmData.cs"));

            // 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, "XrmData.cs"));
        }
Beispiel #9
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")));
        }