0

我正在使用 Aspose 在 Microsoft CRM Dynamics 2011 中的幻灯片中生成动态内容。即使代码中的逻辑似乎是正确的并且不应产生空值或空值,也没有为多个字段和关系正确填充数据,并且我已经确认数据库中的字段确实存在数据(某些字段和关系的数据确实正确填充)。所有这些问题都发生在 powerpoint 本身甚至开始生成之前,因此实际上这些问题可能不是“Aspose”问题,它们可能只是异步检索数据的 Web 服务/CRM 问题。

Aspose幻灯片工作流程:

1) HTML Web 资源包括用于下载 powerpoint 报告的 Silverlight 按钮
2) 在单击按钮时,Silverlight 应用程序通过 Web 服务请求从 CRM 中的项目实体异步收集所需的所有数据
3) 数据被编译成一个项目类,该类是然后传递给 ReportGenerator 服务并使用数据填充 powerpoint 的各个部分(这是我们使用自定义 Aspose 内容的部分)
4)Aspose 功能遍历每个指定的幻灯片并解析它们,并在需要的地方添加数据。5) Powerpoint 完成并为用户吐出填充的数据。

这是我在获取要填充的数据时遇到困难的两个例子。下面的 project.Pwins 值最终为 null,这告诉我 lambda 表达式没有正确执行,它在方法结束时仍然为 null,这告诉我突出显示的行根本没有被执行。

示例 1:

    /// <summary>
    /// Retrieves and stores information required for P(win) report, and then tries to send a web service request.
    /// </summary>
    /// <param name="service"></param>
    private void LoadPwin(ReportServiceClient service)
    {
        string filter = string.Format("?$filter=sfa_Project/Id eq guid'{0}'", GetProjectId());
        string url = GetEntitySetAddress("sfa_pwin_competitor") + filter;

        WebClient client = new WebClient();
        client.DownloadStringCompleted += (sender, args) =>
        {
            if (args.Error == null)
            {
                StringReader stream = new StringReader(args.Result);
                XmlReader reader = XmlReader.Create(stream);

                List<PWin> pwins = new List<PWin>();
                List<Dictionary<string, string>> dictionaries = LoadEntitiesFromXml(reader);
                foreach (Dictionary<string, string> dictionary in dictionaries)
                {
                    PWin pwin = new PWin();
                    pwin.CompanyName = ParseDictionaryValue(dictionary["sfa_competitor"]);
                    pwin.IsBoeing = (ParseDictionaryValue(dictionary["sfa_is_boeing"]) == "true");
                    pwin.IsDomestic = (ParseDictionaryValue(dictionary["sfa_domestic_or_international"]) == "true");
                    pwin.AffordabilityWeight = ParseDictionaryValueToNumber(dictionary["sfa_affordability_weight"]);
                    pwin.AffordabilityScore = ParseDictionaryValueToNumber(dictionary["sfa_affordability_score"]);
                    pwin.CustomerRelationshipWeight = ParseDictionaryValueToNumber(dictionary["sfa_customer_relationship_weight"]);
                    pwin.CustomerRelationshipScore = ParseDictionaryValueToNumber(dictionary["sfa_customer_relationship_score"]);
                    pwin.CustomerAdvantageWeight = ParseDictionaryValueToNumber(dictionary["sfa_customer_advantage_weight"]);
                    pwin.CustomerAdvantageScore = ParseDictionaryValueToNumber(dictionary["sfa_customer_advantage_score"]);
                    pwin.CompetitionWeight = ParseDictionaryValueToNumber(dictionary["sfa_competition_weight"]);
                    pwin.CompetitionScore = ParseDictionaryValueToNumber(dictionary["sfa_competition_score"]);
                    pwin.CPOBCWeight = ParseDictionaryValueToNumber(dictionary["sfa_cpobc_weight"]);
                    pwin.CPOBCScore = ParseDictionaryValueToNumber(dictionary["sfa_cpobc_score"]);
                    pwin.CompanyResourcesWeight = ParseDictionaryValueToNumber(dictionary["sfa_company_resources_weight"]);
                    pwin.CompanyResourcesScore = ParseDictionaryValueToNumber(dictionary["sfa_company_resources_score"]);
                    pwin.CompanyResourcesInvestmentWeight = ParseDictionaryValueToNumber(dictionary["sfa_company_resources_investment_weight"]);
                    pwin.CompanyResourcesInvestmentScore = ParseDictionaryValueToNumber(dictionary["sfa_company_resources_investment_score"]);
                    pwin.ProgramBackgroundWeight = ParseDictionaryValueToNumber(dictionary["sfa_program_background_weight"]);
                    pwin.ProgramBackgroundScore = ParseDictionaryValueToNumber(dictionary["sfa_program_background_score"]);
                    pwin.ContinuityOfEffortWeight = ParseDictionaryValueToNumber(dictionary["sfa_continuity_of_effort_weight"]);
                    pwin.ContinuityOfEffortScore = ParseDictionaryValueToNumber(dictionary["sfa_continuity_of_effort_score"]);
                    pwin.ExecutionWeight = ParseDictionaryValueToNumber(dictionary["sfa_execution_weight"]);
                    pwin.ExecutionScore = ParseDictionaryValueToNumber(dictionary["sfa_execution_score"]);
                    pwin.TechnicalSolutionWeight = ParseDictionaryValueToNumber(dictionary["sfa_technical_solution_weight"]);
                    pwin.TechnicalSolutionScore = ParseDictionaryValueToNumber(dictionary["sfa_technical_solution_score"]);
                    pwin.StrategyToWinWeight = ParseDictionaryValueToNumber(dictionary["sfa_strategy_to_win_weight"]);
                    pwin.StrategyToWinScore = ParseDictionaryValueToNumber(dictionary["sfa_strategy_to_win_score"]);
                    pwin.ManagementStrengthWeight = ParseDictionaryValueToNumber(dictionary["sfa_management_strength_weight"]);
                    pwin.ManagementStrengthScore = ParseDictionaryValueToNumber(dictionary["sfa_management_strength_score"]);
                    pwin.CustomerPercievedCommitmentWeight = ParseDictionaryValueToNumber(dictionary["sfa_customers_percieved_commitment_weight"]);
                    pwin.CustomerPercievedCommitmentScore = ParseDictionaryValueToNumber(dictionary["sfa_customers_percieved_commitment_score"]);
                    pwin.PastPerformanceWeight = ParseDictionaryValueToNumber(dictionary["sfa_past_performance_weight"]);
                    pwin.PastPerformanceScore = ParseDictionaryValueToNumber(dictionary["sfa_past_performance_score"]);

                    pwin.RawPWin = ParseDictionaryValueToDecimal(dictionary["sfa_pwin_score"]);
                    pwin.RelativePWin = ParseDictionaryValueToDecimal(dictionary["sfa_relative_pwin_score"]);
                    pwins.Add(pwin);
                }

                project.PWins = new ObservableCollection<PWin>(pwins);
                PwinReady = true;

                reader.Close();
                TrySendRequest(service);
            }
        };

        client.DownloadStringAsync(new Uri(url));
    }

