public IEnumerable <Navigation> GetNavigationItems(string NavPath, string[] NavTypes)
        {
            var NavigationItems = DocumentHelper.GetDocuments <Navigation>()
                                  .OrderBy("NodeLevel, NodeOrder")
                                  .Culture(cultureName)
                                  .CombineWithDefaultCulture()
                                  .CombineWithAnyCulture()
                                  .Published(!latestVersionEnabled)
                                  .LatestVersion(latestVersionEnabled)
                                  .Columns(new string[] {
                "NodeParentID", "NodeID", "NavigationType", "NavigationPageNodeGuid", "NavigationLinkText", "NavigationLinkTarget", "NavigationLinkUrl",
                "NavigationIsMegaMenu", "NavigationLinkCSS", "NavigationLinkOnClick", "NavigationLinkAlt", "NodeAliasPath",
                "IsDynamic", "Path", "PageTypes", "OrderBy", "WhereCondition", "MaxLevel", "TopNumber"
            });

            if (!string.IsNullOrWhiteSpace(NavPath))
            {
                NavigationItems.Path(NavPath.Trim('%'), PathTypeEnum.Section);
            }

            // Handle Nav Type with Categories found
            if (NavTypes != null && NavTypes.Length > 0)
            {
                NavigationItems.Where(RelHelper.GetNodeCategoryWhere(NavTypes));
            }
            return(NavigationItems.TypedResult);
        }
示例#2
0
 private void LogTask_Before(object sender, StagingLogTaskEventArgs e)
 {
     RelHelper.UpdateTaskDataWithNodeBinding(e, new NodeBinding_DocumentLogTaskBefore_Configuration[]
     {
         new NodeBinding_DocumentLogTaskBefore_Configuration(new NodeBazInfo(), nameof(NodeBazInfo.NodeBazNodeID) + " = {0}")
     });
 }
示例#3
0
    /// <summary>
    /// Fires on the grid action.
    /// </summary>
    /// <param name="actionName">Action name</param>
    /// <param name="actionArgument">Action argument</param>
    private void UniGridRelationship_OnAction(string actionName, object actionArgument)
    {
        // Check modify permissions
        if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)
        {
            return;
        }

        switch (actionName.ToLowerInvariant())
        {
        case "delete":
            var relationshipId = actionArgument.ToInteger(0);

            // If parameters are valid
            if (relationshipId > 0)
            {
                // Remove relationship
                RelationshipInfoProvider.RemoveRelationship(relationshipId);
                if (RelHelper.IsStagingEnabled())
                {
                    // Log synchronization
                    DocumentSynchronizationHelper.LogDocumentChange(TreeNode.NodeSiteName, TreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider);
                }
                ShowConfirmation(GetString("relationship.wasdeleted"));
                URLHelper.RefreshCurrentPage();
            }

            break;
        }
    }
        // GET: Polygomy
        public ActionResult Index()
        {
            Polygomy Page = DynamicRouteHelper.GetPage <Polygomy>();

            HttpContext.Kentico().PageBuilder().Initialize(Page.DocumentID);
            // Get Categories
            List <int> PageCategories = TreeCategoryInfoProvider.GetTreeCategories()
                                        .WhereEquals("NodeID", Page.NodeID)
                                        .Select(x => x.CategoryID).ToList();

            PolygomyViewModel model = new PolygomyViewModel()
            {
                MemeCategories = CategoryInfoProvider.GetCategories()
                                 .WhereIn("CategoryID", PageCategories)
                                 .Select(x => x.CategoryDisplayName).ToArray(),
            };

            if (PageCategories.Count > 0)
            {
                model.Memes = MemeProvider.GetMemes()
                              .Where(RelHelper.GetNodeCategoryWhere(PageCategories.Select(x => (object)x)))
                              .ToList();
            }
            return(View("NEWCC/Polygomy", model));
        }
