Пример #1
0
        private static void AddToCache(DTE dte, string fullFileName, Guid resourceId, string resourceName)
        {
            var webResources = (List <NameValueGuid>)UtilityPackage.GetGlobal("WebResources", dte);

            if (webResources == null)
            {
                webResources = new List <NameValueGuid>();
            }
            webResources.Add(new NameValueGuid
            {
                Name  = fullFileName,
                Value = resourceId
            });
            UtilityPackage.SetGlobal("WebResources", webResources, dte);
            var selected = DevKitSetting.SelectedWebResources.Where(x => x.FullFileName == fullFileName).FirstOrDefault();

            if (selected != null)
            {
                DevKitSetting.SelectedWebResources.Remove(selected);
            }
            DevKitSetting.SelectedWebResources.Add(new SavedMappingWebResource
            {
                FullFileName    = fullFileName,
                WebResourceName = resourceName
            });
        }
Пример #2
0
        private static void AddToCache(DTE dte, int language, string solution, string reportName, Guid reportId, string fullFileName)
        {
            //Save to VS caeched, get this first
            var reports = (List <NameValueGuid>)UtilityPackage.GetGlobal("Reports", dte);

            if (reports == null)
            {
                reports = new List <NameValueGuid>();
            }
            var selectedCacheFromVS = reports.Where(x => x.Name == fullFileName).FirstOrDefault();

            if (selectedCacheFromVS != null)
            {
                reports.Remove(selectedCacheFromVS);
            }
            reports.Add(new NameValueGuid
            {
                Name  = fullFileName,
                Value = reportId
            });
            UtilityPackage.SetGlobal("Reports", reports, dte);

            //Saved to existing file, get later
            var selectedCacheFromFile = DevKitSetting.SelectedReports.Where(x => x.FullFileName == fullFileName).FirstOrDefault();

            if (selectedCacheFromFile != null)
            {
                DevKitSetting.SelectedReports.Remove(selectedCacheFromFile);
            }
            DevKitSetting.SelectedReports.Add(new SavedMappingReport
            {
                Language     = language,
                FullFileName = fullFileName,
                ReportName   = reportName,
                Solution     = solution
            });
        }
