private void ProcessParameterSetId()
        {
            var result = default(VirtualMachine);

            if (MyInvocation.BoundParameters.ContainsKey("VirtualDataCenterId") ||
                MyInvocation.BoundParameters.ContainsKey("VirtualApplianceId"))
            {
                try
                {
                    result = ModuleConfiguration.Current.Client.GetVirtualMachine(VirtualDataCenterId, VirtualApplianceId, Id);
                }
                catch (Exception ex)
                {
                    WriteError(ErrorRecordFactory.GetGeneric(ex));
                }
            }
            else
            {
                var collection = ModuleConfiguration.Current.Client
                                 .GetAllVirtualMachines()
                                 .Collection ?? new List <VirtualMachine>();

                result = collection.FirstOrDefault(e => e.Id.HasValue && e.Id.Value == Id);
            }

            if (null == result)
            {
                WriteError(ErrorRecordFactory.GetNotFound(Messages.GetMachineIdNotFound, Constants.EventId.GetMachineIdNotFound.ToString(), Id));
                return;
            }

            WriteObject(result);
        }
Example #2
0
        public void GetNotFoundWithEmptyErrorIdThrowsContractException()
        {
            var messageOrTemplate = "arbitrary-message";
            var errorId           = string.Empty;
            var objects           = new object[] { };

            ErrorRecordFactory.GetNotFound(messageOrTemplate, errorId, objects);
        }
Example #3
0
        public void GetNotFoundWithInvalidFormtStringThrowsContractException()
        {
            var messageOrTemplate = "arbitrary-message-'{0}'";
            var errorId           = "arbitrary-errorid";
            var objects           = new object[] { };

            ErrorRecordFactory.GetNotFound(messageOrTemplate, errorId, objects);
        }
Example #4
0
        public void GetGenericSucceeds()
        {
            var exception = new ArgumentException("arbitrary-message");

            var result = ErrorRecordFactory.GetGeneric(exception);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.FullyQualifiedErrorId.StartsWith(ErrorCategory.NotSpecified.ToString()));
            Assert.IsInstanceOfType(result.Exception, typeof(ArgumentException));
            Assert.AreEqual(exception.Message, result.Exception.Message);
        }
 private void ProcessParameterSetId()
 {
     try
     {
         var result = ModuleConfiguration.Current.Client.GetVirtualDataCenter(Id);
         WriteObject(result);
     }
     catch (Exception ex)
     {
         WriteError(ErrorRecordFactory.GetGeneric(ex));
         WriteError(ErrorRecordFactory.GetNotFound(Messages.GetVirtualDataCenterIdNotFound, Constants.EventId.GetVirtualDataCenterIdNotFound.ToString(), Id));
     }
 }
 private void ProcessParameterSetId()
 {
     try
     {
         var result = ModuleConfiguration.Current.Client.GetEnterprise(Id);
         WriteObject(result);
     }
     catch (Exception ex)
     {
         WriteError(ErrorRecordFactory.GetGeneric(ex));
         WriteError(ErrorRecordFactory.GetNotFound(Messages.GetMachineIdNotFound, Constants.EventId.GetEnterpriseIdNotFound.ToString(), Id), writeToTraceSource: true);
     }
 }
 private void ProcessParameterSetId()
 {
     try
     {
         var coreContext = (Api::Net.Appclusive.Api.Core.Core)Svc[nameof(Api::Net.Appclusive.Api.Core.Core)];
         var result = coreContext.Tenants.Id(Id);
         WriteObject(result);
     }
     catch (Exception ex)
     {
         WriteError(ErrorRecordFactory.GetGeneric(ex));
         WriteError(ErrorRecordFactory.GetNotFound(Messages.Cmdlet_ProcessParameterSetId__NotFound, Logging.EventId.GetTenantIdNotFound.ToString(), nameof(Tenant), Id), writeToTraceSource: true);
     }
 }
