Ejemplo n.º 1
0
 protected override void CheckIsBeingUsed(Models.View item)
 {
     if (!item.HasParentVersion() && Relations(item).Count() > 0)
     {
         throw new KoobooException(string.Format("'{0}' is being used.".Localize(), item.Name));
     }
 }
Ejemplo n.º 2
0
        public void SaveFav(int UserID, int segID)
        {
            var DataContext = new DataClasses1DataContext();


            var segct = from u in DataContext.Views
                        where u.UserID == UserID
                        where u.SegID == segID
                        select u;

            if (segct.Count() > 0)
            {
                var sc = db.Views
                         .Where(s => s.SegID == segID)
                         .First();

                datarepo.Delete(sc);
            }
            else
            {
                //save new
                View vnew = new Models.View();
                vnew.SegID  = segID;
                vnew.UserID = UserID;
                // vnew.Timestamp = DateTime.Now
                datarepo.Add(vnew);
                datarepo.Save();
            }
        }
Ejemplo n.º 3
0
 public IEnumerable <Page> ByView(Models.View view)
 {
     return(AllPagesNested(view.Site).Select(it => it.AsActual())
            .Where(it => it.PagePositions != null &&
                   it.PagePositions.Any(p => p is ViewPosition && ((ViewPosition)p).ViewName.EqualsOrNullEmpty(view.Name, StringComparison.CurrentCultureIgnoreCase)))
            .ToArray());
 }
