Ejemplo n.º 1
0
        private void UpdateUIwithUserAttributes()
        {
            //remove "sip:" prefix if the string isnt empty
            SipAddressTextBox.Text      = String.IsNullOrEmpty(SipAddress) ?  SipAddress : SipAddress.Remove(0, 4);
            RegistrarPoolTextBlock.Text = RegistrarPool;
            //remove "tel:" prefix if the string isnt empty
            LineURITextBox.Text = String.IsNullOrEmpty(LineURI) ? LineURI : LineURI.Remove(0, 4);
            EnterpriseVoiceEnabledCheckBox.IsChecked = EnterpriseVoiceEnabled;
            HostedVoicemailCheckBox.IsChecked        = HostedVoicemail;

            if (UserPolicies != null)
            {
                //select effective policies for current user in the comboboxes
                ConferencingPolicyComboBox.SelectedValue    = UserPolicies["ConferencingPolicy"];
                VoicePolicyComboBox.SelectedValue           = UserPolicies["VoicePolicy"];
                ExternalAccessPolicyComboBox.SelectedValue  = UserPolicies["ExternalAccessPolicy"];
                HostedVoicemailPolicyComboBox.SelectedValue = UserPolicies["HostedVoicemailPolicy"];
                MobilityPolicyComboBox.SelectedValue        = UserPolicies["MobilityPolicy"];
            }

            //select first value in comboboxes if the user policies are empty
            else
            {
                ConferencingPolicyComboBox.SelectedIndex    = 0;
                VoicePolicyComboBox.SelectedIndex           = 0;
                ExternalAccessPolicyComboBox.SelectedIndex  = 0;
                HostedVoicemailPolicyComboBox.SelectedIndex = 0;
                MobilityPolicyComboBox.SelectedIndex        = 0;
            }
        }
