internal override ResultObject DeleteBlackBerryUserInternal(string primaryEmailAddress)
        {
            ResultObject res = HostedSolutionLog.StartLog <ResultObject>("DeleteBlackBerry5UserInternal");

            string file = Path.Combine(UtilityPath, "besuseradminclient.exe");

            if (!File.Exists(file))
            {
                HostedSolutionLog.EndLog("DeleteBlackBerry5User", res, BlackBerryErrorsCodes.FILE_PATH_IS_INVALID);
                return(res);
            }

            string arguments = string.Format("-username {0} -password {1} -delete -u {2} -b {3} -n {4}",
                                             User,
                                             Password,
                                             primaryEmailAddress,
                                             EnterpriseServer,
                                             EnterpriseServerFQDN);

            try
            {
                string output;
                int    exitCode = Execute(file, arguments, out output);
                if (exitCode == 0)
                {
                    Log.WriteInfo(output);
                }
                else
                {
                    throw new ApplicationException(
                              string.Format("Exit code is not 0. {0}, ExitCode = {1}", output, exitCode));
                }

                for (int i = 0; i < 10; i++)
                {
                    BlackBerryUserDeleteState states = GetBlackBerryUserState(primaryEmailAddress);
                    if (states != BlackBerryUserDeleteState.Pending)
                    {
                        break;
                    }
                    Thread.Sleep(10000);
                }
            }
            catch (Exception ex)
            {
                HostedSolutionLog.EndLog("DeleteBlackBerry5UserInternal", res, BlackBerryErrorsCodes.CANNOT_EXECUTE_COMMAND, ex);
                return(res);
            }

            HostedSolutionLog.EndLog("DeleteBlackBerry5UserInternal");
            return(res);
        }
        internal override ResultObject SetEmailActivationPasswordInternal(string primaryEmailAddress)
        {
            ResultObject res = HostedSolutionLog.StartLog <ResultObject>("SetEmailActivationPassword");

            ResultObject removeRes = RemoveEmailActivationPassword(primaryEmailAddress);

            res.ErrorCodes.AddRange(removeRes.ErrorCodes);

            if (!removeRes.IsSuccess)
            {
                HostedSolutionLog.EndLog("SetEmailActivationPassword", res);
                return(res);
            }

            string file = Path.Combine(UtilityPath, "besuseradminclient.exe");

            if (!File.Exists(file))
            {
                HostedSolutionLog.EndLog("SetEmailActivationPassword", res, BlackBerryErrorsCodes.FILE_PATH_IS_INVALID);
                return(res);
            }

            string arguments = string.Format("-username {0} -password {1}  -change -u {2}  -b {3} -wrandom -n {4}",
                                             User,
                                             Password,
                                             primaryEmailAddress,
                                             EnterpriseServer,
                                             EnterpriseServerFQDN);

            try
            {
                string output;
                int    exitCode = Execute(file, arguments, out output);
                if (exitCode == 0)
                {
                    Log.WriteInfo(output);
                }
                else
                {
                    throw new ApplicationException(
                              string.Format("Exit code is not 0. {0}, ExitCode = {1}", output, exitCode));
                }
            }
            catch (Exception ex)
            {
                HostedSolutionLog.EndLog("SetEmailActivationPassword", res, BlackBerryErrorsCodes.CANNOT_EXECUTE_COMMAND, ex);
                return(res);
            }

            HostedSolutionLog.EndLog("SetEmailActivationPassword");
            return(res);
        }
Example #3
0
        /// <summary> Deletes user.</summary>
        /// <param name="runspace"> The runspace.</param>
        /// <param name="userUpn"> The user UPN.</param>
        internal void DeleteUser(Runspace runspace, string userUpn)
        {
            HostedSolutionLog.LogStart("DeleteUser");
            HostedSolutionLog.DebugInfo("userUpn : {0}", userUpn);

            var command = new Command("Disable-CsUser");

            command.Parameters.Add("Identity", userUpn);
            command.Parameters.Add("Confirm", false);

            ExecuteShellCommand(runspace, command, false);
            HostedSolutionLog.LogEnd("DeleteUser");
        }