Пример #3
0
        internal static void Click(DTE dte)
        {
            try
            {
                dte.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationDeploy);
                var config = UtilityPackage.IsValid(dte);
                if (config == null)
                {
                    return;
                }
                UtilityPackage.SetDTEStatusBar(dte, " !!! Read DynamicsCrm.DevKit.Cli.json config !!! ");
                var check = UtilityPackage.GetGlobal("CrmService", dte);
                if (check == null)
                {
                    var connection = UtilityPackage.IsConnection(config.CrmConnection);
                    if (connection == null)
                    {
                        UtilityPackage.SetDTEStatusBar(dte, " !!! Connection Dynamics CRM  failed !!! ", true);
                        return;
                    }
                    UtilityPackage.SetGlobal("CrmService", connection, dte);
                }
                var crmService = (OrganizationServiceProxy)UtilityPackage.GetGlobal("CrmService", dte);
                UtilityPackage.SetDTEStatusBar(dte, " !!! Connected Dynamics CRM !!! ");
                var webResourceId = IsFoundWebResource(dte, crmService, config.JsonWebResource.prefix);
                if (webResourceId == Guid.Empty)
                {
                    UtilityPackage.SetDTEStatusBar(dte, " !!! WebResource not found !!! ", true);
                    return;
                }
                var requests = new OrganizationRequestCollection();

                var webResource = new Entity("webresource")
                {
                    Id = webResourceId
                };
                var content = File.ReadAllText(dte.ActiveDocument.FullName);
                webResource["content"] = Convert.ToBase64String(Encoding.UTF8.GetBytes(content));
                var request = new UpdateRequest {
                    Target = webResource
                };
                requests.Add(request);

                var publishXml = $"<importexportxml><webresources><webresource>{webResource.Id}</webresource></webresources></importexportxml>";
                var pubRequest = new PublishXmlRequest {
                    ParameterXml = publishXml
                };
                requests.Add(pubRequest);

                var multipleRequest = new ExecuteMultipleRequest
                {
                    Requests = requests,
                    Settings = new ExecuteMultipleSettings
                    {
                        ContinueOnError = false,
                        ReturnResponses = true
                    }
                };
                UtilityPackage.SetDTEStatusBar(dte, " !!! Updating & publishing WebResource !!! ");
                var multipleResponse = (ExecuteMultipleResponse)crmService.Execute(multipleRequest);
                foreach (var response in multipleResponse.Responses)
                {
                    if (response.Fault == null)
                    {
                        continue;
                    }
                    UtilityPackage.SetDTEStatusBar(dte, " !!! Deploy WebResource failed !!! ", true);
                    return;
                }
                UtilityPackage.SetDTEStatusBar(dte, " !!! Deploy WebResource succeeded !!! ", true);
            }
            catch
            {
                UtilityPackage.SetDTEStatusBar(dte, " !!! Deploy WebResource failed !!! ", true);
            }
        }
        private static void BuildEvents_OnBuildProjConfigDone(string Project, string ProjectConfig, string Platform, string SolutionConfig, bool Success)
        {
            DTE.Events.BuildEvents.OnBuildProjConfigDone -= BuildEvents_OnBuildProjConfigDone;
            if (!Success || !ProjectUniqueName.EndsWith(Project))
            {
                return;
            }
            UtilityPackage.SetDTEStatusBar(DTE, "Build project report succeeded!");
#if DEBUG
            ProjectUniqueName = @"C:\src\github\phuocle\Dynamics-Crm-DevKit\test\TestReport\Test.Abc.Report.2015\Test.Abc.Report.2015.rptproj";
#endif
            var xml  = File.ReadAllText(ProjectUniqueName);
            var xdoc = XDocument.Parse(xml);
            //Fist check for project VS2015
            var node = (from x in xdoc?.Descendants("Project")?.Descendants("Configurations")?.Elements("Configuration")
                        where x?.Element("Name")?.Value == ProjectConfig
                        select x)?.FirstOrDefault();
            var outputPath = node?.Descendants("Options")?.FirstOrDefault()?.Element("OutputPath")?.Value;
            //if null, then check for project VS2017
            if (outputPath == null)
            {
                var nodes = (from x in xdoc?.Root.Elements()
                             where x?.Name?.LocalName == "PropertyGroup"
                             select x);
                foreach (var n in nodes)
                {
                    if (n.Elements().Where(x => x?.Name?.LocalName == "FullPath" && x?.Value == "Debug").Any())
                    {
                        outputPath = n.Elements().Where(x => x?.Name?.LocalName == "OutputPath").FirstOrDefault()?.Value;
                        break;
                    }
                }
            }
            if (outputPath == null)
            {
                throw new Exception("Cannot read the Output directory of the current report project");
            }
            var folderOutput = Path.Combine(Path.GetDirectoryName(ProjectUniqueName), outputPath);
            var fileName     = Path.GetFileName(DTE.SelectedItems.Item(1).ProjectItem.FileNames[0]);
            var deployFile   = Path.Combine(folderOutput, fileName);
            if (!File.Exists(deployFile))
            {
                throw new Exception($"Cannot find deployable report: {deployFile}");
            }

            var config = UtilityPackage.IsValid(DTE);
            if (config == null)
            {
                return;
            }
            UtilityPackage.SetDTEStatusBar(DTE, " !!! Read DynamicsCrm.DevKit.Cli.json config !!! ");
            var check = UtilityPackage.GetGlobal("CrmService", DTE);
            if (check == null)
            {
                var connection = UtilityPackage.IsConnection(config.CrmConnection);
                if (connection == null)
                {
                    UtilityPackage.SetDTEStatusBar(DTE, " !!! Connection Dynamics CRM  failed !!! ", true);
                    return;
                }
                UtilityPackage.SetGlobal("CrmService", connection, DTE);
            }
            var crmService = (IOrganizationService)UtilityPackage.GetGlobal("CrmService", DTE);
            UtilityPackage.SetDTEStatusBar(DTE, " !!! Connected Dynamics CRM !!! ");

            var fetchData = new
            {
                ismanaged = "0",
                filename  = fileName
            };
            var fetchXml = $@"
<fetch>
  <entity name='report'>
    <attribute name='reportid' />
    <filter type='and'>
      <condition attribute='ismanaged' operator='eq' value='{fetchData.ismanaged/*0*/}'/>
      <condition attribute='filename' operator='eq' value='{fetchData.filename/*ReportTemplate.rdl*/}'/>
    </filter>
  </entity>
</fetch>";
            var rows     = crmService.RetrieveMultiple(new FetchExpression(fetchXml));
            if (rows.Entities.Count == 0)
            {
                throw new Exception("Please deploy this report first by Dynamics 365");
            }
            if (rows.Entities.Count != 1)
            {
                throw new Exception($"Found {rows.Entities.Count} reports file name: {fileName} in the system. Cannot deploy.");
            }
            UtilityPackage.SetDTEStatusBar(DTE, "Deploying Report ...");
            var update = new Entity("report", rows.Entities[0].Id);
            update["bodytext"] = File.ReadAllText(deployFile);
            crmService.Update(update);
            UtilityPackage.SetDTEStatusBar(DTE, "   !!!   Deploy Report succeeded   !!!   ", true);
        }