/// <summary> /// Processes the restoration of an instance backup operation. /// </summary> /// <param name="opts">The commandline options.</param> /// <returns>0 if successful.</returns> private int Process(RestoreInstanceBackupOptions opts) { Service.IOnlineManagementAgent service = new Service.CrmOnlineManagmentRestService(opts.ServiceUrl, opts.Username, opts.Password); if (string.IsNullOrEmpty(opts.Label) && opts.InstanceBackupId == Guid.Empty) { throw new ArgumentException("Label or backup id not provided."); } Task.Run(() => { var status = service.RestoreInstanceBackup( new Model.RestoreInstanceBackupRequest() { TargetInstanceId = opts.TargetInstanceId, RestoreInstanceBackup = new Model.RestoreInstanceBackup() { InstanceBackupId = opts.InstanceBackupId, Label = opts.Label, CreatedOn = opts.CreatedOn, SourceInstanceId = opts.SourceInstanceId } }).Result; this.WriteLog(status); }) .Wait(); return(0); }
/// <summary> /// Processes the retrieval of available instance backups. /// </summary> /// <param name="opts">The commandline options.</param> /// <returns>0 if successful.</returns> private int Process(GetInstanceBackupsOptions opts) { Service.IOnlineManagementAgent service = new Service.CrmOnlineManagmentRestService(opts.ServiceUrl, opts.Username, opts.Password); Task.Run(() => { var backupInstances = service.GetInstanceBackups(new Model.GetInstanceBackupsRequest() { InstanceId = opts.InstanceId }).Result; var backupInstancesCount = backupInstances?.Count(); Log.Information("{@instancesCount} backups found.", backupInstancesCount); foreach (var i in backupInstances) { #warning minimize the verbosity Log.Information("{@i}", i); Log.Debug("{@i}", i); } }) .Wait(); return(0); }
/// <summary> /// Processes the create instance of backup operation. /// </summary> /// <param name="opts">The commandline options.</param> /// <returns>0 if successful.</returns> private int Process(CreateInstanceBackupOptions opts) { Service.IOnlineManagementAgent service = new Service.CrmOnlineManagmentRestService(opts.ServiceUrl, opts.Username, opts.Password); Task.Run(() => { var status = service.CreateInstanceBackup( new Model.CreateInstanceBackupRequest() { CreateInstanceBackup = new Model.CreateInstanceBackup() { InstanceId = opts.InstanceId, Label = opts.Label, IsAzureBackup = opts.IsAzureBackup, Notes = opts.Notes } }).Result; this.WriteLog(status); }) .Wait(); return(0); }
/// <summary> /// Processes the Get instances operation. /// </summary> /// <param name="opts">The commandline options.</param> /// <returns>0 if successfull.</returns> private int Process(GetInstancesOptions opts) { Service.IOnlineManagementAgent service = new Service.CrmOnlineManagmentRestService(opts.ServiceUrl, opts.Username, opts.Password); Task.Run(() => { var instances = service.GetInstances().Result; var instancesCount = instances?.Count(); if (!string.IsNullOrEmpty(opts.FriendlyName)) { instances = instances .Where(x => x.FriendlyName.Equals(opts.FriendlyName, StringComparison.InvariantCultureIgnoreCase)); } else if (!string.IsNullOrEmpty(opts.UniqueName)) { instances = instances.Where(x => x.UniqueName.Equals(opts.UniqueName, StringComparison.InvariantCultureIgnoreCase)); } Log.Information("{@instancesCount} instances found.", instancesCount); foreach (var i in instances) { Log.Information("{@i}", i); } }) .Wait(); return(0); }
/// <summary> /// Processes the create instance operation. /// </summary> /// <param name="opts">The commandline options.</param> /// <returns>0 if successfull.</returns> private int Process(CreateInstanceOptions opts) { Service.IOnlineManagementAgent service = new Service.CrmOnlineManagmentRestService(opts.ServiceUrl, opts.Username, opts.Password); Task.Run(() => { Log.Information($"Attempting to retrieve service version ..."); var availableServiceVersions = service.GetServiceVersion().Result; Log.Information($"{availableServiceVersions.Count() } service versions available."); // resolve the service version that is being used. Model.ServiceVersion serviceVersion = null; // ensure that a specific service version name has been specified. if (!string.IsNullOrEmpty(opts.ServiceVersionName)) { serviceVersion = availableServiceVersions .Where(x => x.Name.Equals(opts.ServiceVersionName, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); } else { serviceVersion = availableServiceVersions.FirstOrDefault(); } if (serviceVersion == null) { throw new InvalidOperationException("Unable to find any service versions associated with login."); } Log.Information($"Using service version: {serviceVersion.Name}."); var c = new Model.CreateInstance() { ServiceVersionId = serviceVersion.Id, Type = opts.Type, BaseLanguage = opts.BaseLanguage, FriendlyName = opts.FriendlyName, DomainName = opts.DomainName, InitialUserEmail = opts.InitialUserEmail, IsValidateOnlyRequest = opts.ValidateOnly }; Log.Information("Creating new instance with parameters ({@c}) ...", c); var status = service.CreateInstance(c).Result; this.WriteLog(status); }) .Wait(); return(0); }
/// <summary> /// Processes the get service version operation. /// </summary> /// <param name="opts">The commandline options.</param> /// <returns>0 if successful.</returns> private int Process(GetServiceVersions opts) { Service.IOnlineManagementAgent service = new Service.CrmOnlineManagmentRestService(opts.ServiceUrl, opts.Username, opts.Password); Task.Run(() => { service.GetServiceVersion(); }) .Wait(); return(0); }
/// <summary> /// Processes the get operation status operation. /// </summary> /// <param name="opts">The commandline options.</param> /// <returns>0 if successfull.</returns> private int Process(GetOperationStatusOptions opts) { Service.IOnlineManagementAgent service = new Service.CrmOnlineManagmentRestService(opts.ServiceUrl, opts.Username, opts.Password); Task.Run(() => { var status = service.GetOperationStatus(new Model.GetOperationStatusRequest() { OperationId = opts.OperationId }).Result; this.WriteLog(status); }) .Wait(); return(0); }
/// <summary> /// Processes the delete instance operation. /// </summary> /// <param name="opts">The commandline options.</param> /// <returns>0 if successfull.</returns> private int Process(DeleteInstanceOptions opts) { Service.IOnlineManagementAgent service = new Service.CrmOnlineManagmentRestService(opts.ServiceUrl, opts.Username, opts.Password); if (!opts.ValidateOnly && !opts.Confirm) { if (opts.InstanceId != Guid.Empty) { Log.Information($"Are you sure to proceed with deletion of the instance [{opts.InstanceId}]?"); } else { Log.Information($"Are you sure to proceed with deletion of the instance [{opts.InstanceFriendlyName}]?"); } var key = Console.ReadKey(); if (key.KeyChar != 'Y' && key.KeyChar != 'y') { Console.Write(Environment.NewLine); Log.Warning("User aborted deletion of instance. Exiting."); return(1); } Console.Write(Environment.NewLine); } Task.Run(() => { Guid?instanceId = Guid.Empty; if (opts.InstanceId != Guid.Empty) { instanceId = opts.InstanceId; } else if (!string.IsNullOrEmpty(opts.InstanceFriendlyName)) { Log.Debug($"Attempting to retrieve instance from instance friendly name: {opts.InstanceFriendlyName}"); var instances = service.GetInstances().Result; instanceId = instances? .Where(x => x.FriendlyName.Equals(opts.InstanceFriendlyName, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault()?.Id; } else { throw new ArgumentException("Instance Id or instance friendly name not provided."); } if (!instanceId.HasValue || instanceId == Guid.Empty) { throw new InvalidOperationException("Unable to resolve unique instance identifier."); } Log.Debug($"Instance Id resolved: {opts.InstanceId}"); var status = service.DeleteInstance(new Model.DeleteInstance() { InstanceId = instanceId.Value, IsValidateOnlyRequest = opts.ValidateOnly }).Result; this.WriteLog(status); }) .Wait(); return(0); }