public override ContentItem GetById(ValidUrl url_, ContentViewType viewType_) { ContentItem item = new ContentItem(); item.Url = url_; JObject jsonBody = LoadPageContents(url_, viewType_,true); item.Body = jsonBody; item.Head = GetHeadContentByViewName(url_, jsonBody, viewType_); string temp2 = null; foreach (JToken token in jsonBody.Children()) { if (token is JProperty) { temp2 = (token as JProperty).Value.ToString(); if (temp2.Contains("@")) { string hashCode = temp2.GetHashCode().ToString(); if (DependencyManager.CachingService.Get<ITemplate>(hashCode) == null) { var task = Task.Factory.StartNew(() => CreateTemplateAndSetInCache(hashCode, (token as JProperty).Value.ToString())); DependencyManager.CachingService.Set<Task>("Task." + hashCode, task); } } } } return item; }
public override ContentItem GetById(ValidUrl url_, ContentViewType viewType_) { //ContentItem item = _db.GetCollection<ContentItem>(COLLNAME).AsQueryable<ContentItem>().Where(x => x.Url.Id == url_.Id && x.ContentView.ViewType == viewType_).FirstOrDefault<ContentItem>(); ContentItem item = _db.GetCollection <ContentItem>(COLLNAME).Find(Query.And(Query.EQ("Url.Id", url_.Id), Query.EQ("ViewType", Convert.ToInt32(viewType_)))).FirstOrDefault <ContentItem>(); if (item == null) { DependencyManager.Logger.Log(new LogEventInfo(LogLevel.Debug, ECMSSettings.DEFAULT_LOGGER, "Specific content not found now going to search for default content.")); item = _db.GetCollection <ContentItem>(COLLNAME).Find(Query.And(Query.EQ("ContentView.SiteId", url_.SiteId), Query.EQ("ContentView.ViewName", url_.View), Query.EQ("ContentView.ViewType", Convert.ToInt32(viewType_)))).FirstOrDefault <ContentItem>(); } //TODO : Optimize this if (item != null) { using (StringReader streamReader = new StringReader(item.Body[0].ToString())) { using (var csv = new CsvHelper.CsvReader(streamReader)) { //csv.Configuration.IgnoreQuotes = true; csv.Read(); item.Body = JObject.FromObject(csv.GetRecord(typeof(object))); } } } return(item); }
public override ContentItem GetById(ValidUrl url_, ContentViewType viewType_) { ContentItem item = new ContentItem(); item.Url = url_; JObject jsonBody = LoadPageContents(url_, viewType_, true); item.Body = jsonBody; item.Head = GetHeadContentByViewName(url_, jsonBody, viewType_); string temp2 = null; foreach (JToken token in jsonBody.Children()) { if (token is JProperty) { temp2 = (token as JProperty).Value.ToString(); if (temp2.Contains("@")) { string hashCode = temp2.GetHashCode().ToString(); if (DependencyManager.CachingService.Get <ITemplate>(hashCode) == null) { var task = Task.Factory.StartNew(() => CreateTemplateAndSetInCache(hashCode, (token as JProperty).Value.ToString())); DependencyManager.CachingService.Set <Task>("Task." + hashCode, task); } } } } return(item); }
public ActionResult UrlDataEdit(Guid id, ContentItem item_, ContentViewType vm) { ValidUrl url = DependencyManager.URLRepository.GetById(this.GetSiteIdFromContext(), id, false); item_.Url = url; DependencyManager.ContentRepository.Save(item_, vm); return(RedirectToAction("Index", "Urls")); }
private string ConstructPath(ValidUrl url_, ContentViewType viewType_, bool forBodyContent_) { string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\app_data\\" + url_.SiteId + "\\" + Convert.ToInt32(viewType_).ToString() + (forBodyContent_ ? "\\bodycontent\\" : "\\headcontent\\") + url_.Id + ECMS_FILE_EXTENSION; //if (!File.Exists(filePath)) //{ // filePath = AppDomain.CurrentDomain.BaseDirectory + "\\app_data\\" + url_.SiteId + "\\" + Convert.ToInt32(viewType_).ToString() + (forBodyContent_ ? "\\bodycontent\\" : "\\headcontent\\") + url_.View + "-default-content" + ECMS_FILE_EXTENSION; //} return(filePath); }
//private static void LoadPageContents(DirectoryInfo dirInfo) //{ // using (StreamReader streamReader = new StreamReader(dirInfo.FullName + "\\content.etxt")) // { // using (var csv = new CsvReader(streamReader)) // { // ContentBodyList = new Dictionary<int, Dictionary<Guid, JObject>>(); // var temp = new Dictionary<Guid, JObject>(); // while (csv.Read()) // { // temp[Guid.Parse(csv.GetField("UrlId"))] = JObject.FromObject(csv.GetRecord<object>()); // } // ContentBodyList[Convert.ToInt32(dirInfo.Name)] = temp; // } // } //} private JObject LoadPageContents(ValidUrl url_, ContentViewType viewType_, bool forBodyContent_) { string filePath = ConstructPath(url_, viewType_, forBodyContent_); if (!File.Exists(filePath)) { ECMSView view = DependencyManager.ViewRepository.GetByViewName(url_.View); filePath = ConstructPath(view, forBodyContent_); } return(ReadPageContentFromDisk(filePath)); }
public override ContentItemHead GetHeadContentByViewName(ValidUrl url_, ContentViewType viewType_) { JObject jsonBody = ContentBodyList[url_.SiteId][url_.Id]; JObject jsonHead = ContentHeadList[url_.SiteId.ToString() + "-" + Convert.ToInt32(viewType_).ToString() + "-" + url_.View.Trim(new char[] { '/' })]; jsonHead.MergeInto(jsonBody); ContentItemHead itemhead = new ContentItemHead(); itemhead.LoadFromJObject(jsonHead); return(itemhead); }
public override ContentItem GetContentForEditing(ValidUrl url_, ContentViewType viewType_) { //ContentItem item = _db.GetCollection<ContentItem>(COLLNAME).AsQueryable<ContentItem>().Where(x => x.Url.Id == url_.Id && x.Url.View == url_.View && Convert.ToInt32(x.ContentView.ViewType) == Convert.ToInt32(viewType_)).FirstOrDefault<ContentItem>(); ContentItem item = _db.GetCollection <ContentItem>(COLLNAME).Find(Query.And(Query.EQ("Url.Id", url_.Id), Query.EQ("ContentView.ViewName", url_.View), Query.EQ("ContentView.ViewType", Convert.ToInt32(viewType_)))).FirstOrDefault <ContentItem>(); if (item != null) { item.Body = item.Body[0]; } return(item); }
public override void Save(ContentItem content_, ContentViewType viewType_) { //ContentItem previousItem = _db.GetCollection<ContentItem>(COLLNAME).AsQueryable<ContentItem>().Where(x => x.ContentId == content_.ContentId && x.ViewType == viewType_).FirstOrDefault<ContentItem>(); ContentItem previousItem = _db.GetCollection <ContentItem>(COLLNAME).Find(Query.And(Query.EQ("ContentId", content_.ContentId), Query.EQ("ViewType", Convert.ToInt32(viewType_)))).FirstOrDefault <ContentItem>(); if (previousItem != null) { previousItem.ContentId = Guid.Empty; _db.GetCollection <ContentItem>(ARC_COLLNAME).Save <ContentItem>(previousItem); } _db.GetCollection <ContentItem>(COLLNAME).Save <ContentItem>(content_); }
public override void Save(ContentItem content_, ContentViewType viewType_) { string bodyContentFilePath = ConstructPath(content_.Url, viewType_, true); string headContentFilePath = ConstructPath(content_.Url, viewType_, false); File.WriteAllText(bodyContentFilePath, Convert.ToString(content_.Body[0])); using (StringWriter stringWriter = new StringWriter()) { using (CsvWriter csvWriter = new CsvWriter(stringWriter)) { csvWriter.WriteHeader <ContentItemHead>(); csvWriter.WriteRecord <ContentItemHead>(content_.Head); File.WriteAllText(headContentFilePath, stringWriter.ToString()); } } }
public ActionResult UrlDataEdit(Guid id, ContentViewType vm) { ValidUrl url = DependencyManager.URLRepository.GetById(this.GetSiteIdFromContext(), id, false); ViewBag.ViewName = url.FriendlyUrl; ViewBag.ViewType = vm; ContentItem item = null; try { item = DependencyManager.ContentRepository.GetContentForEditing(url, vm); } catch (FileNotFoundException) { } if (item != null) { return(View(GetControllerView("DefaultDataEdit"), item)); } else { return(View(GetControllerView("DefaultDataEdit"))); } }
public override ContentItem GetContentForEditing(ValidUrl url_, ContentViewType viewType_) { string bodyContentFilePath = ConstructPath(url_, viewType_, true); string headContentFilePath = ConstructPath(url_, viewType_, false); ContentItem contentItem = new ContentItem(); using (StreamReader streamReader = new StreamReader(headContentFilePath)) { using (var csv = new CsvReader(streamReader)) { while (csv.Read()) { contentItem.Head = csv.GetRecord <ContentItemHead>(); } } } if (File.Exists(bodyContentFilePath)) { contentItem.Body = (dynamic)File.ReadAllText(bodyContentFilePath); } return(contentItem); }
public static ContentViewType CurrentViewType(HttpContextBase context_) { if (context_ != null && context_.Request != null) { if (context_.Request.Cookies["ECMS-View-Mode"] != null) { return(ContentViewType.PREVIEW); } else if (context_.Request.QueryString["vm"] != null) { ContentViewType viewType = (ContentViewType)Enum.Parse(typeof(ContentViewType), context_.Request.QueryString["vm"].ToString(), true); return(viewType); } else { return(ContentViewType.PUBLISH); } } else { return(ContentViewType.PUBLISH); } }
public static string GetTitle(this ContentViewType cvt) { var result = string.Empty; switch (cvt) { case ContentViewType.UserPost: result = "личный пост"; break; case ContentViewType.GroupPost: result = "групповой пост"; break; case ContentViewType.UserPetition: result = "личная петиция"; break; case ContentViewType.GroupPetition: result = "групповая петиция"; break; case ContentViewType.Poll: result = "голосование"; break; case ContentViewType.Election: result = "выборы"; break; case ContentViewType.Survey: result = "опрос"; break; } return(result); }
public abstract ContentItem GetContentForEditing(ValidUrl url_, ContentViewType viewType_);
public abstract ContentItemHead GetHeadContentByViewName(ValidUrl url_, ContentViewType viewType_);
public abstract void Delete(ContentItem content_, ContentViewType viewType_);
public abstract ContentItem GetByUrl(ValidUrl url_, ContentViewType viewType_);
public ActionResult UrlDataEdit(Guid id, ContentItem item_, ContentViewType vm) { ValidUrl url = DependencyManager.URLRepository.GetById(this.GetSiteIdFromContext(), id, false); item_.Url = url; DependencyManager.ContentRepository.Save(item_, vm); return RedirectToAction("Index", "Urls"); }
public ActionResult UrlDataEdit(Guid id, ContentViewType vm) { ValidUrl url = DependencyManager.URLRepository.GetById(this.GetSiteIdFromContext(), id, false); ViewBag.ViewName = url.FriendlyUrl; ViewBag.ViewType = vm; ContentItem item = null; try { item = DependencyManager.ContentRepository.GetContentForEditing(url, vm); } catch (FileNotFoundException) { } if (item != null) { return View(GetControllerView("DefaultDataEdit"), item); } else { return View(GetControllerView("DefaultDataEdit")); } }
private string ConstructPath(ValidUrl url_, ContentViewType viewType_, bool forBodyContent_) { string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\app_data\\" + url_.SiteId + "\\" + Convert.ToInt32(viewType_).ToString() + (forBodyContent_ ? "\\bodycontent\\" : "\\headcontent\\") +url_.Id + ECMS_FILE_EXTENSION; //if (!File.Exists(filePath)) //{ // filePath = AppDomain.CurrentDomain.BaseDirectory + "\\app_data\\" + url_.SiteId + "\\" + Convert.ToInt32(viewType_).ToString() + (forBodyContent_ ? "\\bodycontent\\" : "\\headcontent\\") + url_.View + "-default-content" + ECMS_FILE_EXTENSION; //} return filePath; }
public override ContentItem GetContentForEditing(ValidUrl url_,ContentViewType viewType_) { string bodyContentFilePath = ConstructPath(url_, viewType_, true); string headContentFilePath = ConstructPath(url_, viewType_, false); ContentItem contentItem = new ContentItem(); using (StreamReader streamReader = new StreamReader(headContentFilePath)) { using (var csv = new CsvReader(streamReader)) { while (csv.Read()) { contentItem.Head = csv.GetRecord<ContentItemHead>(); } } } if (File.Exists(bodyContentFilePath)) { contentItem.Body = (dynamic)File.ReadAllText(bodyContentFilePath); } return contentItem; }
public override ContentItem GetContentForEditing(ValidUrl url_, ContentViewType viewType_) { //ContentItem item = _db.GetCollection<ContentItem>(COLLNAME).AsQueryable<ContentItem>().Where(x => x.Url.Id == url_.Id && x.Url.View == url_.View && Convert.ToInt32(x.ContentView.ViewType) == Convert.ToInt32(viewType_)).FirstOrDefault<ContentItem>(); ContentItem item = _db.GetCollection<ContentItem>(COLLNAME).Find(Query.And(Query.EQ("Url.Id", url_.Id), Query.EQ("ContentView.ViewName", url_.View), Query.EQ("ContentView.ViewType", Convert.ToInt32(viewType_)))).FirstOrDefault<ContentItem>(); if (item != null) { item.Body = item.Body[0]; } return item; }
public override void Save(ContentItem content_, ContentViewType viewType_) { //ContentItem previousItem = _db.GetCollection<ContentItem>(COLLNAME).AsQueryable<ContentItem>().Where(x => x.ContentId == content_.ContentId && x.ViewType == viewType_).FirstOrDefault<ContentItem>(); ContentItem previousItem = _db.GetCollection<ContentItem>(COLLNAME).Find(Query.And(Query.EQ("ContentId", content_.ContentId), Query.EQ("ViewType", Convert.ToInt32(viewType_)))).FirstOrDefault<ContentItem>(); if (previousItem != null) { previousItem.ContentId = Guid.Empty; _db.GetCollection<ContentItem>(ARC_COLLNAME).Save<ContentItem>(previousItem); } _db.GetCollection<ContentItem>(COLLNAME).Save<ContentItem>(content_); }
public ContentItemHead GetHeadContentByViewName(ValidUrl url_, JObject jsonBody, ContentViewType viewType_) { JObject jsonHead = ContentHeadList[url_.SiteId.ToString() + "-" + Convert.ToInt32(viewType_).ToString() + "-" + url_.View.Trim(new char[] { '/' })]; jsonHead.MergeInto(jsonBody); ContentItemHead itemhead = new ContentItemHead(); itemhead.LoadFromJObject(jsonHead); return itemhead; }
public override void Delete(ContentItem content_, ContentViewType viewType_) { throw new NotImplementedException(); }
//private static void LoadPageContents(DirectoryInfo dirInfo) //{ // using (StreamReader streamReader = new StreamReader(dirInfo.FullName + "\\content.etxt")) // { // using (var csv = new CsvReader(streamReader)) // { // ContentBodyList = new Dictionary<int, Dictionary<Guid, JObject>>(); // var temp = new Dictionary<Guid, JObject>(); // while (csv.Read()) // { // temp[Guid.Parse(csv.GetField("UrlId"))] = JObject.FromObject(csv.GetRecord<object>()); // } // ContentBodyList[Convert.ToInt32(dirInfo.Name)] = temp; // } // } //} private JObject LoadPageContents(ValidUrl url_, ContentViewType viewType_, bool forBodyContent_) { string filePath = ConstructPath(url_, viewType_, forBodyContent_); if (!File.Exists(filePath)) { ECMSView view = DependencyManager.ViewRepository.GetByViewName(url_.View); filePath = ConstructPath(view, forBodyContent_); } return ReadPageContentFromDisk(filePath); }
public override ContentItem GetByUrl(ValidUrl url_, ContentViewType viewType_) { throw new NotImplementedException(); }
public override void Save(ContentItem content_, ContentViewType viewType_) { string bodyContentFilePath = ConstructPath(content_.Url, viewType_, true); string headContentFilePath = ConstructPath(content_.Url, viewType_, false); File.WriteAllText(bodyContentFilePath, Convert.ToString(content_.Body[0])); using (StringWriter stringWriter = new StringWriter()) { using (CsvWriter csvWriter = new CsvWriter(stringWriter)) { csvWriter.WriteHeader<ContentItemHead>(); csvWriter.WriteRecord<ContentItemHead>(content_.Head); File.WriteAllText(headContentFilePath, stringWriter.ToString()); } } }
public override ContentItemHead GetHeadContentByViewName(ValidUrl url_, ContentViewType viewType_) { throw new NotImplementedException(); //_db.GetCollection<ContentItem>(COLLNAME).AsQueryable().Where(x=>x.ViewType==viewType_ && x.) }
public abstract void Save(ContentItem content_, ContentViewType viewType_);
public override ContentItem GetById(ValidUrl url_, ContentViewType viewType_) { //ContentItem item = _db.GetCollection<ContentItem>(COLLNAME).AsQueryable<ContentItem>().Where(x => x.Url.Id == url_.Id && x.ContentView.ViewType == viewType_).FirstOrDefault<ContentItem>(); ContentItem item = _db.GetCollection<ContentItem>(COLLNAME).Find(Query.And(Query.EQ("Url.Id", url_.Id), Query.EQ("ViewType", Convert.ToInt32(viewType_)))).FirstOrDefault<ContentItem>(); if (item == null) { DependencyManager.Logger.Log(new LogEventInfo(LogLevel.Debug, ECMSSettings.DEFAULT_LOGGER, "Specific content not found now going to search for default content.")); item = _db.GetCollection<ContentItem>(COLLNAME).Find(Query.And(Query.EQ("ContentView.SiteId", url_.SiteId), Query.EQ("ContentView.ViewName", url_.View), Query.EQ("ContentView.ViewType", Convert.ToInt32(viewType_)))).FirstOrDefault<ContentItem>(); } //TODO : Optimize this if (item != null) { using (StringReader streamReader = new StringReader(item.Body[0].ToString())) { using (var csv = new CsvHelper.CsvReader(streamReader)) { //csv.Configuration.IgnoreQuotes = true; csv.Read(); item.Body = JObject.FromObject(csv.GetRecord(typeof(object))); } } } return item; }