예제 #1
0
        private void SeedOtherPages(string siteId, string homePageId)
        {
            var otherPages = _dbContext.Pages.Where(x => x.SiteId == siteId && x.Id != homePageId).ToList();

            foreach (var page in otherPages)
            {
                // Init published version and content tree
                var publishedVersion = new ContentVersion
                {
                    ContentId    = page.Id,
                    ContentType  = HtmlDbSeedConstants.ContentType_SitePage,
                    VersionLabel = "Master Page Content Added",
                    UserId       = "admin",
                    Status       = ContentStatus.Published,
                };

                var contentTree = new ContentTree(publishedVersion);

                _dbContext.ContentVersions.Add(publishedVersion);
                _dbContext.ContentTrees.Add(contentTree);
                _dbContext.SaveChanges();

                // build generic tree content
                SeedGenericTreeContent(contentTree, page);
            }
        }
예제 #2
0
        public void Parse(ContentTree contentTree)
        {
            //var json = Json.Encode(contentTree);

            foreach (var composition in contentTree.Compositions)
            {
                CreateContentType(composition);
            }

            foreach (var contentType in contentTree.ContentTypes)
            {
                CreateContentType(contentType);
            }

            foreach (var file in contentTree.SupportingFiles)
            {
                CreateFile(file);
            }

            foreach (var page in contentTree.Content)
            {
                if (page.Parent == 0)
                {
                    page.Parent = contentTree.Content.Single(p => p.Name == page.ParentName).Id;
                }

                if (page.Parent != 0)
                {
                    CreatePage(page);
                }
            }
        }
예제 #3
0
        public async Task <ContentVersion> CreateInitialVersion(Page page, IEnumerable <string> seedFiles = null)
        {
            var initialVersion = new ContentVersion
            {
                ContentId    = page.Id,
                ContentType  = _pageContentType,
                VersionLabel = "Initial Version",
                Status       = ContentStatus.Published,
                UserId       = "system",
            };

            var contentTree = new ContentTree(initialVersion);

            _db.ContentVersions.Add(initialVersion);
            _db.ContentTrees.Add(contentTree);

            await _db.SaveChangesAsync();

            if (seedFiles != null && seedFiles.Count() > 0)
            {
                var treeBuilder = _contentManager.CreateTreeBuilder(contentTree);

                foreach (var filePath in seedFiles)
                {
                    treeBuilder.SeedFromFile(filePath);
                }

                treeBuilder.SaveChanges();
            }

            return(initialVersion);
        }
예제 #4
0
        /// <summary>
        /// Registers JavaScript for the contentTree
        /// </summary>
        private void RenderJS()
        {
            StringBuilder sb = new StringBuilder();

            ContentTree.RenderJS(ref sb);
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "treeJS", sb.ToString(), true);
        }
예제 #5
0
        public static MvcHtmlString ContentTreeView(ContentTree contentItems)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append($"<ol class=\"{Constants.AdminCssClasses.cContentTreeClass}\">");

            foreach (var item in contentItems.ContentTreeNodes)
            {
                sb.Append($"<li class=\"{Constants.AdminCssClasses.cFolderItemClass}\">{item.NodeName}");

                if (item.HasChildren())
                {
                    sb.Append("<ol>");
                    foreach (var childItem in item.ChildNodes)
                    {
                        sb.Append($"<li class=\"{Constants.AdminCssClasses.cDefaultFileClass}\">{childItem.DisplayName}</li>");
                    }
                    sb.Append("</ol></li>");
                }
                else
                {
                    sb.Append("</li>");
                }
            }

            sb.Append("</ol>");

            return(MvcHtmlString.Create(sb.ToString()));
        }
