Esempio n. 1
0
        public virtual void InstallWebPartsPackage(string url, string fileName)
        {
            string tempPath = Path.GetTempPath();

            // unzip uploaded files if required
            string expandedFile = fileName;

            if (Path.GetExtension(fileName).ToLower() == ".zip")
            {
                // unpack file
                expandedFile = FileUtils.UnzipFiles(fileName, tempPath)[0];

                // delete zip archive
                FileUtils.DeleteFile(fileName);
            }

            // install webparts
            string cmdPath = GetAdminToolPath();
            string cmdArgs = String.Format(@"-o addwppack -url http://{0} -filename {1} -force",
                                           url, expandedFile);

            ProcessExecutionResults result = ExecuteSystemCommand(cmdPath, cmdArgs);

            if (result.ExitCode < 0)
            {
                throw new Exception("Error while installing WebParts package: " + result.Output);
            }

            // delete expanded file
            FileUtils.DeleteFile(expandedFile);
        }
Esempio n. 2
0
        public virtual void RestoreVirtualServer(string url, string fileName)
        {
            string tempPath = Path.GetTempPath();

            // unzip uploaded files if required
            string expandedFile = fileName;

            if (Path.GetExtension(fileName).ToLower() == ".zip")
            {
                // unpack file
                expandedFile = FileUtils.UnzipFiles(fileName, tempPath)[0];

                // delete zip archive
                FileUtils.DeleteFile(fileName);
            }

            // restore portal
            string cmdPath = GetAdminToolPath();
            string cmdArgs = String.Format(@"-o restore -url http://{0} -filename {1} -overwrite",
                                           url, expandedFile);

            ProcessExecutionResults result = ExecuteSystemCommand(cmdPath, cmdArgs);

            if (result.ExitCode < 0)
            {
                throw new Exception("Error while restoring SharePoint site: " + result.Output);
            }

            // delete expanded file
            FileUtils.DeleteFile(expandedFile);
        }
Esempio n. 3
0
        public virtual void UnextendVirtualServer(string url, bool deleteContent)
        {
            // uninstall SharePoint
            string cmdPath = GetAdminToolPath();
            string cmdArgs = String.Format(@"-o unextendvs -url http://{0}{1}", url,
                                           (deleteContent ? " -deletecontent" : ""));

            ProcessExecutionResults result = ExecuteSystemCommand(cmdPath, cmdArgs);

            if (result.ExitCode < 0)
            {
                throw new Exception("Error while uninstalling SharePoint: " + result.Output);
            }
        }
Esempio n. 4
0
        public virtual void DeleteWebPartsPackage(string url, string packageName)
        {
            // uninstall webparts
            string cmdPath = GetAdminToolPath();
            string cmdArgs = String.Format(@"-o deletewppack -url http://{0} -name {1}",
                                           url, packageName);

            ProcessExecutionResults result = ExecuteSystemCommand(cmdPath, cmdArgs);

            if (result.ExitCode < 0)
            {
                throw new Exception("Error while installing WebParts package: " + result.Output);
            }
        }
Esempio n. 5
0
        public virtual void ExtendVirtualServer(SharePointSite site)
        {
            // install SharePoint
            string cmdPath = GetAdminToolPath();
            string cmdArgs = String.Format(@"-o extendvs -url http://{0} -ownerlogin {1}\{2} -owneremail {3} -databaseserver {4} -databasename {5} -databaseuser {6} -databasepassword {7}",
                                           site.Name, Environment.MachineName, site.OwnerLogin, site.OwnerEmail,
                                           site.DatabaseServer, site.DatabaseName, site.DatabaseUser, site.DatabasePassword);

            ProcessExecutionResults result = ExecuteSystemCommand(cmdPath, cmdArgs);

            if (result.ExitCode < 0)
            {
                throw new Exception("Error while installing SharePoint: " + result.Output);
            }
        }
Esempio n. 6
0
        private ProcessExecutionResults ExecuteSystemCommand(string cmd, string args)
        {
            ProcessExecutionResults result = new ProcessExecutionResults();

            // launch system process
            ProcessStartInfo startInfo = new ProcessStartInfo(cmd, args);

            startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute        = false;
            Process proc = Process.Start(startInfo);

            // analyze results
            StreamReader reader = proc.StandardOutput;

            result.Output   = reader.ReadToEnd();
            result.ExitCode = proc.ExitCode;
            reader.Close();

            return(result);
        }
Esempio n. 7
0
        public virtual string[] GetInstalledWebParts(string url)
        {
            string cmdPath = GetAdminToolPath();
            string cmdArgs = String.Format(@"-o enumwppacks -url http://{0}", url);

            ProcessExecutionResults result = ExecuteSystemCommand(cmdPath, cmdArgs);

            List <string> list   = new List <string>();
            string        line   = null;
            StringReader  reader = new StringReader(result.Output);

            while ((line = reader.ReadLine()) != null)
            {
                line = line.Trim();
                int commaIdx = line.IndexOf(",");
                if (!String.IsNullOrEmpty(line) && commaIdx != -1)
                {
                    list.Add(line.Substring(0, commaIdx));
                }
            }

            return(list.ToArray());
        }
