示例#1
0
 private void Init(DBItemType type)
 {
     ListAvailables  = VMHelper.SetListFromType(type);
     DependencyType  = type;
     CommandeAjouter = new RelayCommand(btn_Ajouter);
     CommandeRetirer = new RelayCommand(btn_Retirer);
 }
示例#2
0
        /// <summary>
        /// Gets the resource components for the compute hours of the Virtual machine resource. This includes components for software cost if present.
        /// </summary>
        /// <returns> Returns the list of resource components </returns>
        private List <ResourceComponent> GetResourceComponentForComputeHours()
        {
            List <ResourceComponent> componentList = new List <ResourceComponent>();

            // Create the compute hours component, Meter SubCategory value will be set later
            ResourceComponent computeHoursComponent = new ResourceComponent
            {
                ResourceType     = this.resource.Type,
                MeterCategory    = VMResourceConstants.VMMeterCategory,
                MeterSubCategory = null,
                MeterName        = VMResourceConstants.VMMeterName,
                Quantity         = Constants.HoursinaMonth,
                IsChargeable     = true
            };

            // Create the software cost component, Meter SubCategory value will be set later
            ResourceComponent softwareCostComponent = new ResourceComponent
            {
                ResourceType     = this.resource.Type,
                MeterCategory    = VMResourceConstants.VMMeterCategory,
                MeterSubCategory = null,
                MeterName        = VMResourceConstants.VMMeterName,
                Quantity         = Constants.HoursinaMonth,
                IsChargeable     = true
            };

            string vmSize = null, osType = null, createOption = null;

            if (this.prop.HardwareProfile != null && this.prop.HardwareProfile.VmSize != null)
            {
                // Fetch the VM Size
                vmSize = PropertyHelper.GetValueIfVariableOrParam(this.prop.HardwareProfile.VmSize, this.template.Variables, this.template.Parameters, this.paramValue.Parameters);
            }
            else
            {
                throw new Exception(ExceptionLogger.GenerateLoggerTextForMissingField("properties.hardwareProfile.vmSize", this.nameOfResource));
            }

            if (vmSize.Equals(string.Empty))
            {
                throw new Exception(ExceptionLogger.GenerateLoggerTextForMissingField("properties.hardwareProfile.vmSize", this.nameOfResource));
            }

            if (this.prop.StorageProfile != null && this.prop.StorageProfile.OsDisk != null)
            {
                // Fetch the OS Disk related info
                osType       = PropertyHelper.GetValueIfVariableOrParam(this.prop.StorageProfile.OsDisk.OsType, this.template.Variables, this.template.Parameters, this.paramValue.Parameters);
                createOption = PropertyHelper.GetValueIfVariableOrParam(this.prop.StorageProfile.OsDisk.CreateOption, this.template.Variables, this.template.Parameters, this.paramValue.Parameters);
            }
            else
            {
                throw new Exception(ExceptionLogger.GenerateLoggerTextForMissingField("properties.storageProfile.osDisk", this.nameOfResource));
            }

            if (createOption == null)
            {
                throw new Exception(ExceptionLogger.GenerateLoggerTextForMissingField("properties.storageProfile.osDisk.createOption", this.nameOfResource));
            }

            if (osType == null)
            {
                if (createOption != null && createOption.Equals("FromImage", StringComparison.OrdinalIgnoreCase))
                {
                    string vmImagePublisher = null, vmImageOffer = null, vmImageSKU = null;

                    // Fetch the VM Image info - Publisher, Offer and SKU
                    if (this.prop.StorageProfile != null && this.prop.StorageProfile.ImageReference != null)
                    {
                        vmImagePublisher = PropertyHelper.GetValueIfVariableOrParam(this.prop.StorageProfile.ImageReference.Publisher, this.template.Variables, this.template.Parameters, this.paramValue.Parameters);
                        vmImageOffer     = PropertyHelper.GetValueIfVariableOrParam(this.prop.StorageProfile.ImageReference.Offer, this.template.Variables, this.template.Parameters, this.paramValue.Parameters);
                        vmImageSKU       = PropertyHelper.GetValueIfVariableOrParam(this.prop.StorageProfile.ImageReference.Sku, this.template.Variables, this.template.Parameters, this.paramValue.Parameters);
                    }
                    else
                    {
                        throw new Exception(ExceptionLogger.GenerateLoggerTextForMissingField("properties.storageProfile.imageReference", this.nameOfResource));
                    }

                    if (vmImagePublisher != null && vmImageOffer != null && vmImageSKU != null)
                    {
                        // Get the OS Type of the VM Image from the Online Helper method
                        osType = VMOnlineHelper.GetVMImageOSType(this.cspCreds, vmImagePublisher, vmImageOffer, vmImageSKU, this.location);
                        string meterSubCategoryForVMImageWithSoftwareCost = null;

                        // Get the Meter SubCategory for software cost of the VM Image is applicable
                        meterSubCategoryForVMImageWithSoftwareCost = VMImageHelper.GetMeterSubCategoryForVMImageWithSoftwareCost(this.cspCreds, vmImagePublisher, vmImageOffer, vmImageSKU, vmSize, this.location);
                        if (meterSubCategoryForVMImageWithSoftwareCost != null)
                        {
                            // Set the Meter SubCategory for Software Cost component, Add to the List of resource components
                            softwareCostComponent.MeterSubCategory = meterSubCategoryForVMImageWithSoftwareCost;
                            componentList.Add(softwareCostComponent);
                        }
                    }
                    else
                    {
                        throw new Exception(ExceptionLogger.GenerateLoggerTextForMissingField("properties.storageProfile.publisher/offer/sku", this.nameOfResource));
                    }
                }
                else
                {
                    throw new Exception(ExceptionLogger.GenerateLoggerTextForInvalidField("storageProfile.osDisk.createOption", createOption, this.nameOfResource));
                }
            }

            string meterSubCategory     = null;
            string modifiedVMSizeString = VMHelper.ModifyVMSizeStringAsPerPricingSpecs(vmSize);

            if (osType != null)
            {
                // Fetch the Meter SubCategory as per the OS Type
                switch (osType.ToUpper())
                {
                case "WINDOWS":
                    meterSubCategory = string.Format(VMResourceConstants.VMMeterSubCategoryWindowsString, modifiedVMSizeString, osType);
                    break;

                case "LINUX":
                    meterSubCategory = string.Format(VMResourceConstants.VMMeterSubCategoryLinuxString, modifiedVMSizeString);
                    break;

                default:
                    throw new Exception(ExceptionLogger.GenerateLoggerTextForInvalidField("OSType", osType, this.nameOfResource));
                }
            }
            else
            {
                throw new Exception(ExceptionLogger.GenerateLoggerTextForInvalidField("OSType", string.Empty, this.nameOfResource));
            }

            // Set the Meter SubCategory for Compute Hours Cost component, Add to the List of resource components
            computeHoursComponent.MeterSubCategory = meterSubCategory;
            componentList.Add(computeHoursComponent);

            return(componentList);
        }
示例#3
0
 protected void ExecuteScript(ExecutionEngine engine, ScriptBuilder sb, bool throwOnFault = false)
 {
     engine.LoadScript(sb.ToArray());
     engine.Execute();
     VMHelper.AssertNoFaultState(engine, Output, throwOnFault);
 }