示例#5
0
        private void ProcessTask_After(object sender, StagingSynchronizationEventArgs e)
        {
            List <TaskTypeEnum> DocumentTaskTypes = new List <TaskTypeEnum>()
            {
                TaskTypeEnum.CreateDocument,
                TaskTypeEnum.UpdateDocument
            };

            if (DocumentTaskTypes.Contains(e.TaskType))
            {
                // First table is the Node Data
                DataTable NodeTable = e.TaskData.Tables[0];

                if (NodeTable != null && NodeTable.Columns.Contains("NodeGuid"))
                {
                    // Get node ID
                    TreeNode NodeObj = new DocumentQuery().WhereEquals("NodeGUID", NodeTable.Rows[0]["NodeGuid"]).FirstOrDefault();

                    // Don't want to trigger updates as we set the data in the database, so we won't log synchronziations
                    using (new CMSActionContext()
                    {
                        LogSynchronization = false,
                        LogIntegration = false
                    })
                    {
                        #region "Node Baz (Node object w/out Ordering)"

                        // Get NodeBaz and Handle
                        List <int> BazIDs = RelHelper.NewBoundObjectIDs(e, NodeBazInfo.OBJECT_TYPE, nameof(NodeBazInfo.NodeBazNodeID), nameof(NodeBazInfo.NodeBazBazID), BazInfo.TYPEINFO);

                        // Delete Ones not found
                        NodeBazInfo.Provider.Get().WhereEquals("NodeID", NodeObj.NodeID).WhereNotIn("BazID", BazIDs).ForEachObject(x => x.Delete());

                        // Find ones that need to be added and add
                        List <int> CurrentBazIDs = NodeBazInfo.Provider.Get().WhereEquals(nameof(NodeBazInfo.NodeBazNodeID), NodeObj.NodeID).Select(x => x.NodeBazBazID).ToList();
                        foreach (int NewBazID in BazIDs.Except(CurrentBazIDs))
                        {
                            NodeBazInfo.Provider.Add(NodeObj.NodeID, NewBazID);
                        }

                        #endregion
                    }
                    if (RelHelper.IsStagingEnabled(NodeObj.NodeSiteID))
                    {
                        // Check if we need to generate a task for a server that isn't the origin server
                        RelHelper.CheckIfTaskCreationShouldOccur(NodeObj.NodeGUID);
                    }
                }
                else if (NodeTable == null || !NodeTable.Columns.Contains("NodeGuid"))
                {
                    Service.Resolve <IEventLogService>().LogEvent(EventTypeEnum.Error, "DemoProcessTask", "No Node Table Found", eventDescription: "First Table in the incoming Staging Task did not contain the Node GUID, could not processes.");
                }
            }
        }
