private static List <string> CrmPluginRegistrationDataForPlugin(DTE dte, string fullName)
        {
            IOrganizationService CrmService = null;

            Shared.Models.CrmConnection CrmConnection = null;
            var list = new List <string>();
            var form = new FormConnection2(dte);

            if (form.ShowDialog() == DialogResult.Cancel)
            {
                return(list);
            }
            if (form.Check == "1")
            {
                var loginForm = new FormLogin();
                loginForm.ConnectionToCrmCompleted += loginForm_ConnectionToCrmCompleted;
                loginForm.ShowDialog();
                if (loginForm.CrmConnectionMgr != null && loginForm.CrmConnectionMgr.CrmSvc != null && loginForm.CrmConnectionMgr.CrmSvc.IsReady)
                {
                    if (loginForm.CrmConnectionMgr.CrmSvc.OrganizationServiceProxy != null)
                    {
                        CrmService = (IOrganizationService)loginForm.CrmConnectionMgr.CrmSvc.OrganizationServiceProxy;
                    }
                    else if (loginForm.CrmConnectionMgr.CrmSvc.OrganizationWebProxyClient != null)
                    {
                        CrmService = (IOrganizationService)loginForm.CrmConnectionMgr.CrmSvc.OrganizationWebProxyClient;
                    }
                    else
                    {
                        return(list);
                    }
                }
                else
                {
                    return(list);
                }
            }
            else
            {
                CrmConnection = form.CrmConnection;
                CrmService    = form.CrmService;
            }
            if (form.Check == "1")
            {
                var deployText = Utility.ReadEmbeddedResource("DynamicsCrm.DevKit.Resources.plugin.deploy.debug.bat");
                deployText = deployText
                             .Replace("set CrmConnection=\"$CrmConnectionString$\"\r\n", string.Empty)
                             .Replace("/conn:%CrmConnection%", "/sdklogin:\"yes\"")
                             .Replace("$ProjectName$", Path.GetFileNameWithoutExtension(dte.ActiveDocument.ProjectItem.ContainingProject.FullName));
                AddDeployBatIfNeed(dte, deployText);
            }
            else
            {
                var crmConnectionString = XrmHelper.BuildConnectionString(CrmConnection);
                var deployText          = Utility.ReadEmbeddedResource("DynamicsCrm.DevKit.Resources.plugin.deploy.debug.bat");
                deployText = deployText
                             .Replace("$CrmConnectionString$", crmConnectionString)
                             .Replace("$ProjectName$", Path.GetFileNameWithoutExtension(dte.ActiveDocument.ProjectItem.ContainingProject.FullName));
                AddDeployBatIfNeed(dte, deployText);
            }

            var fetchData = new
            {
                ismanaged      = "0",
                iscustomizable = "1",
                typename       = fullName
            };
            var fetchXml = $@"
<fetch>
  <entity name='sdkmessageprocessingstep'>
    <attribute name='filteringattributes' />
    <attribute name='name' />
    <attribute name='impersonatinguserid' />
    <attribute name='rank' />
    <attribute name='description' />
    <attribute name='stage' />
    <attribute name='supporteddeployment' />
    <attribute name='componentstate' />
    <attribute name='asyncautodelete' />
    <attribute name='mode' />
    <attribute name='configuration' />
    <attribute name='statecode' />
    <filter type='and'>
      <condition attribute='ismanaged' operator='eq' value='{fetchData.ismanaged/*0*/}'/>
      <condition attribute='iscustomizable' operator='eq' value='{fetchData.iscustomizable/*1*/}'/>
    </filter>
    <link-entity name='sdkmessage' from='sdkmessageid' to='sdkmessageid' alias='m'>
      <attribute name='name' />
    </link-entity>
    <link-entity name='plugintype' from='plugintypeid' to='plugintypeid' link-type='inner' alias='t'>
      <filter type='and'>
        <condition attribute='typename' operator='eq' value='{fetchData.typename/*AccountPlugin.PostDeleteAccount*/}'/>
      </filter>
      <link-entity name='pluginassembly' from='pluginassemblyid' to='pluginassemblyid' link-type='inner' alias='p'>
        <attribute name='isolationmode' />
      </link-entity>
    </link-entity>
    <link-entity name='sdkmessagefilter' from='sdkmessagefilterid' to='sdkmessagefilterid' link-type='inner' alias='f'>
      <attribute name='primaryobjecttypecode' />
    </link-entity>
    <link-entity name='sdkmessageprocessingstepsecureconfig' from='sdkmessageprocessingstepsecureconfigid' to='sdkmessageprocessingstepsecureconfigid' link-type='outer' alias='s'>
      <attribute name='secureconfig' />
    </link-entity>
  </entity>
</fetch>";

            var rows = CrmService.RetrieveMultiple(new FetchExpression(fetchXml));

            if (rows.Entities.Count == 0)
            {
                return(list);
            }
            foreach (var row in rows.Entities)
            {
                var message             = GetAliasedValue <string>(row, "m.name");
                var entity              = GetAliasedValue <string>(row, "f.primaryobjecttypecode");
                var stage               = row.GetAttributeValue <OptionSetValue>("stage").Value;
                var stageName           = stage == 10 ? "StageEnum.PreValidation" : (stage == 20 ? "StageEnum.PreOperation" : "StageEnum.PostOperation");
                var mode                = row.GetAttributeValue <OptionSetValue>("mode").Value;
                var modeName            = mode == 0 ? "ExecutionModeEnum.Synchronous" : "ExecutionModeEnum.Asynchronous";
                var filteringAttributes = row.GetAttributeValue <string>("filteringattributes");
                var name                = row.GetAttributeValue <string>("name");
                var rank                = row.GetAttributeValue <int>("rank");
                var isolationMode       = GetAliasedValue <OptionSetValue>(row, "p.isolationmode").Value;
                var isolationModeName   = isolationMode == 0 ? "IsolationModeEnum.None" : "IsolationModeEnum.Sandbox";
                var asyncautodelete     = row.GetAttributeValue <bool>("asyncautodelete");
                var description         = row.GetAttributeValue <string>("description");
                var supportedDeployment = row.GetAttributeValue <OptionSetValue>("supporteddeployment").Value;
                var status              = row.GetAttributeValue <OptionSetValue>("statecode").Value;
                var configuration       = row.GetAttributeValue <string>("configuration");
                var secureconfig        = GetAliasedValue <string>(row, "s.secureconfig");
                var impersonatinguserid = row.GetAttributeValue <EntityReference>("impersonatinguserid");

                var attribute = string.Empty;
                attribute += $"\"{message}\"";
                attribute += $", \"{entity}\"";
                attribute += $", {stageName}";
                attribute += $", {modeName}";
                attribute += $", \"{filteringAttributes}\",\r\n\t";
                attribute += $"\"{name}\"";
                attribute += $", {rank}";
                attribute += $", {isolationModeName},\r\n\t";
                if (asyncautodelete)
                {
                    attribute += $"DeleteAsyncOperation = true, ";
                }
                if (description != null)
                {
                    attribute += $"Description = \"{description}\", ";
                }
                if (supportedDeployment == 2)
                {
                    attribute += $"Server = true, Offline = true, ";
                }
                else if (supportedDeployment == 1)
                {
                    attribute += $"Server = false, Offline = true, ";
                }
                if (status == 1)
                {
                    attribute += $"Action = PluginStepOperationEnum.Deactivate, ";
                }
                if (configuration != null)
                {
                    attribute += $"UnSecureConfiguration = \"{configuration}\", ";
                }
                if (secureconfig != null)
                {
                    attribute += $"SecureConfiguration = \"{secureconfig}\", ";
                }
                if (impersonatinguserid != null)
                {
                    attribute += $"RunAs = \"{impersonatinguserid.Name}\", ";
                }
                if (attribute.EndsWith(", "))
                {
                    attribute  = attribute.TrimEnd();
                    attribute += "\r\n\t";
                }
                var images = GetPluginImages(CrmService, fullName, row.Id);
                var image  = "Image{0}Name = \"{1}\", Image{0}Alias = \"{2}\", Image{0}Type = ImageTypeEnum.{3}, Image{0}Attributes = \"{4}\",\r\n\t";
                if (images.Count > 0)
                {
                    var i = 1;
                    foreach (var item in images)
                    {
                        attribute += string.Format(image, i, item.Name, item.Alias, item.Type.ToString(), item.Attributes);
                        i++;
                        if (i == 5)
                        {
                            break;
                        }
                    }
                    attribute = attribute.TrimEnd(",\r\n\t".ToCharArray());
                }
                else
                {
                    attribute += string.Format(image, 1, string.Empty, string.Empty, "PreImage", string.Empty);
                    attribute  = attribute.TrimEnd(",\r\n\t".ToCharArray());
                }
                list.Add(attribute);
            }
            return(list);
        }
        private static List <string> CrmPluginRegistrationDataForWorkflow(DTE dte, string fullName)
        {
            IOrganizationService CrmService = null;

            Shared.Models.CrmConnection CrmConnection = null;
            var list = new List <string>();
            var form = new FormConnection2(dte);

            if (form.ShowDialog() == DialogResult.Cancel)
            {
                return(list);
            }
            if (form.Check == "1")
            {
                var loginForm = new FormLogin();
                loginForm.ConnectionToCrmCompleted += loginForm_ConnectionToCrmCompleted;
                loginForm.ShowDialog();
                if (loginForm.CrmConnectionMgr != null && loginForm.CrmConnectionMgr.CrmSvc != null && loginForm.CrmConnectionMgr.CrmSvc.IsReady)
                {
                    if (loginForm.CrmConnectionMgr.CrmSvc.OrganizationServiceProxy != null)
                    {
                        CrmService = (IOrganizationService)loginForm.CrmConnectionMgr.CrmSvc.OrganizationServiceProxy;
                    }
                    else if (loginForm.CrmConnectionMgr.CrmSvc.OrganizationWebProxyClient != null)
                    {
                        CrmService = (IOrganizationService)loginForm.CrmConnectionMgr.CrmSvc.OrganizationWebProxyClient;
                    }
                    else
                    {
                        return(list);
                    }
                }
                else
                {
                    return(list);
                }
            }
            else
            {
                CrmConnection = form.CrmConnection;
                CrmService    = form.CrmService;
            }

            if (form.Check == "1")
            {
                var deployText = Utility.ReadEmbeddedResource("DynamicsCrm.DevKit.Resources.workflow.deploy.debug.bat");
                deployText = deployText
                             .Replace("set CrmConnection=\"$CrmConnectionString$\"\r\n", string.Empty)
                             .Replace("/conn:%CrmConnection%", "/sdklogin:\"yes\"")
                             .Replace("$ProjectName$", Path.GetFileNameWithoutExtension(dte.ActiveDocument.ProjectItem.ContainingProject.FullName));
                AddDeployBatIfNeed(dte, deployText);
            }
            else
            {
                var crmConnectionString = XrmHelper.BuildConnectionString(CrmConnection);
                var deployText          = Utility.ReadEmbeddedResource("DynamicsCrm.DevKit.Resources.workflow.deploy.debug.bat");
                deployText = deployText
                             .Replace("$CrmConnectionString$", crmConnectionString)
                             .Replace("$ProjectName$", Path.GetFileNameWithoutExtension(dte.ActiveDocument.ProjectItem.ContainingProject.FullName));
                AddDeployBatIfNeed(dte, deployText);
            }
            var fetchData = new
            {
                ismanaged          = "0",
                isworkflowactivity = "1",
                typename           = fullName
            };
            var fetchXml = $@"
<fetch>
  <entity name='plugintype'>
    <attribute name='name' />
    <attribute name='workflowactivitygroupname' />
    <attribute name='description' />
    <attribute name='typename' />
    <attribute name='assemblyname' />
    <attribute name='friendlyname' />
    <filter type='and'>
      <condition attribute='ismanaged' operator='eq' value='{fetchData.ismanaged/*0*/}'/>
      <condition attribute='isworkflowactivity' operator='eq' value='{fetchData.isworkflowactivity/*1*/}'/>
      <condition attribute='typename' operator='eq' value='{fetchData.typename/*CustomWorkflow.RetrieveUsers*/}'/>
    </filter>
    <link-entity name='pluginassembly' from='pluginassemblyid' to='pluginassemblyid' alias='a'>
      <attribute name='isolationmode' />
    </link-entity>
  </entity>
</fetch>";

            var rows = CrmService.RetrieveMultiple(new FetchExpression(fetchXml));

            if (rows.Entities.Count == 0)
            {
                return(list);
            }
            foreach (var row in rows.Entities)
            {
                var name         = row.GetAttributeValue <string>("name");
                var friendlyname = row.GetAttributeValue <string>("friendlyname");
                var description  = row.GetAttributeValue <string>("description");
                var workflowactivitygroupname = row.GetAttributeValue <string>("workflowactivitygroupname");
                var isolationMode             = GetAliasedValue <OptionSetValue>(row, "a.isolationmode").Value;
                var isolationModeName         = isolationMode == 0 ? "IsolationModeEnum.None" : "IsolationModeEnum.Sandbox";
                var attribute = string.Empty;
                attribute += $"\"{name}\"";
                attribute += $", \"{friendlyname}\"";
                attribute += $", \"{description}\"";
                attribute += $", \"{workflowactivitygroupname}\"";
                attribute += $", {isolationModeName}";
                list.Add(attribute);
            }
            return(list);
        }