Example #4
0
        /// <summary> Deletes mobility policy.</summary>
        /// <param name="runspace"> The runspace.</param>
        /// <param name="policyName"> The policy name.</param>
        internal void DeleteMobilityPolicy(Runspace runspace, string policyName)
        {
            HostedSolutionLog.LogStart("DeleteMobilityPolicy");
            HostedSolutionLog.DebugInfo("policyName : {0}", policyName);

            var command = new Command("Remove-CsMobilityPolicy");

            command.Parameters.Add("Identity", policyName);
            command.Parameters.Add("Confirm", false);
            command.Parameters.Add("Force", true);

            ExecuteShellCommand(runspace, command, false);
            HostedSolutionLog.LogEnd("DeleteMobilityPolicy");
        }
 /// <summary>Closes runspace.</summary>
 /// <param name="runspace">The runspace.</param>
 private void CloseRunspace(Runspace runspace)
 {
     try
     {
         if (runspace != null && runspace.RunspaceStateInfo.State == RunspaceState.Opened)
         {
             runspace.Close();
         }
     }
     catch (Exception ex)
     {
         HostedSolutionLog.LogError("Runspace error", ex);
     }
 }
        /// <summary> Backups site collection under give url.</summary>
        /// <param name="rootWebApplicationUri">Root web application uri.</param>
        /// <param name="url">Url that uniquely identifies site collection to be deleted.</param>
        /// <param name="filename">Resulting backup file name.</param>
        /// <param name="zip">A value which shows whether created backup must be archived.</param>
        /// <param name="tempPath">Custom temp path for backup</param>
        /// <returns>Full path to created backup.</returns>
        /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception>
        public string BackupSiteCollection(Uri rootWebApplicationUri, string url, string filename, bool zip, string tempPath)
        {
            try
            {
                string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port);
                HostedSolutionLog.LogStart("BackupSiteCollection");
                HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl);

                if (String.IsNullOrEmpty(tempPath))
                {
                    tempPath = Path.GetTempPath();
                }

                string backupFileName = Path.Combine(tempPath, (zip ? StringUtils.CleanIdentifier(siteCollectionUrl) + ".bsh" : StringUtils.CleanIdentifier(filename)));
                HostedSolutionLog.DebugInfo("backupFilePath: {0}", backupFileName);
                Runspace runspace = null;

                try
                {
                    runspace = OpenRunspace();
                    var command = new Command("Backup-SPSite");
                    command.Parameters.Add("Identity", siteCollectionUrl);
                    command.Parameters.Add("Path", backupFileName);
                    ExecuteShellCommand(runspace, command);

                    if (zip)
                    {
                        string zipFile = Path.Combine(tempPath, filename);
                        string zipRoot = Path.GetDirectoryName(backupFileName);

                        FileUtils.ZipFiles(zipFile, zipRoot, new[] { Path.GetFileName(backupFileName) });
                        FileUtils.DeleteFile(backupFileName);

                        backupFileName = zipFile;
                    }

                    return(backupFileName);
                }
                finally
                {
                    CloseRunspace(runspace);
                    HostedSolutionLog.LogEnd("BackupSiteCollection");
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Failed to backup site collection.", ex);
            }
        }
Example #7
0
        private string FindUserByPrimaryUri(string uri)
        {
            string ret = null;

            HostedSolutionLog.LogStart("FindUserByPrimaryUri");
            using (ManagementObject objUser = Wmi.GetWmiObject("MSFT_SIPESUserSetting", "PrimaryURI = '{0}'", uri))
            {
                if (objUser != null)
                {
                    ret = (string)objUser["InstanceID"];
                }
            }
            HostedSolutionLog.LogEnd("FindUserByPrimaryUri");
            return(ret);
        }
Example #8
0
        private string FindUserByDistinguishedName(string userDistinguishedName)
        {
            string ret = null;

            HostedSolutionLog.LogStart("FindUserByDistinguishedName");
            using (ManagementObject objUser = Wmi.GetWmiObject("MSFT_SIPESUserSetting", "UserDN = '{0}'", userDistinguishedName))
            {
                if (objUser != null)
                {
                    ret = (string)objUser["InstanceID"];
                }
            }
            HostedSolutionLog.LogEnd("FindUserByDistinguishedName");
            return(ret);
        }