Example #8
0
        public void GetNotFound1Succeeds()
        {
            var messageOrTemplateStart = "arbitrary-message-";
            var messageOrTemplate      = messageOrTemplateStart + "'{0}'";
            var errorId = "arbitrary-errorid";
            var objects = new object[] { "tralala" };

            var result = ErrorRecordFactory.GetNotFound(messageOrTemplate, errorId, objects);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.FullyQualifiedErrorId.StartsWith(errorId));
            Assert.AreNotEqual(messageOrTemplate, result.Exception.Message);
            Assert.IsTrue(result.Exception.Message.Contains(objects[0].ToString()));
            Assert.IsTrue(result.Exception.Message.StartsWith(messageOrTemplateStart));
        }
        private void ProcessParameterSetList()
        {
            var collection = new List <VirtualMachine>();

            if (0 >= VirtualDataCenterId && 0 >= VirtualApplianceId)
            {
                collection = ModuleConfiguration.Current.Client
                             .GetAllVirtualMachines()
                             .Collection ?? new List <VirtualMachine>();
                collection.ForEach(WriteObject);
                return;
            }

            try
            {
                var virtualAppliances = new List <VirtualAppliance>();
                if (0 < VirtualApplianceId)
                {
                    virtualAppliances.Add(new VirtualAppliance()
                    {
                        Id = VirtualApplianceId
                    });
                }
                else
                {
                    virtualAppliances.AddRange(ModuleConfiguration.Current.Client.GetVirtualAppliances(VirtualDataCenterId).Collection ?? new List <VirtualAppliance>());
                }

                foreach (var virtualAppliance in virtualAppliances)
                {
                    collection.AddRange(ModuleConfiguration.Current.Client.GetVirtualMachines(VirtualDataCenterId, virtualAppliance.Id).Collection ?? new List <VirtualMachine>());
                }

                collection.ForEach(WriteObject);
            }
            catch (Exception ex)
            {
                WriteError(ErrorRecordFactory.GetGeneric(ex));
                WriteError(0 < VirtualApplianceId
                    ? ErrorRecordFactory.GetNotFound(Messages.GetMachineVdcVappNotFound,
                                                     Constants.EventId.GetMachineVirtualDataCenterOrVirtualApplianceNotFound.ToString(),
                                                     VirtualDataCenterId, VirtualApplianceId)
                    : ErrorRecordFactory.GetNotFound(Messages.GetMachineVdcNotFound,
                                                     Constants.EventId.GetMachineVirtualDataCenterOrVirtualApplianceNotFound.ToString(),
                                                     VirtualDataCenterId));
            }
        }
        private void ProcessParameterSetName()
        {
            var collection = ModuleConfiguration.Current.Client
                             .GetVirtualDataCenters()
                             .Collection ?? new List <VirtualDataCenter>();
            var results = collection
                          .Where(e => Name.Equals(e.Name, StringComparison.InvariantCultureIgnoreCase))
                          .ToList();

            if (0 == results.Count)
            {
                WriteError(ErrorRecordFactory.GetNotFound(Messages.GetVirtualDataCenterNameNotFound, Constants.EventId.GetVirtualDataCenterNameNotFound.ToString(), Name));
                return;
            }

            results.ForEach(WriteObject);
        }
        private void ProcessParameterSetList()
        {
            var virtualDataCenters = new List <VirtualDataCenter>();

            if (0 >= VirtualDataCenterId)
            {
                virtualDataCenters = ModuleConfiguration.Current.Client
                                     .GetVirtualDataCenters()
                                     .Collection ?? new List <VirtualDataCenter>();
            }
            else
            {
                virtualDataCenters.Add(new VirtualDataCenter()
                {
                    Id = VirtualDataCenterId
                });
            }

            try
            {
                var collection = new List <VirtualAppliance>();
                foreach (var virtualDataCenter in virtualDataCenters)
                {
                    collection = ModuleConfiguration.Current.Client
                                 .GetVirtualAppliances(virtualDataCenter.Id)
                                 .Collection ?? new List <VirtualAppliance>();
                }

                collection.ForEach(WriteObject);
            }
            catch (Exception ex)
            {
                WriteError(ErrorRecordFactory.GetGeneric(ex));
                WriteError(ErrorRecordFactory.GetNotFound(Messages.GetVirtualApplianceVdcNotFound,
                                                          Constants.EventId.GetVirtualApplianceVirtualDataCenterNotFound.ToString(), VirtualDataCenterId));
            }
        }
Example #12
0
        public void GetGenericThrowsContractException()
        {
            var exception = default(Exception);

            ErrorRecordFactory.GetGeneric(exception);
        }