示例#6
0
    // USE THE BELOW FOR CREATING OVERRIDES FOR THE OnExternalDataBound of this control so you do not lose the custom display and tooltip!

    /*
     * using CMS;
     * using CMS.Base.Web.UI;
     * using CMS.DataEngine;
     * using CMS.DocumentEngine;
     * using CMS.Helpers;
     * using CMS.Localization;
     * using CMS.MacroEngine;
     * using CMS.SiteProvider;
     * using CMS.UIControls;
     * using My.Classes.Extensions;
     * using System;
     * using System.Collections.Generic;
     * using System.Data;
     * using System.Linq;
     * using System.Text;
     * using System.Threading.Tasks;
     * using System.Web;
     * using System.Web.UI;
     *
     * [assembly: RegisterCustomClass("RelatedPagesCustomUniGridExtension", typeof(RelatedPagesCustomUniGridExtension))]
     * namespace My.Classes.Extensions
     * {
     * public class RelatedPagesCustomUniGridExtension : ControlExtender<UniGrid>
     * {
     *  private string AllowedPageTypes;
     *  private string DisplayNameFormat;
     *  private string ToolTipFormat;
     *
     *  public override void OnInit()
     *  {
     *      Control.OnExternalDataBound += Control_OnExternalDataBound;
     *  }
     *
     *  private object Control_OnExternalDataBound(object sender, string sourceName, object parameter)
     *  {
     *      switch (sourceName.ToLowerInvariant())
     *      {
     *          case "lefnodename":
     *          case "rightnodename":
     *              UniGrid GridObj = GetUniGridControl((Control)sender);
     *              // Retrieve properties from grid's attributes
     *              if(GridObj != null) {
     *                  AllowedPageTypes = ValidationHelper.GetString(GridObj.Attributes["AllowedPageTypes"], "");
     *                  DisplayNameFormat = ValidationHelper.GetString(GridObj.Attributes["DisplayNameFormat"], "");
     *                  ToolTipFormat = ValidationHelper.GetString(GridObj.Attributes["ToolTipFormat"], "");
     *              }
     *              int NodeID = ValidationHelper.GetInteger(parameter, 0);
     *              var NodeObj = new DocumentQuery().WhereEquals("NodeID", NodeID).Columns("NodeID, NodeLevel, NodeName, ClassName").FirstObject;
     *              // Not root and is in the allowed page types
     *              if (GridObj != null && NodeObj.NodeLevel != 0 && (!string.IsNullOrWhiteSpace(ToolTipFormat) || !string.IsNullOrWhiteSpace(DisplayNameFormat)) && AllowedPageTypes.ToLower().Split(";,|".ToCharArray()).Contains(NodeObj.NodeClassName.ToLower()))
     *              {
     *                  string tooltip = null;
     *                  string customName = null;
     *                  ValidationHelper.GetInteger(parameter, 0);
     *                  MacroResolver NodeResolver = GetNodeMacroResolver(NodeObj.NodeID, NodeObj.ClassName);
     *                  if (!string.IsNullOrWhiteSpace(ToolTipFormat))
     *                  {
     *                      tooltip = NodeResolver.ResolveMacros(ToolTipFormat);
     *                  }
     *                  if (!string.IsNullOrWhiteSpace(DisplayNameFormat))
     *                  {
     *                      customName = NodeResolver.ResolveMacros(DisplayNameFormat);
     *                  }
     *                  return string.Format("<div title=\"{0}\" class=\"CustomUniGridEntry\">{1}</div>", HTMLHelper.EncodeForHtmlAttribute(tooltip), (!string.IsNullOrWhiteSpace(customName) ? customName : NodeObj.NodeName));
     *              }
     *              else
     *              {
     *                  var tr = new ObjectTransformation(PredefinedObjectType.NODE, NodeID);
     *                  tr.EncodeOutput = false;
     *                  tr.Transformation = "{%NodeName|(default)" + LocalizationHelper.LocalizeExpression("{$ general.root $}") + "|(encode)%}";
     *                  return tr;
     *              }
     *          case "delete":
     *              var btn = ((CMSGridActionButton)sender);
     *              btn.PreRender += imgDelete_PreRender;
     *              break;
     *          case "mycustomthing":
     *              return "the custom stuff";
     *      }
     *      return parameter;
     *  }
     *
     *  /// <summary>
     *  /// Recursively goes up the current control until it finds a control of type UniGrid
     *  /// </summary>
     *  /// <param name="control">the starting control, usually the "sender" object</param>
     *  /// <returns>The UniGrid Control, or null if not found</returns>
     *  private UniGrid GetUniGridControl(Control control)
     *  {
     *      while(!(control is UniGrid))
     *      {
     *          if(control.Parent != null)
     *          {
     *              control = control.Parent;
     *          } else
     *          {
     *              return null;
     *          }
     *      }
     *      return (UniGrid)control;
     *  }
     *
     *  /// <summary>
     *  /// Renders the Delete Image
     *  /// </summary>
     *  /// <param name="sender"></param>
     *  /// <param name="e"></param>
     *  protected void imgDelete_PreRender(object sender, EventArgs e)
     *  {
     *      CMSGridActionButton imgDelete = (CMSGridActionButton)sender;
     *      if (!Control.GridView.Enabled)
     *      {
     *          // Disable delete icon in case that editing is not allowed
     *          imgDelete.Enabled = false;
     *          imgDelete.Style.Add("cursor", "default");
     *      }
     *  }
     *
     *  /// <summary>
     *  /// Gets macro resolver for the Node with the classes needed to render the Tooltip / display name format
     *  /// </summary>
     *  /// <param name="NodeID"></param>
     *  /// <param name="ClassName"></param>
     *  /// <returns></returns>
     *  private MacroResolver GetNodeMacroResolver(int NodeID, string ClassName)
     *  {
     *      string Culture = URLHelper.GetQueryValue(HttpContext.Current.Request.RawUrl, "culture");
     *      return CacheHelper.Cache<MacroResolver>(cs =>
     *      {
     *          MacroResolver resolver = MacroResolver.GetInstance();
     *
     *          List<string> Columns = new List<string>();
     *
     *          if (!string.IsNullOrWhiteSpace(ToolTipFormat))
     *          {
     *              Columns.AddRange(DataHelper.GetNotEmpty(MacroProcessor.GetMacros(ToolTipFormat, true), "NodeName").Split(';'));
     *          }
     *          if (!string.IsNullOrWhiteSpace(DisplayNameFormat))
     *          {
     *              Columns.AddRange(DataHelper.GetNotEmpty(MacroProcessor.GetMacros(DisplayNameFormat, true), "NodeName").Split(';'));
     *          }
     *          // Get data for this node and render it out
     *          DataSet FullData = new DocumentQuery(ClassName)
     *              .WhereEquals("NodeID", NodeID)
     *              .Columns(Columns)
     *              .Culture(Culture)
     *              .CombineWithDefaultCulture(true).Result;
     *
     *          foreach (DataColumn item in FullData.Tables[0].Columns)
     *          {
     *              resolver.SetNamedSourceData(item.ColumnName, FullData.Tables[0].Rows[0][item.ColumnName]);
     *          }
     *
     *          if (cs.Cached)
     *          {
     *              cs.CacheDependency = CacheHelper.GetCacheDependency("nodeid|" + NodeID);
     *          }
     *          return resolver;
     *      }, new CacheSettings(CacheHelper.CacheMinutes(SiteContext.CurrentSiteName), "RelationshipTree_GetNodeMacroResolver", NodeID, Culture, ToolTipFormat, DisplayNameFormat));
     *  }
     * }
     * }
     */
    #endregion



    #region "Methods"

    /// <summary>
    /// Saves relationship.
    /// </summary>
    public void SaveRelationship()
    {
        if (TreeNode == null)
        {
            return;
        }

        // Check modify permissions
        if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)
        {
            return;
        }

        bool currentNodeIsOnLeftSide = !DefaultSide;

        // Selected node Id
        int selectedNodeId = ValidationHelper.GetInteger(hdnSelectedNodeId.Value, 0);

        // Get relationshipNameId
        var relationshipNameId = GetRelationshipNameId();

        if ((selectedNodeId <= 0) || (relationshipNameId <= 0))
        {
            return;
        }

        try
        {
            // Left side
            if (currentNodeIsOnLeftSide)
            {
                RelationshipInfo.Provider.Add(TreeNode.NodeID, selectedNodeId, relationshipNameId);
            }
            // Right side
            else
            {
                RelationshipInfo.Provider.Add(selectedNodeId, TreeNode.NodeID, relationshipNameId);
            }

            if (RelHelper.IsStagingEnabled())
            {
                // Log synchronization
                DocumentSynchronizationHelper.LogDocumentChange(TreeNode.NodeSiteName, TreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider);
            }

            ShowConfirmation(GetString("relationship.wasadded"));
        }
        catch (Exception ex)
        {
            ShowError(ex.Message);
        }
    }