Example #9
0
        private string GetPoolDistinguishedName(string poolFQDN)
        {
            HostedSolutionLog.LogStart("GetPoolDistinguishedName");
            string ret = null;

            using (ManagementObject objPool = Wmi.GetWmiObject("MSFT_SIPPoolSetting", "PoolFQDN = '{0}'", poolFQDN))
            {
                if (objPool != null)
                {
                    ret = (string)objPool["PoolDN"];
                }
            }
            HostedSolutionLog.LogEnd("GetPoolDistinguishedName");
            return(ret);
        }
Example #10
0
        internal OrganizationUser GetUserGeneralSettingsInternal(string loginName, string organizationId)
        {
            HostedSolutionLog.LogStart("GetUserGeneralSettingsInternal");
            HostedSolutionLog.DebugInfo("loginName : {0}", loginName);
            HostedSolutionLog.DebugInfo("organizationId : {0}", organizationId);

            if (string.IsNullOrEmpty(loginName))
            {
                throw new ArgumentNullException("loginName");
            }

            string         path  = GetUserPath(organizationId, loginName);
            DirectoryEntry entry = ActiveDirectoryUtils.GetADObject(path);

            OrganizationUser retUser = new OrganizationUser();

            retUser.FirstName         = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.FirstName);
            retUser.LastName          = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.LastName);
            retUser.DisplayName       = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.DisplayName);
            retUser.Initials          = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Initials);
            retUser.JobTitle          = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.JobTitle);
            retUser.Company           = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Company);
            retUser.Department        = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Department);
            retUser.Office            = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Office);
            retUser.BusinessPhone     = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.BusinessPhone);
            retUser.Fax               = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Fax);
            retUser.HomePhone         = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.HomePhone);
            retUser.MobilePhone       = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.MobilePhone);
            retUser.Pager             = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Pager);
            retUser.WebPage           = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.WebPage);
            retUser.Address           = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Address);
            retUser.City              = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.City);
            retUser.State             = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.State);
            retUser.Zip               = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Zip);
            retUser.Country           = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Country);
            retUser.Notes             = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Notes);
            retUser.ExternalEmail     = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.ExternalEmail);
            retUser.Disabled          = (bool)entry.InvokeGet(ADAttributes.AccountDisabled);
            retUser.Manager           = GetManager(entry);
            retUser.DomainUserName    = GetDomainName(loginName);
            retUser.DistinguishedName = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.DistinguishedName);
            retUser.Locked            = (bool)entry.InvokeGet(ADAttributes.AccountLocked);

            HostedSolutionLog.LogEnd("GetUserGeneralSettingsInternal");
            return(retUser);
        }
Example #11
0
        /// <summary> Gets organization distinguished name.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="runspace"> The runspace.</param>
        /// <returns> The distinguished name.</returns>
        private string GetResultObjectDN(string organizationId, Runspace runspace)
        {
            HostedSolutionLog.LogStart("GetResultObjectDN");

            string path    = GetOrganizationPath(organizationId);
            var    scripts = new List <string> {
                string.Format("Get-ADOrganizationalUnit -Identity \"{0}\"", path)
            };
            Collection <PSObject> result = ExecuteShellCommand(runspace, scripts);

            if (result != null && result.Any())
            {
                return(result.First().Properties["DistinguishedName"].Value.ToString());
            }

            throw new ArgumentException("Execution result does not contain DistinguishedName property");
        }
        internal override BlackBerryUserStatsResult GetBlackBerryUserStatsInternal(string primaryEmailAddress)
        {
            BlackBerryUserStatsResult res =
                HostedSolutionLog.StartLog <BlackBerryUserStatsResult>("GetBlackBerry5UserStatsInternal");

            string[] keys;
            string[] values;

            ResultObject tempRes = GetBlackBerryUserData(primaryEmailAddress, out keys, out values);

            res.ErrorCodes.AddRange(tempRes.ErrorCodes);
            if (!res.IsSuccess)
            {
                HostedSolutionLog.EndLog("GetBlackBerry5UserStatsInternal", res);
                return(res);
            }

            try
            {
                List <BlackBerryStatsItem> items = new List <BlackBerryStatsItem>();

                int[] inds = new int[] { 3, 4, 5, 7, 8, 10, 11, 12, 13, 14, 15, 25 };

                foreach (int i in inds)
                {
                    if (keys.Length > i && values.Length > i)
                    {
                        items.Add(new BlackBerryStatsItem()
                        {
                            Name = keys[i], Value = values[i]
                        });
                    }
                }


                res.Value = items;
            }
            catch (Exception ex)
            {
                HostedSolutionLog.EndLog("GetBlackBerry5UserStatsInternal", res, BlackBerryErrorsCodes.CANNOT_POPULATE_STATS, ex);
                return(res);
            }

            HostedSolutionLog.EndLog("GetBlackBerry5UserStatsInternal");
            return(res);
        }
