private void Connect() { ServerConnection serverConnect = new ServerConnection(); ServerConnection.Configuration serverConfig = serverConnect.GetServerConfiguration(); this.service = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials); }
static public void Main(string[] args) { // The connection to the Organization web service. OrganizationServiceProxy serviceProxy = null; try { // Obtain the target organization's web address and client logon credentials // from the user by using a helper class. ServerConnection serverConnect = new ServerConnection(); ServerConnection.Configuration config = serverConnect.GetServerConfiguration(); // Establish an authenticated connection to the Organization web service. serviceProxy = new OrganizationServiceProxy(config.OrganizationUri, config.HomeRealmUri, config.Credentials, config.DeviceCredentials); CRUDOperations app = new CRUDOperations(); // Create any records that must exist in the database. These record references are // stored in a collection so the records can be deleted later. EntityReferenceCollection records = app.CreateRequiredEntityRecords(serviceProxy); // Perform the primary operation of this sample. app.Run(serviceProxy, records); // Delete all remaining records that were created by this sample. app.DeleteEntityRecords(serviceProxy, records, true); } // Some exceptions to consider catching. //<snippetCRUDOperations3> catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> e) { HandleException(e); } catch (TimeoutException e) { HandleException(e); } catch (SecurityTokenValidationException e) { HandleException(e); } catch (ExpiredSecurityTokenException e) { HandleException(e); } catch (MessageSecurityException e) { HandleException(e); } catch (SecurityNegotiationException e) { HandleException(e); } catch (SecurityAccessDeniedException e) { HandleException(e); } catch (Exception e) { HandleException(e); } //</snippetCRUDOperations3> finally { // Always dispose the service object to close the service connection and free resources. if (serviceProxy != null) serviceProxy.Dispose(); Console.WriteLine("Press <Enter> to exit."); Console.ReadLine(); } }
static void Main(string[] args) { var options = new Options(); if (CommandLine.Parser.Default.ParseArguments(args, options)) { ServerConnection serverConnect = new ServerConnection(); ServerConnection.Configuration config = serverConnect.GetServerConfiguration(); Console.Write("\n Connection Server: {0}, Org: {1}, User: {2}\t", config.ServerAddress, config.OrganizationName, config.Credentials.UserName); // Values are available here if (!string.IsNullOrEmpty(options.ExportPackageLocation) && !string.IsNullOrEmpty(options.SolutionName)) { ExportSolution app = new ExportSolution(); app.Run(config, false, options.ExportPackageLocation, options.SolutionName); } } Console.ReadLine(); }
/// <summary> /// Standard Main() method used by most SDK samples. /// </summary> /// <param name="args"></param> static public void Main(string[] args) { try { // Obtain the target organization's Web address and client logon // credentials from the user. ServerConnection serverConnect = new ServerConnection(); ServerConnection.Configuration config = serverConnect.GetServerConfiguration(); EndRecurringAppointmentSeries app = new EndRecurringAppointmentSeries(); app.Run(config, true); } catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp); Console.WriteLine("Code: {0}", ex.Detail.ErrorCode); Console.WriteLine("Message: {0}", ex.Detail.Message); Console.WriteLine("Plugin Trace: {0}", ex.Detail.TraceText); Console.WriteLine("Inner Fault: {0}", null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } catch (System.TimeoutException ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine("Message: {0}", ex.Message); Console.WriteLine("Stack Trace: {0}", ex.StackTrace); Console.WriteLine("Inner Fault: {0}", null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message); } catch (System.Exception ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine(ex.Message); // Display the details of the inner exception. if (ex.InnerException != null) { Console.WriteLine(ex.InnerException.Message); FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> fe = ex.InnerException as FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>; if (fe != null) { Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp); Console.WriteLine("Code: {0}", fe.Detail.ErrorCode); Console.WriteLine("Message: {0}", fe.Detail.Message); Console.WriteLine("Plugin Trace: {0}", fe.Detail.TraceText); Console.WriteLine("Inner Fault: {0}", null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } } } // Additional exceptions to catch: SecurityTokenValidationException, ExpiredSecurityTokenException, // SecurityAccessDeniedException, MessageSecurityException, and SecurityNegotiationException. finally { Console.WriteLine("Press <Enter> to exit."); Console.ReadLine(); } }
/// <summary> /// Main. Runs the sample and provides error output. /// <param name="args">Array of arguments to Main method.</param> /// </summary> static public void Main(string[] args) { try { // Obtain the target organization's Web address and client logon // credentials from the user. ServerConnection serverConnect = new ServerConnection(); ServerConnection.Configuration config = serverConnect.GetServerConfiguration(); CreateAndShareAccessTeam app = new CreateAndShareAccessTeam(); app.Run(config, true); } catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp); Console.WriteLine("Code: {0}", ex.Detail.ErrorCode); Console.WriteLine("Message: {0}", ex.Detail.Message); Console.WriteLine("Plugin Trace: {0}", ex.Detail.TraceText); Console.WriteLine("Inner Fault: {0}", null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } catch (System.TimeoutException ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine("Message: {0}", ex.Message); Console.WriteLine("Stack Trace: {0}", ex.StackTrace); Console.WriteLine("Inner Fault: {0}", null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message); } catch (System.Exception ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine(ex.Message); // Display the details of the inner exception. if (ex.InnerException != null) { Console.WriteLine(ex.InnerException.Message); FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> fe = ex.InnerException as FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>; if (fe != null) { Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp); Console.WriteLine("Code: {0}", fe.Detail.ErrorCode); Console.WriteLine("Message: {0}", fe.Detail.Message); Console.WriteLine("Plugin Trace: {0}", fe.Detail.TraceText); Console.WriteLine("Inner Fault: {0}", null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } } } finally { Console.WriteLine("Press <Enter> to exit."); Console.ReadLine(); } }
/// <summary> /// Main entry point for the application. /// </summary> /// <param name="CmdArgs">Entities to place on the diagram</param> public static int Main(string[] args) { String filename = String.Empty; VisioApi.Application application; VisioApi.Document document; DiagramBuilder builder = new DiagramBuilder(); try { // Obtain the target organization's Web address and client logon // credentials from the user. ServerConnection serverConnect = new ServerConnection(); ServerConnection.Configuration config = serverConnect.GetServerConfiguration(); // Connect to the Organization service. // The using statement assures that the service proxy will be properly disposed. using (_serviceProxy = ServerConnection.GetOrganizationProxy(config)) { // This statement is required to enable early-bound type support. _serviceProxy.EnableProxyTypes(); // Load Visio and create a new document. application = new VisioApi.Application(); application.Visible = false; // Not showing the UI increases rendering speed builder.VersionName = application.Version; document = application.Documents.Add(String.Empty); builder._application = application; builder._document = document; // Load the metadata. Console.WriteLine("Loading Metadata..."); RetrieveAllEntitiesRequest request = new RetrieveAllEntitiesRequest() { EntityFilters = EntityFilters.Entity | EntityFilters.Attributes | EntityFilters.Relationships, RetrieveAsIfPublished = true, }; RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)_serviceProxy.Execute(request); builder._metadataResponse = response; // Diagram all entities if given no command-line parameters, otherwise diagram // those entered as command-line parameters. if (args.Length < 1) { ArrayList entities = new ArrayList(); foreach (EntityMetadata entity in response.EntityMetadata) { // Only draw an entity if it does not exist in the excluded entity table. if (!_excludedEntityTable.ContainsKey(entity.LogicalName.GetHashCode())) { entities.Add(entity.LogicalName); } else { Console.WriteLine("Excluding entity: {0}", entity.LogicalName); } } builder.BuildDiagram((string[])entities.ToArray(typeof(string)), "All Entities"); filename = "AllEntities.vsd"; } else { builder.BuildDiagram(args, String.Join(", ", args)); filename = String.Concat(args[0], ".vsd"); } // Save the diagram in the current directory using the name of the first // entity argument or "AllEntities" if none were given. Close the Visio application. document.SaveAs(Directory.GetCurrentDirectory() + "\\" + filename); application.Quit(); } } catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp); Console.WriteLine("Code: {0}", ex.Detail.ErrorCode); Console.WriteLine("Message: {0}", ex.Detail.Message); Console.WriteLine("Plugin Trace: {0}", ex.Detail.TraceText); Console.WriteLine("Inner Fault: {0}", null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } catch (System.TimeoutException ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine("Message: {0}", ex.Message); Console.WriteLine("Stack Trace: {0}", ex.StackTrace); Console.WriteLine("Inner Fault: {0}", null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message); } catch (System.Exception ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine(ex.Message); // Display the details of the inner exception. if (ex.InnerException != null) { Console.WriteLine(ex.InnerException.Message); FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> fe = ex.InnerException as FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>; if (fe != null) { Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp); Console.WriteLine("Code: {0}", fe.Detail.ErrorCode); Console.WriteLine("Message: {0}", fe.Detail.Message); Console.WriteLine("Plugin Trace: {0}", fe.Detail.TraceText); Console.WriteLine("Inner Fault: {0}", null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } } } // Additional exceptions to catch: SecurityTokenValidationException, ExpiredSecurityTokenException, // SecurityAccessDeniedException, MessageSecurityException, and SecurityNegotiationException. finally { //Console.WriteLine("Rendering complete."); Console.WriteLine("Rendering complete. Press any key to continue."); Console.ReadLine(); } return 0; }
/// <summary> /// Standard Main() method used by most SDK samples. /// </summary> /// <param name="args"></param> static public void Main(string[] args) { try { // Obtain the target organization's Web address and client logon // credentials from the user. ServerConnection serverConnect = new ServerConnection(); ServerConnection.Configuration config = serverConnect.GetServerConfiguration(); CreateUpdateEntityMetadata app = new CreateUpdateEntityMetadata(); app.Run(config, true); } catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp); Console.WriteLine("Code: {0}", ex.Detail.ErrorCode); Console.WriteLine("Message: {0}", ex.Detail.Message); Console.WriteLine("Plugin Trace: {0}", ex.Detail.TraceText); Console.WriteLine("Inner Fault: {0}", null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } catch (System.TimeoutException ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine("Message: {0}", ex.Message); Console.WriteLine("Stack Trace: {0}", ex.StackTrace); Console.WriteLine("Inner Fault: {0}", null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message); } catch (System.Exception ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine(ex.Message); // Display the details of the inner exception. if (ex.InnerException != null) { Console.WriteLine(ex.InnerException.Message); FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> fe = ex.InnerException as FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault>; if (fe != null) { Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp); Console.WriteLine("Code: {0}", fe.Detail.ErrorCode); Console.WriteLine("Message: {0}", fe.Detail.Message); Console.WriteLine("Plugin Trace: {0}", fe.Detail.TraceText); Console.WriteLine("Inner Fault: {0}", null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } } } // Additional exceptions to catch: SecurityTokenValidationException, ExpiredSecurityTokenException, // SecurityAccessDeniedException, MessageSecurityException, and SecurityNegotiationException. finally { Console.WriteLine("Press <Enter> to exit."); Console.ReadLine(); } }
/// <summary> /// Main entry point for the application. /// </summary> /// <param name="CmdArgs">Entities to place on the diagram</param> public static int Main(string[] args) { String filename = String.Empty; VisioApi.Application application; VisioApi.Document document; DiagramBuilder builder = new DiagramBuilder(); try { // Obtain the target organization's Web address and client logon // credentials from the user. ServerConnection serverConnect = new ServerConnection(); ServerConnection.Configuration config = serverConnect.GetServerConfiguration(); // Connect to the Organization service. // The using statement assures that the service proxy will be properly disposed. using (_serviceProxy = ServerConnection.GetOrganizationProxy(config)) { // This statement is required to enable early-bound type support. _serviceProxy.EnableProxyTypes(); // Load Visio and create a new document. application = new VisioApi.Application(); application.Visible = false; // Not showing the UI increases rendering speed builder.VersionName = application.Version; document = application.Documents.Add(String.Empty); builder._application = application; builder._document = document; // Load the metadata. Console.WriteLine("Loading Metadata..."); RetrieveAllEntitiesRequest request = new RetrieveAllEntitiesRequest() { EntityFilters = EntityFilters.Entity | EntityFilters.Attributes | EntityFilters.Relationships, RetrieveAsIfPublished = false, }; RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)_serviceProxy.Execute(request); builder._metadataResponse = response; // Diagram all entities if given no command-line parameters, otherwise diagram // those entered as command-line parameters. if (args.Length < 1) { ArrayList entities = new ArrayList(); foreach (EntityMetadata entity in response.EntityMetadata) { // Only draw an entity if it does not exist in the excluded entity table. if (!_excludedEntityTable.ContainsKey(entity.LogicalName.GetHashCode())) { entities.Add(entity.LogicalName); } else { Console.WriteLine("Excluding entity: {0}", entity.LogicalName); } } builder.BuildDiagram((string[])entities.ToArray(typeof(string)), "All Entities"); filename = "AllEntities.vsd"; } else { builder.BuildDiagram(args, String.Join(", ", args)); filename = String.Concat(args[0], ".vsd"); } // Save the diagram in the current directory using the name of the first // entity argument or "AllEntities" if none were given. Close the Visio application. document.SaveAs(Directory.GetCurrentDirectory() + "\\" + filename); application.Quit(); } } catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp); Console.WriteLine("Code: {0}", ex.Detail.ErrorCode); Console.WriteLine("Message: {0}", ex.Detail.Message); Console.WriteLine("Plugin Trace: {0}", ex.Detail.TraceText); Console.WriteLine("Inner Fault: {0}", null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } catch (System.TimeoutException ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine("Message: {0}", ex.Message); Console.WriteLine("Stack Trace: {0}", ex.StackTrace); Console.WriteLine("Inner Fault: {0}", null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message); } catch (System.Exception ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine(ex.Message); // Display the details of the inner exception. if (ex.InnerException != null) { Console.WriteLine(ex.InnerException.Message); FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> fe = ex.InnerException as FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault>; if (fe != null) { Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp); Console.WriteLine("Code: {0}", fe.Detail.ErrorCode); Console.WriteLine("Message: {0}", fe.Detail.Message); Console.WriteLine("Plugin Trace: {0}", fe.Detail.TraceText); Console.WriteLine("Inner Fault: {0}", null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } } } // Additional exceptions to catch: SecurityTokenValidationException, ExpiredSecurityTokenException, // SecurityAccessDeniedException, MessageSecurityException, and SecurityNegotiationException. finally { //Console.WriteLine("Rendering complete."); Console.WriteLine("Rendering complete. Press any key to continue."); Console.ReadLine(); } return(0); }