示例#7
0
 private void NodeBaz_Insert_Or_Delete_After(object sender, ObjectEventArgs e)
 {
     RelHelper.HandleNodeBindingInsertUpdateDeleteEvent(((NodeBazInfo)e.Object).NodeBazNodeID, NodeBazInfo.OBJECT_TYPE);
 }
    /// <summary>
    /// Saves relationship.
    /// </summary>
    public void SaveRelationship()
    {
        if (TreeNode == null)
        {
            return;
        }

        // Check modify permissions
        if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)
        {
            return;
        }

        bool currentNodeIsOnLeftSide = !DefaultSide;

        // Selected node Id
        int selectedNodeId = ValidationHelper.GetInteger(hdnSelectedNodeId.Value, 0);

        if (BindOnPrimaryNodeOnly)
        {
            selectedNodeId = RelHelper.GetPrimaryNodeID(selectedNodeId);
        }

        var relationshipName     = RelationshipName;
        var relationshipNameInfo = RelationshipNameInfoProvider.GetRelationshipNameInfo(relationshipName);

        int relationshipNameId;

        if (relationshipNameInfo != null)
        {
            relationshipNameId = relationshipNameInfo.RelationshipNameId;
        }
        else
        {
            throw new NullReferenceException("[RelatedDocuments.SaveRelationship]: Missing relationship name to use for relation.");
        }

        if ((selectedNodeId <= 0) || (relationshipNameId <= 0))
        {
            return;
        }

        try
        {
            // Test to make sure the selected page is a Right Side macro-allowed page or left side, and also matches the Page type limiter
            var SelectedTreeNode = (AllowAllTypes ? new DocumentQuery() : new DocumentQuery(AllowedPageTypes)).WhereEquals("NodeID", selectedNodeId).FirstOrDefault();

            // If null probably not an allowed page type, but we will need it to validate below
            if (SelectedTreeNode == null)
            {
                SelectedTreeNode = new DocumentQuery().WhereEquals("NodeID", selectedNodeId).FirstOrDefault();
            }
            var CurrentPageMacroResolver = MacroResolver.GetInstance();
            CurrentPageMacroResolver.SetNamedSourceData("CurrentDocument", TreeNode);
            var PageMacroResolver = MacroResolver.GetInstance();
            PageMacroResolver.SetNamedSourceData("CurrentDocument", SelectedTreeNode);

            // Left side
            if (currentNodeIsOnLeftSide)
            {
                if (!AllowAllTypes && !ClassNames.Contains(SelectedTreeNode.ClassName.ToLower()))
                {
                    AddError(ResHelper.LocalizeExpression("RelatedPages.BadPageType"));
                }
                else if (!ValidationHelper.GetBoolean(CurrentPageMacroResolver.ResolveMacros(IsLeftSideMacro), false) || !ValidationHelper.GetBoolean(PageMacroResolver.ResolveMacros(IsRightSideMacro), false))
                {
                    AddError(ResHelper.LocalizeExpression("RelatedPages.LeftSideRightSideInvalid"));
                }
                else if (TreeNode.NodeID == SelectedTreeNode.NodeID)
                {
                    AddError(ResHelper.LocalizeExpression("RelatedPages.CannotSelectSelf"));
                }
                else
                {
                    RelationshipInfoProvider.AddRelationship(TreeNode.NodeID, selectedNodeId, relationshipNameId);

                    if (RelHelper.IsStagingEnabled())
                    {
                        // Log synchronization
                        DocumentSynchronizationHelper.LogDocumentChange(TreeNode.NodeSiteName, TreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider);
                    }

                    ShowConfirmation(GetString("relationship.wasadded"));
                }
            }
            // Right side
            else
            {
                if (!AllowAllTypes && !ClassNames.Contains(SelectedTreeNode.ClassName.ToLower()))
                {
                    AddError(ResHelper.LocalizeExpression("RelatedPages.BadPageType"));
                }
                else if (!ValidationHelper.GetBoolean(CurrentPageMacroResolver.ResolveMacros(IsLeftSideMacro), false) || !ValidationHelper.GetBoolean(PageMacroResolver.ResolveMacros(IsRightSideMacro), false))
                {
                    AddError(ResHelper.LocalizeExpression("RelatedPages.LeftSideRightSideInvalid"));
                }
                else if (TreeNode.NodeID == SelectedTreeNode.NodeID)
                {
                    AddError(ResHelper.LocalizeExpression("RelatedPages.CannotSelectSelf"));
                }
                else
                {
                    RelationshipInfoProvider.AddRelationship(selectedNodeId, TreeNode.NodeID, relationshipNameId);

                    if (RelHelper.IsStagingEnabled())
                    {
                        // Log synchronization
                        DocumentSynchronizationHelper.LogDocumentChange(TreeNode.NodeSiteName, SelectedTreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider);
                    }

                    ShowConfirmation(GetString("relationship.wasadded"));
                }
            }
        }
        catch (Exception ex)
        {
            ShowError(ex.Message);
        }
    }
