Пример #1
0
    /// <summary>
    /// Allowed parent types selector event.
    /// </summary>
    protected void selParent_OnSelectionChanged(object sender, EventArgs e)
    {
        bool reloadSecond = false;

        // Remove old items
        string newValues = ValidationHelper.GetString(selParent.Value, null);
        string items     = DataHelper.GetNewItemsInList(newValues, parentValues);

        if (!String.IsNullOrEmpty(items))
        {
            var newItems = items.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            // Add all new items to site
            foreach (string item in newItems)
            {
                int parentId = ValidationHelper.GetInteger(item, 0);
                AllowedChildClassInfoProvider.RemoveAllowedChildClass(parentId, classId);

                if (classId == parentId)
                {
                    reloadSecond = true;
                }
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(parentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            var newItems = items.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            // Add all new items to site
            foreach (string item in newItems)
            {
                int parentId = ValidationHelper.GetInteger(item, 0);
                AllowedChildClassInfoProvider.AddAllowedChildClass(parentId, classId);

                if (classId == parentId)
                {
                    reloadSecond = true;
                }
            }
        }

        // Reload second unigrid
        if (reloadSecond)
        {
            LoadChildData(true);
            uniSelector.Reload(true);
        }

        ShowChangesSaved();
    }
Пример #2
0
    /// <summary>
    /// Loads data for allowed child types selector.
    /// </summary>
    private void LoadChildData(bool forceReload = false)
    {
        DataSet ds = AllowedChildClassInfoProvider.GetAllowedChildClasses().WhereEquals("ParentClassID", classId);

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            currentValues = TextHelper.Join(";", DataHelper.GetStringValues(ds.Tables[0], "ChildClassID"));
            if (!RequestHelper.IsPostBack() || forceReload)
            {
                uniSelector.Value = currentValues;
            }
        }
        else
        {
            if (forceReload)
            {
                uniSelector.Value = String.Empty;
            }
        }
    }
Пример #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        classId = QueryHelper.GetInteger("documenttypeid", 0);
        if (classId > 0)
        {
            // Get the active child classes
            DataSet ds = AllowedChildClassInfoProvider.GetAllowedChildClasses("ParentClassID = " + classId, null);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                currentValues = TextHelper.Join(";", SystemDataHelper.GetStringValues(ds.Tables[0], "ChildClassID"));
            }

            if (!RequestHelper.IsPostBack())
            {
                uniSelector.Value = currentValues;
            }

            pnlChildren.GroupingText = GetString("DocumentType.AllowedChildren");
            pnlParents.GroupingText  = GetString("DocumentType.AllowedParents");

            uniSelector.ResourcePrefix      = "allowedclasscontrol";
            uniSelector.DisplayNameFormat   = "{%ClassDisplayName%} ({%ClassName%})";
            uniSelector.OnSelectionChanged += uniSelector_OnSelectionChanged;

            // Get the active child classes
            ds = AllowedChildClassInfoProvider.GetAllowedChildClasses("ChildClassID = " + classId, null);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                parentValues = TextHelper.Join(";", SystemDataHelper.GetStringValues(ds.Tables[0], "ParentClassID"));
            }

            if (!RequestHelper.IsPostBack())
            {
                selParent.Value = parentValues;
            }

            selParent.ResourcePrefix      = "allowedclasscontrol";
            selParent.DisplayNameFormat   = "{%ClassDisplayName%} ({%ClassName%})";
            selParent.OnSelectionChanged += selParent_OnSelectionChanged;
        }
    }
