Пример #1
0
        /// <summary>
        /// Adds the file.
        /// </summary>
        /// <param name="pageContent">Content of the page.</param>
        /// <param name="packagePath">The package path.</param>
        /// <returns></returns>
        private void AddFile(string pageContent, string packagePath)
        {
            Assert.ArgumentNotNullOrEmpty(pageContent, nameof(pageContent));
            Assert.ArgumentNotNullOrEmpty(packagePath, nameof(packagePath));

            var uploadPackagePage = new HtmlResponse(pageContent);

            var viewState   = uploadPackagePage.GetValueByElementName("__VIEWSTATE", false);
            var csrfToken   = uploadPackagePage.GetValueByElementName("__CSRFTOKEN", false);
            var fileHandler = uploadPackagePage.GetNameByElementType("file");

            this.formData = new NameValueCollection
            {
                { "__CSRFTOKEN", csrfToken },
                { "__VIEWSTATE", viewState },
                { "Unzip", "0" },
                { "Overwrite", "1" },
                { "__EVENTTARGET", "NextButton" },
                { "__EVENTARGUMENT", "" },
                { "__SOURCE", "NextButton" },
                { "__EVENTTYPE", "click" },
                { "__ISEVENT", "1" },
                { "__BUTTON", "0" },
                { fileHandler, packagePath }
            };

            this.Client.Post(uploadPackageWizardUrl, this.formData);
        }
Пример #2
0
        /// <summary>
        ///   Processes the specified client.
        /// </summary>
        /// <param name="pipelineContext">The args.</param>
        public void Process(IPipelineContext <IHttpClient> pipelineContext)
        {
            var client = pipelineContext.Model;

            var loginContent = this.GetLoginPageContent(client);

            if (string.IsNullOrEmpty(loginContent))
            {
                pipelineContext.Aborted = true;
                return;
            }

            var loginPage = new HtmlResponse(loginContent);

            var viewState          = loginPage.GetValueByElementName("__VIEWSTATE");
            var submit             = loginPage.GetNameByElementType("submit");
            var submitValue        = loginPage.GetValueByElementName(submit);
            var viewStateGenerator = loginPage.GetValueByElementName("__VIEWSTATEGENERATOR");
            var eventValidation    = loginPage.GetValueByElementName("__EVENTVALIDATION");

            var loginPrefix = GetLoginPrefix(submit);

            var data = new NameValueCollection
            {
                { "__EVENTTARGET", "" },
                { "__EVENTARGUMENT", "" },
                { "__VIEWSTATE", viewState },
                { "__VIEWSTATEGENERATOR", viewStateGenerator },
                { "__EVENTVALIDATION", eventValidation },
                { loginPrefix + "UserName", pipelineContext.Model.Connection.Credentials.UserName },
                { loginPrefix + "Password", pipelineContext.Model.Connection.Credentials.Password },
                { submit, submitValue }
            };

            client.Post("sitecore/login", data);
        }