private void SaveZone() { string CurrentZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.ZoneName, true); string NewZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.NewZoneName); Property DescriptionProperty = ServiceBroker.Service.ServiceObjects[0].Properties[Constants.SOProperties.WorkingHoursConfiguration.Description]; Property GMTOffsetProperty = ServiceBroker.Service.ServiceObjects[0].Properties[Constants.SOProperties.WorkingHoursConfiguration.GMTOffset]; int GmtOffSet = base.GetIntProperty(Constants.SOProperties.WorkingHoursConfiguration.GMTOffset); bool DefaultZone = base.GetBoolProperty(Constants.SOProperties.WorkingHoursConfiguration.DefaultZone); WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); if (!String.IsNullOrEmpty(NewZoneName) && !Helper.SpecialCharactersExist(NewZoneName)) { throw new ApplicationException(Constants.ErrorMessages.SpecialCharactersAreNotAllowed); } else if (!String.IsNullOrEmpty(NewZoneName) && mngServer.ZoneExists(NewZoneName)) { throw new ApplicationException(Constants.ErrorMessages.ZoneExists + NewZoneName + "."); } else if (!mngServer.ZoneExists(CurrentZoneName)) { throw new ApplicationException(Constants.ErrorMessages.ZoneDoesNotExist + CurrentZoneName + "."); } else if (GmtOffSet > 13 || GmtOffSet < -13) { throw new ApplicationException(Constants.ErrorMessages.GMTOffSetValidationFailed); } else { AvailabilityZone aZone = mngServer.ZoneLoad(CurrentZoneName); aZone.ZoneName = String.IsNullOrEmpty(NewZoneName) ? CurrentZoneName : NewZoneName; if ((DescriptionProperty.Value != null) || (DescriptionProperty.IsClear)) { aZone.ZoneDescription = DescriptionProperty.Value == null ? String.Empty : DescriptionProperty.Value as string; } if ((GmtOffSet != 0) || (GMTOffsetProperty.IsClear)) { aZone.ZoneGMTOffset = GmtOffSet; } aZone.DefaultZone = DefaultZone; //even if the value is false, you cannot make a zone nonDefault without setting other zone to default mngServer.ZoneSave(CurrentZoneName, aZone); } } }
private void SaveZone() { string CurrentZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.ZoneName, true); string NewZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.NewZoneName); Property DescriptionProperty = ServiceBroker.Service.ServiceObjects[0].Properties[Constants.SOProperties.WorkingHoursConfiguration.Description]; Property GMTOffsetProperty = ServiceBroker.Service.ServiceObjects[0].Properties[Constants.SOProperties.WorkingHoursConfiguration.GMTOffset]; int GmtOffSet = base.GetIntProperty(Constants.SOProperties.WorkingHoursConfiguration.GMTOffset); bool DefaultZone = base.GetBoolProperty(Constants.SOProperties.WorkingHoursConfiguration.DefaultZone); WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); if (!String.IsNullOrEmpty(NewZoneName) && !Helper.SpecialCharactersExist(NewZoneName)) { throw new ApplicationException(Constants.ErrorMessages.SpecialCharactersAreNotAllowed); } else if (!String.IsNullOrEmpty(NewZoneName) && mngServer.ZoneExists(NewZoneName)) { throw new ApplicationException(Constants.ErrorMessages.ZoneExists + NewZoneName + "."); } else if (!mngServer.ZoneExists(CurrentZoneName)) { throw new ApplicationException(Constants.ErrorMessages.ZoneDoesNotExist + CurrentZoneName + "."); } else if (GmtOffSet > 13 || GmtOffSet < -13) { throw new ApplicationException(Constants.ErrorMessages.GMTOffSetValidationFailed); } else { AvailabilityZone aZone = mngServer.ZoneLoad(CurrentZoneName); aZone.ZoneName = String.IsNullOrEmpty(NewZoneName) ? CurrentZoneName : NewZoneName; if ((DescriptionProperty.Value != null) || (DescriptionProperty.IsClear)) { aZone.ZoneDescription = DescriptionProperty.Value == null ? String.Empty : DescriptionProperty.Value as string; } if ((GmtOffSet != 0) || (GMTOffsetProperty.IsClear)) { aZone.ZoneGMTOffset = GmtOffSet; } aZone.DefaultZone = DefaultZone; //even if the value is false, you cannot make a zone nonDefault without setting other zone to default mngServer.ZoneSave(CurrentZoneName, aZone); } } }