예제 #6
0
    public static TreeNode <Category> Generate(ContentTree source)
    {
        var root = new TreeNode <Category>(BuildNew("Free content pack"));

        foreach (var qp in source.QuestionPacks)
        {
            var cat   = BuildNew(qp.Name);
            var child = root.AddChild(cat);

            foreach (var subchilds in qp.Childs)
            {
                var subcat = BuildNew(subchilds.Name);
                foreach (var final in subchilds.QuestionsGroup)
                {
                }
            }
        }
        string[] type1 = { "Kindergarden", "MiddleSchool", "High School" };
        string[] type2 = { "math", "sport", "music" };
        foreach (var entry in type1)
        {
            var cat   = BuildNew(entry);
            var child = root.AddChild(cat);

            foreach (var matiere in type2)
            {
                var subcat = BuildNew(matiere);
                subcat.QuestionPack = GenerateQp();
                child.AddChild(subcat);
            }
        }

        return(root);
    }
예제 #7
0
        public ContentTree GetContentTree()
        {
            ContentTree contentTree = new ContentTree();

            List<Item> contentItems = _itemRepository.GetAll().ToList();

            if (contentItems == null)
                return null;

            ParentNode parentNode = null;

            contentTree.ContentTreeNodes = new List<ParentNode>();

            foreach (Item contentItem in contentItems)
            {

                if (contentItem.IsParentItem)
                {
                    parentNode = new ParentNode();

                    parentNode.IsContentNode = contentItem.ParentItemId.HasValue ? false : true;

                    parentNode.NodeName = contentItem.DisplayName;
                    parentNode.NodeId = contentItem.Id;
                    parentNode.ChildNodes = new List<ChildNode>();
                }

                if (contentItem.IsParentItem)
                {
                    foreach (Item childNode in contentItems)
                    {
                        if (parentNode != null)
                        {
                            if (childNode.ParentItemId.HasValue )
                            {
                                if (childNode.ParentItemId.Value == parentNode.NodeId)
                                {
                                    ChildNode node = new ChildNode();

                                    node.Id = childNode.Id;
                                    node.ParentItemId = childNode.ParentItemId.Value;
                                    node.ItemTypeId = childNode.ItemTypeId;
                                    node.ItemName = childNode.ItemName;
                                    node.DisplayName = childNode.DisplayName;
                                    node.Created = childNode.Created;
                                    node.ContentOwner = childNode.ContentOwner;

                                    parentNode.ChildNodes.Add(node);
                                }
                            }
                        }
                    }

                    contentTree.ContentTreeNodes.Add(parentNode);
                }
            }

            return contentTree;
        }
예제 #8
0
 public ContentRoute(IContentTreeProvider contentTreeProvider)
     : base(string.Empty, new MvcRouteHandler())
 {
     contentTree = contentTreeProvider.GetContentTree();
     Url = GetUrlPattern();
     Constraints = GetConstraints();
     Defaults = GetDefaults();
 }
예제 #9
0
 public ContentTree DuplicateTree(ContentTree Model, string UserID)
 {
     using (var _c = db)
     {
         var _CPToDuplicate = _c.ContentProperties.Where(m => m.ContentPropertyID == Model.ContentPropertyID).SingleOrDefault();
         Can(_CPToDuplicate.SiteID, UserID, _c);
         int _CPID  = Duplicate(Model.ContentPropertyID, _CPToDuplicate.ContentPropertyParentID, false);
         var _Model = new List <ContentProperty>();
         _Model.Add(_c.ContentProperties.Where(m => m.ContentPropertyID == _CPID).SingleOrDefault());
         return(GetTreeOrder(_Model, _CPToDuplicate.ContentPropertyParentID, Model.CultureID, _c)[0]);
     }
 }
예제 #10
0
        private void SyncScrollViewers()
        {
            ContentTree.ApplyTemplate();
            TheGantt.ApplyTemplate();
            ScrollViewer treeSV     = WpfUtility.FindVisualChild <ScrollViewer>(ContentTree);
            ScrollViewer timelineSV = WpfUtility.FindVisualChild <ScrollViewer>(TheGantt);

            if (treeSV != null && timelineSV != null)
            {
                syncher = new ScrollViewerSyncer(treeSV, timelineSV);
            }
        }