Example #13
0
        public void UpdateQuotas(Uri root, string url, long maxStorage, long warningStorage)
        {
            WindowsImpersonationContext wic = null;

            try
            {
                wic = WindowsIdentity.GetCurrent().Impersonate();

                SPWebApplication rootWebApplication = SPWebApplication.Lookup(root);

                SPQuota quota = new SPQuota();
                if (maxStorage != -1)
                {
                    quota.StorageMaximumLevel = maxStorage * 1024 * 1024;
                }
                else
                {
                    quota.StorageMaximumLevel = 0;
                }


                if (warningStorage != -1 && maxStorage != -1)
                {
                    quota.StorageWarningLevel = Math.Min(warningStorage, maxStorage) * 1024 * 1024;
                }
                else
                {
                    quota.StorageWarningLevel = 0;
                }

                rootWebApplication.GrantAccessToProcessIdentity(WindowsIdentity.GetCurrent().Name);
                rootWebApplication.Sites[url].Quota = quota;
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError(ex);
                throw;
            }
            finally
            {
                if (wic != null)
                {
                    wic.Undo();
                }
            }
        }
        /// <summary> Creates site collection within predefined root web application.</summary>
        /// <param name="runspace"> The runspace.</param>
        /// <param name="rootWebApplicationUri">Root web application uri.</param>
        /// <param name="siteCollection">Information about site coolection to be created.</param>
        /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception>
        private void CreateCollection(Runspace runspace, Uri rootWebApplicationUri, SharePointEnterpriseSiteCollection siteCollection)
        {
            string siteCollectionUrl = String.Format("{0}:{1}", siteCollection.Url, rootWebApplicationUri.Port);

            HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl);

            try
            {
                SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
                rootWebApplication.Sites.Add(siteCollectionUrl, siteCollection.Title, siteCollection.Description, (uint)siteCollection.LocaleId, String.Empty, siteCollection.OwnerLogin, siteCollection.OwnerName, siteCollection.OwnerEmail, null, null, null, true);
                rootWebApplication.Update();
            }
            catch (Exception)
            {
                DeleteSiteCollection(runspace, siteCollectionUrl, true);
                throw;
            }

            try
            {
                GrantAccess(runspace, rootWebApplicationUri);
                var command = new Command("Set-SPSite");
                command.Parameters.Add("Identity", siteCollectionUrl);

                if (siteCollection.MaxSiteStorage != -1)
                {
                    command.Parameters.Add("MaxSize", siteCollection.MaxSiteStorage * 1024 * 1024);
                }

                if (siteCollection.WarningStorage != -1 && siteCollection.MaxSiteStorage != -1)
                {
                    command.Parameters.Add("WarningSize", Math.Min(siteCollection.WarningStorage, siteCollection.MaxSiteStorage) * 1024 * 1024);
                }

                ExecuteShellCommand(runspace, command);
            }
            catch (Exception)
            {
                DeleteQuotaTemplate(siteCollection.Title);
                DeleteSiteCollection(runspace, siteCollectionUrl, true);
                throw;
            }

            AddHostsRecord(siteCollection);
        }
