質問

I am having with using Aspose to generate dynamic content in slides within Microsoft CRM Dynamics 2011. The data is not populating correctly for several fields and relationals even though the logic in the code seems to be correct and should not yield a null or empty value, and I have confirmed there is indeed data for the fields in the database (The data does populate correctly for some of the fields and relationals). All of these issues occur before the powerpoint itself even starts to be generated, so in reality the issues may not be “Aspose” issues they may just be Web Service / CRM issues with retrieving the data asynchronously.

Aspose Slide Workflow:

1) An HTML web resource includes a Silverlight button to download powerpoint report
2) On button click the Silverlight application Asyncronosously collects all the data needed from the Project entity in CRM through web service requests
3) The data is compiled into a Project class that is then passed over to the ReportGenerator Service and uses the data to populate the parts of the powerpoint (This is the part where we use the custom Aspose stuff)
4) Aspose functionality goes through each specified slide and parses them adding in the data where required. 5) Powerpoint is completed and spit out for the user with the data populated.

These are two examples of where I am having troubles getting data to populate. The project.Pwins value below ends up being null which tells me the lambda expression is not executing appropriately, it remains null at the end of the method which tells me the highlighted line is not even being executed at all.

Example 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));
    }

Example 2 the project.TeamMembers value below ends up being null:

    /// <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));
    }

Here is another example that is not an issue with a relational, but instead is an issue with a field populated on a project entity in CRM that shows up empty after retrieving the data. Both CaptureTeamLeader and ProgramManager end up being empty strings, however the ProjectName and ProjectNumber have no troubles populating

    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);
    }

Any help would be greatly appreciated. Thanks in advance!

EDIT:

This is the AttributeValue method asked for:

    /// <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;
        }
    }
役に立ちましたか?

解決

The solution to this problem was that number 1 The downloadstringasync and other places in my code were doing things asynchronously and therefore the debugger was throwing me off and showing things as null when they were really just being executed later. The actual fix required some changes to a client.xml file in the folder the webservice was being hosted from.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top