/// <summary>
 /// Create default backup policy object
 /// </summary>
 /// <param name="virtualDiskGroupId">virtual disk group id associated with policy</param>
 /// <param name="policyName">Name of the policy to be created</param>
 /// <returns>Migration backup policy object</returns>
 private MigrationBackupPolicy CreateDefaultBackupPolicy(string virtualDiskGroupId, string policyName)
 {
     MigrationBackupPolicy backupPolicy = new MigrationBackupPolicy();
     backupPolicy.InstanceId = Guid.NewGuid().ToString();
     backupPolicy.LastRunTime = null;
     backupPolicy.MaxRetentionCount = MaxRetentionCount;
     backupPolicy.Name = policyName;
     backupPolicy.Type = BackupType.CloudSnapshot;
     backupPolicy.VirtualDiskGroupId = virtualDiskGroupId;
     backupPolicy.OperationInProgress = OperationInProgress.None;
     backupPolicy.Disabled = true;
     backupPolicy.CreatedOn = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");
     backupPolicy.BackupSchedules = new List<BackupScheduleBase>();
     backupPolicy.BackupSchedules.Add(this.CreateDefaultBackupPolicySchedule());
     return backupPolicy;
 }
        private List<MigrationBackupPolicy> ParseBackupPolicy(XmlDocument document)
        {
            List<MigrationBackupPolicy> backupPolicyList = new List<MigrationBackupPolicy>();
            XmlNodeList nodeList = document.SelectNodes(@"//BackupPolicy");
            backupPolicyList = new List<MigrationBackupPolicy>();
            foreach (XmlNode node in nodeList)
            {
                MigrationBackupPolicy backupPolicy = new MigrationBackupPolicy();
                backupPolicy.Name = node.Attributes["Name"].Value;
                backupPolicy.InstanceId = node.Attributes["Id"].Value;
                backupPolicy.MaxRetentionCount = long.Parse(node.Attributes["RetentionCount"].Value);
                backupPolicy.CreatedOn = node.Attributes["CreatedOn"].Value;
                backupPolicy.Type = (BackupType)Enum.Parse(typeof(BackupType), node.Attributes["Type"].Value, true);
                backupPolicy.LastRunTime = null;
                if (null != node.Attributes["LastRunTime"])
                {
                    backupPolicy.LastRunTime = node.Attributes["LastRunTime"].Value;
                }

                backupPolicy.VirtualDiskGroupId = node.Attributes["VirtualDiskGroupId"].Value;
                backupPolicyList.Add(backupPolicy);
            }

            return backupPolicyList;
        }
        /// <summary>
        /// Parse the backup policy
        /// </summary>
        private void ParseBackupPolicy()
        {
            this.policyList = new List<MigrationBackupPolicy>();
            var backupDataInfoList = this.GetSubElements(doc.Root, "BackupData");
            foreach (var backupDataInfo in backupDataInfoList)
            {
                var backupPolicyInfoList = this.GetSubElements(backupDataInfo, "BackupPolicies");
                foreach (var backupPolicyInfo in backupPolicyInfoList)
                {
                    var policyInfo = this.GetSubElements(backupPolicyInfo, "BackupPolicyInfo");
                    foreach (var policyItem in policyInfo)
                    {
                        MigrationBackupPolicy backupPolicy = new MigrationBackupPolicy();
                        backupPolicy.BackupSchedules = new List<BackupScheduleBase>();
                        foreach (var policyProperty in policyItem.Elements())
                        {
                            switch (policyProperty.Name.LocalName)
                            {
                                case "Alias":
                                {
                                    backupPolicy.Name = policyProperty.Value;
                                    break;
                                }
                                case "Id":
                                {
                                    backupPolicy.InstanceId = policyProperty.Value;
                                    break;
                                }
                                case "BackupType":
                                {
                                    backupPolicy.Type = BackupTypeMap[policyProperty.Value];
                                    break;
                                }
                                case "CollectionId":
                                {
                                    backupPolicy.VirtualDiskGroupId = policyProperty.Value;
                                    break;
                                }
                                case "Disabled":
                                {
                                    backupPolicy.Disabled = bool.Parse(policyProperty.Value);
                                    break;
                                }
                                case "CreatedOn":
                                {
                                    backupPolicy.CreatedOn =
                                        policyProperty.Elements()
                                            .ToList()
                                            .Find(property => "_d" == property.Name.LocalName)
                                            .Value;
                                    break;
                                }
                                case "LastRun":
                                {
                                    if (null != policyProperty.Elements())
                                    {
                                        var lastRunProperty =
                                            policyProperty.Elements()
                                                .ToList()
                                                .Find(property => "_d" == property.Name.LocalName);
                                        if (null != lastRunProperty)
                                        {
                                            backupPolicy.LastRunTime = lastRunProperty.Value;
                                        }
                                    }

                                    break;
                                }
                                case "MaxRetentionCount":
                                {
                                    backupPolicy.MaxRetentionCount = long.Parse(policyProperty.Value);
                                    break;
                                }
                                case "Schedule":
                                {
                                    backupPolicy.BackupSchedules.Add(this.ParseBackupScheduleImpl(policyProperty));
                                    break;
                                }
                                default:
                                {
                                    break;
                                }
                            }
                        }

                        this.policyList.Add(backupPolicy);
                    }

                }
            }
        }