Example #15
0
        /// <summary> Opens runspace.</summary>
        /// <returns> The runspace.</returns>
        internal Runspace OpenRunspace()
        {
            HostedSolutionLog.LogStart("OpenRunspace");

            if (session == null)
            {
                session = InitialSessionState.CreateDefault();
                session.ImportPSModule(new[] { "ActiveDirectory", "Lync" });
            }

            Runspace runspace = RunspaceFactory.CreateRunspace(session);

            runspace.Open();
            runspace.SessionStateProxy.SetVariable("ConfirmPreference", "none");
            HostedSolutionLog.LogEnd("OpenRunspace");

            return(runspace);
        }
Example #16
0
 public override void DeleteServiceItems(ServiceProviderItem[] items)
 {
     foreach (ServiceProviderItem item in items)
     {
         try
         {
             if (item is Organization)
             {
                 Organization org = item as Organization;
                 DeleteOrganizationInternal(org.OrganizationId);
             }
         }
         catch (Exception ex)
         {
             HostedSolutionLog.LogError(String.Format("Error deleting '{0}' {1}", item.Name, item.GetType().Name), ex);
         }
     }
 }
Example #17
0
 public override void ChangeServiceItemsState(ServiceProviderItem[] items, bool enabled)
 {
     foreach (ServiceProviderItem item in items)
     {
         try
         {
             if (item is Organization)
             {
                 Organization org = item as Organization;
                 ChangeOrganizationState(org, enabled);
             }
         }
         catch (Exception ex)
         {
             HostedSolutionLog.LogError(
                 String.Format("Error deleting '{0}' {1}", item.Name, item.GetType().Name), ex);
         }
     }
 }
        internal virtual ResultObject SetActivationPasswordWithExpirationTimeInternal(string primaryEmailAddress, string password, int time)
        {
            ResultObject res = HostedSolutionLog.StartLog <ResultObject>("SetActivationPasswordWithExpirationTimeInternal");

            string file = Path.Combine(UtilityPath, "besuseradminclient.exe");

            if (!File.Exists(file))
            {
                HostedSolutionLog.EndLog("SetActivationPasswordWithExpirationTimeInternal", res, BlackBerryErrorsCodes.FILE_PATH_IS_INVALID);
                return(res);
            }

            string arguments = string.Format("-change  -u {0} -p {1} -b {2} -n {3} -w {4} -wt {5}",
                                             primaryEmailAddress,
                                             Password,
                                             EnterpriseServer,
                                             AdministrationToolService,
                                             password,
                                             time);

            try
            {
                string output;
                int    exitCode = Execute(file, arguments, out output);
                if (exitCode == 0)
                {
                    Log.WriteInfo(output);
                }
                else
                {
                    throw new ApplicationException(
                              string.Format("Exit code is not 0. {0}, ExitCode = {1}", output, exitCode));
                }
            }
            catch (Exception ex)
            {
                HostedSolutionLog.EndLog("SetActivationPasswordWithExpirationTimeInternal", res, BlackBerryErrorsCodes.CANNOT_EXECUTE_COMMAND, ex);
                return(res);
            }

            HostedSolutionLog.EndLog("SetActivationPasswordWithExpirationTimeInternal");
            return(res);
        }
        internal override ResultObject CreateBlackBerryUserInternal(string primaryEmailAddress)
        {
            ResultObject res = HostedSolutionLog.StartLog <ResultObject>("CreateBlackBerryUser5Internal");

            string file = Path.Combine(UtilityPath, "besuseradminclient.exe");

            if (!File.Exists(file))
            {
                HostedSolutionLog.EndLog("CreateBlackBerry5UserInternal", res, BlackBerryErrorsCodes.FILE_PATH_IS_INVALID);
                return(res);
            }

            string arguments = string.Format("-username {0} -password {1} -add -u {2} -b {3}",
                                             User,
                                             Password,
                                             primaryEmailAddress,
                                             EnterpriseServer);

            try
            {
                string output;

                int exitCode = Execute(file, arguments, out output);
                if (exitCode == 0)
                {
                    Log.WriteInfo(output);
                }
                else
                {
                    throw new ApplicationException(
                              string.Format("Excit code is not 0. {0}, ExitCode = {1}", output, exitCode));
                }
            }
            catch (Exception ex)
            {
                HostedSolutionLog.EndLog("CreateBlackBerry5UserInternal", res, BlackBerryErrorsCodes.CANNOT_EXECUTE_COMMAND, ex);
                return(res);
            }

            HostedSolutionLog.EndLog("CreateBlackBerry5UserInternal");
            return(res);
        }