Ejemplo n.º 4
0
        public virtual ActionResult ExecutePlugins()
        {
            // Execute plugins on page
            var page       = PageRequestContext.Page.AsActual();
            var httpMethod = this.ControllerContext.HttpContext.Request.HttpMethod.ToUpper();

            if (page.Plugins != null)
            {
                foreach (var plugin in page.Plugins)
                {
                    var result = ExecutePlugin(plugin, null, httpMethod);
                    if (result != null)
                    {
                        return(result);
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.PageLayout))
            {
                // Execute plugins on Layout
                var layout = new Layout(this.PageRequestContext.Site, this.PageLayout).LastVersion().AsActual();
                if (layout != null && layout.Plugins != null)
                {
                    foreach (var plugin in layout.Plugins)
                    {
                        var result = ExecutePlugin(plugin, null, httpMethod);
                        if (result != null)
                        {
                            return(result);
                        }
                    }
                }
            }


            // Execute plugins on views
            var viewPositions = page.PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);

            foreach (ViewPosition viewPosition in viewPositions)
            {
                var view = new Models.View(PageRequestContext.Site, viewPosition.ViewName).LastVersion().AsActual();
                if (view != null)
                {
                    if (view.Plugins != null)
                    {
                        var positionContext = new PagePositionContext(view, viewPosition.ToParameterDictionary(), GetPositionViewData(viewPosition.PagePositionId));

                        foreach (var plugin in view.Plugins)
                        {
                            var result = ExecutePlugin(plugin, positionContext, httpMethod);
                            if (result != null)
                            {
                                return(result);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 5
0
        public override void Add(Site site, Models.View o)
        {
            HasSameName(site, o.Name);

            base.Add(site, o);

            VersionManager.LogVersion(o);
        }
Ejemplo n.º 6
0
            public override void Revert(Models.View o, int version)
            {
                var versionData = GetVersion(o, version);

                if (versionData != null)
                {
                    Providers.ViewProvider.Update(versionData, o);
                }
            }
Ejemplo n.º 7
0
 public override void Remove(Site site, Models.View o)
 {
     o.Site = site;
     if (!o.HasParentVersion() && RelationsPages(o).Where(i => i.Site == site).Count() > 0)
     {
         throw new KoobooException(string.Format("'{0}' is being used".Localize(), o.Name));
     }
     base.Remove(site, o);
 }
Ejemplo n.º 8
0
        public string Get(string zoneId)
        {
            int id;

            int.TryParse(zoneId, out id);
            Response.StatusCode = 400;

            using (var db = Db.Instance)
            {
                var where = db.BannersZones.Where(x => x.ZoneId == id);
                var count = where.Count();

                if (count == 0)
                {
                    Response.StatusCode = 404;
                    return("");
                }

                var res = where.Skip(new Random().Next(count)).First();

                if (res == null)
                {
                    return("");
                }

                var banner = db.Banners.Find(res.BannerId);
                var zone   = db.Zones.Find(res.ZoneId);

                var view = new Models.View();

                db.Entry(banner).State = EntityState.Unchanged;
                db.Entry(zone).State   = EntityState.Unchanged;

                view.BannerId  = banner.Id;
                view.Zone      = zone;
                view.UserAgent = Request.Headers["User-Agent"];

                db.Add(view);
                db.SaveChanges();

                var linkBase  = "http://" + Request.Host;
                var clickLink = linkBase + "/api/click/" + view.Id;

                Response.StatusCode = 200;
                return(View("ApiReturn", new Dictionary <string, object>
                {
                    { "layout", "empty" },
                    { "Height", zone.Height },
                    { "Width", zone.Width },
                    { "ClickLink", clickLink },
                    { "Type", banner.Type },
                    { "Html", banner.Html },
                    { "ImageLink", banner.ImageFormat != null ? (linkBase + "/" + FileStorage.GetLink(banner, banner.ImageFormat)) : "" }
                }));
            }
        }
Ejemplo n.º 9
0
 public virtual IEnumerable <Page> RelationsPages(Models.View view)
 {
     if (view.Exists())
     {
         view = view.AsActual();
         var pageRepository = (IPageProvider)Providers.ProviderFactory.GetRepository <IProvider <Page> >();
         return(pageRepository.ByView(view));
     }
     return(new Page[0]);
 }
Ejemplo n.º 10
0
 public void Localize(Models.View o, Models.Site targetSite)
 {
     try
     {
         inner.Localize(o, targetSite);
     }
     finally
     {
         ClearObjectCache(targetSite);
     }
 }
Ejemplo n.º 11
0
        public override IEnumerable <RelationModel> Relations(Models.View view)
        {
            view = view.AsActual();
            var pageRepository = (IPageProvider)Providers.ProviderFactory.GetProvider <IProvider <Page> >();

            return(pageRepository.ByView(view).Select(it => new RelationModel()
            {
                DisplayName = it.FriendlyName,
                ObjectUUID = it.FullName,
                RelationObject = it,
                RelationType = "Page"
            }));
        }
Ejemplo n.º 12
0
            public override void Revert(Models.View o, int version, string userName)
            {
                var versionData = GetVersion(o, version);

                if (versionData != null)
                {
                    versionData.UserName       = userName;
                    versionData.LastUpdateDate = DateTime.UtcNow;
                    Providers.ViewProvider.Update(versionData, o);
                    //log a new version when revert
                    LogVersion(versionData);
                }
            }
Ejemplo n.º 13
0
        private IEnumerable <Models.View> GetViewsInPage(Site site, Page page)
        {
            var viewPositions = page.AsActual().PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);

            foreach (ViewPosition viewPosition in viewPositions)
            {
                var view = new Models.View(site, viewPosition.ViewName).LastVersion();
                if (!view.Exists())
                {
                    throw new KoobooException(string.Format("The view '{0}' does not exists.Name.", view.Name));
                }
                yield return(view);
            }
        }
Ejemplo n.º 14
0
        public virtual void Localize(string name, Site targetSite, string userName = null)
        {
            var target = new Models.View(targetSite, name);
            var source = target.LastVersion();

            if (target.Site != source.Site)
            {
                ((IViewProvider)Provider).Localize(source, targetSite);
                target = target.AsActual();
                if (target != null)
                {
                    target.UserName = userName;
                    Update(targetSite, target, target);
                }
            }
        }
Ejemplo n.º 15
0
 public async void OpenChat(GroupChat chat)
 {
     if (chat.Views != null && chat.Views.Count != 0)
     {
         var list = chat.Views.Where(x => x.UserId == User.Id);
         if (list.Count() != 0)
         {
             var view = new Models.View
             {
                 UserId = User.Id
             };
             await _api.AddViewToGroupChat(view, chat.Id);
         }
     }
     Application.Current.MainPage = new MainPage(new ChatPage(chat));
 }
Ejemplo n.º 16
0
        public Models.View Copy(Site site, string sourceName, string destName)
        {
            GetLocker().EnterWriteLock();

            try
            {
                var sourceView = new Models.View(site, sourceName).LastVersion();
                var destView   = new Models.View(site, destName);

                IOUtility.CopyDirectory(sourceView.PhysicalPath, destView.PhysicalPath);

                return(destView);
            }
            finally
            {
                GetLocker().ExitWriteLock();
            }
        }
Ejemplo n.º 17
0
        public async void OpenChat(GroupChatDisplayModel gcdm)
        {
            var chat = GroupChats.Where(x => x.Id == gcdm.Id).First();

            if (chat.Views != null)
            {
                var list = chat.Views.Where(x => x.UserId == User.Id);
                if (list.Count() != 0)
                {
                    var view = new Models.View
                    {
                        UserId = User.Id
                    };
                    await _api.AddViewToGroupChat(view, chat.Id);
                }
            }
            Application.Current.MainPage = new MainPage(new ChatPage(chat));
        }
Ejemplo n.º 18
0
        public virtual void ExecuteDataRules()
        {
            var pageViewData = ControllerContext.Controller.ViewData;

            var site = PageRequestContext.Site.AsActual();
            var page = PageRequestContext.Page.AsActual();

            var dataRuleContext = new DataRuleContext(PageRequestContext.Site, PageRequestContext.Page)
            {
                ValueProvider = PageRequestContext.GetValueProvider()
            };

            if (page.DataRules != null)
            {
                DataRuleExecutor.Execute(pageViewData, dataRuleContext, page.DataRules);
            }
            var viewPositions = page.PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);

            foreach (ViewPosition viewPosition in viewPositions)
            {
                var view = new Models.View(site, viewPosition.ViewName).LastVersion().AsActual();
                if (view != null)
                {
                    var positionViewData = (ViewDataDictionary)GetPositionViewData(viewPosition.PagePositionId).Merge(pageViewData);
                    var viewDataContext  = new PagePositionContext(view, viewPosition.ToParameterDictionary(), positionViewData);
                    var dataRules        = view.DataRules;
                    if (dataRules != null)
                    {
                        var valueProvider = PageRequestContext.GetValueProvider();
                        valueProvider.Insert(0, new ViewParameterValueProvider(viewDataContext.Parameters));
                        dataRuleContext.ValueProvider = valueProvider;
                        DataRuleExecutor.Execute(positionViewData, dataRuleContext, dataRules);
                    }
                    if (positionViewData.Model == null)
                    {
                        positionViewData.Model = positionViewData.Values.FirstOrDefault();
                    }
                    SetPositionViewData(viewPosition.PagePositionId, positionViewData);
                }
            }
        }
Ejemplo n.º 19
0
        private IEnumerable <DataRuleSetting> AggregateDataRules(Site site, Page page)
        {
            page = page.AsActual();
            IEnumerable <DataRuleSetting> datarules = page.DataRules ?? new List <DataRuleSetting>();

            if (page.PagePositions != null)
            {
                var viewPositions = page.PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);
                foreach (ViewPosition viewPosition in viewPositions)
                {
                    var view = new Models.View(site, viewPosition.ViewName).LastVersion();

                    if (view.Exists())
                    {
                        datarules = datarules.Concat(view.AsActual().DataRules ?? new List <DataRuleSetting>());
                    }
                }
            }

            return(datarules);
        }
Ejemplo n.º 20
0
        public virtual ActionResult ExecutePlugins()
        {
            // Execute plugins on page
            var page = PageRequestContext.Page.AsActual();
            var httpMethod = this.ControllerContext.HttpContext.Request.HttpMethod.ToUpper();
            if (page.Plugins != null)
            {
                foreach (var plugin in page.Plugins)
                {
                    var result = ExecutePlugin(plugin, null, httpMethod);
                    if (result != null)
                    {
                        return result;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.PageLayout))
            {
                // Execute plugins on Layout
                var layout = new Layout(this.PageRequestContext.Site, this.PageLayout).LastVersion().AsActual();
                if (layout != null && layout.Plugins != null)
                {
                    foreach (var plugin in layout.Plugins)
                    {
                        var result = ExecutePlugin(plugin, null, httpMethod);
                        if (result != null)
                        {
                            return result;
                        }
                    }
                }
            }

            // Execute plugins on views
            var viewPositions = page.PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);
            foreach (ViewPosition viewPosition in viewPositions)
            {
                var view = new Models.View(PageRequestContext.Site, viewPosition.ViewName).LastVersion().AsActual();
                if (view != null)
                {
                    if (view.Plugins != null)
                    {
                        var positionContext = new PagePositionContext(view, viewPosition.ToParameterDictionary(), GetPositionViewData(viewPosition.PagePositionId));

                        foreach (var plugin in view.Plugins)
                        {
                            var result = ExecutePlugin(plugin, positionContext, httpMethod);
                            if (result != null)
                            {
                                return result;
                            }
                        }
                    }
                }
            }
            return null;
        }
Ejemplo n.º 21
0
 protected override string GetItemCacheKey(Models.View o)
 {
     return(string.Format("View:{0}", o.Name.ToLower()));
 }
Ejemplo n.º 22
0
 public void Localize(Models.View o, Models.Site targetSite)
 {
     ClearObjectCache(new Models.View(targetSite, o.Name));
     inner.Localize(o, targetSite);
 }
Ejemplo n.º 23
0
 public IEnumerable <Models.Page> ByView(Models.View view)
 {
     return(inner.ByView(view));
 }
Ejemplo n.º 24
0
        public virtual void Localize(string name, Site targetSite)
        {
            var source = new Models.View(targetSite, name).LastVersion();

            ((IViewProvider)Provider).Localize(source, targetSite);
        }
Ejemplo n.º 25
0
        public static Models.View RaiseViewEvent(enumEventType eventtype, RenderContext context, ComponentSetting setting, Models.View view = null)
        {
            if (eventtype == enumEventType.ViewFinding)
            {
                ViewFinding finding = new ViewFinding(context, setting);
                RaiseEvent(context, finding);
                return(finding.View);
            }
            else if (eventtype == enumEventType.ViewFound)
            {
                if (view != null)
                {
                    ViewFound found = new ViewFound(context, setting, view);

                    RaiseEvent(context, found);

                    if (found.DataChange && found.View != null)
                    {
                        return(found.View);
                    }
                }
            }
            else if (eventtype == enumEventType.ViewNotFound)
            {
                ViewNotFound notfound = new ViewNotFound(context, setting);
                RaiseEvent(context, notfound);
                return(notfound.View);
            }
            return(null);
        }
Ejemplo n.º 26
0
        public override void Update(Site site, Models.View @new, Models.View old)
        {
            base.Update(site, @new, old);

            VersionManager.LogVersion(@new);
        }
Ejemplo n.º 27
0
 public PagePositionContext(Models.View view, IDictionary <string, object> parameters, ViewDataDictionary viewData)
 {
     this.View       = view.AsActual();
     this.Parameters = new DynamicDictionary(View.CombineDefaultParameters(parameters));
     this.ViewData   = viewData;
 }
Ejemplo n.º 28
0
        public void SaveFav(int UserID, int segID)
        {

            var DataContext = new DataClasses1DataContext();


            var segct = from u in DataContext.Views
                        where u.UserID == UserID
                        where u.SegID == segID
                        select u;

            if (segct.Count() > 0)
            {
                var sc = db.Views
                 .Where(s => s.SegID == segID)
                 .First();

                datarepo.Delete(sc);
               

            }
            else
            {
                //save new
                View vnew = new Models.View();
                vnew.SegID = segID;
                vnew.UserID = UserID;
               // vnew.Timestamp = DateTime.Now
                datarepo.Add(vnew);
                datarepo.Save();


            }



        

    }
Ejemplo n.º 29
0
 public void Localize(Models.View o, Site targetSite)
 {
     ILocalizableHelper.Localize <Models.View>(o, targetSite);
 }
Ejemplo n.º 30
0
        public virtual void ExecuteDataRules()
        {
            var pageViewData = ControllerContext.Controller.ViewData;

            var site = PageRequestContext.Site.AsActual();
            var page = PageRequestContext.Page.AsActual();

            var dataRuleContext = new DataRuleContext(PageRequestContext.Site, PageRequestContext.Page) { ValueProvider = PageRequestContext.GetValueProvider() };
            if (page.DataRules != null)
            {
                DataRuleExecutor.Execute(pageViewData, dataRuleContext, page.DataRules);
            }
            var viewPositions = page.PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);
            foreach (ViewPosition viewPosition in viewPositions)
            {
                var view = new Models.View(site, viewPosition.ViewName).LastVersion().AsActual();
                if (view != null)
                {
                    var positionViewData = (ViewDataDictionary)GetPositionViewData(viewPosition.PagePositionId).Merge(pageViewData);
                    var viewDataContext = new PagePositionContext(view, viewPosition.ToParameterDictionary(), positionViewData);
                    var dataRules = view.DataRules;
                    if (dataRules != null)
                    {
                        var valueProvider = PageRequestContext.GetValueProvider();
                        valueProvider.Insert(0, new ViewParameterValueProvider(viewDataContext.Parameters));
                        dataRuleContext.ValueProvider = valueProvider;
                        DataRuleExecutor.Execute(positionViewData, dataRuleContext, dataRules);
                    }
                    if (positionViewData.Model == null)
                    {
                        positionViewData.Model = positionViewData.Values.FirstOrDefault();
                    }
                    SetPositionViewData(viewPosition.PagePositionId, positionViewData);
                }
            }
        }
Ejemplo n.º 31
0
 private IEnumerable<Models.View> GetViewsInPage(Site site, Page page)
 {
     var viewPositions = page.AsActual().PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);
     foreach (ViewPosition viewPosition in viewPositions)
     {
         var view = new Models.View(site, viewPosition.ViewName).LastVersion();
         if (!view.Exists())
         {
             throw new KoobooException(string.Format("The view '{0}' does not exists.Name.", view.Name));
         }
         yield return view;
     }
 }
Ejemplo n.º 32
0
 public IQueryable <Models.Page> ByView(Models.View view)
 {
     return(inner.ByView(view));
 }