Exemplo n.º 1
0
            private void PopulatePostMultiPart(string post_string)
            {
                var boundary_index = _ctx.Request.ContentType.IndexOf("boundary=") + 9;
                var boundary       = _ctx.Request.ContentType.Substring(boundary_index, _ctx.Request.ContentType.Length - boundary_index);

                var upper_bound = post_string.Length - 4;

                if (post_string.Substring(2, boundary.Length) != boundary)
                {
                    throw (new InvalidDataException());
                }

                var current_string = new StringBuilder();

                for (var x = 4 + boundary.Length; x < upper_bound; ++x)
                {
                    if (post_string.Substring(x, boundary.Length) == boundary)
                    {
                        x += boundary.Length + 1;

                        var post_variable_string = current_string.Remove(current_string.Length - 4, 4).ToString();

                        var end_of_header = post_variable_string.IndexOf("\r\n\r\n");

                        if (end_of_header == -1)
                        {
                            throw (new InvalidDataException());
                        }

                        var filename_index      = post_variable_string.IndexOf("filename=\"", 0, end_of_header);
                        var filename_starts     = filename_index + 10;
                        var content_type_starts = post_variable_string.IndexOf("Content-Type: ", 0, end_of_header) + 14;
                        var name_starts         = post_variable_string.IndexOf("name=\"") + 6;
                        var data_starts         = end_of_header + 4;

                        if (filename_index != -1)
                        {
                            var filename     = post_variable_string.Substring(filename_starts, post_variable_string.IndexOf("\"", filename_starts) - filename_starts);
                            var content_type = post_variable_string.Substring(content_type_starts, post_variable_string.IndexOf("\r\n", content_type_starts) - content_type_starts);
                            var file_data    = post_variable_string.Substring(data_starts, post_variable_string.Length - data_starts);
                            var name         = post_variable_string.Substring(name_starts, post_variable_string.IndexOf("\"", name_starts) - name_starts);
                            Files.Add(name, new File()
                            {
                                FileName = filename, ContentType = content_type, FileData = file_data
                            });
                        }
                        else
                        {
                            var name  = post_variable_string.Substring(name_starts, post_variable_string.IndexOf("\"", name_starts) - name_starts);
                            var value = post_variable_string.Substring(data_starts, post_variable_string.Length - data_starts);
                            Post.Add(name, value);
                        }

                        current_string.Clear();
                        continue;
                    }

                    current_string.Append(post_string[x]);
                }
            }
        /// <summary>
        /// Queues the specified key into the request.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public void Queue(string key, string value)
        {
            //allow for pushing of new bits...
            if (!String.IsNullOrEmpty(Post.Get(key)))
            {
                Post.Remove(key);
            }

            Post.Add(key, value);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Queues the specified key into the request.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public void Queue(string key, string value)
        {
            //allow for pushing of new bits...
            if (Post.ContainsKey(key))
            {
                Post.Remove(key);
            }

            Post.Add(key, value);
        }
Exemplo n.º 4
0
        public void AddPost()
        {
            string url         = GetRandomUrl();
            string description = url;
            bool   added       = Post.Add(url, description);

            CleanupPostList.Add(url);

            Assert.IsTrue(added, "The url was NOT sucessfully added to del.icio.us (" + url + ")");
        }
        public IHttpActionResult Create(Post post)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            post.Add(db);

            return(Created("", post.Serializer()));
        }
        /// <summary>
        /// Adds a line item to the current order
        /// </summary>
        /// <returns></returns>
        public IGatewayRequest AddLineItem(string itemID, string name, string description, int quantity, decimal price, bool taxable)
        {
            String sFld       = ApiFields.LineItem;
            var    lineFormat = string.Format("{0}<|>{1}<|>{2}<|>{3}<|>{4}<|>{5}",
                                              itemID,
                                              name,
                                              description,
                                              quantity.ToString(), price.ToString(CultureInfo.InvariantCulture), taxable.ToString());

            Post.Add(sFld, lineFormat);
            return(this);
        }
