/// <summary>
    /// Clears HashTables.
    /// </summary>
    private void ClearHashtables()
    {
        // Clear the object type hashtable
        ProviderStringDictionary.ReloadDictionaries(ClassName, true);

        // Clear the classes hashtable
        ProviderStringDictionary.ReloadDictionaries("cms.class", true);

        // Clear class structures
        ClassStructureInfo.Remove(ClassName, true);

        // Clear form resolver
        FormControlsResolvers.ClearResolvers(true);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Adds GUID field to form definition.
    /// </summary>
    private void CreateGUID()
    {
        try
        {
            // Create GUID field
            FormFieldInfo ffiGuid = new FormFieldInfo();

            // Fill FormInfo object
            ffiGuid.Name = "ItemGUID";
            ffiGuid.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "GUID");
            ffiGuid.DataType = FieldDataType.Guid;
            ffiGuid.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffiGuid.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, String.Empty);
            ffiGuid.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffiGuid.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffiGuid.PrimaryKey = false;
            ffiGuid.System     = true;
            ffiGuid.Visible    = false;
            ffiGuid.Size       = 0;
            ffiGuid.AllowEmpty = false;

            FormInfo.AddFormItem(ffiGuid);

            // Update table structure - columns could be added
            bool old = TableManager.UpdateSystemFields;
            TableManager.UpdateSystemFields = true;
            string schema = FormInfo.GetXmlDefinition();

            TableManager tm = new TableManager(null);
            tm.UpdateTableByDefinition(dci.ClassTableName, schema);

            TableManager.UpdateSystemFields = old;

            // Update xml schema and form definition
            dci.ClassFormDefinition = schema;
            dci.ClassXmlSchema      = tm.GetXmlSchema(dci.ClassTableName);

            dci.Generalized.LogEvents = false;

            // Save the data
            DataClassInfoProvider.SetDataClassInfo(dci);

            dci.Generalized.LogEvents = true;

            // Clear the default queries
            QueryInfoProvider.ClearDefaultQueries(dci, true, false);

            // Clear the object type hashtable
            ProviderStringDictionary.ReloadDictionaries(className, true);

            // Clear the classes hashtable
            ProviderStringDictionary.ReloadDictionaries("cms.class", true);

            // Clear class strucures
            ClassStructureInfo.Remove(className, true);

            // Ensure GUIDs for all items
            using (CMSActionContext ctx = new CMSActionContext())
            {
                ctx.UpdateSystemFields = false;
                ctx.LogSynchronization = false;
                DataSet dsItems = CustomTableItemProvider.GetItems(className);
                if (!DataHelper.DataSourceIsEmpty(dsItems))
                {
                    foreach (DataRow dr in dsItems.Tables[0].Rows)
                    {
                        CustomTableItem item = CustomTableItem.New(className, dr);
                        item.ItemGUID = Guid.NewGuid();
                        item.Update();
                    }
                }
            }

            // Log event
            UserInfo currentUser = MembershipContext.AuthenticatedUser;
            EventLogProvider.LogEvent(EventType.INFORMATION, "Custom table", "GENERATEGUID", string.Format(ResHelper.GetAPIString("customtable.GUIDGenerated", "Field 'ItemGUID' for custom table '{0}' was created and GUID values were generated."), dci.ClassName), null, currentUser.UserID, currentUser.UserName);

            URLHelper.Redirect(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "gen", "1"));
        }
        catch (Exception ex)
        {
            FieldEditor.ShowError(GetString("customtable.ErrorGUID") + ex.Message);

            // Log event
            EventLogProvider.LogException("Custom table", "GENERATEGUID", ex);
        }
    }
Exemplo n.º 3
0
    void btnGUID_Click(object sender, EventArgs e)
    {
        try
        {
            // Create GUID field
            FormFieldInfo ffiGuid = new FormFieldInfo();

            // Fill FormInfo object
            ffiGuid.Name                    = "ItemGUID";
            ffiGuid.Caption                 = "GUID";
            ffiGuid.DataType                = FormFieldDataTypeEnum.GUID;
            ffiGuid.DefaultValue            = "";
            ffiGuid.Description             = "";
            ffiGuid.FieldType               = FormFieldControlTypeEnum.CustomUserControl;
            ffiGuid.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLower();
            ffiGuid.PrimaryKey              = false;
            ffiGuid.System                  = true;
            ffiGuid.Visible                 = false;
            ffiGuid.Size                    = 0;
            ffiGuid.AllowEmpty              = false;

            FormInfo.AddFormField(ffiGuid);

            // Update table structure - columns could be added
            bool old = TableManager.UpdateSystemFields;
            TableManager.UpdateSystemFields = true;
            string schema = FormInfo.GetXmlDefinition();
            TableManager.UpdateTableBySchema(dci.ClassTableName, schema);
            TableManager.UpdateSystemFields = old;

            // Update xml schema and form definition
            dci.ClassFormDefinition = schema;
            dci.ClassXmlSchema      = TableManager.GetXmlSchema(dci.ClassTableName);

            dci.Generalized.LogEvents = false;

            // Save the data
            DataClassInfoProvider.SetDataClass(dci);

            dci.Generalized.LogEvents = true;

            // Generate default queries
            SqlGenerator.GenerateDefaultQueries(dci, true, false);

            // Clear cached data
            CMSObjectHelper.RemoveReadOnlyObjects(CustomTableItemProvider.GetObjectType(className), true);
            CustomTableItemProvider.Remove(className, true);
            // Clear the object type hashtable
            ProviderStringDictionary.ReloadDictionaries(className, true);

            // Clear the classes hashtable
            ProviderStringDictionary.ReloadDictionaries("cms.class", true);

            // Clear class strucures
            ClassStructureInfo.Remove(className, true);

            // Ensure GUIDs for all items
            CustomTableItemProvider tableProvider = new CustomTableItemProvider();
            tableProvider.UpdateSystemFields = false;
            tableProvider.LogSynchronization = false;
            DataSet dsItems = tableProvider.GetItems(className, null, null);
            if (!DataHelper.DataSourceIsEmpty(dsItems))
            {
                foreach (DataRow dr in dsItems.Tables[0].Rows)
                {
                    CustomTableItem item = new CustomTableItem(dr, className, tableProvider);
                    item.ItemGUID = Guid.NewGuid();
                    item.Update();
                }
            }

            // Log event
            UserInfo currentUser = CMSContext.CurrentUser;
            EventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Custom table", "GENERATEGUID", currentUser.UserID, currentUser.UserName, 0, null, null, string.Format(ResHelper.GetAPIString("customtable.GUIDGenerated", "Field 'ItemGUID' for custom table '{0}' was created and GUID values were generated."), dci.ClassName), 0, null);

            URLHelper.Redirect(URLHelper.AddParameterToUrl(URLRewriter.CurrentURL, "gen", "1"));
        }
        catch (Exception ex)
        {
            lblError.Visible = true;
            lblError.Text    = GetString("customtable.ErrorGUID") + ex.Message;

            // Log event
            EventLog.LogEvent("Custom table", "GENERATEGUID", ex);
        }
    }