VersioningController.cs :  » Content-Management-Systems-CMS » Kooboo » Everest » CmsServices » Controllers » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » Kooboo 
Kooboo » Everest » CmsServices » Controllers » VersioningController.cs
/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.

This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

using Everest.Library;
using Everest.Library.Mvc;
using Everest.Library.Extjs;
using Everest.Library.Data.Entity;
using Everest.Library.Json;
using Everest.Library.ExtensionMethod;
using Everest.Library.Versioning;

using Everest.CmsServices.Services;
using Everest.CmsServices.Models;

namespace Everest.CmsServices.Controllers{
    public class VersioningController : CmsExtController
    {
        IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
        IVersioning versioning = UnityManager.Resolve<IVersioning>();
        /// <summary>
        /// Gets the history list.
        /// </summary>
        /// <param name="uuid">The UUID.</param>
        /// <returns></returns>
        public ActionResult GetHistory(Guid uuid)
        {
            var histories = versioning.GetVersions(uuid);
            return Json(new ExtJsonReaderObject(histories.Select(v => new
            {
                v.CheckinComment,
                v.CheckinUser,
                v.CheckoutBy,
                v.CheckoutComment,
                v.DateTime,
                v.Revision,
                v.UUID,
                v.SnapshotFormName
            }), histories.Count()));
        }

        #region Get Snapshot