Exemplo n.º 7
0
        public ActionResult Create(string subject, string point, string status, HttpPostedFileBase cover)
        {
            string permissions = "";
            int    stat        = 0;

            if (HasPermission("[slider]", ref permissions, ref stat))
            {
                return(RedirectToAction("AccessDeny"));
            }
            ViewBag.permissions = permissions;
            ViewBag.stat        = stat;
            ViewBag.Title       = "ثبت اسلایدر جدید";
            Post tk = new Post();

            try
            {
                if (cover != null)
                {
                    string rnd = DateTime.Now.Year.ToString("0000") + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00") + DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00") + DateTime.Now.Second.ToString("00") + Path.GetExtension(cover.FileName);
                    cover.SaveAs(Server.MapPath("~/media/cover/" + rnd));
                    tk.Cover = rnd;
                }
                tk.Point = 0;
                try
                {
                    tk.Point = int.Parse(point);
                }
                catch { }
                tk.Type        = 3;
                tk.CreateDate  = DateTime.Now;
                tk.FriendlyUrl = subject.Replace("%", "").Replace("?", "").Replace(".", "").Replace("<", "").Replace(">", "").Replace(")", "").Replace("(", "").Replace("'", "").Replace("\"", "").Replace("\\", "").Replace("/", "").Replace("!", "").Replace("+", "").Replace("_", "").Replace("-", "").Replace("#", "").Replace("}", "").Replace("{", "").Replace("]", "").Replace("[", "").Trim().Replace(" ", "-");
                tk.ModifyDate  = DateTime.Now;
                tk.PostContent = "";
                tk.Seen        = 0;
                tk.Status      = int.Parse(status);
                tk.Subject     = subject;
                tk.UserId      = int.Parse(Session["user_id"].ToString());
                tk.Add();
                return(RedirectToAction("", "Slider"));
            }
            catch (Exception ex)
            {
                ErrorLog log = new ErrorLog();
                log.Description = ex.Message;
                if (ex.InnerException != null)
                {
                    log.Description += ";" + ex.Message;
                }
                log.ErrorDate = DateTime.Now;
                log.Add();
            }
            return(View(tk));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Sets the POST superglobal by using the Javascript interoperability.
        /// </summary>
        public void SetPost()
        {
            if (CallJs <bool>(JsResource.IsPost))
            {
                var postData = CallJs <Dictionary <string, string> >(JsResource.getPost);
                Log.PrintPost(_logger, postData);

                foreach (var item in postData)
                {
                    Post.Add(item.Key, item.Value);
                }
            }
        }
Exemplo n.º 9
0
        public ActionResult Create(string subject, string content, string status, string point)
        {
            string permissions = "";
            int    stat        = 0;

            if (HasPermission("[faq]", ref permissions, ref stat))
            {
                return(RedirectToAction("AccessDeny"));
            }
            ViewBag.permissions = permissions;
            ViewBag.stat        = stat;

            ViewBag.Title = "ثبت سوال جدید";
            Post tk = new Post();

            try
            {
                tk.Point = 0;
                try
                {
                    tk.Point = int.Parse(point);
                }
                catch { }
                tk.Type        = 2;
                tk.CreateDate  = DateTime.Now;
                tk.FriendlyUrl = subject.Replace("%", "").Replace("?", "").Replace(".", "").Replace("<", "").Replace(">", "").Replace(")", "").Replace("(", "").Replace("'", "").Replace("\"", "").Replace("\\", "").Replace("/", "").Replace("!", "").Replace("+", "").Replace("_", "").Replace("-", "").Replace("#", "").Replace("}", "").Replace("{", "").Replace("]", "").Replace("[", "").Trim().Replace(" ", "-");
                tk.ModifyDate  = DateTime.Now;
                tk.PostContent = content;
                tk.Seen        = 0;
                tk.Status      = int.Parse(status);
                tk.Subject     = subject;
                tk.UserId      = int.Parse(Session["user_id"].ToString());
                tk.Add();
                return(RedirectToAction("", "Questions"));
            }
            catch (Exception ex)
            {
                ErrorLog log = new ErrorLog();
                log.Description = ex.Message;
                if (ex.InnerException != null)
                {
                    log.Description += ";" + ex.Message;
                }
                log.ErrorDate = DateTime.Now;
                log.Add();
            }
            return(View(tk));
        }
Exemplo n.º 10
0
        public void DeletePost()
        {
            string url         = GetRandomUrl();
            string description = url;
            bool   added       = Post.Add(url, description);

            CleanupPostList.Add(url);
            Assert.IsTrue(added, "The url was NOT sucessfully added to del.icio.us (" + url + ")");

            bool deleted = Post.Delete(url);

            Assert.IsTrue(deleted, "The DeletePost method did not return a valid status.");
            Post post = Post.GetPost(url);

            Assert.IsNull(post, "The url was NOT sucessfully deleted from del.icio.us (" + url + ")");
        }
Exemplo n.º 11
0
        internal static string AddTestPost(string tags)
        {
            string url         = GetRandomUrl();
            string description = url;
            bool   added;

            if (tags == null || tags.Length == 0)
            {
                added = Post.Add(url, description);
            }
            else
            {
                added = Post.Add(url, description, null, tags, null);
            }
            CleanupPostList.Add(url);
            Assert.IsTrue(added, "The Post '" + url + "' was not sucessfully added with tags '" + tags + "'");
            return(url);
        }
Exemplo n.º 12
0
        public void GetSharedPosts()
        {
            string urlShared = AddTestPost();

            string urlNotShared = GetRandomUrl();

            Post.Add(urlNotShared, urlNotShared, null, null, null, false, false);
            CleanupPostList.Add(urlNotShared);

            Post postShared = Post.GetPost(urlShared);

            Assert.IsTrue(postShared.Shared,
                          "This url was imported into Delicious.Net as NOT shared but in fact it is shared on delicious.  (" + urlShared + ")");

            Post postNotShared = Post.GetPost(urlNotShared);

            Assert.IsTrue(!postNotShared.Shared,
                          "This url was imported into Delicious.Net as shared but in fact it is NOT shared on delicious.  (" + urlNotShared + ")");
        }
Exemplo n.º 13
0
        public ActionResult Add(Post post, HttpPostedFileBase poster)
        {
            IDatabaseUtility connection = new MySQLUtility();

            try
            {
                connection.Connect();
            }catch (DBException e)
            {
                ViewBag.ErrorMessage = e.Message;
                return(View("_errors"));
            }



            try
            {
                Authenticate authenticate = new Authenticate(connection);
                User         user         = authenticate.GetUser();

                if (user.IsLogin() && user.HaveRole(NewsApplication.Models.User.JOURNALIST))
                {
                    if (poster == null)
                    {
                        post.AddErrorMessage("poster", "Bạn chưa chọn ảnh bìa cho tin tức");
                    }
                    post.SetConnection(connection);
                    ViewBag.categories = new CategoryListModel(connection).GetAll();

                    post.CheckValidForSummary().CheckValidForContent().CheckValidForTitle().CheckValidForCategoryId();

                    if (post.GetErrorsMap().Count() == 0)
                    {
                        PostImage image = new PostImage(connection);
                        post.valid         = 0;
                        post.journalist_id = user.id;
                        post.Add();
                        image.post_id = (int)connection.GetLastInsertedId();
                        image.path    = PostImage.POSTER_IMAGE_DIR + image.post_id + "_" + new Random().Next() + System.IO.Path.GetExtension(poster.FileName);
                        image.Add();

                        poster.SaveAs(Server.MapPath(image.path));
                        TempData["SuccessMessage"] = "Bạn đã đăng bài thành công hãy tìm nhà kiểm duyệt để duyệt bài của bạn và hiển thị nó";
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ViewBag.postback = post;
                        throw new InputException(1, post.GetErrorsMap());
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = "Bạn không thể truy cập trang web này";
                    return(View("_errors"));
                }
            }catch (DBException e)
            {
                ViewBag.ErrorMessage = "" + e.Message;
                return(View("_errors"));
            }catch (InputException e)
            {
                ViewBag.ErrorsMap = e.Errors;
                return(View());
            }
            finally
            {
                connection.Close();
            }
        }