/// <summary>
    /// Handles OnAfterSave event of the UI Form.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Event argument</param>
    protected void Control_OnAfterSave(object sender, EventArgs e)
    {
        string newSiteCodeName = ValidationHelper.GetString(Control.GetFieldValue("SiteName"), String.Empty);

        if (newSiteCodeName.ToLowerCSafe() != siteInfo.SiteName.ToLowerCSafe())
        {
            // Clear settings if sitename changes
            ProviderHelper.ClearHashtables(SettingsKeyInfo.OBJECT_TYPE, true);

            // Reindex hashtable with sessions if SiteName changes and change info message
            SessionManager.ReindexSessionsInfosHashtable(formerCodeName, siteInfo.SiteName);
            if (SearchIndexInfoProvider.SearchEnabled)
            {
                Control.ShowInformation(String.Format(ResHelper.GetString("general.changessaved") + " " + ResHelper.GetString("srch.indexrequiresrebuild"), "<a href=\"javascript:" + ControlsHelper.GetPostBackEventReference(Control.ObjectManager.HeaderActions, "RebuildSiteIndex;") + "\">" + ResHelper.GetString("General.clickhere") + "</a>"));
            }
        }

        // Remove cached cultures for site
        CultureSiteInfoProvider.ClearSiteCultures(true);

        // Run the site if it was running previously
        try
        {
            if (runSite)
            {
                DataSet ds = SiteInfoProvider.CheckDomainNameForCollision(siteInfo.DomainName, siteInfo.SiteID);
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    SiteInfo runningSiteInfo = SiteInfoProvider.GetSiteInfo(ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["SiteID"], 0));
                    if (runningSiteInfo != null)
                    {
                        string collisionSite   = HTMLHelper.HTMLEncode(runningSiteInfo.DisplayName);
                        string collisionDomain = HTMLHelper.HTMLEncode(ValidationHelper.GetString(ds.Tables[0].Rows[0]["SiteDomainAliasName"], ""));

                        Control.ShowWarning(String.Format(ResHelper.GetString("SiteDomain.RunError"), collisionSite, collisionDomain, HTMLHelper.HTMLEncode(siteInfo.DisplayName)));
                    }
                }
                else
                {
                    // Run current site
                    SiteInfoProvider.RunSite(siteInfo.SiteName);
                }
            }
        }
        catch (RunningSiteException ex)
        {
            Control.ShowError(ex.Message);
        }
    }
コード例 #2
0
    /// <summary>
    /// Copies role binding from parent UI element.
    /// </summary>
    /// <param name="element">Element which are permissions copied to</param>
    private void CopyFromParent(UIElementInfo element)
    {
        using (var tr = new CMSTransactionScope())
        {
            if (element != null)
            {
                // Delete existing bindings
                DataSet elemRoles = RoleUIElementInfoProvider.GetRoleUIElements().WhereEquals("ElementID", element.ElementID);
                if (!DataHelper.DataSourceIsEmpty(elemRoles))
                {
                    foreach (DataRow dr in elemRoles.Tables[0].Rows)
                    {
                        // Get role id
                        int roleId = ValidationHelper.GetInteger(dr["RoleID"], 0);
                        // Remove binding
                        RoleUIElementInfoProvider.DeleteRoleUIElementInfo(roleId, element.ElementID);
                    }
                }

                // Add same bindings as parent has
                int parentElemId = element.ElementParentID;

                DataSet parentRoles = RoleUIElementInfoProvider.GetRoleUIElements().WhereEquals("ElementID", parentElemId);
                if (!DataHelper.DataSourceIsEmpty(parentRoles))
                {
                    foreach (DataRow dr in parentRoles.Tables[0].Rows)
                    {
                        // Get role id
                        int roleId = ValidationHelper.GetInteger(dr["RoleID"], 0);
                        // Create binding
                        RoleUIElementInfoProvider.AddRoleUIElementInfo(roleId, element.ElementID);
                    }
                }
            }

            // Commit transaction
            tr.Commit();
        }

        // Invalidate all users
        UserInfo.TYPEINFO.InvalidateAllObjects();

        // Clear hashtables with users
        ProviderHelper.ClearHashtables(UserInfo.OBJECT_TYPE, true);
    }