Esempio n. 8
0
        public virtual string BackupVirtualServer(string url, string fileName, bool zipBackup)
        {
            string tempPath = Path.GetTempPath();
            string bakFile  = Path.Combine(tempPath, (zipBackup
                                ? StringUtils.CleanIdentifier(url) + ".bsh"
                                : StringUtils.CleanIdentifier(fileName)));

            // backup portal
            string cmdPath = GetAdminToolPath();
            string cmdArgs = String.Format(@"-o backup -url http://{0} -filename {1} -overwrite",
                                           url, bakFile);

            ProcessExecutionResults result = ExecuteSystemCommand(cmdPath, cmdArgs);

            if (result.ExitCode < 0)
            {
                throw new Exception("Error while backing up SharePoint site: " + result.Output);
            }

            // zip backup file
            if (zipBackup)
            {
                string zipFile = Path.Combine(tempPath, fileName);
                string zipRoot = Path.GetDirectoryName(bakFile);

                // zip files
                FileUtils.ZipFiles(zipFile, zipRoot, new string[] { Path.GetFileName(bakFile) });

                // delete data files
                FileUtils.DeleteFile(bakFile);

                bakFile = zipFile;
            }

            return(bakFile);
        }
Esempio n. 9
0
        private ProcessExecutionResults ExecuteSystemCommand(string cmd, string args)
        {
            ProcessExecutionResults result = new ProcessExecutionResults();

            // launch system process
            ProcessStartInfo startInfo = new ProcessStartInfo(cmd, args);
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute = false;
            Process proc = Process.Start(startInfo);

            // analyze results
            StreamReader reader = proc.StandardOutput;
            result.Output = reader.ReadToEnd();
            result.ExitCode = proc.ExitCode;
            reader.Close();

            return result;
        }
Esempio n. 10
0
    public ExitCode RunApkInstrumentation(
        string apkPackageName,
        string?instrumentationName,
        Dictionary <string, string> instrumentationArguments,
        string outputDirectory,
        string?deviceOutputFolder,
        TimeSpan timeout,
        int expectedExitCode)
    {
        int?instrumentationExitCode = null;

        // No class name = default Instrumentation
        ProcessExecutionResults result = _runner.RunApkInstrumentation(apkPackageName, instrumentationName, instrumentationArguments, timeout);

        bool processCrashed      = false;
        bool failurePullingFiles = false;
        bool logCatSucceeded;

        using (_logger.BeginScope("Post-test copy and cleanup"))
        {
            if (result.ExitCode == (int)ExitCode.SUCCESS)
            {
                (instrumentationExitCode, processCrashed, failurePullingFiles) = ParseInstrumentationResult(apkPackageName, outputDirectory, result.StandardOutput);
            }

            // Optionally copy off an entire folder
            if (!string.IsNullOrEmpty(deviceOutputFolder))
            {
                try
                {
                    var logs = _runner.PullFiles(apkPackageName, deviceOutputFolder, outputDirectory);
                    foreach (string log in logs)
                    {
                        _logger.LogDebug($"Found output file: {log}");
                    }
                }
                catch (Exception toLog)
                {
                    _logger.LogError(toLog, "Hit error (typically permissions) trying to pull {filePathOnDevice}", deviceOutputFolder);
                    failurePullingFiles = true;
                }
            }

            logCatSucceeded = _runner.TryDumpAdbLog(Path.Combine(outputDirectory, $"adb-logcat-{apkPackageName}-{(instrumentationName ?? "default")}.log"));

            if (processCrashed)
            {
                _runner.DumpBugReport(Path.Combine(outputDirectory, $"adb-bugreport-{apkPackageName}"));
            }
        }

        // In case emulator crashes halfway through, we can tell by failing to pull ADB logs from it
        if (!logCatSucceeded)
        {
            return(ExitCode.SIMULATOR_FAILURE);
        }

        if (result.ExitCode == (int)AdbExitCodes.INSTRUMENTATION_TIMEOUT)
        {
            return(ExitCode.TIMED_OUT);
        }

        if (processCrashed)
        {
            return(ExitCode.APP_CRASH);
        }

        if (failurePullingFiles)
        {
            _logger.LogError($"Received expected instrumentation exit code ({instrumentationExitCode}), " +
                             "but we hit errors pulling files from the device (see log for details.)");
            return(ExitCode.DEVICE_FILE_COPY_FAILURE);
        }

        if (!instrumentationExitCode.HasValue)
        {
            return(ExitCode.RETURN_CODE_NOT_SET);
        }

        if (instrumentationExitCode != expectedExitCode)
        {
            _logger.LogError($"Non-success instrumentation exit code: {instrumentationExitCode}, expected: {expectedExitCode}");
            return(ExitCode.TESTS_FAILED);
        }

        return(ExitCode.SUCCESS);
    }