Пример #4
0
    /// <summary>
    /// Loads data for allowed parent types selector.
    /// </summary>
    private void LoadParentData(bool forceReload = false)
    {
        // Get the active child classes
        DataSet ds = AllowedChildClassInfoProvider.GetAllowedChildClasses().WhereEquals("ChildClassID", classId);

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            parentValues = TextHelper.Join(";", DataHelper.GetStringValues(ds.Tables[0], "ParentClassID"));
            if (!RequestHelper.IsPostBack() || forceReload)
            {
                selParent.Value = parentValues;
            }
        }
        else
        {
            if (forceReload)
            {
                selParent.Value = String.Empty;
            }
        }
    }
    protected void uniSelector_OnSelectionChanged(object sender, EventArgs e)
    {
        // Remove old items
        string newValues = ValidationHelper.GetString(uniSelector.Value, null);
        string items     = DataHelper.GetNewItemsInList(newValues, currentValues);

        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int childId = ValidationHelper.GetInteger(item, 0);
                    AllowedChildClassInfoProvider.RemoveAllowedChildClass(classId, childId);
                }
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(currentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int childId = ValidationHelper.GetInteger(item, 0);
                    AllowedChildClassInfoProvider.AddAllowedChildClass(classId, childId);
                }
            }
        }

        lblInfo.Visible = true;
        lblInfo.Text    = GetString("general.changessaved");
    }
Пример #6
0
    protected void selParent_OnSelectionChanged(object sender, EventArgs e)
    {
        // Remove old items
        string newValues = ValidationHelper.GetString(selParent.Value, null);
        string items     = DataHelper.GetNewItemsInList(newValues, parentValues);

        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int parentId = ValidationHelper.GetInteger(item, 0);
                    AllowedChildClassInfoProvider.RemoveAllowedChildClass(parentId, classId);
                }
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(parentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int parentId = ValidationHelper.GetInteger(item, 0);
                    AllowedChildClassInfoProvider.AddAllowedChildClass(parentId, classId);
                }
            }
        }

        ShowChangesSaved();
    }
Пример #7
0
        private void _processCoreConfig(BridgeCoreConfig coreConfig, Stream stream)
        {
            string       serializationFolder = BridgeConfiguration.GetConfig().SerializationFolder;
            var          deserializer        = new DeserializerBuilder().Build();
            TreeProvider tree  = new TreeProvider(MembershipContext.AuthenticatedUser);
            var          watch = new Stopwatch();

            //have this driven by config
            var serializationPath    = $"{serializationFolder}/core/{coreConfig.Name}";
            var classTypes           = coreConfig.GetClassTypes();
            var ignoreFields         = coreConfig.GetIgnoreFields();
            var allAllowedChildInfos = new List <AllowedChildClassInfo>();


            int retryCount = 3;

            _processClasses(retryCount, allAllowedChildInfos, coreConfig.Name, stream, deserializer, watch, serializationPath, classTypes, ignoreFields);
            //at this point we should have all children, lets post process these
            foreach (var allowedChildClass in allAllowedChildInfos)
            {
                AllowedChildClassInfoProvider.SetAllowedChildClassInfo(allowedChildClass);
            }
        }
