Ejemplo n.º 1
0
        /// <summary>
        /// Create and configure the organization service proxy.
        /// Retrieve the history limit of a report.
        /// Optionally delete any entity records that were created for this sample.
        /// </summary>
        /// <param name="serverConfig">Contains server connection information.</param>
        /// <param name="promptforDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        public void Run(ServerConnection.Configuration serverConfig, bool promptForDelete)
        {
            try
            {
                // Connect to the Organization service.
                // The using statement assures that the service proxy will be properly disposed.
                using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    // This statement is required to enable early-bound type support.
                    _serviceProxy.EnableProxyTypes();

                    // Call the method to create any data that this sample requires.
                    CreateRequiredRecords();

                    //<snippetGetReportHistoryLimit1>

                    // Query for an an existing report: Account Overview. This is a default report in Microsoft Dynamics CRM.
                    QueryByAttribute reportQuery = new QueryByAttribute(Report.EntityLogicalName);
                    reportQuery.AddAttributeValue("name", "Account Overview");
                    reportQuery.ColumnSet = new ColumnSet("reportid");

                    // Get the report.
                    EntityCollection retrieveReports = _serviceProxy.RetrieveMultiple(reportQuery);

                    // Convert retrieved Entity to a report
                    Report retrievedReport = (Report)retrieveReports.Entities[0];
                    Console.WriteLine("Retrieved the 'Account Overview' report.");

                    // Use the Download Report Definition message.
                    GetReportHistoryLimitRequest reportHistoryRequest = new GetReportHistoryLimitRequest
                    {
                        ReportId = retrievedReport.ReportId.Value
                    };

                    GetReportHistoryLimitResponse reportHistoryResponse = (GetReportHistoryLimitResponse)_serviceProxy.Execute(reportHistoryRequest);

                    // Access the history limit data
                    int historyLimit = reportHistoryResponse.HistoryLimit;

                    Console.WriteLine("The report history limit is {0}.", historyLimit);

                    //</snippetGetReportHistoryLimit1>
                }
            }
            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create and configure the organization service proxy.        
        /// Retrieve the history limit of a report.
        /// Optionally delete any entity records that were created for this sample.
        /// </summary>
        /// <param name="serverConfig">Contains server connection information.</param>
        /// <param name="promptforDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        public void Run(ServerConnection.Configuration serverConfig, bool promptForDelete)
        {
            try
            {

                // Connect to the Organization service. 
                // The using statement assures that the service proxy will be properly disposed.
                using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    // This statement is required to enable early-bound type support.
                    _serviceProxy.EnableProxyTypes();

                    // Call the method to create any data that this sample requires.
                    CreateRequiredRecords();

                    //<snippetGetReportHistoryLimit1>

                    // Query for an an existing report: Account Overview. This is a default report in Microsoft Dynamics CRM.				    
                    QueryByAttribute reportQuery = new QueryByAttribute(Report.EntityLogicalName);
                    reportQuery.AddAttributeValue("name", "Account Overview");
                    reportQuery.ColumnSet = new ColumnSet("reportid");

                    // Get the report.
                    EntityCollection retrieveReports = _serviceProxy.RetrieveMultiple(reportQuery);

                    // Convert retrieved Entity to a report
                    Report retrievedReport = (Report)retrieveReports.Entities[0];
                    Console.WriteLine("Retrieved the 'Account Overview' report.");

                    // Use the Download Report Definition message.
                    GetReportHistoryLimitRequest reportHistoryRequest = new GetReportHistoryLimitRequest
                    {
                        ReportId = retrievedReport.ReportId.Value
                    };

                    GetReportHistoryLimitResponse reportHistoryResponse = (GetReportHistoryLimitResponse)_serviceProxy.Execute(reportHistoryRequest);

                    // Access the history limit data
                    int historyLimit = reportHistoryResponse.HistoryLimit;

                    Console.WriteLine("The report history limit is {0}.", historyLimit);

                    //</snippetGetReportHistoryLimit1>
                    
                }
            }
            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
        [STAThread] // Required to support the interactive login experience
        static void Main(string[] args)
        {
            CrmServiceClient service = null;

            try
            {
                service = SampleHelpers.Connect("Connect");
                if (service.IsReady)
                {
                    // Create any entity records that the demonstration code requires
                    SetUpSample(service);
                    #region Demonstrate
                    // Query for an an existing report: Account Overview. This is a default report in Microsoft Dynamics CRM.
                    QueryByAttribute reportQuery = new QueryByAttribute(Report.EntityLogicalName);
                    reportQuery.AddAttributeValue("name", "Account Overview");
                    reportQuery.ColumnSet = new ColumnSet("reportid");

                    // Get the report.
                    EntityCollection retrieveReports = service.RetrieveMultiple(reportQuery);

                    // Convert retrieved Entity to a report
                    Report retrievedReport = (Report)retrieveReports.Entities[0];
                    Console.WriteLine("Retrieved the 'Account Overview' report.");

                    // Use the Download Report Definition message.
                    var reportHistoryRequest = new GetReportHistoryLimitRequest
                    {
                        ReportId = retrievedReport.ReportId.Value
                    };

                    var reportHistoryResponse = (GetReportHistoryLimitResponse)service.Execute(reportHistoryRequest);

                    // Access the history limit data
                    int historyLimit = reportHistoryResponse.HistoryLimit;

                    Console.WriteLine("The report history limit is {0}.", historyLimit);

                    #endregion Demonstrate

                    #region Clean up
                    CleanUpSample(service);
                    #endregion Clean up
                }
                else
                {
                    const string UNABLE_TO_LOGIN_ERROR = "Unable to Login to Microsoft Dataverse";
                    if (service.LastCrmError.Equals(UNABLE_TO_LOGIN_ERROR))
                    {
                        Console.WriteLine("Check the connection string values in cds/App.config.");
                        throw new Exception(service.LastCrmError);
                    }
                    else
                    {
                        throw service.LastCrmException;
                    }
                }
            }
            catch (Exception ex)
            {
                SampleHelpers.HandleException(ex);
            }

            finally
            {
                if (service != null)
                {
                    service.Dispose();
                }

                Console.WriteLine("Press <Enter> to exit.");
                Console.ReadLine();
            }
        }