当前位置: 首页>>代码示例>>C#>>正文


C# Content.Save方法代码示例

本文整理汇总了C#中Content.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Content.Save方法的具体用法?C# Content.Save怎么用?C# Content.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Content的用法示例。


在下文中一共展示了Content.Save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnSave

 private void OnSave(ContentView contentView, Content content)
 {
     contentView.UpdateContent();
     if (contentView.IsUserInputValid && content.IsValid)
     {
         try
         {
             content.Save();
         }
         catch (Exception ex) //logged
         {
             Logger.WriteException(ex);
             contentView.ContentException = ex;
         }
     }
 }
开发者ID:maxpavlov,项目名称:FlexNet,代码行数:16,代码来源:TagEditPortlet.cs

示例2: UploadContent

        public static Content UploadContent()
        {
            try
            {
                Content content = (Content)Provider.CreateEntity("Content");
                content.SetFieldsByPostData(Provider.Request.Form);

                string authorName = Provider.Request.Form["Author"];
                if (!string.IsNullOrWhiteSpace(authorName))
                {
                    Author author = (Author)Provider.Database.Read(typeof(Author), "Name={0}", authorName);
                    bool authorVarAmaResmiYok = author != null && String.IsNullOrEmpty(author.Picture);
                    if (author == null || authorVarAmaResmiYok)
                    {
                        if (author == null)
                            author = new Author();
                        author.Name = authorName;
                        string authorPicture = Provider.Request.Form["AuthorPicture"];
                        if (authorPicture != null && authorPicture.StartsWith("http://"))
                        {
                            try
                            {
                                string imgFileName = Provider.AppSettings["authorDir"] + "/" + author.Name.MakeFileName() + "_" + (DateTime.Now.Millisecond % 1000) + authorPicture.Substring(authorPicture.LastIndexOf('.'));
                                WebClient wc = new WebClient();
                                wc.Proxy.Credentials = CredentialCache.DefaultCredentials;
                                wc.DownloadFile(authorPicture, Provider.MapPath(imgFileName));
                                author.Picture = imgFileName;
                            }
                            catch (Exception ex)
                            {
                                Provider.Log("Notice", "UploadContent", ex.Message + "\n (Yazar resmi:" + author.Picture + ")");
                                author.Picture = "";
                            }
                        }
                        author.Save();
                    }
                    content.AuthorId = author.Id;
                }

                string sourceName = Provider.Request.Form["Source"];
                if (!string.IsNullOrWhiteSpace(sourceName))
                {
                    Source source = (Source)Provider.Database.Read(typeof(Source), "Name={0}", sourceName);
                    if (source == null)
                    {
                        source = new Source();
                        source.Name = sourceName;
                        source.Save();
                    }
                    content.SourceId = source.Id;
                }

                string categoryTitle = Provider.Request.Form["Category"];
                if (!string.IsNullOrWhiteSpace(categoryTitle))
                {
                    Content category = (Content)Provider.Database.Read(typeof(Content), "Title={0}", categoryTitle);
                    if (category == null)
                    {
                        category = new Content();
                        category.ClassName = "Category";
                        category.CategoryId = 2; // int.Parse(Provider.AppSettings["newsParentCatId"]);
                        category.Title = categoryTitle;
                        category.Save();
                    }
                    content.CategoryId = category.Id;
                }

                content.Save();

                return Provider.Database.Read<Content>(content.Id);
            }
            catch (Exception ex)
            {
                Provider.Log("Error", "UploadContent", Provider.ToString(ex, true, true, true));
                return null;
            }
        }
开发者ID:fizikci,项目名称:Cinar,代码行数:77,代码来源:Provider.cs