Пример #8
0
    /// <summary>
    /// Reloads control.
    /// </summary>
    /// <param name="forceReload">Forces nested CMSForm to reload if true</param>
    public void ReloadData(bool forceReload)
    {
        if (!mFormLoaded || forceReload)
        {
            // Check License
            LicenseHelper.CheckFeatureAndRedirect(RequestContext.CurrentDomain, FeatureEnum.UserContributions);

            if (!StopProcessing)
            {
                // Set document manager mode
                if (NewDocument)
                {
                    DocumentManager.Mode           = FormModeEnum.Insert;
                    DocumentManager.ParentNodeID   = NodeID;
                    DocumentManager.NewNodeClassID = ClassID;
                    DocumentManager.CultureCode    = CultureCode;
                    DocumentManager.SiteName       = SiteName;
                }
                else if (NewCulture)
                {
                    DocumentManager.Mode             = FormModeEnum.InsertNewCultureVersion;
                    DocumentManager.NodeID           = NodeID;
                    DocumentManager.CultureCode      = CultureCode;
                    DocumentManager.SiteName         = SiteName;
                    DocumentManager.SourceDocumentID = CopyDefaultDataFromDocumentID;
                }
                else
                {
                    DocumentManager.Mode        = FormModeEnum.Update;
                    DocumentManager.NodeID      = NodeID;
                    DocumentManager.SiteName    = SiteName;
                    DocumentManager.CultureCode = CultureCode;
                }

                ScriptHelper.RegisterDialogScript(Page);

                titleElem.TitleText = String.Empty;

                pnlSelectClass.Visible = false;
                pnlEdit.Visible        = false;
                pnlInfo.Visible        = false;
                pnlNewCulture.Visible  = false;
                pnlDelete.Visible      = false;

                // If node found, init the form

                if (NewDocument || (Node != null))
                {
                    // Delete action
                    if (Delete)
                    {
                        // Delete document
                        pnlDelete.Visible = true;

                        titleElem.TitleText = GetString("Content.DeleteTitle");
                        chkAllCultures.Text = GetString("ContentDelete.AllCultures");
                        chkDestroy.Text     = GetString("ContentDelete.Destroy");

                        lblQuestion.Text = GetString("ContentDelete.Question");
                        btnYes.Text      = GetString("general.yes");
                        // Prevent button double-click
                        btnYes.Attributes.Add("onclick", string.Format("document.getElementById('{0}').disabled=true;this.disabled=true;{1};", btnNo.ClientID, ControlsHelper.GetPostBackEventReference(btnYes, string.Empty, true, false)));
                        btnNo.Text = GetString("general.no");

                        DataSet culturesDS = CultureSiteInfoProvider.GetSiteCultures(SiteName);
                        if ((DataHelper.DataSourceIsEmpty(culturesDS)) || (culturesDS.Tables[0].Rows.Count <= 1))
                        {
                            chkAllCultures.Visible = false;
                            chkAllCultures.Checked = true;
                        }

                        if (Node.IsLink)
                        {
                            titleElem.TitleText    = GetString("Content.DeleteTitleLink") + " \"" + HTMLHelper.HTMLEncode(Node.NodeName) + "\"";
                            lblQuestion.Text       = GetString("ContentDelete.QuestionLink");
                            chkAllCultures.Checked = true;
                            plcCheck.Visible       = false;
                        }
                        else
                        {
                            titleElem.TitleText = GetString("Content.DeleteTitle") + " \"" + HTMLHelper.HTMLEncode(Node.NodeName) + "\"";
                        }
                    }
                    // New document or edit action
                    else
                    {
                        if (NewDocument)
                        {
                            titleElem.TitleText = GetString("Content.NewTitle");
                        }

                        // Document type selection
                        if (NewDocument && (ClassID <= 0))
                        {
                            // Use parent node
                            TreeNode parentNode = DocumentManager.ParentNode;
                            if (parentNode != null)
                            {
                                // Select document type
                                pnlSelectClass.Visible = true;

                                // Apply document type scope
                                string whereCondition = DocumentTypeScopeInfoProvider.GetScopeClassWhereCondition(parentNode);

                                var parentClassId = ValidationHelper.GetInteger(parentNode.GetValue("NodeClassID"), 0);
                                var siteId        = SiteInfoProvider.GetSiteID(SiteName);

                                // Get the allowed child classes
                                DataSet ds = AllowedChildClassInfoProvider.GetAllowedChildClasses(parentClassId, siteId)
                                             .Where(whereCondition)
                                             .OrderBy("ClassID")
                                             .Columns("ClassName", "ClassDisplayName", "ClassID");

                                ArrayList deleteRows = new ArrayList();

                                if (!DataHelper.DataSourceIsEmpty(ds))
                                {
                                    // Get the unwanted classes
                                    string allowed = AllowedChildClasses.Trim().ToLowerCSafe();
                                    if (!string.IsNullOrEmpty(allowed))
                                    {
                                        allowed = String.Format(";{0};", allowed);
                                    }

                                    var    userInfo  = MembershipContext.AuthenticatedUser;
                                    string className = null;
                                    // Check if the user has 'Create' permission per Content
                                    bool isAuthorizedToCreateInContent = userInfo.IsAuthorizedPerResource("CMS.Content", "Create");
                                    bool hasNodeAllowCreate            = (userInfo.IsAuthorizedPerTreeNode(parentNode, NodePermissionsEnum.Create) != AuthorizationResultEnum.Allowed);
                                    foreach (DataRow dr in ds.Tables[0].Rows)
                                    {
                                        className = ValidationHelper.GetString(DataHelper.GetDataRowValue(dr, "ClassName"), String.Empty).ToLowerCSafe();
                                        // Document type is not allowed or user hasn't got permission, remove it from the data set
                                        if ((!string.IsNullOrEmpty(allowed) && (!allowed.Contains(";" + className + ";"))) ||
                                            (CheckPermissions && CheckDocPermissionsForInsert && !isAuthorizedToCreateInContent && !userInfo.IsAuthorizedPerClassName(className, "Create") && (!userInfo.IsAuthorizedPerClassName(className, "CreateSpecific") || !hasNodeAllowCreate)))
                                        {
                                            deleteRows.Add(dr);
                                        }
                                    }

                                    // Remove the rows
                                    foreach (DataRow dr in deleteRows)
                                    {
                                        ds.Tables[0].Rows.Remove(dr);
                                    }
                                }

                                // Check if some classes are available
                                if (!DataHelper.DataSourceIsEmpty(ds))
                                {
                                    // If number of classes is more than 1 display them in grid
                                    if (ds.Tables[0].Rows.Count > 1)
                                    {
                                        ds.Tables[0].DefaultView.Sort = "ClassDisplayName";
                                        lblError.Visible = false;
                                        lblInfo.Visible  = true;
                                        lblInfo.Text     = GetString("Content.NewInfo");

                                        DataSet sortedResult = new DataSet();
                                        sortedResult.Tables.Add(ds.Tables[0].DefaultView.ToTable());
                                        gridClass.DataSource = sortedResult;
                                        gridClass.ReloadData();
                                    }
                                    // else show form of the only class
                                    else
                                    {
                                        ClassID = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(ds.Tables[0].Rows[0], "ClassID"), 0);
                                        ReloadData(true);
                                        return;
                                    }
                                }
                                else
                                {
                                    // Display error message
                                    lblError.Visible  = true;
                                    lblError.Text     = GetString("Content.NoAllowedChildDocuments");
                                    lblInfo.Visible   = false;
                                    gridClass.Visible = false;
                                }
                            }
                            else
                            {
                                pnlInfo.Visible  = true;
                                lblFormInfo.Text = GetString("EditForm.DocumentNotFound");
                            }
                        }
                        // Insert or update of a document
                        else
                        {
                            // Display the form
                            pnlEdit.Visible = true;

                            // Try to get GroupID if group context exists
                            int currentGroupId = ModuleCommands.CommunityGetCurrentGroupID();

                            btnDelete.Attributes.Add("style", "display: none;");
                            btnRefresh.Attributes.Add("style", "display: none;");

                            // CMSForm initialization
                            formElem.NodeID                 = Node.NodeID;
                            formElem.SiteName               = SiteName;
                            formElem.CultureCode            = CultureCode;
                            formElem.ValidationErrorMessage = ValidationErrorMessage;
                            formElem.IsLiveSite             = IsLiveSite;

                            // Set group ID if group context exists
                            formElem.GroupID = currentGroupId;

                            // External editing is allowed for live site only if the permissions are checked or user is global administrator or for group context - user is group administrator
                            formElem.AllowExternalEditing = !IsLiveSite || CheckPermissions || MembershipContext.AuthenticatedUser.IsGlobalAdministrator || MembershipContext.AuthenticatedUser.IsGroupAdministrator(currentGroupId);

                            // Set the form mode
                            if (NewDocument)
                            {
                                ci = DataClassInfoProvider.GetDataClassInfo(ClassID);
                                if (ci == null)
                                {
                                    throw new Exception(String.Format("[CMSAdminControls/EditForm.aspx]: Class ID '{0}' not found.", ClassID));
                                }

                                string classDisplayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ci.ClassDisplayName));
                                titleElem.TitleText = GetString("Content.NewTitle") + ": " + classDisplayName;

                                // Set default template ID
                                formElem.DefaultPageTemplateID = TemplateID > 0 ? TemplateID : ci.ClassDefaultPageTemplateID;

                                // Set document owner
                                formElem.OwnerID  = OwnerID;
                                formElem.FormMode = FormModeEnum.Insert;
                                string newClassName = ci.ClassName;
                                string newFormName  = newClassName + ".default";
                                if (!String.IsNullOrEmpty(AlternativeFormName))
                                {
                                    // Set the alternative form full name
                                    formElem.AlternativeFormFullName = GetAltFormFullName(ci.ClassName);
                                }
                                if (newFormName.ToLowerCSafe() != formElem.FormName.ToLowerCSafe())
                                {
                                    formElem.FormName = newFormName;
                                }
                            }
                            else if (NewCulture)
                            {
                                formElem.FormMode = FormModeEnum.InsertNewCultureVersion;
                                // Default data document ID
                                formElem.CopyDefaultDataFromDocumentId = CopyDefaultDataFromDocumentID;

                                ci = DataClassInfoProvider.GetDataClassInfo(Node.NodeClassName);
                                formElem.FormName = Node.NodeClassName + ".default";
                                if (!String.IsNullOrEmpty(AlternativeFormName))
                                {
                                    // Set the alternative form full name
                                    formElem.AlternativeFormFullName = GetAltFormFullName(ci.ClassName);
                                }
                            }
                            else
                            {
                                formElem.FormMode = FormModeEnum.Update;
                                ci = DataClassInfoProvider.GetDataClassInfo(Node.NodeClassName);
                                formElem.FormName = String.Empty;
                                if (!String.IsNullOrEmpty(AlternativeFormName))
                                {
                                    // Set the alternative form full name
                                    formElem.AlternativeFormFullName = GetAltFormFullName(ci.ClassName);
                                }
                            }

                            // Allow the CMSForm
                            formElem.StopProcessing = false;

                            ReloadForm();
                            formElem.LoadForm(true);
                        }
                    }
                }
                // New culture version
                else
                {
                    // Switch to new culture version mode
                    DocumentManager.Mode        = FormModeEnum.InsertNewCultureVersion;
                    DocumentManager.NodeID      = NodeID;
                    DocumentManager.CultureCode = CultureCode;
                    DocumentManager.SiteName    = SiteName;

                    if (Node != null)
                    {
                        // Offer a new culture creation
                        pnlNewCulture.Visible = true;

                        titleElem.TitleText    = GetString("Content.NewCultureVersionTitle") + " (" + HTMLHelper.HTMLEncode(MembershipContext.AuthenticatedUser.PreferredCultureCode) + ")";
                        lblNewCultureInfo.Text = GetString("ContentNewCultureVersion.Info");
                        radCopy.Text           = GetString("ContentNewCultureVersion.Copy");
                        radEmpty.Text          = GetString("ContentNewCultureVersion.Empty");

                        radCopy.Attributes.Add("onclick", "ShowSelection();");
                        radEmpty.Attributes.Add("onclick", "ShowSelection()");

                        AddScript(
                            "function ShowSelection() { \n" +
                            "   if (document.getElementById('" + radCopy.ClientID + "').checked) { document.getElementById('divCultures').style.display = 'block'; } \n" +
                            "   else { document.getElementById('divCultures').style.display = 'none'; } \n" +
                            "} \n"
                            );

                        btnOk.Text = GetString("ContentNewCultureVersion.Create");

                        // Load culture versions
                        SiteInfo si = SiteInfoProvider.GetSiteInfo(Node.NodeSiteID);
                        if (si != null)
                        {
                            lstCultures.Items.Clear();

                            DataSet nodes = TreeProvider.SelectNodes(si.SiteName, Node.NodeAliasPath, TreeProvider.ALL_CULTURES, false, null, null, null, 1, false);
                            foreach (DataRow nodeCulture in nodes.Tables[0].Rows)
                            {
                                ListItem li = new ListItem();
                                li.Text  = CultureInfoProvider.GetCultureInfo(nodeCulture["DocumentCulture"].ToString()).CultureName;
                                li.Value = nodeCulture["DocumentID"].ToString();
                                lstCultures.Items.Add(li);
                            }
                            if (lstCultures.Items.Count > 0)
                            {
                                lstCultures.SelectedIndex = 0;
                            }
                        }
                    }
                    else
                    {
                        pnlInfo.Visible  = true;
                        lblFormInfo.Text = GetString("EditForm.DocumentNotFound");
                    }
                }
            }
            // Set flag that the form is loaded
            mFormLoaded = true;
        }
    }