예제 #11
0
        public void CreateContentTreeTest()
        {
            var Result = ContentTree.Create("content", "content\\bin", "MyNamespace", "content");

            Assert.IsTrue(Result.Contains("namespace MyNamespace"));
            Assert.IsTrue(Result.Contains("public static partial class content"));

            Assert.IsTrue(Result.Contains("public static partial class Skins"));
            Assert.IsTrue(Result.Contains("public const string _path_ = \"Skins/\";"));
            Assert.IsTrue(Result.Contains("public const string Default = \"Skins/Default\";"));
            Assert.IsTrue(Result.Contains("public const string Normalmap = \"shaders/Normalmap\";"));
            Assert.IsTrue(Result.Contains("public const string stacklogo = \"stacklogo\";"));
            Assert.IsTrue(Result.Contains("public const string stack = \"fonts/stack\";"));
        }
    /// <summary>
    /// OnPreRender event handler
    /// </summary>
    /// <param name="e"></param>
    protected override void OnPreRender(EventArgs e)
    {
        ScriptHelper.RegisterJQuery(Page);

        // Select node
        if (!String.IsNullOrEmpty(SelectNodeScript))
        {
            ScriptHelper.RegisterStartupScript(this, typeof(string), "SelectTreeNode", SelectNodeScript, true);
        }

        // Load data
        ContentTree.ReloadData();

        base.OnPreRender(e);
    }
예제 #13
0
        public ContentTreeBuilder
        (
            ConnectDbContext dbContext,
            WidgetProvider widgetProvider,
            ContentTree contentTree
        )
        {
            _dbContext      = dbContext;
            _widgetProvider = widgetProvider;
            _targetTree     = contentTree;

            if (_targetTree.ContentNodes == null)
            {
                _targetTree.ContentNodes = new List <ContentNode>();
            }
        }
예제 #14
0
        public async Task <ContentTree> CreateContentTree(string contentType, string contentId, string versionCode = null)
        {
            var tree = new ContentTree
            {
                Id           = Guid.NewGuid().ToString("N"),
                ContentId    = contentId,
                ContentType  = contentType,
                VersionCode  = versionCode,
                ContentNodes = new List <ContentNode>()
            };

            _connectDb.ContentTrees.Add(tree);
            await _connectDb.SaveChangesAsync();

            return(tree);
        }
예제 #15
0
        public async Task <ContentVersion> CreateInitialVersion(string pageMasterId, string[] seedFiles)
        {
            var masterPage = await _db.PageMasters
                             .Include(x => x.Site)
                             .AsNoTracking()
                             .FirstOrDefaultAsync(x => x.Id == pageMasterId);

            if (masterPage == null)
            {
                throw new NullReferenceException($"Cannot locate MasterPage {pageMasterId}");
            }

            var publishedVersion = new ContentVersion
            {
                ContentId    = masterPage.Id,
                ContentType  = _contentType,
                VersionLabel = "Initial Version",
                Status       = ContentStatus.Published,
                UserId       = "system",
            };

            var masterPageContent = new ContentTree(publishedVersion);

            _db.ContentVersions.Add(publishedVersion);
            _db.ContentTrees.Add(masterPageContent);

            await _db.SaveChangesAsync();

            if (seedFiles != null && seedFiles.Length > 0)
            {
                var treeBuilder = _contentManager.CreateTreeBuilder(masterPageContent);

                foreach (var filePath in seedFiles)
                {
                    treeBuilder.SeedFromFile(filePath);
                }

                treeBuilder.SaveChanges();
            }

            return(publishedVersion);
        }
예제 #16
0
        private void SeedGenericTreeContent(ContentTree contentTree, Page sitePage)
        {
            var treeBuilder = _contentManager.CreateTreeBuilder(contentTree);

            treeBuilder.AddRootContent("body", new Models.Title
            {
                Text = sitePage.Title
            });

            treeBuilder.AddRootContent("body", content => {
                content.WidgetType = "alert";
                content.ModelName  = "page-seed-notice";
            });

            treeBuilder.AddRootContent("body", content => {
                content.WidgetType = "html";
                content.ModelName  = "lorem-ipsum";
            });

            treeBuilder.SaveChanges();
        }
예제 #17
0
 public IHttpActionResult DuplicateTree(ContentTree Model)
 {
     return(Ok(_ContentService.DuplicateTree(Model, User.Identity.GetUserId())));
 }
