예제 #1
0
        /// <summary>
        /// Capture the return results for any commands that return lists
        /// </summary>
        /// <param name="action">The command passed</param>
        /// <param name="outputFromScript">The raw text from the powershell script</param>
        /// <returns>An array of processed lines</returns>
        internal static SharePointDeploymentStatus[] ProcessPowerShellOutput(SharePointAppAction action, string outputFromScript)
        {
            var results = new List <SharePointDeploymentStatus>();

            switch (action)
            {
            case SharePointAppAction.Get_SPAppInstance:
                var lines = outputFromScript.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                SharePointDeploymentStatus newItem = null;
                foreach (var line in lines)
                {
                    if (!string.IsNullOrEmpty(line))
                    {
                        var sections = line.Split(':');
                        if (sections.Length == 2)
                        {
                            switch (sections[0].Trim())
                            {
                            case "DisplayName":
                                newItem          = new SharePointDeploymentStatus();
                                newItem.Name     = sections[1].Trim();
                                newItem.Deployed = true;         // set a default as features don't pass this
                                break;

                            case "Id":
                                newItem.Id = Guid.Parse(sections[1].Trim());
                                results.Add(newItem);         // we need to make sure the ID is the last in the list
                                break;

                            case "Deployed":
                                newItem.Deployed = bool.Parse(sections[1].Trim());
                                break;
                            }
                        }
                    }
                }

                break;
            }

            return(results.ToArray());
        }
        /// <summary>
        /// Capture the return results for any commands that return lists
        /// </summary>
        /// <param name="action">The command passed</param>
        /// <param name="outputFromScript">The raw text from the powershell script</param>
        /// <returns>An array of processed lines</returns>
        internal static SharePointDeploymentStatus[] ProcessPowerShellOutput(SharePointAppAction action, string outputFromScript)
        {
            var results = new List<SharePointDeploymentStatus>();

            switch (action)
            {
                case SharePointAppAction.Get_SPAppInstance:
                    var lines = outputFromScript.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    SharePointDeploymentStatus newItem = null;
                    foreach (var line in lines)
                    {
                        if (!string.IsNullOrEmpty(line))
                        {
                            var sections = line.Split(':');
                            if (sections.Length == 2)
                            {
                                switch (sections[0].Trim())
                                {
                                    case "DisplayName":
                                        newItem = new SharePointDeploymentStatus();
                                        newItem.Name = sections[1].Trim();
                                        newItem.Deployed = true; // set a default as features don't pass this
                                        break;
                                    case "Id":
                                        newItem.Id = Guid.Parse(sections[1].Trim());
                                        results.Add(newItem); // we need to make sure the ID is the last in the list
                                        break;
                                    case "Deployed":
                                        newItem.Deployed = bool.Parse(sections[1].Trim());
                                        break;
                                }
                            }
                        }
                    }

                    break;
            }

            return results.ToArray();
        }