示例3: parseContentsAndSave

        private static bool parseContentsAndSave(string url, ContentSource contentSource)
        {
            bool contentFetched = false;
            WebRequest req = WebRequest.Create(url);
            if (req.Proxy != null)
                req.Proxy.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse webResponse = (HttpWebResponse)req.GetResponse();
            string response = null;
            if (!String.IsNullOrEmpty(contentSource.Encoding))
            {
                string orjResponse = new System.IO.StreamReader(webResponse.GetResponseStream(), Encoding.GetEncoding(contentSource.Encoding)).ReadToEnd();
                response = orjResponse.ConvertEncoding(contentSource.Encoding, "iso-8859-9");
            }
            else
                response = new System.IO.StreamReader(webResponse.GetResponseStream(), Encoding.GetEncoding("iso-8859-9")).ReadToEnd();
            response = response.Replace(Environment.NewLine, "\n");

            Regex regexObj = new Regex(contentSource.ListRegExp, RegexOptions.Singleline);
            Match match = regexObj.Match(response);
            while (match.Success)
            {
                Content content = new Content();

                if (match.Groups["author"].Value != "")
                {
                    string authorName = CMSUtility.ClearTextFromWeb(match.Groups["author"].Value);
                    Author author = (Author)Provider.Database.Read(typeof(Author), "Name={0}", authorName);
                    //object authorId = Provider.Database.GetValue("select Id from Author where Name={0}", authorName);
                    if (author == null)
                    {
                        author = new Author();
                        author.Description = url + " adresinden otomatik olarak kaydedildi.";
                        author.Name = authorName;
                        if (match.Groups["authorpic"].Value != "")
                        {
                            string authorImgUrl = match.Groups["authorpic"].Value.Trim().ConvertToAbsoluteURL(url);
                            WebClient wc = new WebClient();
                            wc.Proxy.Credentials = CredentialCache.DefaultCredentials;
                            string imgFileName = Provider.AppSettings["authorDir"] + "/" + authorName.MakeFileName() + authorImgUrl.Substring(authorImgUrl.LastIndexOf('.'));
                            wc.DownloadFile(authorImgUrl, MapPath(imgFileName));
                            author.Picture = imgFileName;
                        }
                        author.Save();
                        content.AuthorId = author.Id;
                    }
                    else
                    {
                        content.AuthorId = author.Id;
                        if (author.DisableAutoContent)
                        {
                            match = match.NextMatch();
                            continue; //***
                        }
                    }
                }

                try { content.PublishDate = DateTime.Parse(match.Groups["date"].Value.Trim()); }
                catch { }
                content.Title = CMSUtility.ClearTextFromWeb(match.Groups["title"].Value);
                content.Description = "<p>" + CMSUtility.ClearTextFromWeb(match.Groups["desc"].Value) + "</p>";
                content.Metin = ""; // burada metin kaydedilemez (liste çünkü) (metin ve picture daha sonra kaydediliyor - detaya bakıldığında)
                content.CategoryId = contentSource.CategoryId;
                content.ClassName = contentSource.ClassName;
                content.SourceId = contentSource.SourceId;
                string sourceLink = match.Groups["link"].Value.Trim();
                content.SourceLink = (new Uri(new Uri(url), sourceLink)).ToString();
                content.ContentSourceId = contentSource.Id;
                if (content.AuthorId == 0) content.AuthorId = contentSource.AuthorId;
                try
                {
                    content.Save();
                }
                catch { }

                contentFetched = true;

                match = match.NextMatch();
            }

            return contentFetched;
        }
开发者ID:fizikci,项目名称:Cinar,代码行数:81,代码来源:Provider.cs

示例4: FetchAutoContentDetails

        public static void FetchAutoContentDetails(Content content)
        {
            ContentSource contentSource = (ContentSource)Provider.Database.Read(typeof(ContentSource), content.ContentSourceId);

            if (contentSource.ContentRegExp == "")
            {
                content.Metin = "Content regExp not defined.";
                content.Save();
                return; //***
            }

            WebRequest req = WebRequest.Create(content.SourceLink);
            if (req.Proxy != null)
                req.Proxy.Credentials = CredentialCache.DefaultCredentials;
            WebResponse webResponse = req.GetResponse();
            string response = new System.IO.StreamReader(webResponse.GetResponseStream(), Encoding.GetEncoding("iso-8859-9")).ReadToEnd();
            response = response.Replace(Environment.NewLine, "\n");

            Regex regexObj = new Regex(contentSource.ContentRegExp, RegexOptions.Singleline);
            Match match = regexObj.Match(response);

            if (!match.Success)
            {
                content.Metin = "RegExp match failed.";
            }
            else
            {
                if (match.Groups["metin"].Value == "")
                    content.Metin = "RegExp matched, but named group 'metin' is empty.";
                else
                    content.Metin = "<p>" + CMSUtility.ClearTextFromWeb(match.Groups["metin"].Value) + "</p>";

                if (match.Groups["title"].Value != "")
                    content.Title = CMSUtility.ClearTextFromWeb(match.Groups["title"].Value);

                if (match.Groups["desc"].Value != "")
                    content.Description = "<p>" + CMSUtility.ClearTextFromWeb(match.Groups["desc"].Value) + "</p>";

                if (match.Groups["date"].Value != "")
                    try { content.PublishDate = DateTime.Parse(match.Groups["desc"].Value.Trim()); }
                    catch { }

                if (match.Groups["contentpic"].Value != "")
                {
                    string contentImgUrl = match.Groups["contentpic"].Value.Trim();
                    WebClient wc = new WebClient();
                    wc.Proxy.Credentials = CredentialCache.DefaultCredentials;
                    string imgFileName = Provider.AppSettings["uploadDir"] + "/" + content.Title.MakeFileName() + contentImgUrl.Substring(contentImgUrl.LastIndexOf('.'));
                    wc.DownloadFile(contentImgUrl, MapPath(imgFileName));
                    content.Picture = imgFileName;
                }
            }
            content.Save();
        }
开发者ID:fizikci,项目名称:Cinar,代码行数:54,代码来源:Provider.cs


注:本文中的Content.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。