Example #20
0
        internal PasswordPolicyResult GetPasswordPolicyInternal()
        {
            HostedSolutionLog.LogStart("GetPasswordPolicyInternal");

            PasswordPolicyResult res = new PasswordPolicyResult {
                IsSuccess = true
            };

            string[] policyAttributes = new[] { "minPwdLength",
                                                "pwdProperties",
                                                "objectClass" };
            try
            {
                DirectoryEntry domainRoot = new DirectoryEntry(ActiveDirectoryUtils.ConvertDomainName(RootDomain));

                DirectorySearcher ds = new DirectorySearcher(
                    domainRoot,
                    "(objectClass=domainDNS)",
                    policyAttributes,
                    SearchScope.Base
                    );


                SearchResult result = ds.FindOne();

                PasswordPolicy ret = new PasswordPolicy
                {
                    MinLength          = ((int)result.Properties["minPwdLength"][0]),
                    IsComplexityEnable = ((int)result.Properties["pwdProperties"][0] == 1)
                };
                res.Value = ret;
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError(ex);
                res.IsSuccess = false;
                res.ErrorCodes.Add(ErrorCodes.CANNOT_GET_PASSWORD_COMPLEXITY);
            }

            HostedSolutionLog.LogEnd("GetPasswordPolicyInternal");
            return(res);
        }
        /// <summary>
        /// Returns the identity of the PS object
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        internal string GetPSObjectIdentity(PSObject obj)
        {
            HostedSolutionLog.LogStart("GetPSObjectIdentity");
            if (obj == null)
            {
                throw new ArgumentNullException("obj", "PSObject is not specified");
            }


            PSMemberInfo info = obj.Members["Identity"];

            if (info == null)
            {
                throw new ArgumentException("PSObject does not contain Identity property", "obj");
            }

            string ret = info.Value.ToString();

            HostedSolutionLog.LogEnd("GetPSObjectIdentity");
            return(ret);
        }
Example #22
0
        /// <summary> Executes shell command.</summary>
        /// <param name="runspace"> The runspace.</param>
        /// <param name="command"> The command.</param>
        /// <param name="useDomainController"> True - if domain controller should be used.</param>
        /// <param name="errors"> Errors list.</param>
        /// <returns> The result.</returns>
        internal Collection <PSObject> ExecuteShellCommand(Runspace runspace, Command command, bool useDomainController, out object[] errors)
        {
            HostedSolutionLog.LogStart("ExecuteShellCommand");
            var errorList = new List <object>();

            if (useDomainController)
            {
                var dc = new CommandParameter("DomainController", PrimaryDomainController);
                if (!command.Parameters.Contains(dc))
                {
                    command.Parameters.Add(dc);
                }
            }

            HostedSolutionLog.DebugCommand(command);
            Collection <PSObject> results;
            Pipeline pipeLine = runspace.CreatePipeline();

            using (pipeLine)
            {
                pipeLine.Commands.Add(command);
                results = pipeLine.Invoke();

                if (pipeLine.Error != null && pipeLine.Error.Count > 0)
                {
                    foreach (object item in pipeLine.Error.ReadToEnd())
                    {
                        errorList.Add(item);
                        string errorMessage = string.Format("Invoke error: {0}", item);
                        HostedSolutionLog.LogWarning(errorMessage);
                    }
                }
            }

            errors = errorList.ToArray();
            HostedSolutionLog.LogEnd("ExecuteShellCommand");

            return(results);
        }