コード例 #3
0
    protected void gridMatrix_OnItemChanged(object sender, int rowItemId, int colItemId, bool newState)
    {
        if (newState)
        {
            RoleUIElementInfoProvider.AddRoleUIElementInfo(rowItemId, colItemId);
        }
        else
        {
            RoleUIElementInfoProvider.DeleteRoleUIElementInfo(rowItemId, colItemId);
        }

        // Invalidate all users
        UserInfo.TYPEINFO.InvalidateAllObjects();

        // Forget old user
        CurrentUser = null;

        // Clear hashtables with users
        ProviderHelper.ClearHashtables(UserInfo.OBJECT_TYPE, true);

        // Update content before rows
        GenerateBeforeRowsContent();
    }
コード例 #4
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);
        }
コード例 #5
0
ファイル: Step4.cs プロジェクト: dmn58/ADImport
        private void BindSites()
        {
            // Create new datatable
            DataTable sitesTable = new DataTable();

            // Create columns
            DataColumn selectedCol = new DataColumn(COLUMN_SELECTED, typeof(Boolean));
            DataColumn siteNameCol = new DataColumn(COLUMN_SITENAME, typeof(String));
            DataColumn codeNameCol = new DataColumn(COLUMN_CODENAME, typeof(String));

            // Add columns to datatable
            sitesTable.Columns.Add(selectedCol);
            sitesTable.Columns.Add(siteNameCol);
            sitesTable.Columns.Add(codeNameCol);

            // Bind DataGridView to CMS sites
            DataSet sites = SiteInfoProvider.GetSites()
                            .OrderBy("SiteDisplayName")
                            .Columns("SiteDisplayName, SiteName");

            bool sitesAvailable = !DataHelper.DataSourceIsEmpty(sites);

            pnlImportGroups.Enabled = sitesAvailable;
            if (sitesAvailable)
            {
                // Remove non-existing sites
                IEnumerator   sitesEnumerator = ImportProfile.Sites.GetEnumerator();
                List <string> removeSites     = new List <string>();
                while (sitesEnumerator.MoveNext())
                {
                    // Get site
                    if (sitesEnumerator.Current != null)
                    {
                        KeyValuePair <string, List <Guid> > importedSite = (KeyValuePair <string, List <Guid> >)sitesEnumerator.Current;

                        // Clear hash tables
                        ProviderHelper.ClearHashtables(SiteInfo.OBJECT_TYPE, true);

                        // Get info object
                        SiteInfo site = SiteInfoProvider.GetSiteInfo(importedSite.Key);

                        // If site is not present
                        if (site == null)
                        {
                            // Add to removal list
                            removeSites.Add(importedSite.Key);
                        }
                    }
                }
                foreach (string siteToRemove in removeSites)
                {
                    ImportProfile.Sites.Remove(siteToRemove.ToLowerCSafe());
                }
                foreach (DataRow site in sites.Tables[0].Rows)
                {
                    // Create new row with the table schema
                    DataRow dr = sitesTable.NewRow();

                    // Preselect sites
                    bool checkSite = (ImportProfile.Sites.ContainsKey(site["SiteName"].ToString().ToLowerCSafe()));

                    // Localize display name
                    string siteDisplayName = CMS.Helpers.ResHelper.LocalizeString(site["SiteDisplayName"].ToString());

                    // Add data to row
                    object[] dataRow = { checkSite, siteDisplayName, site["SiteName"] };
                    dr.ItemArray = dataRow;

                    // Add row to table
                    sitesTable.Rows.Add(dr);
                }
                // Bind table as a grid's datasource
                grdSites.DataSource = sitesTable;

                // Adjust columns
                DataGridViewColumn columnSelected = grdSites.Columns[COLUMN_SELECTED];
                if (columnSelected != null)
                {
                    columnSelected.HeaderText   = ResHelper.GetString("General_Import");
                    columnSelected.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
                }
                DataGridViewColumn columnSiteName = grdSites.Columns[COLUMN_SITENAME];
                if (columnSiteName != null)
                {
                    columnSiteName.HeaderText   = ResHelper.GetString("General_Sitename");
                    columnSiteName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                    columnSiteName.ReadOnly     = true;
                }
                DataGridViewColumn columnCodeName = grdSites.Columns[COLUMN_CODENAME];
                if (columnCodeName != null)
                {
                    columnCodeName.Visible = false;
                }
            }
            else
            {
                // No sites to import
                ImportProfile.Sites.Clear();
            }
        }
