/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpdatePlan_Click(object sender, EventArgs e) { BaseActivesyncPolicy policy = new BaseActivesyncPolicy(); ExchCmds powershell = null; try { // Fill in custom object policy.CompanyCode = ""; policy.DisplayName = txtDisplayName.Text; policy.Description = txtDescription.Text; policy.AllowNonProvisionableDevice = cbAllowNonProvisionableDevices.Checked; if (!string.IsNullOrEmpty(txtRefreshInterval.Text)) policy.DevicePolicyRefreshInterval = int.Parse(txtRefreshInterval.Text); else policy.DevicePolicyRefreshInterval = 0; // // PASSWORD TAB // policy.DevicePasswordEnabled = cbRequirePassword.Checked; if (policy.DevicePasswordEnabled) { policy.AlphanumericDevicePasswordRequired = cbRequireAlphaNumericPassword.Checked; if (!string.IsNullOrEmpty(txtMinimumNumberOfCharacterSets.Text)) policy.MinDevicePasswordComplexCharacters = int.Parse(txtMinimumNumberOfCharacterSets.Text); else policy.MinDevicePasswordComplexCharacters = 0; policy.PasswordRecoveryEnabled = cbEnablePasswordRecovery.Checked; policy.RequireDeviceEncryption = cbRequireEncryption.Checked; policy.RequireStorageCardEncryption = cbRequireEncryptionOnStorageCard.Checked; policy.AllowSimpleDevicePassword = cbAllowSimplePassword.Checked; if (!string.IsNullOrEmpty(txtNumberOfFailedAttemptsAllowed.Text)) policy.MaxDevicePasswordFailedAttempts = int.Parse(txtNumberOfFailedAttemptsAllowed.Text); else policy.MaxDevicePasswordFailedAttempts = 0; if (!string.IsNullOrEmpty(txtMinimumPasswordLength.Text)) policy.MinDevicePasswordLength = int.Parse(txtMinimumPasswordLength.Text); else policy.MinDevicePasswordLength = 0; if (!string.IsNullOrEmpty(txtInactivityTimeout.Text)) policy.MaxInactivityTimeDeviceLock = int.Parse(txtInactivityTimeout.Text); else policy.MaxInactivityTimeDeviceLock = 0; if (!string.IsNullOrEmpty(txtPasswordExpiration.Text)) policy.DevicePasswordExpiration = int.Parse(txtPasswordExpiration.Text); else policy.DevicePasswordExpiration = 0; if (!string.IsNullOrEmpty(txtEnforcePasswordHistory.Text)) policy.DevicePasswordHistory = int.Parse(txtEnforcePasswordHistory.Text); else policy.DevicePasswordHistory = 0; } // // SYNC SETTINGS // policy.MaxCalendarAgeFilter = ddlPastCalendarItems.SelectedValue; policy.MaxEmailAgeFilter = ddlPastEmailItems.SelectedValue; if (!string.IsNullOrEmpty(txtLimitEmailSize.Text)) policy.MaxEmailBodyTruncationSize = int.Parse(txtLimitEmailSize.Text); else policy.MaxEmailBodyTruncationSize = 0; policy.RequireManualSyncWhenRoaming = cbAllowDirectPushWhenRoaming.Checked; policy.AllowHTMLEmail = cbAllowHTMLEmail.Checked; policy.AttachmentsEnabled = cbAllowAttachmentDownload.Checked; if (policy.AttachmentsEnabled) { if (!string.IsNullOrEmpty(txtMaximumAttachmentSize.Text)) policy.MaxAttachmentSize = int.Parse(txtMaximumAttachmentSize.Text); else policy.MaxAttachmentSize = 0; } // // DEVICE // policy.AllowStorageCard = cbAllowRemovableStorage.Checked; policy.AllowCamera = cbAllowCamera.Checked; policy.AllowWiFi = cbAllowWiFi.Checked; policy.AllowIrDA = cbAllowInfrared.Checked; policy.AllowInternetSharing = cbAllowInternetSharing.Checked; policy.AllowRemoteDesktop = cbAllowRemoteDesktop.Checked; policy.AllowDesktopSync = cbAllowDesktopSync.Checked; policy.AllowBluetooth = ddlAllowBluetooth.SelectedValue; policy.AllowTextMessaging = cbAllowTextMessaging.Checked; // // DEVICE APPLICATIONS // policy.AllowBrowser = cbAllowBrowser.Checked; policy.AllowConsumerEmail = cbAllowConsumerMail.Checked; policy.AllowUnsignedApplications = cbAllowUnsignedApplications.Checked; policy.AllowUnsignedInstallationPackages = cbAllowUnsignedInstallPackages.Checked; // Initialize powershell powershell = new ExchCmds(Config.ExchangeURI, Config.Username, Config.Password, Config.ExchangeConnectionType, Config.PrimaryDC); // Check if we are creating a new policy or updating existing if (ddlActiveSyncPlan.SelectedIndex > 0) { policy.ASID = int.Parse(ddlActiveSyncPlan.SelectedValue); // Update Exchange powershell.Update_ActiveSyncPolicy(policy, Config.ExchangeVersion); // Update SQL database SQLExchange.UpdateExchangeActiveSyncPolicy(policy); // Update notification notification1.SetMessage(controls.notification.MessageType.Success, Resources.LocalizedText.NotificationSuccessUpdateAS + policy.DisplayName); } else { // Create new policy powershell.New_ActiveSyncPolicy(policy, Config.ExchangeVersion); // Add to SQL database SQLExchange.AddExchangeActiveSyncPolicy(policy); // Update notification notification1.SetMessage(controls.notification.MessageType.Success, Resources.LocalizedText.NotificationSuccessCreatedAS + policy.DisplayName); } } catch (Exception ex) { notification1.SetMessage(controls.notification.MessageType.Error, ex.Message); } finally { if (powershell != null) powershell.Dispose(); // Refresh view GetPolicies(); } }