예제 #18
0
        protected virtual object GetContentTreeContext([NotNull] ContentTree tree)
        {
            Debug.ArgumentNotNull(tree, nameof(tree));

            return(new ContentTreeContext(tree.ContentTreeView, tree.ContentTreeView.SelectedItems));
        }
예제 #19
0
        private void SeedHomePage(string homePageId)
        {
            // init version & content tree
            var publishedVersion = new ContentVersion
            {
                ContentId    = homePageId,
                ContentType  = HtmlDbSeedConstants.ContentType_SitePage,
                VersionLabel = "Master Page Content Added",
                UserId       = "admin",
                Status       = ContentStatus.Published,
            };

            var contentTree = new ContentTree(publishedVersion);

            _dbContext.ContentVersions.Add(publishedVersion);
            _dbContext.ContentTrees.Add(contentTree);


            // styles
            var topImageStyle = new ContentStyle
            {
                FullWidth       = true,
                BackgroundClass = SiteTemplateConstants.Backgrounds.Default,
            };

            var topGridStyle = new ContentStyle
            {
                BackgroundClass = SiteTemplateConstants.Backgrounds.Default,
                PaddingTop      = SiteTemplateConstants.RootContentPaddingTop,
                PaddingBottom   = SiteTemplateConstants.RootContentPaddingBottom
            };

            var heroUnitStyle = new ContentStyle
            {
                BackgroundClass = SiteTemplateConstants.Backgrounds.Fancy,
                PaddingTop      = SiteTemplateConstants.RootContentPaddingTop,
                PaddingBottom   = SiteTemplateConstants.RootContentPaddingBottom
            };

            var bottomGridStyle = new ContentStyle
            {
                BackgroundClass = SiteTemplateConstants.Backgrounds.Contrast,
                PaddingTop      = SiteTemplateConstants.RootContentPaddingTop,
                PaddingBottom   = SiteTemplateConstants.RootContentPaddingBottom
            };


            // content nodes
            var homePageContentNodes = new ContentNode[]
            {
                // full width zone with image
                new ContentNode(topImageStyle)
                {
                    Id            = Guid.NewGuid().ToString(),
                    ContentTreeId = contentTree.Id,
                    Zone          = "body",
                    Index         = 0,
                    WidgetId      = HtmlDbSeedConstants.WidgetId_Image_GuidanceImageMain,
                    WidgetType    = "image",
                    ViewId        = "image-fitted",
                    Locked        = false,
                },

                // Hero Unit
                new ContentNode(heroUnitStyle)
                {
                    Id            = Guid.NewGuid().ToString(),
                    ContentTreeId = contentTree.Id,
                    ParentId      = null,
                    Zone          = "body",
                    Index         = 1,
                    WidgetId      = null,
                    WidgetType    = "zone",
                    ViewId        = "zone-1",
                    Locked        = false,

                    ChildNodes = new ContentNode[]
                    {
                        new ContentNode
                        {
                            Id            = Guid.NewGuid().ToString(),
                            ContentTreeId = contentTree.Id,
                            Zone          = "cell-1",
                            Index         = 1,
                            WidgetId      = HtmlDbSeedConstants.WidgetId_Hero_GuidanceWelcome,
                            WidgetType    = "hero",
                            ViewId        = "hero-hero1",
                            Locked        = false,
                        }
                    }
                },

                // 4 images in a grid
                new ContentNode(topGridStyle)
                {
                    Id            = Guid.NewGuid().ToString(),
                    ContentTreeId = contentTree.Id,
                    ParentId      = null,
                    Zone          = "body",
                    Index         = 2,
                    WidgetId      = null,
                    WidgetType    = "zone",
                    ViewId        = "zone-3",
                    Locked        = false,

                    ChildNodes = new ContentNode[]
                    {
                        new ContentNode
                        {
                            Id            = Guid.NewGuid().ToString(),
                            ContentTreeId = contentTree.Id,
                            Zone          = "cell-1",
                            Index         = 0,
                            WidgetId      = HtmlDbSeedConstants.WidgetId_Image_GuidanceImage1,
                            WidgetType    = "image",
                            ViewId        = "image-fitted",
                            Locked        = false
                        },
                        new ContentNode
                        {
                            Id            = Guid.NewGuid().ToString(),
                            ContentTreeId = contentTree.Id,
                            Zone          = "cell-2",
                            Index         = 1,
                            WidgetId      = HtmlDbSeedConstants.WidgetId_Image_GuidanceImage2,
                            WidgetType    = "image",
                            ViewId        = "image-fitted",
                            Locked        = false
                        },
                        new ContentNode
                        {
                            Id            = Guid.NewGuid().ToString(),
                            ContentTreeId = contentTree.Id,
                            Zone          = "cell-3",
                            Index         = 2,
                            WidgetId      = HtmlDbSeedConstants.WidgetId_Image_GuidanceImage3,
                            WidgetType    = "image",
                            ViewId        = "image-fitted",
                            Locked        = false
                        }
                    }
                },
            };


            _dbContext.ContentNodes.AddRange(homePageContentNodes);
            _dbContext.SaveChanges();
        }