예제 #3
0
        internal static string GeneratePowerShellScript(
            string serverName,
            SharePointAppAction action,
            string version,
            string appSource,
            string appName,
            string siteUrl,
            string appLiteralPath,
            string otherParameters)
        {
            var command = string.Empty;

            switch (version)
            {
            case "2013":
                command = "Add-PsSnapin Microsoft.SharePoint.PowerShell; ";
                switch (action)
                {
                case SharePointAppAction.Import_SPAppPackage:
                    command = command.AppendFormat(CultureInfo.InvariantCulture, "Import-SPAppPackage -Path '{0}' –Site {1} -Source '{2}' -Confirm:$false", appLiteralPath, siteUrl, appSource);
                    break;

                case SharePointAppAction.Install_SPApp:
                    command = command.AppendFormat(CultureInfo.InvariantCulture, "Install-SPApp –Identity {0} –WebUrl {1}", appName, siteUrl);
                    break;

                case SharePointAppAction.Update_SPAppInstance:
                    command = command.AppendFormat(CultureInfo.InvariantCulture, "Update-SPAppInstance –Identity {0} –App '{1}'", appLiteralPath, appName);
                    break;

                case SharePointAppAction.Uninstall_SPAppInstance:
                    command = command.AppendFormat(CultureInfo.InvariantCulture, "Uninstall-SPAppInstance –Identity {0}", appName);
                    break;

                case SharePointAppAction.Get_SPAppInstance:
                    if (string.IsNullOrEmpty(appName))
                    {
                        command = command.AppendFormat(CultureInfo.InvariantCulture, "Get-SPAppInstance");
                    }
                    else
                    {
                        try
                        {
                            var guid = Guid.Parse(appName);
                            command = command.AppendFormat(CultureInfo.InvariantCulture, "Get-SPAppInstance | where {{$_.id -eq '{0}'}}", appName);
                        }
                        catch (FormatException)
                        {
                            command = command.AppendFormat(CultureInfo.InvariantCulture, "Get-SPAppInstance | where {{$_.name -eq '{0}'}}", appName);
                        }
                    }

                    command += " | fl -property Displayname, Deployed, Id ;";
                    break;

                default:
                    throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture, "Unknown SharePointAction [{0}] specified", action));
                }

                break;

            case "Online":
                command = "Add-PsSnapin Microsoft.Online.SharePoint.PowerShell; ";
                break;
            }

            if (string.IsNullOrEmpty(otherParameters) == false)
            {
                command = command.AppendFormat(" {0}", otherParameters);
            }

            if (string.IsNullOrEmpty(serverName))
            {
                return(command);
            }

            return(string.Format(CultureInfo.InvariantCulture, "invoke-command -computername {0} {{{1}}}", serverName, command));
        }
        internal static string GeneratePowerShellScript(
            string serverName,
            SharePointAppAction action,
            string version,
            string appSource,
            string appName,
            string siteUrl,
            string appLiteralPath,                   
            string otherParameters)
        {
            var command = string.Empty;

            switch (version)
            {
                case "2013":
                    command = "Add-PsSnapin Microsoft.SharePoint.PowerShell; ";
                    switch (action)
                    {
                        case SharePointAppAction.Import_SPAppPackage:
                            command = command.AppendFormat(CultureInfo.InvariantCulture, "Import-SPAppPackage -Path '{0}' –Site {1} -Source '{2}' -Confirm:$false", appLiteralPath, siteUrl, appSource);
                            break;
                        case SharePointAppAction.Install_SPApp:
                            command = command.AppendFormat(CultureInfo.InvariantCulture, "Install-SPApp –Identity {0} –WebUrl {1}", appName, siteUrl);
                            break;
                        case SharePointAppAction.Update_SPAppInstance:
                            command = command.AppendFormat(CultureInfo.InvariantCulture, "Update-SPAppInstance –Identity {0} –App '{1}'", appLiteralPath, appName);
                            break;
                        case SharePointAppAction.Uninstall_SPAppInstance:
                            command = command.AppendFormat(CultureInfo.InvariantCulture, "Uninstall-SPAppInstance –Identity {0}", appName);
                            break;
                        case SharePointAppAction.Get_SPAppInstance:
                            if (string.IsNullOrEmpty(appName))
                            {
                                command = command.AppendFormat(CultureInfo.InvariantCulture, "Get-SPAppInstance");
                            }
                            else
                            {
                                try
                                {
                                    var guid = Guid.Parse(appName);
                                    command = command.AppendFormat(CultureInfo.InvariantCulture, "Get-SPAppInstance | where {{$_.id -eq '{0}'}}", appName);
                                }
                                catch (FormatException)
                                {
                                    command = command.AppendFormat(CultureInfo.InvariantCulture, "Get-SPAppInstance | where {{$_.name -eq '{0}'}}", appName);
                                }
                            }

                            command += " | fl -property Displayname, Deployed, Id ;";
                            break;
                        default:
                            throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture, "Unknown SharePointAction [{0}] specified", action));
                    }

                    break;
                case "Online":
                    command = "Add-PsSnapin Microsoft.Online.SharePoint.PowerShell; ";
                    break;
            }

            if (string.IsNullOrEmpty(otherParameters) == false)
            {
                command = command.AppendFormat(" {0}", otherParameters);
            }

            if (string.IsNullOrEmpty(serverName))
            {
                return command;
            }

            return string.Format(CultureInfo.InvariantCulture, "invoke-command -computername {0} {{{1}}}", serverName, command);
        }