Example #23
0
        /// <summary> Gets users general settings.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="userUpn"> The user UPN.</param>
        /// <returns> User settings.</returns>
        internal override LyncUser GetLyncUserGeneralSettingsInternal(string organizationId, string userUpn)
        {
            HostedSolutionLog.LogStart("GetLyncUserGeneralSettingsInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn);
            var      lyncUser = new LyncUser();
            Runspace runspace = null;

            try
            {
                runspace = OpenRunspace();

                var command = new Command("Get-CsUser");
                command.Parameters.Add("Identity", userUpn);
                Collection <PSObject> result = ExecuteShellCommand(runspace, command, false);
                PSObject user = result[0];

                lyncUser.DisplayName = (string)GetPSObjectProperty(user, "DisplayName");
                lyncUser.SipAddress  = (string)GetPSObjectProperty(user, "SipAddress");
                lyncUser.LineUri     = (string)GetPSObjectProperty(user, "LineURI");

                lyncUser.SipAddress = lyncUser.SipAddress.ToLower().Replace("sip:", "");
                lyncUser.LineUri    = lyncUser.LineUri.ToLower().Replace("tel:+", "");
                lyncUser.LineUri    = lyncUser.LineUri.ToLower().Replace("tel:", "");
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("GetLyncUserGeneralSettingsInternal", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("GetLyncUserGeneralSettingsInternal");

            return(lyncUser);
        }
Example #24
0
        internal void DeleteOrganizationInternal(string organizationId)
        {
            HostedSolutionLog.LogStart("DeleteOrganizationInternal");
            HostedSolutionLog.DebugInfo("OrganizationId : {0}", organizationId);

            if (string.IsNullOrEmpty(organizationId))
            {
                throw new ArgumentNullException("organizationId");
            }

            string groupPath = GetGroupPath(organizationId);

            ActiveDirectoryUtils.DeleteADObject(groupPath);

            string path = GetOrganizationPath(organizationId);

            ActiveDirectoryUtils.DeleteADObject(path, true);



            HostedSolutionLog.LogEnd("DeleteOrganizationInternal");
        }
        /// <summary>Gets SharePoint site collection.</summary>
        /// <param name="rootWebApplicationUri">The root web application uri.</param>
        /// <param name="url">The required site url.</param>
        /// <returns>The SharePoint sites.</returns>
        private SPSite GetSPSiteCollection(Uri rootWebApplicationUri, string url)
        {
            Runspace runspace = null;

            try
            {
                string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port);
                runspace = OpenRunspace();
                var cmd = new Command("Get-SPSite");
                cmd.Parameters.Add("Identity", siteCollectionUrl);
                Collection <PSObject> result = ExecuteShellCommand(runspace, cmd);

                if (result != null && result.Count() == 1)
                {
                    var spSite = result.First().BaseObject as SPSite;

                    if (spSite == null)
                    {
                        throw new ApplicationException(string.Format("SiteCollection {0} does not exist", url));
                    }

                    return(result.First().BaseObject as SPSite);
                }
                else
                {
                    throw new ApplicationException(string.Format("SiteCollection {0} does not exist", url));
                }
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError(ex);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }
        }
Example #26
0
        private OCSUser GetUserGeneralSettingsInternal(string instanceId)
        {
            HostedSolutionLog.LogStart("GetUserGeneralSettingsInternal");
            try
            {
                if (string.IsNullOrEmpty(instanceId))
                {
                    throw new ArgumentException("instanceId");
                }

                using (ManagementObject userObject = GetUserByInstanceId(instanceId))
                {
                    if (userObject == null)
                    {
                        throw new Exception(string.Format("OCS user {0} not found", instanceId));
                    }

                    OCSUser user = new OCSUser();
                    user.InstanceId                     = instanceId;
                    user.PrimaryUri                     = (string)userObject["PrimaryURI"];
                    user.DisplayName                    = (string)userObject["DisplayName"];
                    user.EnabledForFederation           = (bool)userObject["EnabledForFederation"];
                    user.EnabledForPublicIMConectivity  = (bool)userObject["PublicNetworkEnabled"];
                    user.ArchiveInternalCommunications  = (bool)userObject["ArchiveInternalCommunications"];
                    user.ArchiveFederatedCommunications = (bool)userObject["ArchiveFederatedCommunications"];
                    user.EnabledForEnhancedPresence     = (bool)userObject["EnabledForEnhancedPresence"];

                    HostedSolutionLog.LogEnd("GetUserGeneralSettingsInternal");

                    return(user);
                }
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("GetUserGeneralSettingsInternal", ex);
                throw;
            }
        }
Example #27
0
        /// <summary> Adds domain to allowed list.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="domainName"> The domain name.</param>
        /// <param name="proxyFqdn"> The ProxyFQDN.</param>
        /// <returns> The result.</returns>
        internal override bool AddFederationDomainInternal(string organizationId, string domainName, string proxyFqdn)
        {
            domainName = domainName.ToLower();
            Runspace runspace = null;

            try
            {
                runspace = OpenRunspace();
                var command = new Command("Get-CsAllowedDomain");
                command.Parameters.Add("Identity", domainName);
                Collection <PSObject> result = ExecuteShellCommand(runspace, command, false);

                if (result != null && !result.Any())
                {
                    command = new Command("New-CsAllowedDomain");
                    command.Parameters.Add("Identity", domainName);
                    ExecuteShellCommand(runspace, command, false);

                    command = new Command("Set-CsAllowedDomain");
                    command.Parameters.Add("Identity", domainName);
                    command.Parameters.Add("ProxyFQDN", PoolFQDN);
                    ExecuteShellCommand(runspace, command, false);
                }
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("AddFederationDomainInternal", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("AddFederationDomainInternal");

            return(true);
        }
        /// <summary>Deletes site collection under given url.</summary>
        /// <param name="rootWebApplicationUri">Root web application uri.</param>
        /// <param name="siteCollection">The site collection to be deleted.</param>
        /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception>
        public void DeleteSiteCollection(Uri rootWebApplicationUri, SharePointEnterpriseSiteCollection siteCollection)
        {
            HostedSolutionLog.LogStart("DeleteSiteCollection");
            Runspace runspace = null;

            try
            {
                string siteCollectionUrl = String.Format("{0}:{1}", siteCollection.Url, rootWebApplicationUri.Port);
                HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl);
                runspace = OpenRunspace();
                DeleteSiteCollection(runspace, siteCollectionUrl, false);
                RemoveHostsRecord(siteCollection);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Failed to delete site collection.", ex);
            }
            finally
            {
                CloseRunspace(runspace);
                HostedSolutionLog.LogEnd("DeleteSiteCollection");
            }
        }
        /// <summary> Creates site collection within predefined root web application.</summary>
        /// <param name="rootWebApplicationUri">Root web application uri.</param>
        /// <param name="siteCollection">Information about site coolection to be created.</param>
        /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception>
        public void CreateSiteCollection(Uri rootWebApplicationUri, SharePointEnterpriseSiteCollection siteCollection)
        {
            HostedSolutionLog.LogStart("CreateSiteCollection");
            WindowsImpersonationContext wic = null;
            Runspace runspace = null;

            try
            {
                wic      = WindowsIdentity.GetCurrent().Impersonate();
                runspace = OpenRunspace();
                CreateCollection(runspace, rootWebApplicationUri, siteCollection);
            }
            finally
            {
                CloseRunspace(runspace);
                HostedSolutionLog.LogEnd("CreateSiteCollection");

                if (wic != null)
                {
                    wic.Undo();
                }
            }
        }
        /// <summary>Sets people picker OU.</summary>
        /// <param name="site">The site.</param>
        /// <param name="ou">OU.</param>
        public void SetPeoplePickerOu(string site, string ou)
        {
            HostedSolutionLog.LogStart("SetPeoplePickerOu");
            HostedSolutionLog.LogInfo("  Site: {0}", site);
            HostedSolutionLog.LogInfo("  OU: {0}", ou);

            Runspace runspace = null;

            try
            {
                runspace = OpenRunspace();
                var cmd = new Command("Set-SPSite");
                cmd.Parameters.Add("Identity", site);
                cmd.Parameters.Add("UserAccountDirectoryPath", ou);
                ExecuteShellCommand(runspace, cmd);
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("SetPeoplePickerOu");
        }