示例#9
0
    private void ProcessTask_After(object sender, StagingSynchronizationEventArgs e)
    {
        if (e.TaskType == TaskTypeEnum.UpdateDocument)
        {
            // First table is the Node Data
            DataTable NodeTable = e.TaskData.Tables[0];

            if (NodeTable != null && NodeTable.Columns.Contains("NodeGuid"))
            {
                // Get node ID
                TreeNode NodeObj = new DocumentQuery().WhereEquals("NodeGUID", NodeTable.Rows[0]["NodeGuid"]).FirstOrDefault();

                // Don't want to trigger updates as we set the data in the database, so we won't log synchronziations
                using (new CMSActionContext()
                {
                    LogSynchronization = false,
                    LogIntegration = false
                })
                {
                    #region "Node Baz (Node object w/out Ordering)"
                    // Get NodeBaz and Handle
                    List <int> BazIDs = RelHelper.NewBoundObjectIDs(e, "demo.nodebaz", "NodeID", "BazID", BazInfo.TYPEINFO);
                    NodeBazInfoProvider.GetNodeBazes().WhereEquals("NodeID", NodeObj.NodeID).WhereNotIn("BazID", BazIDs).ForEachObject(x => x.Delete());
                    List <int> CurrentBazIDs = NodeBazInfoProvider.GetNodeBazes().WhereEquals("NodeID", NodeObj.NodeID).Select(x => x.BazID).ToList();
                    foreach (int NewBazID in BazIDs.Except(CurrentBazIDs))
                    {
                        NodeBazInfoProvider.AddTreeToBaz(NodeObj.NodeID, NewBazID);
                    }
                    #endregion

                    #region "Node Region (Node object w/out Ordering)"
                    // Get NodeRegion and Handle
                    List <int> RegionCategoryIDs = RelHelper.NewBoundObjectIDs(e, "demo.nodeRegion", "NodeID", "RegionCategoryID", CategoryInfo.TYPEINFO);
                    NodeRegionInfoProvider.GetNodeRegions().WhereEquals("NodeID", NodeObj.NodeID).WhereNotIn("RegionCategoryID", RegionCategoryIDs).ForEachObject(x => x.Delete());
                    List <int> CurrentRegionCategoryIDs = NodeRegionInfoProvider.GetNodeRegions().WhereEquals("NodeID", NodeObj.NodeID).Select(x => x.RegionCategoryID).ToList();
                    foreach (int NewRegionCategoryID in RegionCategoryIDs.Except(CurrentRegionCategoryIDs))
                    {
                        NodeRegionInfoProvider.AddTreeToCategory(NodeObj.NodeID, NewRegionCategoryID);
                    }
                    #endregion

                    #region "Node Foo  (Node object with Ordering)"

                    // Get NodeFoo and Handle
                    List <int> FooIDInOrders = RelHelper.NewOrderedBoundObjectIDs(e, "demo.nodeFoo", "NodeID", "FooID", "NodeFooOrder", FooInfo.TYPEINFO);
                    NodeFooInfoProvider.GetNodeFoos().WhereEquals("NodeID", NodeObj.NodeID).WhereNotIn("FooID", FooIDInOrders).ForEachObject(x => x.Delete());
                    List <int> CurrentFooIDs = NodeFooInfoProvider.GetNodeFoos().WhereEquals("NodeID", NodeObj.NodeID).Select(x => x.FooID).ToList();
                    foreach (int NewFooID in FooIDInOrders.Except(CurrentFooIDs))
                    {
                        NodeFooInfoProvider.AddTreeToFoo(NodeObj.NodeID, NewFooID);
                    }
                    // Now handle the ordering
                    for (int FooIndex = 0; FooIndex < FooIDInOrders.Count; FooIndex++)
                    {
                        int         FooID      = FooIDInOrders[FooIndex];
                        NodeFooInfo CurrentObj = NodeFooInfoProvider.GetNodeFooInfo(NodeObj.NodeID, FooID);
                        if (CurrentObj != null && CurrentObj.NodeFooOrder != (FooIndex + 1))
                        {
                            CurrentObj.SetObjectOrder(FooIndex + 1);
                        }
                    }
                    #endregion
                }
                if (RelHelper.IsStagingEnabled(NodeObj.NodeSiteID))
                {
                    // Check if we need to generate a task for a server that isn't the origin server
                    RelHelper.CheckIfTaskCreationShouldOccur(NodeObj.NodeGUID);
                }
            }
            else if (NodeTable == null || !NodeTable.Columns.Contains("NodeGuid"))
            {
                EventLogProvider.LogEvent("E", "DemoProcessTask", "No Node Table Found", eventDescription: "First Table in the incoming Staging Task did not contain the Node GUID, could not processes.");
            }
        }
    }