コード例 #6
0
        /// <summary>
        /// Deserialize what is on disk and save back to the Database
        /// </summary>
        public Sync()
        {
            this.RequiresAuthentication(HttpContext.Current);
            Get("/synccore/{id}", parameters =>
            {
                var response = new Response();

                response.ContentType = "text/plain";
                response.Contents    = stream =>
                {
                    var bridgeCoreConfigs = BridgeConfiguration.GetConfig().CoreConfigs;
                    string configName     = parameters.id;
                    foreach (BridgeCoreConfig coreConfig in bridgeCoreConfigs)
                    {
                        if (configName.ToLower() == coreConfig.Name.ToLower())
                        {
                            _processCoreConfig(coreConfig, stream);
                        }
                        ProviderHelper.ClearHashtables("cms.class", false);
                        byte[] bytes = Encoding.UTF8.GetBytes($"Completed sync!");
                        stream.Write(bytes, 0, bytes.Length);
                        stream.WriteByte(10);
                        stream.Flush();
                    }
                };
                return(response);
            });

            Get("/synccore", parameters =>
            {
                var response = new Response();

                response.ContentType = "text/plain";
                response.Contents    = stream =>
                {
                    var bridgeCoreConfigs = BridgeConfiguration.GetConfig().CoreConfigs;
                    foreach (BridgeCoreConfig coreConfig in bridgeCoreConfigs)
                    {
                        _processCoreConfig(coreConfig, stream);
                    }
                    ProviderHelper.ClearHashtables("cms.class", false);
                    byte[] bytes = Encoding.UTF8.GetBytes($"Completed sync!");
                    stream.Write(bytes, 0, bytes.Length);
                    stream.WriteByte(10);
                    stream.Flush();
                };
                return(response);
            });

            Get("/synccontent/{id}", parameters =>
            {
                var response = new Response();

                response.ContentType = "text/plain";
                response.Contents    = stream =>
                {
                    var bridgecontentConfigs = BridgeConfiguration.GetConfig().ContentConfigs;
                    string configName        = parameters.id;
                    foreach (BridgeContentConfig contentConfig in bridgecontentConfigs)
                    {
                        if (configName.ToLower() == contentConfig.Name.ToLower())
                        {
                            _processContentConfing(contentConfig, stream);
                        }
                        byte[] bytes = Encoding.UTF8.GetBytes($"Completed sync!");
                        stream.Write(bytes, 0, bytes.Length);
                        stream.WriteByte(10);
                        stream.Flush();
                    }
                };
                return(response);
            });

            Get("/synccontent", parameters =>
            {
                var response = new Response();

                response.ContentType = "text/plain";
                response.Contents    = stream =>
                {
                    var bridgecontentConfigs = BridgeConfiguration.GetConfig().ContentConfigs;
                    foreach (BridgeContentConfig contentConfig in bridgecontentConfigs)
                    {
                        _processContentConfing(contentConfig, stream);
                    }
                    byte[] bytes = Encoding.UTF8.GetBytes($"Completed sync!");
                    stream.Write(bytes, 0, bytes.Length);
                    stream.WriteByte(10);
                    stream.Flush();
                };
                return(response);
            });
        }