Ejemplo n.º 2
0
        private void UpdateUserButton_Click(object sender, RoutedEventArgs e)
        {
            bool IsSipAddressChanged = false,
            //   IsRegistrarPoolChanged = false,
                 IsLineURIChanged = false,
                 IsEnterpriseVoiceEnabledChanged = false,
                 IsHostedVoicemailChanged        = false,
                 IsConferencingPolicyChanged     = false,
                 IsVoicePolicyChanged            = false,
                 IsExternalAccessPolicyChanged   = false,
                 IsHostedVoicemailPolicyChanged  = false,
                 IsMobilityPolicyChanged         = false;
            string ChangedAttr = "";


            //check which attributes have been changed
            if (SipAddressTextBox.Text != (String.IsNullOrEmpty(SipAddress) ? SipAddress : SipAddress.Remove(0, 4)))
            {
                ChangedAttr        += "\nSip address from " + SipAddress + " to sip:" + SipAddressTextBox.Text + "\n";
                IsSipAddressChanged = true;
            }

            //if (RegistrarPoolTextBlock.Text == RegistrarPool);

            if (LineURITextBox.Text != (String.IsNullOrEmpty(LineURI) ? LineURI : LineURI.Remove(0, 4)))
            {
                ChangedAttr     += "\nLine URI from " + LineURI + " to tel:" + LineURITextBox.Text + "\n";
                IsLineURIChanged = true;
            }

            if (EnterpriseVoiceEnabledCheckBox.IsChecked != EnterpriseVoiceEnabled)
            {
                ChangedAttr += "\nEV Enabled from " + EnterpriseVoiceEnabled.ToString() +
                               " to " + EnterpriseVoiceEnabledCheckBox.IsChecked.ToString() + "\n";
                IsEnterpriseVoiceEnabledChanged = true;
            }

            if (HostedVoicemailCheckBox.IsChecked != HostedVoicemail)
            {
                ChangedAttr += "\nHosted VM enabled from " + HostedVoicemail.ToString() +
                               " to " + HostedVoicemailCheckBox.IsChecked.ToString() + "\n";
                IsHostedVoicemailChanged = true;
            }

            //check conf pol
            if (ConferencingPolicyComboBox.SelectedValue != UserPolicies["ConferencingPolicy"])
            {
                ChangedAttr += "\nConf policy from " + UserPolicies["ConferencingPolicy"] +
                               " to " + ConferencingPolicyComboBox.SelectedValue + "\n";
                IsConferencingPolicyChanged = true;
            }

            //voice pol
            if (VoicePolicyComboBox.SelectedValue != UserPolicies["VoicePolicy"])
            {
                ChangedAttr += "\nVoice policy from " + UserPolicies["VoicePolicy"] +
                               " to " + VoicePolicyComboBox.SelectedValue + "\n";
                IsVoicePolicyChanged = true;
            }

            //ExternalAccess
            if (ExternalAccessPolicyComboBox.SelectedValue != UserPolicies["ExternalAccessPolicy"])
            {
                ChangedAttr += "\nExternal Access policy from " + UserPolicies["ExternalAccessPolicy"] +
                               " to " + ExternalAccessPolicyComboBox.SelectedValue + "\n";
                IsExternalAccessPolicyChanged = true;
            }

            //HostedVM
            if (HostedVoicemailPolicyComboBox.SelectedValue != UserPolicies["HostedVoicemailPolicy"])
            {
                ChangedAttr += "\nHosted VM policy from " + UserPolicies["HostedVoicemailPolicy"] +
                               " to " + HostedVoicemailPolicyComboBox.SelectedValue + "\n";
                IsHostedVoicemailPolicyChanged = true;
            }

            //mobility pol
            if (MobilityPolicyComboBox.SelectedValue != UserPolicies["MobilityPolicy"])
            {
                ChangedAttr += "\nMobility policy from " + UserPolicies["MobilityPolicy"] +
                               " to " + MobilityPolicyComboBox.SelectedValue + "\n";
                IsMobilityPolicyChanged = true;
            }

            //start dialog if any of attributes were changed
            if (IsSipAddressChanged ||
                IsLineURIChanged ||
                IsEnterpriseVoiceEnabledChanged ||
                IsHostedVoicemailChanged ||
                IsConferencingPolicyChanged ||
                IsVoicePolicyChanged ||
                IsExternalAccessPolicyChanged ||
                IsHostedVoicemailPolicyChanged ||
                IsMobilityPolicyChanged)
            {
                //if confirmed, run set-csuser and\ or grant policies
                if (MessageBox.Show("Do you really want to change following attributes for the "
                                    + SipAddress + " user? (if Global or Site: policies are chosen, the user " +
                                    "will be granted with automatic policy)\n" + ChangedAttr,
                                    "Confirm",
                                    MessageBoxButton.YesNo,
                                    MessageBoxImage.Information, MessageBoxResult.No) == MessageBoxResult.Yes)
                {
                    if (IsSipAddressChanged)
                    {
                        Collection <PSObject> result = new Collection <PSObject>();
                        result = PSExecute("Set-CsUser -Identity '" + Identity +
                                           "'" + " -SipAddress 'sip:" + SipAddressTextBox.Text + "'");

                        if (result != null)
                        {
                            AppendMainText("\nsip address changed\n");
                        }

                        else
                        {
                            AppendMainText("\nThe error occured, please find the error details above, try again\n");
                        }
                    }

                    if (IsLineURIChanged)
                    {
                        string NewLineURI;
                        //if lineuri string is empty, set argument as $null
                        if (String.IsNullOrEmpty(LineURITextBox.Text))
                        {
                            NewLineURI = "$null";
                        }
                        else
                        {
                            NewLineURI = "'tel:" + LineURITextBox.Text + "'";
                        }
                        Collection <PSObject> result = new Collection <PSObject>();
                        result = PSExecute("Set-CsUser -Identity '" + Identity + "'" + "-LineURI " + NewLineURI);

                        if (result != null)
                        {
                            AppendMainText("\nLineURI changed\n");
                        }

                        else
                        {
                            AppendMainText("\nThe error occured, please find the error details above, try again\n");
                        }
                    }

                    if (IsEnterpriseVoiceEnabledChanged)
                    {
                        Collection <PSObject> result = new Collection <PSObject>();
                        result = PSExecute("Set-CsUser -Identity '" + Identity +
                                           "'" + " -EnterpriseVoiceEnabled $" + (!EnterpriseVoiceEnabled).ToString());

                        if (result != null)
                        {
                            AppendMainText("\nEV changed\n");
                        }

                        else
                        {
                            AppendMainText("\nThe error occured, please find the error details above, try again\n");
                        }
                    }

                    if (IsHostedVoicemailChanged)
                    {
                        Collection <PSObject> result = new Collection <PSObject>();
                        result = PSExecute("Set-CsUser -Identity '" + Identity +
                                           "'" + " -HostedVoicemail $" + (!HostedVoicemail).ToString());

                        if (result != null)
                        {
                            AppendMainText("\nHosted VM enabled changed\n");
                        }

                        else
                        {
                            AppendMainText("\nThe error occured, please find the error details above, try again\n");
                        }
                    }

                    if (IsConferencingPolicyChanged)
                    {
                        Collection <PSObject> result = new Collection <PSObject>();
                        //for Global and Site policies use $null for automatical assigment
                        if (ConferencingPolicyComboBox.SelectedValue.ToString() != "Global" && !(ConferencingPolicyComboBox.SelectedValue.ToString().StartsWith("Site:")))
                        {
                            result = PSExecute("Grant-CsConferencingPolicy -Identity '" + Identity + "'"
                                               + " -PolicyName '" + ConferencingPolicyComboBox.SelectedValue + "'");
                        }
                        else
                        {
                            result = PSExecute("Grant-CsConferencingPolicy -Identity '" + Identity + "'" + " -PolicyName $null");
                        }
                        if (result != null)
                        {
                            AppendMainText("\nNew Conferencing Policy granted\n");
                        }

                        else
                        {
                            AppendMainText("\nThe error occured, please find the error details above, try again\n");
                        }
                    }
                    if (IsVoicePolicyChanged)
                    {
                        Collection <PSObject> result = new Collection <PSObject>();
                        //for Global and Site policies use $null for automatical assigment
                        if (VoicePolicyComboBox.SelectedValue.ToString() != "Global" && !(VoicePolicyComboBox.SelectedValue.ToString().StartsWith("Site:")))
                        {
                            result = PSExecute("Grant-CsVoicePolicy -Identity '" + Identity + "'"
                                               + " -PolicyName '" + VoicePolicyComboBox.SelectedValue + "'");
                        }
                        else
                        {
                            result = PSExecute("Grant-CsVoicePolicy -Identity '" + Identity + "'" + " -PolicyName $null");
                        }
                        if (result != null)
                        {
                            AppendMainText("\nNew Voice Policy granted\n");
                        }

                        else
                        {
                            AppendMainText("\nThe error occured, please find the error details above, try again\n");
                        }
                    }
                    if (IsExternalAccessPolicyChanged)
                    {
                        Collection <PSObject> result = new Collection <PSObject>();
                        //for Global and Site policies use $null for automatical assigment
                        if (ExternalAccessPolicyComboBox.SelectedValue.ToString() != "Global" && !(ExternalAccessPolicyComboBox.SelectedValue.ToString().StartsWith("Site:")))
                        {
                            result = PSExecute("Grant-CsExternalAccessPolicy -Identity '" + Identity + "'"
                                               + " -PolicyName '" + ExternalAccessPolicyComboBox.SelectedValue + "'");
                        }
                        else
                        {
                            result = PSExecute("Grant-CsExternalAccessPolicy -Identity '" + Identity + "'" + " -PolicyName $null");
                        }
                        if (result != null)
                        {
                            AppendMainText("\nNew External Access Policy granted\n");
                        }

                        else
                        {
                            AppendMainText("\nThe error occured, please find the error details above, try again\n");
                        }
                    }
                    if (IsHostedVoicemailPolicyChanged)
                    {
                        Collection <PSObject> result = new Collection <PSObject>();
                        //for Global and Site policies use $null for automatical assigment
                        if (HostedVoicemailPolicyComboBox.SelectedValue.ToString() != "Global" && !(HostedVoicemailPolicyComboBox.SelectedValue.ToString().StartsWith("Site:")))
                        {
                            result = PSExecute("Grant-CsHostedVoicemailPolicy -Identity '" + Identity + "'"
                                               + " -PolicyName '" + HostedVoicemailPolicyComboBox.SelectedValue + "'");
                        }
                        else
                        {
                            result = PSExecute("Grant-CsHostedVoicemailPolicy -Identity '" + Identity + "'" + " -PolicyName $null");
                        }
                        if (result != null)
                        {
                            AppendMainText("\nNew Hosted Voicemail Policy granted\n");
                        }

                        else
                        {
                            AppendMainText("\nThe error occured, please find the error details above, try again\n");
                        }
                    }
                    if (IsMobilityPolicyChanged)
                    {
                        Collection <PSObject> result = new Collection <PSObject>();
                        //for Global and Site policies use $null for automatical assigment
                        if (MobilityPolicyComboBox.SelectedValue.ToString() != "Global" && !(MobilityPolicyComboBox.SelectedValue.ToString().StartsWith("Site:")))
                        {
                            result = PSExecute("Grant-CsMobilityPolicy -Identity '" + Identity + "'"
                                               + " -PolicyName '" + MobilityPolicyComboBox.SelectedValue + "'");
                        }
                        else
                        {
                            result = PSExecute("Grant-CsMobilityPolicy -Identity '" + Identity + "'" + " -PolicyName $null");
                        }
                        if (result != null)
                        {
                            AppendMainText("\nNew Mobility Policy granted\n");
                        }

                        else
                        {
                            AppendMainText("\nThe error occured, please find the error details above, try again\n");
                        }
                    }
                }

                //disable Update Button until next user will be found
                UpdateButton("UpdateUserButton", false, "Search again");
            }

            else
            {
                MessageBox.Show("None of attributes were changed", "Nothing to change", MessageBoxButton.OK,
                                MessageBoxImage.Information, MessageBoxResult.OK);
            }
        }