예제 #20
0
        public void LoadConfigration()
        {
            try
            {
                Logger.Information("SiteRouteInfo", "{0} LoadConfigration start", this.Domain.DistinctName);
                ContentTree tree = ContentTree.GetByDistinctName(this.Domain.DistinctName, this.Domain.TemplateDomainDistinctName, false);
                if (tree != null)
                {
                    RouteCollection routeCollection = new RouteCollection();
                    Dictionary <string, RouteExtraInfo> routeExtraInfos = new Dictionary <string, RouteExtraInfo>(StringComparer.InvariantCultureIgnoreCase);

                    Type[] types = ControllerEx.GetControllerAssembly().GetTypes();

                    foreach (KeyValuePair <string, ContentNode> item in tree.AllNodes)
                    {
                        ContentNode node = item.Value;
                        if (node.NodeType == ContentNode.ContentNodeType.Page)
                        {
                            PageNode pageNode = new PageNode(node);

                            if (string.IsNullOrWhiteSpace(pageNode.Controller))
                            {
                                continue;
                            }

                            // Get the controller class
                            Type controllerType = types.FirstOrDefault(t => t.FullName == pageNode.Controller);

                            if (controllerType == null)
                            {
                                Logger.Error("CMS", "Error, can't find the type [{0}].", pageNode.Controller);
                                continue;
                            }
                            else
                            {
                                object[] attributes = controllerType.GetCustomAttributes(typeof(ControllerExtraInfoAttribute), false);
                                ControllerExtraInfoAttribute attribute = null;
                                if (attributes.Length > 0)
                                {
                                    attribute = attributes[0] as ControllerExtraInfoAttribute;
                                }
                                else
                                {
                                    attribute = new ControllerExtraInfoAttribute()
                                    {
                                        DefaultAction = "Index"
                                    }
                                };

                                string url = pageNode.ContentNode.RelativePath;
                                if (!url.StartsWith("/"))
                                {
                                    url = "/" + url;
                                }
                                url = url.TrimEnd('/');

                                RouteExtraInfo extraInfo = new RouteExtraInfo();
                                extraInfo.RouteName = pageNode.RouteName;
                                extraInfo.RouteUrl  = string.Format("{0}/{{action}}/{1}", url.TrimStart('/').TrimEnd('/'), attribute.ParameterUrl);
                                Route route = routeCollection.MapRoute(extraInfo.RouteName, extraInfo.RouteUrl);
                                extraInfo.Action = attribute.DefaultAction.DefaultIfNullOrEmpty("Index");
                                route.Defaults.Add("action", extraInfo.Action);
                                extraInfo.Controller = Regex.Replace(controllerType.Name, "(Controller)$", string.Empty, RegexOptions.IgnoreCase | RegexOptions.ECMAScript | RegexOptions.CultureInvariant | RegexOptions.Compiled);
                                route.Defaults.Add("controller", extraInfo.Controller);

                                if (!string.IsNullOrEmpty(attribute.ParameterUrl))
                                {
                                    string[] parameters = attribute.ParameterUrl.Split('/');
                                    foreach (string parameter in parameters)
                                    {
                                        string p = parameter.TrimStart('{').TrimEnd('}');
                                        extraInfo.Parameters.Add(p);
                                        route.Defaults.Add(p, UrlParameter.Optional);
                                    }
                                }
                                extraInfo.Url                 = url;
                                extraInfo.ControllerType      = controllerType;
                                route.DataTokens["RouteName"] = extraInfo.RouteName;

                                routeExtraInfos[extraInfo.RouteName] = extraInfo;
                            } // if_else
                        }     // if
                    }         // foreach

                    this.RouteExtraInfos = routeExtraInfos;
                    this.RouteCollection = routeCollection;

                    ObjectHelper.BinarySerialize <Dictionary <string, RouteExtraInfo> >(routeExtraInfos, GetCacheFilePath());
                }// if

                Logger.Information("SiteRouteInfo", "{0} LoadConfigration completed", this.Domain.DistinctName);
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
            }
        }// LoadConfigration