Пример #9
0
    protected void gridClasses_OnBeforeDataReload()
    {
        if (ParentNode != null)
        {
            var currentUser = MembershipContext.AuthenticatedUser;

            // Check permission to create new document
            if (currentUser.IsAuthorizedToCreateNewDocument(ParentNode, null))
            {
                // Apply document type scope
                string where = DocumentTypeScopeInfoProvider.GetScopeClassWhereCondition(Scope).ToString(true);

                if (!String.IsNullOrEmpty(gridClasses.CompleteWhereCondition))
                {
                    where = SqlHelper.AddWhereCondition(where, gridClasses.CompleteWhereCondition);
                }

                // Add extra where condition
                where = SqlHelper.AddWhereCondition(where, Where);

                var parentClassId = ValidationHelper.GetInteger(ParentNode.GetValue("NodeClassID"), 0);

                // Get the allowed child classes
                DataSet ds = AllowedChildClassInfoProvider.GetAllowedChildClasses(parentClassId, SiteContext.CurrentSiteID)
                             .Where(where)
                             .OrderBy("ClassID")
                             .TopN(gridClasses.TopN)
                             .Columns("ClassName", "ClassDisplayName", "ClassID", "ClassIconClass");

                List <DataRow> priorityRows = new List <DataRow>();

                // Check user permissions for "Create" permission
                bool hasNodeAllowCreate            = (currentUser.IsAuthorizedPerTreeNode(ParentNode, NodePermissionsEnum.Create) == AuthorizationResultEnum.Allowed);
                bool isAuthorizedToCreateInContent = currentUser.IsAuthorizedPerResource("CMS.Content", "Create");

                // No data loaded yet
                ClassesCount = 0;

                // If dataSet is not empty
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    List <DataRow> rowsToRemove = new List <DataRow>();

                    DataTable table = ds.Tables[0];
                    table.DefaultView.Sort = "ClassDisplayName";

                    DataTable resultTable = table.DefaultView.ToTable();

                    for (int i = 0; i < resultTable.Rows.Count; ++i)
                    {
                        DataRow dr  = resultTable.Rows[i];
                        string  doc = DataHelper.GetStringValue(dr, "ClassName");

                        // Document type is not allowed, remove it from the data set (Extra check for 'CreateSpecific' permission)
                        if (!isAuthorizedToCreateInContent && !currentUser.IsAuthorizedPerClassName(doc, "Create") && (!currentUser.IsAuthorizedPerClassName(doc, "CreateSpecific") || !hasNodeAllowCreate))
                        {
                            rowsToRemove.Add(dr);
                        }
                        // Priority document types
                        else if (doc.EqualsCSafe(SystemDocumentTypes.MenuItem, true))
                        {
                            priorityRows.Add(dr);
                            lastPriorityClassName = doc;
                        }
                    }

                    // Remove the document types
                    foreach (DataRow dr in rowsToRemove)
                    {
                        resultTable.Rows.Remove(dr);
                    }

                    if (!DataHelper.DataSourceIsEmpty(resultTable))
                    {
                        int index = 0;

                        // Put priority rows to first position
                        foreach (DataRow priorityRow in priorityRows)
                        {
                            DataRow dr = resultTable.NewRow();
                            dr.ItemArray = priorityRow.ItemArray;

                            resultTable.Rows.Remove(priorityRow);
                            resultTable.Rows.InsertAt(dr, index);

                            index++;
                        }

                        ClassesCount = resultTable.Rows.Count;

                        dsClasses = new DataSet();
                        dsClasses.Tables.Add(resultTable);

                        gridClasses.DataSource = dsClasses;
                    }
                    else
                    {
                        // Show message
                        SetInformationMessage(GetString(Scope != null ? "Content.ScopeApplied" : "Content.NoPermissions"));

                        gridClasses.Visible = false;

                        ClassesCount = -1;
                    }
                }
                else
                {
                    if (!gridClasses.FilterIsSet)
                    {
                        // Show message
                        SetInformationMessage(NoDataMessage);
                    }
                    else
                    {
                        gridClasses.ZeroRowsText = NoDataMessage;
                    }
                }
            }
            else
            {
                // Show message
                SetInformationMessage(GetString("Content.NoPermissions"));
            }
        }
    }