示例#10
0
 private void NodeRegion_Insert_Or_Delete_After(object sender, ObjectEventArgs e)
 {
     RelHelper.HandleNodeBindingInsertUpdateDeleteEvent(((NodeRegionInfo)e.Object).NodeID, "demo.noderegion");
 }
示例#11
0
        private void ProcessTask_After(object sender, StagingSynchronizationEventArgs e)
        {
            List <TaskTypeEnum> DocumentTaskTypes = new List <TaskTypeEnum>()
            {
                TaskTypeEnum.CreateDocument,
                TaskTypeEnum.UpdateDocument
            };

            if (DocumentTaskTypes.Contains(e.TaskType))
            {
                // First table is the Node Data
                DataTable NodeTable = e.TaskData.Tables[0];

                if (NodeTable != null && NodeTable.Columns.Contains("NodeGuid"))
                {
                    // Get node ID
                    TreeNode NodeObj = new DocumentQuery().WhereEquals("NodeGUID", NodeTable.Rows[0]["NodeGuid"]).FirstOrDefault();

                    // Don't want to trigger updates as we set the data in the database, so we won't log synchronziations
                    using (new CMSActionContext()
                    {
                        LogSynchronization = false,
                        LogIntegration = false
                    })
                    {
                        #region "Node Foo  (Node object with Ordering)"

                        // Get NodeFoo and Handle
                        List <int> FooIDInOrders = RelHelper.NewOrderedBoundObjectIDs(e, NodeFooInfo.OBJECT_TYPE, nameof(NodeFooInfo.NodeFooNodeID), nameof(NodeFooInfo.NodeFooFooID), nameof(NodeFooInfo.NodeFooOrder), FooInfo.TYPEINFO);

                        // Delete those not found
                        NodeFooInfo.Provider.Get().WhereEquals(nameof(NodeFooInfo.NodeFooNodeID), NodeObj.NodeID).WhereNotIn(nameof(NodeFooInfo.NodeFooFooID), FooIDInOrders).ForEachObject(x => x.Delete());

                        // Get a list of the Current Foos, add missing
                        List <int> CurrentFooIDs = NodeFooInfo.Provider.Get().WhereEquals(nameof(NodeFooInfo.NodeFooNodeID), NodeObj.NodeID).Select(x => x.NodeFooFooID).ToList();
                        foreach (int NewFooID in FooIDInOrders.Except(CurrentFooIDs))
                        {
                            NodeFooInfo.Provider.Add(NodeObj.NodeID, NewFooID);
                        }
                        // Now handle the ordering
                        for (int FooIndex = 0; FooIndex < FooIDInOrders.Count; FooIndex++)
                        {
                            int         FooID      = FooIDInOrders[FooIndex];
                            NodeFooInfo CurrentObj = NodeFooInfo.Provider.Get(NodeObj.NodeID, FooID);
                            if (CurrentObj != null && CurrentObj.NodeFooOrder != (FooIndex + 1))
                            {
                                CurrentObj.SetObjectOrder(FooIndex + 1);
                            }
                        }

                        #endregion
                    }
                    if (RelHelper.IsStagingEnabled(NodeObj.NodeSiteID))
                    {
                        // Check if we need to generate a task for a server that isn't the origin server
                        RelHelper.CheckIfTaskCreationShouldOccur(NodeObj.NodeGUID);
                    }
                }
                else if (NodeTable == null || !NodeTable.Columns.Contains("NodeGuid"))
                {
                    Service.Resolve <IEventLogService>().LogEvent(EventTypeEnum.Error, "DemoProcessTask", "No Node Table Found", eventDescription: "First Table in the incoming Staging Task did not contain the Node GUID, could not processes.");
                }
            }
        }