我在Microsoft CRM Dynamics 2011中使用Aspose在幻灯片中生成动态内容。即使代码中的逻辑似乎正确并且不应产生空值或空值,也无法正确填充多个字段和关系的数据。值,并且我已经确认数据库中的字段确实存在数据(某些字段和关系确实填充了正确的数据)。所有这些问题都是在Powerpoint本身尚未生成之前发生的,因此实际上,这些问题可能不是“ Aspose”问题,它们可能只是Web Service / CRM问题,它们是异步检索数据的。]
设置幻灯片工作流程:
1)HTML Web资源包括一个Silverlight按钮,用于下载PowerPoint报告2)在按钮上单击Silverlight应用程序,通过Web服务请求异步收集CRM中的Project实体所需的所有数据3)数据被编译成一个Project类,然后传递给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; } }
我在Microsoft CRM Dynamics 2011的幻灯片中使用Aspose生成动态内容。即使...中的逻辑,数据也无法正确填充多个字段和关系。
这个问题的解决方案是编号1我的代码中的downloadstringasync和其他位置都是异步执行的,因此调试器使我失望,并在稍后真正执行时将它们显示为null。实际修复需要对托管Web服务的文件夹中的client.xml文件进行一些更改。