예제 #21
0
        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //If the user has closed, ignore any results
            if (!this.Visible)
            {
                return;
            }

            if (e.Cancelled)
            {
                this.Close();
            }
            else if (e.Error != null || e.Result == null)
            {
                Exception ex = e.Error;
                if (ex == null)
                {
                    ex = new Exception(Strings.ListBackupFiles.NoDataError);
                }

                MessageBox.Show(this, string.Format(Strings.Common.GenericError, ex.ToString()), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
            else
            {
                try
                {
                    ContentTree.BeginUpdate();
                    KeyValuePair <IList <string>, List <KeyValuePair <Library.Main.RSync.RSyncDir.PatchFileType, string> > > res = (KeyValuePair <IList <string>, List <KeyValuePair <Library.Main.RSync.RSyncDir.PatchFileType, string> > >)e.Result;

                    IList <string> sourcefolders = res.Key;
                    List <KeyValuePair <Library.Main.RSync.RSyncDir.PatchFileType, string> > entries = res.Value;

                    List <string> addedfolders        = new List <string>();
                    List <string> removedfolders      = new List <string>();
                    List <string> addedOrUpdatedfiles = new List <string>();
                    List <string> updatedfiles        = new List <string>();
                    List <string> addedfiles          = new List <string>();
                    List <string> incompletefiles     = new List <string>();
                    List <string> deletedfiles        = new List <string>();
                    List <string> controlfiles        = new List <string>();

                    foreach (KeyValuePair <Library.Main.RSync.RSyncDir.PatchFileType, string> x in entries)
                    {
                        switch (x.Key)
                        {
                        case Duplicati.Library.Main.RSync.RSyncDir.PatchFileType.AddedFolder:
                            addedfolders.Add(x.Value);
                            break;

                        case Duplicati.Library.Main.RSync.RSyncDir.PatchFileType.DeletedFolder:
                            removedfolders.Add(x.Value);
                            break;

                        case Duplicati.Library.Main.RSync.RSyncDir.PatchFileType.AddedOrUpdatedFile:
                            addedOrUpdatedfiles.Add(x.Value);
                            break;

                        case Duplicati.Library.Main.RSync.RSyncDir.PatchFileType.AddedFile:
                            addedfiles.Add(x.Value);
                            break;

                        case Duplicati.Library.Main.RSync.RSyncDir.PatchFileType.UpdatedFile:
                            updatedfiles.Add(x.Value);
                            break;

                        case Duplicati.Library.Main.RSync.RSyncDir.PatchFileType.IncompleteFile:
                            incompletefiles.Add(x.Value);
                            break;

                        case Duplicati.Library.Main.RSync.RSyncDir.PatchFileType.ControlFile:
                            controlfiles.Add(x.Value);
                            break;

                        case Duplicati.Library.Main.RSync.RSyncDir.PatchFileType.DeletedFile:
                            deletedfiles.Add(x.Value);
                            break;
                        }
                    }


                    addedfolders.Sort();
                    removedfolders.Sort();
                    deletedfiles.Sort();
                    addedOrUpdatedfiles.Sort();
                    addedfiles.Sort();
                    updatedfiles.Sort();
                    incompletefiles.Sort();
                    controlfiles.Sort();

                    foreach (string s in addedfolders)
                    {
                        AddTreeItem(s, NEW_FOLDER_IMAGE_KEY);
                    }
                    foreach (string s in removedfolders)
                    {
                        AddTreeItem(s, REMOVED_FOLDER_IMAGE_KEY);
                    }
                    foreach (string s in addedOrUpdatedfiles)
                    {
                        AddTreeItem(s, ADDED_OR_MODIFIED_FILE_IMAGE_KEY);
                    }
                    foreach (string s in addedfiles)
                    {
                        AddTreeItem(s, ADDED_FILE_IMAGE_KEY);
                    }
                    foreach (string s in updatedfiles)
                    {
                        AddTreeItem(s, MODIFIED_FILE_IMAGE_KEY);
                    }
                    foreach (string s in incompletefiles)
                    {
                        AddTreeItem(s, INCOMPLETE_FILE_IMAGE_KEY);
                    }
                    foreach (string s in controlfiles)
                    {
                        AddTreeItem(s, CONTROL_FILE_IMAGE_KEY);
                    }
                    foreach (string s in deletedfiles)
                    {
                        AddTreeItem(s, DELETED_FILE_IMAGE_KEY);
                    }

                    //Patch display to show actual source folder rather than the internal enumeration system
                    if (sourcefolders != null && sourcefolders.Count > 1)
                    {
                        foreach (TreeNode t in ContentTree.Nodes)
                        {
                            int ix;
                            if (int.TryParse(t.Text, out ix))
                            {
                                if (ix >= 0 && ix < sourcefolders.Count)
                                {
                                    t.Text = sourcefolders[ix];
                                }
                            }
                        }
                    }
                }
                finally
                {
                    ContentTree.EndUpdate();
                    ContentPanel.Visible = true;
                }
            }
        }
예제 #22
0
        public async Task <ContentTree> CloneContentTree(string treeId, string newVersionCode)
        {
            // Use No Tracking since we'll be inserting a new content tree, not updating the source
            var sourceTree = await _connectDb.ContentTrees
                             .AsNoTracking()
                             .Include(x => x.ContentNodes)
                             .FirstOrDefaultAsync(x => x.Id == treeId);

            var sourceNodes = sourceTree.ContentNodes.ToList();
            var nodeKeyMap  = new Dictionary <string, string>();

            if (sourceTree == null)
            {
                throw new NullReferenceException($"Could not locate a record for version id: {treeId}");
            }

            // Initialize the cloned tree
            var clonedTree = new ContentTree
            {
                Id           = Guid.NewGuid().ToString("N"),
                ContentType  = sourceTree.ContentType,
                ContentId    = sourceTree.ContentId,
                VersionCode  = newVersionCode,
                ContentNodes = new List <ContentNode>()
            };

            // Clone the content node structure
            foreach (var node in sourceNodes)
            {
                // Generate a new node key and track old id
                var newNodeId = Guid.NewGuid().ToString("N");

                nodeKeyMap.Add(node.Id, newNodeId);
                node.Id = newNodeId;

                // Instruct the underlying provider to clone a new content instance
                var clonedWidget = _widgetProvider.CloneSettings(node.WidgetType, node.WidgetId);

                // Some content types have static or null models, thus return null clones.
                // This is expected behavior and should result in a null mapping value
                node.WidgetId = clonedWidget?.Id;
            }

            // 2nd pass (efficient) to update parent Ids using the node map
            foreach (var node in sourceNodes)
            {
                if (node.ParentId != null && nodeKeyMap.ContainsKey(node.ParentId))
                {
                    node.ParentId = nodeKeyMap[node.ParentId];
                }
            }

            clonedTree.ContentNodes.AddRange(sourceTree.ContentNodes);

            //TODO: Wrap in transaction to ensure data integrity
            _connectDb.ContentTrees.Add(clonedTree);

            await _connectDb.SaveChangesAsync();

            return(clonedTree);
        }
예제 #23
0
 public ContentTreeBuilder CreateTreeBuilder(ContentTree contentTree)
 {
     return(new ContentTreeBuilder(_connectDb, _widgetProvider, contentTree));
 }