Example #1
0
        /// <summary>
        /// Creates the HTTP request.
        /// </summary>
        /// <param name="httpMethod">The HTTP method.</param>
        /// <param name="resourceName">Name of the resource.</param>
        /// <param name="resourceAction">The resource action.</param>
        /// <param name="key">The key.</param>
        /// <param name="queryString">The query string.</param>
        /// <returns>System.Net.HttpWebRequest.</returns>
        protected HttpWebRequest CreateHttpRequest(string httpMethod, string resourceName, string resourceAction, string key, Dictionary<string, string> queryString = null)
        {
            var url = string.Format("{0}{1}/{2}", this.BaseUrl.SafeToString("htp://localhost/api/"), resourceName, resourceAction).TrimEnd('/') + "/";
            if (!string.IsNullOrWhiteSpace(key))
            {
                url += (key.ToUrlEncodedText() + "/");
            }
            if (queryString.HasItem())
            {
                url += ("?" + queryString.ToKeyValueStringWithUrlEncode());
            }

            var httpRequest = url.CreateHttpWebRequest(httpMethod, acceptGZip: this.AcceptGZip, omitServerCertificateValidation: true);
            FillAdditionalData(httpRequest);

            return httpRequest;
        }
Example #2
0
        /// <summary>
        /// Creates the HTTP request.
        /// </summary>
        /// <param name="httpMethod">The HTTP method.</param>
        /// <param name="resourceName">Name of the resource.</param>
        /// <param name="resourceAction">The resource action.</param>
        /// <param name="key">The key.</param>
        /// <param name="queryString">The query string.</param>
        /// <returns>System.Net.HttpWebRequest.</returns>
        protected HttpWebRequest CreateHttpRequest(string httpMethod, string resourceName, string resourceAction, string key, Dictionary<string, string> queryString = null)
        {
            var url = string.Format("{0}{1}/{2}", this.BaseUrl, resourceName, resourceAction).TrimEnd('/') + "/";
            if (!string.IsNullOrWhiteSpace(key))
            {
                url += (key + "/");
            }
            if (queryString.HasItem())
            {
                url += ("?" + queryString.ToKeyValueStringWithUrlEncode());
            }

            var httpRequest = url.CreateHttpWebRequest(httpMethod, acceptGZip: this.AcceptGZip);
            FillAdditionalData(httpRequest);

            return httpRequest;
        }
        public ActionResult UploadLibrary()
        {
            try
            {
                Dictionary<string, byte[]> assemblyBytes = new Dictionary<string, byte[]>();

                if (Request.Files != null && Request.Files.Keys != null)
                {
                    var key = Request.Files.Keys[0];

                    foreach (HttpPostedFileBase one in Request.Files.GetMultiple(key))
                    {
                        assemblyBytes.Add(string.IsNullOrWhiteSpace(one.FileName) ? string.Empty : Path.GetFileNameWithoutExtension(one.FileName), one.InputStream.ToBytes());
                    }
                }

                if (!assemblyBytes.HasItem())
                {
                    throw ExceptionFactory.CreateInvalidObjectException(nameof(assemblyBytes));
                }

                var workshopKey = WorkshopManager.InitializeWorkshop(assemblyBytes);
                return RedirectToAction("Workshop", new { key = workshopKey });
            }
            catch (Exception ex)
            {
                return this.HandleExceptionToRedirection(ex);
            }
        }