コード例 #1
0
        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;
        }
コード例 #2
0
ファイル: MongoDBRepository.cs プロジェクト: ramkumar013/ECMS
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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"));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        //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));
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: MongoDBRepository.cs プロジェクト: ramkumar013/ECMS
        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);
        }
コード例 #9
0
ファイル: MongoDBRepository.cs プロジェクト: ramkumar013/ECMS
        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_);
        }
コード例 #10
0
        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());
                }
            }
        }
コード例 #11
0
        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")));
            }
        }
コード例 #12
0
        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);
        }
コード例 #13
0
ファイル: ECMSUtility.cs プロジェクト: ramkumar013/ECMS
 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);
     }
 }
コード例 #14
0
        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);
        }
コード例 #15
0
 public abstract ContentItem GetContentForEditing(ValidUrl url_, ContentViewType viewType_);
コード例 #16
0
 public abstract ContentItemHead GetHeadContentByViewName(ValidUrl url_, ContentViewType viewType_);
コード例 #17
0
 public abstract void Delete(ContentItem content_, ContentViewType viewType_);
コード例 #18
0
 public abstract ContentItem GetByUrl(ValidUrl url_, ContentViewType viewType_);
コード例 #19
0
 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");
 }
コード例 #20
0
 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"));
     }
 }
コード例 #21
0
 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;
 }
コード例 #22
0
 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;
 }
コード例 #23
0
ファイル: MongoDBRepository.cs プロジェクト: ramkumar013/ECMS
 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;
 }
コード例 #24
0
ファイル: MongoDBRepository.cs プロジェクト: ramkumar013/ECMS
        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_);
        }
コード例 #25
0
 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;
 }
コード例 #26
0
ファイル: MongoDBRepository.cs プロジェクト: ramkumar013/ECMS
 public override void Delete(ContentItem content_, ContentViewType viewType_)
 {
     throw new NotImplementedException();
 }
コード例 #27
0
 //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);
 }
コード例 #28
0
ファイル: MongoDBRepository.cs プロジェクト: ramkumar013/ECMS
 public override ContentItem GetByUrl(ValidUrl url_, ContentViewType viewType_)
 {
     throw new NotImplementedException();
 }
コード例 #29
0
 public override void Delete(ContentItem content_, ContentViewType viewType_)
 {
     throw new NotImplementedException();
 }
コード例 #30
0
        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());
                }
            }
        }
コード例 #31
0
ファイル: MongoDBRepository.cs プロジェクト: ramkumar013/ECMS
 public override ContentItemHead GetHeadContentByViewName(ValidUrl url_, ContentViewType viewType_)
 {
     throw new NotImplementedException();
     //_db.GetCollection<ContentItem>(COLLNAME).AsQueryable().Where(x=>x.ViewType==viewType_ && x.)
 }
コード例 #32
0
 public abstract ContentItem GetByUrl(ValidUrl url_, ContentViewType viewType_);
コード例 #33
0
 public abstract ContentItemHead GetHeadContentByViewName(ValidUrl url_, ContentViewType viewType_);
コード例 #34
0
ファイル: MongoDBRepository.cs プロジェクト: ramkumar013/ECMS
 public override ContentItemHead GetHeadContentByViewName(ValidUrl url_, ContentViewType viewType_)
 {
     throw new NotImplementedException();
     //_db.GetCollection<ContentItem>(COLLNAME).AsQueryable().Where(x=>x.ViewType==viewType_ && x.)
 }
コード例 #35
0
 public abstract ContentItem GetContentForEditing(ValidUrl url_, ContentViewType viewType_);
コード例 #36
0
 public override ContentItem GetByUrl(ValidUrl url_, ContentViewType viewType_)
 {
     throw new NotImplementedException();
 }
コード例 #37
0
 public abstract void Save(ContentItem content_, ContentViewType viewType_);
コード例 #38
0
ファイル: MongoDBRepository.cs プロジェクト: ramkumar013/ECMS
        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;
        }