public override void ExecuteCmdlet()
        {
            try
            {
                WriteVerbose(string.Format(Resources.MigrationMsgQueringDeviceId, TargetDeviceName));
                string deviceid = StorSimpleClient.GetDeviceId(TargetDeviceName);
                if (!File.Exists(ConfigFilePath))
                {
                    throw new FileNotFoundException(String.Format(Resources.MigrationConfigFileNotFound,
                        StorSimpleContext.ResourceName, ConfigFilePath));
                }
                else if (string.IsNullOrEmpty(deviceid))
                {
                    throw new ArgumentException(String.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage,
                        StorSimpleContext.ResourceName, TargetDeviceName));
                }
                else
                {
                    // creating the config file parser instance - parser decrypt the xml and parses the config xml
                    WriteVerbose(string.Format(Resources.MigrationMsgDeviceFound, deviceid));
                    var secretsEncryptor = new ServiceSecretEncryptor(this.StorSimpleClient);
                    var parser = new LegacyApplianceConfigParser(secretsEncryptor);
                    var legacyApplianceMetaData = new LegacyApplianceConfiguration();

                    legacyApplianceMetaData.Details = parser.ParseLegacyApplianceConfig(ConfigFilePath,
                        ConfigDecryptionKey);
                    LegacyApplianceConfig config = legacyApplianceMetaData.Details;
                    legacyApplianceMetaData.LegacyConfigId = Guid.NewGuid().ToString();
                    config.InstanceId = config.Name = legacyApplianceMetaData.LegacyConfigId;
                    legacyApplianceMetaData.ConfigFile = ConfigFilePath;
                    legacyApplianceMetaData.ImportedOn = DateTime.Now;
                    legacyApplianceMetaData.TargetApplianceName = TargetDeviceName;
                    config.DeviceId = deviceid;

                    legacyApplianceMetaData.Result = Resources.ImportLegacyApplianceConfigSuccessMessage;
                    WriteVerbose(Resources.MigrationMsgUploadingConfig);
                    var configList = ConfigSplitHelper.Split(legacyApplianceMetaData.Details);
                    foreach (var singleConfig in configList)
                    {
                        StorSimpleClient.ImportLegacyApplianceConfig(legacyApplianceMetaData.LegacyConfigId,
                            singleConfig);
                    }

                    WriteObject(legacyApplianceMetaData);
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
コード例 #2
0
        public override void ExecuteCmdlet()
        {
            try
            {
                WriteVerbose(string.Format(Resources.MigrationMsgQueringDeviceId, TargetDeviceName));
                string deviceid = StorSimpleClient.GetDeviceId(TargetDeviceName);
                if (!File.Exists(ConfigFilePath))
                {
                    throw new FileNotFoundException(String.Format(Resources.MigrationConfigFileNotFound,
                                                                  StorSimpleContext.ResourceName, ConfigFilePath));
                }
                else if (string.IsNullOrEmpty(deviceid))
                {
                    throw new ArgumentException(String.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage,
                                                              StorSimpleContext.ResourceName, TargetDeviceName));
                }
                else
                {
                    // creating the config file parser instance - parser decrypt the xml and parses the config xml
                    WriteVerbose(string.Format(Resources.MigrationMsgDeviceFound, deviceid));
                    var secretsEncryptor        = new ServiceSecretEncryptor(this.StorSimpleClient);
                    var parser                  = new LegacyApplianceConfigParser(secretsEncryptor);
                    var legacyApplianceMetaData = new LegacyApplianceConfiguration();

                    legacyApplianceMetaData.Details = parser.ParseLegacyApplianceConfig(ConfigFilePath,
                                                                                        ConfigDecryptionKey);
                    LegacyApplianceConfig config = legacyApplianceMetaData.Details;
                    legacyApplianceMetaData.LegacyConfigId = Guid.NewGuid().ToString();
                    config.InstanceId = config.Name = legacyApplianceMetaData.LegacyConfigId;
                    legacyApplianceMetaData.ConfigFile          = ConfigFilePath;
                    legacyApplianceMetaData.ImportedOn          = DateTime.Now;
                    legacyApplianceMetaData.TargetApplianceName = TargetDeviceName;
                    config.DeviceId = deviceid;

                    legacyApplianceMetaData.Result = Resources.ImportLegacyApplianceConfigSuccessMessage;
                    WriteVerbose(Resources.MigrationMsgUploadingConfig);
                    var configList = ConfigSplitHelper.Split(legacyApplianceMetaData.Details);
                    foreach (var singleConfig in configList)
                    {
                        StorSimpleClient.ImportLegacyApplianceConfig(legacyApplianceMetaData.LegacyConfigId,
                                                                     singleConfig);
                    }

                    WriteObject(legacyApplianceMetaData);
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }