Esempio n. 1
0
        public ActionResult Add(string text)
        {
            // text
            if (text.Trim().Length == 0)
            {
                return Redirect("/Comment/");
            }
            Comment comment = new Comment();
            CreoleParser parser = new CreoleParser();
            comment.Text = parser.ToHTML(HttpUtility.HtmlEncode(text.Replace(Environment.NewLine, "\\\\")));
            comment.User = CurrentUser();

            // upload

            foreach (string inputTagName in Request.Files)
            {
                HttpPostedFileBase file = Request.Files[inputTagName];
                if (file.ContentLength == 0) continue;
                Image image = new Image();
                image.PathRootBased = "Users";
                daoTemplate.Save(image);
                string filePath = HttpContext.Server.MapPath(image.PathRootBasedBig);
                string thumbFilePath = HttpContext.Server.MapPath(image.PathRootBasedSmall);
                if (!Directory.Exists(Path.GetDirectoryName(filePath)))
                    Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                file.SaveAs(filePath);
                ImageUtils.SaveImageToFile(ImageUtils.ResizeImage(filePath, 640), filePath);
                ImageUtils.SaveImageToFile(ImageUtils.ResizeImageSquare(filePath, 100), thumbFilePath);

                comment.Image = image;
                daoTemplate.Save(image);

            }
            daoTemplate.Save(comment);
            return Redirect("/Comment/");
        }
        private void wikiHandleResponse(IAsyncResult result)
        {
            queryUpdateState qState = (queryUpdateState)result.AsyncState;
            HttpWebRequest qRequest = (HttpWebRequest)qState.AsyncRequest;

            qState.AsyncResponse = (HttpWebResponse)qRequest.EndGetResponse(result);

            Stream streamResult;
            try
            {
                streamResult = qState.AsyncResponse.GetResponseStream();

                // load the XML
                XDocument xmlquery = XDocument.Load(streamResult);

                //Wikipedia Data Need to be parsed
                string a = xmlquery.Descendants("query").Descendants("pages").Descendants("page").Descendants("revisions").Descendants("rev").First().Value;
                string h = new CreoleParser().ToHTML(a);

                //this.Dispatcher.BeginInvoke(new Action(() => webBrowser1.UpdateLayout()));
                this.Dispatcher.BeginInvoke(new Action(() => webBrowser1.NavigateToString(h)));
                this.Dispatcher.BeginInvoke(new Action(() => webBrowser1.UpdateLayout()));

                //string x = xmlquery.ToString();
                /* if (x.IndexOf("<Description xml:space=\"preserve\">") != -1)
                 {
                     x = x.Substring(x.IndexOf("<Description xml:space=\"preserve\">") + 34);
                     x = x.Substring(0, x.IndexOf("</Description>"));

                     this.Dispatcher.BeginInvoke(new Action(() => textBlock1.Text = x));
                 }
                 else
                 {
                     this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show("Oy")));
                 }
                 this.Dispatcher.BeginInvoke(new Action(() => this.ProgressBar.Visibility = Visibility.Collapsed));*/
            }
            catch (FormatException)
            {
                return;
            }
        }