示例 2 下面的 project.TeamMembers 值最终为空:

    /// <summary>
    /// Retrieves and stores information required for Capture Team Roster report, and then tries to send a web service request.
    /// </summary>
    /// <param name="service"></param>
    private void LoadCaptureTeamRoster(ReportServiceClient service)
    {
        string filter = string.Format("?$select=sfa_name,sfa_Role&$filter=sfa_Project/Id eq guid'{0}'", GetProjectId());
        string url = GetEntitySetAddress("sfa_team_roster") + filter;

        WebClient client = new WebClient();
        client.DownloadStringCompleted += (sender, args) =>
        {
            if (args.Error == null)
            {
                StringReader stream = new StringReader(args.Result);
                XmlReader reader = XmlReader.Create(stream);

                List<TeamMember> members = new List<TeamMember>();

                List<Dictionary<string, string>> dictionaries = LoadEntitiesFromXml(reader);
                foreach (Dictionary<string, string> dictionary in dictionaries)
                {
                    TeamMember member = new TeamMember();
                    member.Name = ParseDictionaryValue(dictionary["sfa_name"]);
                    member.Role = ParseDictionaryValue(dictionary["sfa_role"]);

                    members.Add(member);
                }

                project.TeamMembers = new ObservableCollection<TeamMember>(members);

                CaptureTeamRosterReady = true;

                reader.Close();

                TrySendRequest(service);
            }
        };
        client.DownloadStringAsync(new Uri(url));
    }

这是另一个与关系无关的示例,而是在 CRM 中的项目实体上填充的字段在检索数据后显示为空的问题。CaptureTeamLeader 和 ProgramManager 最终都是空字符串,但是 ProjectName 和 ProjectNumber 填充没有问题

    private void LoadCampaignTitle(ReportServiceClient service)
    {
        project.ProjectName = GetAttributeValue("sfa_name");
        project.ProjectNumber = GetAttributeValue("sfa_project_number");
        project.CaptureTeamLeader = GetAttributeValue("sfa_capture_team_leader_emp");
        project.ProgramManager = GetAttributeValue("sfa_program_manager_emp");
        CampaignTitleReady = true;

        TrySendRequest(service);
    }

任何帮助将不胜感激。提前致谢!

编辑:

这是要求的 AttributeValue 方法:

    /// <summary>
    /// Gets the value of provided attribute from the current page's Xrm data. If for any reason the retrieval fails, returns an empty string.
    /// </summary>
    /// <param name="attributeName"></param>
    /// <returns></returns>
    private string GetAttributeValue(string attributeName)
    {
        // NOTE: This is the preferred way to retrieve data from the CRM. However for some unknown issue,
        // this always returns NULL. It will be replaced with directly calling .eval to the window object.
        // dynamic Xrm = (ScriptObject)HtmlPage.Window.GetProperty("window.parent.Xrm");
        try
        {
            return HtmlPage.Window.Invoke("getAttributeValue", attributeName).ToString();
        }
        catch (ArgumentNullException)
        {
            return string.Empty;
        }
        catch (ArgumentException)
        {
            return string.Empty;
        }
        catch (InvalidOperationException)
        {
            return string.Empty;
        }
    }
4

1 回答 1

0

这个问题的解决方案是我的代码中的第 1 号 downloadstringasync 和其他地方正在异步执行操作,因此调试器让我失望并在稍后真正执行时将它们显示为 null。实际修复需要对托管 Web 服务的文件夹中的 client.xml 文件进行一些更改。

于 2014-05-09T23:46:04.960 回答