Пример #10
0
        private void _processCoreConfig(BridgeCoreConfig coreConfig, Stream stream)
        {
            var    serializer          = new SerializerBuilder().ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull).Build();
            string serializationFolder = BridgeConfiguration.GetConfig().SerializationFolder;
            var    watch = new Stopwatch();

            _clearTempFolder();
            watch.Start();
            //have this driven by config
            var serializationPath     = $"{serializationFolder}/core/{coreConfig.Name}";
            var tempGUID              = DateTime.Now.Ticks.ToString();
            var tempSerializationPath = $"{serializationFolder}/temp/{tempGUID}/{coreConfig.Name}";
            var classTypes            = coreConfig.GetClassTypes();
            var fieldsToIgnore        = coreConfig.GetIgnoreFields();

            ProviderHelper.ClearHashtables("cms.class", false);
            foreach (var classType in classTypes)
            {
                var dci = DataClassInfoProvider.GetDataClassInfo(classType);
                if (dci != null)
                {
                    var mappedItem = dci.Adapt <BridgeClassInfo>();
                    mappedItem.FieldValues = new Dictionary <string, object>();

                    foreach (string columnName in dci.ColumnNames)
                    {
                        if (!fieldsToIgnore.Contains(columnName))
                        {
                            var columnValue = dci.GetValue(columnName);
                            mappedItem.FieldValues.Add(columnName, columnValue);
                        }
                    }

                    var assignedSites = new List <Guid>();
                    foreach (SiteInfo assignedSite in dci.AssignedSites)
                    {
                        assignedSites.Add(assignedSite.SiteGUID);
                    }
                    mappedItem.AssignedSites = assignedSites;

                    var allowedChildClasses = AllowedChildClassInfoProvider.GetAllowedChildClasses().Where("ParentClassID", QueryOperator.Equals, dci["ClassID"].ToString()).Column("ChildClassID").ToList();

                    var allowedChildrenTypes = new List <string>();
                    foreach (AllowedChildClassInfo allowedChildClass in allowedChildClasses)
                    {
                        var className = new ObjectQuery("cms.class").Where("ClassID", QueryOperator.Equals, allowedChildClass.ChildClassID).Column("ClassName").FirstOrDefault()["ClassName"].ToString();
                        allowedChildrenTypes.Add(className);
                    }
                    mappedItem.AllowedChildTypes = allowedChildrenTypes;

                    var classQueries = QueryInfoProvider.GetQueries().Where("ClassID", QueryOperator.Equals, dci.ClassID).ToList();
                    var queries      = new Dictionary <string, BridgeClassQuery>();
                    foreach (var classQuery in classQueries)
                    {
                        var bcq = classQuery.Adapt <BridgeClassQuery>();
                        queries.Add(classQuery.QueryName, bcq);
                    }
                    mappedItem.Queries = queries;

                    var stringBuilder = new StringBuilder();
                    var res           = serializer.Serialize(mappedItem);
                    stringBuilder.AppendLine(res);

                    var      pathToMatching = $"{tempSerializationPath}/{mappedItem.ClassName.ToLower()}.yaml";
                    var      tempPath       = this.GetRootPath(pathToMatching);
                    FileInfo file           = new FileInfo(tempPath);
                    file.Directory.Create(); // If the directory already exists, this method does nothing.
                    File.WriteAllText(tempPath, res);
                }
            }
            watch.Stop();
            _outputToStream(stream, $"Generating temp {coreConfig.Name} - {watch.ElapsedMilliseconds}ms");
            _processDifferences(stream, watch, serializationPath, tempSerializationPath);
        }