public void DeleteTest() { // arrange ValidUrl temp1 = new ValidUrl { Id = Guid.NewGuid(), SiteId = 0, Action = "/Template/Compose", Active = true, FriendlyUrl = "/flights/v5", Index = true, StatusCode = 200, View = "/home/flights.cshtml", LastModified = DateTime.Now }; _mongodbRepo.Save(temp1); // act _mongodbRepo.Delete(temp1); // assert var actual = _mongodbRepo.GetByFriendlyUrl(temp1.SiteId, temp1.FriendlyUrl); Assert.IsNull(actual); }
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 void GetByFriendlyUrlTest() { ValidUrl expected = new ValidUrl { Id = Guid.NewGuid(), SiteId = 0, Action = "/Template/Compose", Active = true, FriendlyUrl = "/flights/", Index = true, StatusCode = 200, View = "/home/flights.cshtml", LastModified=DateTime.Now }; _mongodbRepo.Save(expected); ValidUrl actual = _mongodbRepo.GetByFriendlyUrl(expected.SiteId, expected.FriendlyUrl); Assert.AreEqual(actual.Id , expected.Id); }
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 void Update(ValidUrl url_) { throw new NotImplementedException(); }
public void Save(ValidUrl url_) { }
private Dictionary<string, ValidUrl> LoadFromDisk(Dictionary<string, ValidUrl> dict_, int siteId_,bool loadActiveUrls_,string filePath_) { string path = filePath_; ValidUrl temp = null; using (StreamReader sreader = new StreamReader(path)) { using (JsonReader jreader = new JsonTextReader(sreader)) { while (jreader.Depth <= 0) { jreader.Read(); } while (jreader.Depth >= 1) { try { jreader.Read(); if (jreader.TokenType == JsonToken.StartObject) { temp = new ValidUrl(); } else if (jreader.TokenType == JsonToken.PropertyName) { switch (jreader.Value.ToString()) { case "FriendlyUrl": jreader.Read(); temp.FriendlyUrl = jreader.Value.ToString(); break; case "View": jreader.Read(); temp.View = jreader.Value.ToString(); break; case "Active": jreader.Read(); temp.Active = Convert.ToBoolean(jreader.Value); break; case "Indexing": jreader.Read(); temp.Index = Convert.ToBoolean(jreader.Value); break; case "StatusCode": jreader.Read(); temp.StatusCode = Convert.ToInt16(jreader.Value); break; case "Id": jreader.Read(); temp.Id = Guid.Parse(jreader.Value.ToString()); break; case "Action": jreader.Read(); temp.Action = jreader.Value.ToString(); break; case "LastModified": jreader.Read(); temp.LastModified = Convert.ToDateTime(jreader.Value.ToString()); break; case "LastModifiedBy": jreader.Read(); temp.LastModifiedBy = jreader.Value.ToString(); break; case "ChangeFrequency": jreader.Read(); temp.ChangeFrequency = jreader.Value.ToString(); break; case "SitemapPriority": jreader.Read(); temp.SitemapPriority =float.Parse(jreader.Value.ToString()); break; } } else if (jreader.TokenType == JsonToken.EndObject) { if (!dict_.ContainsKey(temp.FriendlyUrl.ToLower())) // TODO : To remove this if condition { dict_.Add(temp.FriendlyUrl.ToLower(), temp); } } } catch (Exception ex) { LogEventInfo info = new LogEventInfo(LogLevel.Error, ECMSSettings.DEFAULT_LOGGER, "Error while reading urls for siteid: " + siteId_ + "\r\n" + ex.ToString()); DependencyManager.Logger.Log(info); } } } } return dict_; }
public ActionResult UpdateUrl(ValidUrl url_) { string result = string.Empty; try { url_.LastModified = DateTime.Now; url_.LastModifiedBy = this.CMSUser.UserName; url_.SitemapPriority = float.Parse(url_.SitemapPriority.ToString("N1")); url_.Action = ECMSSettings.Current.DefaultURLRewriteAction; url_.SiteId = (short)this.GetSiteIdFromContext(); if (url_.Id == Guid.Empty) { url_.Id = Guid.NewGuid(); DependencyManager.URLRepository.Save(url_); } else { DependencyManager.URLRepository.Update(url_); } result = "Url Updated Successfully."; } catch (Exception ex) { Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.StatusCode = 500; Response.StatusDescription = "Failed : " + ex.Message; } return Json(result); }
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 abstract ContentItem GetContentForEditing(ValidUrl url_, ContentViewType viewType_);
public void UpdateTest() { // arrange ValidUrl temp1 = new ValidUrl { Id = Guid.NewGuid(), SiteId = 0, Action = "/Template/Compose", Active = true, FriendlyUrl = "/flights/", Index = true, StatusCode = 200, View = "/home/flights.cshtml", LastModified = DateTime.Now }; _mongodbRepo.Save(temp1); ValidUrl expected = _mongodbRepo.GetByFriendlyUrl(temp1.SiteId, temp1.FriendlyUrl); expected.FriendlyUrl = "/flights/v1"; expected.StatusCode = 200; expected.Active = false; // act _mongodbRepo.Update(expected); ValidUrl actual = _mongodbRepo.GetByFriendlyUrl(expected.SiteId, expected.FriendlyUrl); // assert Assert.AreEqual(actual.FriendlyUrl, expected.FriendlyUrl); Assert.AreEqual(actual.StatusCode, expected.StatusCode); Assert.AreEqual(actual.Active, expected.Active); }
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 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 void Delete(ValidUrl url_) { WriteConcernResult result = _db.GetCollection<ValidUrl>(GetCollName(url_.SiteId)).Remove(Query.EQ("Id", url_.Id),RemoveFlags.Single); }
public void Update(ValidUrl url_) { Save(url_); }
public void Save(ValidUrl url_) { WriteConcernResult result = _db.GetCollection<ValidUrl>(GetCollName(url_.SiteId)).Save<ValidUrl>(url_); }
public override ContentItemHead GetHeadContentByViewName(ValidUrl url_, ContentViewType viewType_) { throw new NotImplementedException(); //_db.GetCollection<ContentItem>(COLLNAME).AsQueryable().Where(x=>x.ViewType==viewType_ && x.) }
public void SaveTest() { ValidUrl expected = new ValidUrl { Id = Guid.NewGuid(), SiteId = 0, Action = "/Template/Compose", Active = true, FriendlyUrl = "/flights/", Index = true, StatusCode = 200, View = "/home/flights.cshtml", LastModified = DateTime.Now }; _mongodbRepo.Save(expected); }
//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 abstract ContentItem GetByUrl(ValidUrl url_, ContentViewType viewType_);
public override ContentItem GetByUrl(ValidUrl url_, ContentViewType viewType_) { throw new NotImplementedException(); }
public abstract ContentItemHead GetHeadContentByViewName(ValidUrl url_, 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; }