        /// <summary>
        /// Gets the snapshot.
        /// </summary>
        /// <param name="uuid">The UUID.</param>
        /// <param name="revision">The revision.</param>
        /// <returns></returns>
        public ActionResult GetSnapshot(Guid uuid, int revision)
        {
            JsonResultData resultData = new JsonResultData();
            IVersionItem versionItem = versioning.GetVersion(uuid, revision);
            object o = versionItem.GetObject();

            switch (o.GetType().ToString())
            {
                case "Everest.CmsServices.Models.Cms_Schema":
                    resultData.data = GetSchemaSnapshotData((Cms_Schema)o);
                    break;
                case "Everest.CmsServices.Models.Cms_Validator":
                    resultData.data = GetValidatorData((Cms_Validator)o);
                    break;
                case "Everest.CmsServices.Models.Cms_ContentTemplate":
                    resultData.data = GetContentTemplateSnapshotData((Cms_ContentTemplate)o);
                    break;
                case "Everest.CmsServices.Models.Cms_PageTemplate":
                    resultData.data = GetPageTemplateSnapshotData((Cms_PageTemplate)o);
                    break;
                case "Everest.CmsServices.Models.Cms_Content":
                    resultData.data = GetContentSnapshotData((Cms_Content)o);
                    break;
                case "Everest.CmsServices.Models.Cms_Page":
                    resultData.data = GetPageSnapshotData((Cms_Page)o);
                    break;
                default:
                    resultData.data = o;
                    break;
            }
            return Json(resultData);
        }
        private object GetPageSnapshotData(Cms_Page page)
        {
            return new
            {
                page.UUID,
                page.PageId,
                page.PageName,
                PageTemplate = page.Cms_PageTemplate.Name,
                page.Url,
                Application = CachedData.GetApplication(page.aspnet_Applications.ApplicationId).ApplicationName,
                page.ShowInNavigation,
                page.NavigationText,
                page.NavigationOrder,
                page.Denies,
                page.Allows,
                Parent = page.Cms_ParentPage == null ? string.Empty : page.Cms_ParentPage.PageName,
                DataRules = page.Cms_DataRule.ToDataRuleQuery(),
                Plugins = page.Cms_Plugin.Select(p => new
                {
                    p.PluginId,
                    p.PluginName,
                    p.PluginType
                }).ToArray(),
                ContentTemplateInPage = page.Cms_ContentTemplateInPageHolder.Select(c => new
                {
                    ContentTemplateInPageHolderId = c.ContentTemplateInHolderId,
                    c.Position,
                    ContentTemplate = string.IsNullOrEmpty(c.ComponentValue) ? c.Cms_ContentTemplate.ContentTemplateId.ToString() : c.ComponentValue,
                    Order = c.Order
                }),
                page.DefaultParams
            };
        }
        /// <summary>
        /// Gets the content snapshot data.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <returns></returns>
        private object GetContentSnapshotData(Cms_Content content)
        {
            if (content.Cms_Schema == null || (SchemaType)content.Cms_Schema.SchemaType == SchemaType.Text)
            {
                #region TextContent
                IDictionary<string, object> contentSnapshotData = new Dictionary<string, object>(content.ContentFieldValues);

                //add attachments
                var binaryContents = content.ContentFiles.Where(f => f.BinaryContent != null).Select(f => f.BinaryContent.UUID).ToArray();
                contentSnapshotData.Add("BinaryContents", string.Join(",", binaryContents.Select(v => v.ToString()).ToArray()));

                var fileAttachments = content.ContentFiles.Where(f => f.BinaryContent == null).Select(f => new
                {
                    f.ContentFileId,
                    f.FileUrl
                });
                contentSnapshotData.Add("Attachments", fileAttachments.ToArray());

                //add referencing contents
                var referencingContentsId = content.Cms_ContentReferencing.Select(cf => cf.Cms_ReferencedContent.UUID).ToArray();
                contentSnapshotData.Add("ReferenceContents", string.Join(",", referencingContentsId.Select(v => v.ToString()).ToArray()));

                //add subject
                contentSnapshotData.Add("Title", content.Title);

                contentSnapshotData.Add("UserKey", content.UserKey);
                //add uuid
                contentSnapshotData.Add("UUID", content.UUID);

                if (!contentSnapshotData.ContainsKey("ContentId"))
                {
                    contentSnapshotData.Add("ContentId", content.ContentId);
                }
                if (content.Cms_Folder != null)
                {
                    contentSnapshotData.Add("FolderUUID", content.Cms_Folder.UUID);
                }
                if (content.aspnet_Applications != null)
                {
                    contentSnapshotData.Add("Application", CachedData.GetApplication(content.aspnet_Applications.ApplicationId).ApplicationName);
                }

                return contentSnapshotData;
                #endregion
            }
            else
            {
                #region BinaryContent
                return new
                {
                    Application = content.aspnet_Applications.ApplicationName,
                    UUID = content.UUID,
                    ContentId = content.ContentId,
                    Title = content.Title,
                    FilePath = content.Cms_BinaryContent.FilePath,
                    ContentStatus = content.ContentStatus,
                    FolderUUID = content.Cms_Folder.UUID,
                    FileUrl = Everest.Library.Web.UrlConvertor.PathToUrl(content.Cms_BinaryContent.FilePath)
                };
                #endregion
            }

        }
        /// <summary>
        /// Gets the page template snapshot data.
        /// </summary>
        /// <param name="pageTemplate">The page template.</param>
        /// <returns></returns>
        private object GetPageTemplateSnapshotData(Cms_PageTemplate pageTemplate)
        {
            object jsonData = new
            {
                pageTemplate.UUID,
                Id = pageTemplate.PageTemplateId,
                Name = pageTemplate.Name,
                Body = pageTemplate.Body,
                pageTemplate.Thumbnail,
                ModifiedDate = pageTemplate.ModifiedDate
            };
            return jsonData;
        }
        /// <summary>
        /// Structs the content template snapshot data.
        /// </summary>
        /// <param name="contentTemplate">The content template.</param>
        /// <returns></returns>
        private object GetContentTemplateSnapshotData(Cms_ContentTemplate contentTemplate)
        {
            object jsonData = new
            {
                contentTemplate.UUID,
                Id = contentTemplate.ContentTemplateId,
                Name = contentTemplate.Name,
                Body = contentTemplate.Body,
                contentTemplate.Description,
                Parameters = contentTemplate.Cms_ContentTemplateParameters.Select(p => new
                {
                    p.ParameterId,
                    p.Name,
                    p.DataType
                }).ToArray(),
                DataRules = contentTemplate.Cms_DataRule.ToDataRuleQuery(),
                Plugins = contentTemplate.Cms_Plugin.Select(p => new
                {
                    p.PluginId,
                    p.PluginName,
                    p.PluginType
                }).ToArray()
            };
            return jsonData;
        }
        /// <summary>
        /// Structs the validator data.
        /// </summary>
        /// <param name="validator">The validator.</param>
        /// <returns></returns>
        private object GetValidatorData(Cms_Validator validator)
        {
            return new
            {
                validator.UUID,
                ValidatorId = validator.ValidatorId,
                ValidatorName = validator.ValidatorName,
                Function = validator.Function
            };
        }
        /// <summary>
        /// Schemas the snapshot data.
        /// </summary>
        /// <param name="schema">The schema.</param>
        /// <returns></returns>
        private object GetSchemaSnapshotData(Cms_Schema schema)
        {
            if ((SchemaType)schema.SchemaType == SchemaType.Text)
            {
                List<DetailColumn> columns = new List<DetailColumn>();
                foreach (var item in schema.Cms_Column)
                {
                    var detailColumn = new DetailColumn()
                    {
                        ColumnId = item.ColumnId,
                        ColumnName = item.ColumnName,
                        Label = item.Label,
                        DataType = item.DataType,
                        AllowNull = item.AllowNull,
                        Length = item.Length,
                        Order = item.Order,
                        Queryable = item.Queryable,
                        Modifiable = item.Modifiable,
                        ControlType = item.ControlType,
                        Items = item.Items,
                        DefaultValue = item.DefaultValue,
                        //ValidatorGroup = item.Cms_ValidatorGroup.ValidateGroupId,
                        //RefrenceSchemaId = item.Cms_RefrencedSchema.SchemaId,
                        //RefrenceNameColumnId = item.Cms_RefrencedColumn.ColumnId,
                        IntSortOrder = item.SortOrder,
                        Indexable = item.Indexable,
                        VisibleInList = item.VisibleInList,
                        OriginalUUID = item.OriginalUUID,
                        VType = item.VType,
                        Tpl = item.Tpl,
                        Tooltip = item.Tooltip
                    };
                    if (item.Cms_ValidatorGroup != null)
                    {
                        item.Cms_ValidatorGroup.aspnet_ApplicationsReference.Load(item.Cms_ValidatorGroup.aspnet_Applications, item.EntityState);
                        detailColumn.ValidatorGroupUniqueName = new UniqueName(item.Cms_ValidatorGroup.aspnet_Applications.ApplicationName, item.Cms_ValidatorGroup.ValidateGroupName);
                    }
                    columns.Add(detailColumn);
                }
                List<object> functions = new List<object>();
                foreach (var item in schema.Cms_SchemaFunction)
                {
                    functions.Add(new
                    {
                        item.Name,
                        item.Script,
                        item.FormType
                    });
                }

                Cms_Folder textSchemaFolder = CachedData.GetFolder(schema.aspnet_Applications.ApplicationName, FolderType.TextSchema);

                object jsonData = new
                {
                    UUID = schema.UUID,
                    SchemaId = schema.SchemaId,
                    SchemaName = schema.SchemaName,
                    schema.IncludeUserKey,
                    schema.FileUploadable,
                    schema.Extensions,
                    schema.BinarySchemas,
                    textSchemaFolder.FolderId,
                    FolderUUID = textSchemaFolder.UUID,
                    Application = schema.aspnet_Applications.ApplicationName,//for combobox 
                    schema.ChildSchemas,
                    schema.ReferencingSchemas,
                    Columns = columns,
                    Functions = functions
                };
                return jsonData;
            }
            else
            {
                return new
                {
                    schema.UUID,
                    SchemaId = schema.SchemaId,
                    SchemaName = schema.SchemaName,
                    ModifiedDate = schema.ModifiedDate,
                    UserName = schema.UserName,
                    schema.Extensions,
                    MaxSize = schema.MaxSize
                };
            }
        }


        #endregion

        /// <summary>
        /// Reverts the specified UUID.
        /// </summary>
        /// <param name="uuid">The UUID.</param>
        /// <param name="revision">The revision.</param>
        /// <param name="comment">The comment.</param>
        /// <returns></returns>
        public ActionResult Revert(Guid uuid, int revision, string comment)
        {
            JsonResultData resultData = new JsonResultData();
            versioning.Revert(uuid, User.Identity.Name, revision, comment);
            return Json(resultData);
        }
    }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.