/// <summary> /// Gets all custom table object types /// </summary> public static IEnumerable <string> GetCustomTableObjectTypes() { return(DataClassInfoProvider.GetClasses() .WhereTrue("ClassIsCustomTable") .Columns("ClassName") .Select(r => CustomTableItemProvider.GetObjectType(r["ClassName"].ToString()))); }
/// <summary> /// Page load. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Register Javascripts ScriptHelper.RegisterDialogScript(this.Page); ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "DeleteEditView", ScriptHelper.GetScript( "var deleteConfirmation = ''; " + "function DeleteConfirm() { return confirm(deleteConfirmation); } " + "function EditItem(customtableid, itemId) { " + " document.location.replace('" + ResolveUrl(EditItemPage) + "?" + (String.IsNullOrEmpty(this.mEditItemPageAdditionalParams) ? String.Empty : this.mEditItemPageAdditionalParams + "&") + "customtableid=' + customtableid + '&itemId=' + itemId); } " + "function ViewItem(customtableid, itemId) { " + " modalDialog('" + ResolveUrl(ViewItemPage) + "?" + (String.IsNullOrEmpty(this.mViewItemPageAdditionalParams) ? String.Empty : this.mViewItemPageAdditionalParams + "&") + "customtableid=' + customtableid + '&itemId=' + itemId,'ViewItem',600,600); } " )); // Buttons' tooltips editToolTip = GetString("general.edit"); deleteToolTip = GetString("general.delete"); viewToolTip = GetString("general.view"); upToolTip = GetString("general.up"); downToolTip = GetString("general.down"); // Delete confirmation ltlScript.Text = ScriptHelper.GetScript("deleteConfirmation = '" + GetString("customtable.data.DeleteConfirmation") + "';"); gridData.ObjectType = CustomTableItemProvider.GetObjectType(CustomTableClassInfo.ClassName); gridData.OnLoadColumns += gridData_OnLoadColumns; gridData.OnExternalDataBound += gridData_OnExternalDataBound; gridData.OnAction += gridData_OnAction; if (HasItemOrderField) { gridData.OrderBy = "ItemOrder ASC"; } }
private string GetAllTasksWhere(out bool classesFound) { string where = BASE_TASK_WHERE; string classWhere = string.Empty; classesFound = false; // Ensure only data task selection if (string.IsNullOrEmpty(objectType)) { DataSet dsTables = CustomTableHelper.GetCustomTableClasses(CurrentSiteID).Column("ClassName"); if (!DataHelper.DataSourceIsEmpty(dsTables)) { foreach (DataRow dr in dsTables.Tables[0].Rows) { classWhere += "N'" + SqlHelper.EscapeQuotes(CustomTableItemProvider.GetObjectType(dr["ClassName"].ToString())) + "',"; } classWhere = classWhere.TrimEnd(','); classesFound = true; } where = SqlHelper.AddWhereCondition(where, "TaskObjectType IN (" + classWhere + ")"); } return(where); }
/// <summary> /// Creates tree view. /// </summary> private void CreateTreeView() { objectTree.Nodes.Clear(); // Fill in the custom tables TreeNode rootNode = new TreeNode(); rootNode.Text = "<span class=\"ContentTreeSelectedItem\" id=\"treeSelectedNode\" onclick=\"SelectNode('##ALL##', this); \"><span class=\"Name\">" + GetString("DataStaging.RootNodeText") + "</span></span>"; rootNode.Expanded = true; rootNode.NavigateUrl = "#"; objectTree.Nodes.Add(rootNode); string objectType = null; if (Request.Params["objectType"] != null) { objectType = ValidationHelper.GetString(Request.Params["objectType"], null); } // Initialize tree view with custom tables bool tableSelected = false; DataSet dsTables = DataClassInfoProvider.GetCustomTableClasses(CMSContext.CurrentSiteID, null, null, 0, "ClassID,ClassDisplayName,ClassName"); if (!DataHelper.DataSourceIsEmpty(dsTables)) { DataTable table = dsTables.Tables[0]; foreach (DataRow dr in table.Rows) { string tableDisplayName = ResHelper.LocalizeString(dr["ClassDisplayName"].ToString()); TreeNode tableNode = new TreeNode(); tableNode.ImageUrl = GetImageUrl("Objects/CMS_CustomTable/list.png"); string currentObjectType = CustomTableItemProvider.GetObjectType(dr["ClassName"].ToString()); if (currentObjectType == objectType) { tableNode.Text = "<span class=\"ContentTreeSelectedItem\" id=\"treeSelectedNode\" onclick=\"SelectNode('" + currentObjectType + "', this); \"><span class=\"Name\">" + HTMLHelper.HTMLEncode(tableDisplayName) + "</span></span>"; tableSelected = true; } else { tableNode.Text = "<span class=\"ContentTreeItem\" onclick=\"SelectNode('" + currentObjectType + "', this); \"><span class=\"Name\">" + HTMLHelper.HTMLEncode(tableDisplayName) + "</span></span>"; } tableNode.Value = currentObjectType; tableNode.NavigateUrl = "#"; objectTree.Nodes[0].ChildNodes.Add(tableNode); } } string script = "var currentNode = document.getElementById('treeSelectedNode');\n"; if ((objectType != null) && tableSelected) { script += " \t SelectNode('" + objectType + "');\n"; } ScriptHelper.RegisterStartupScript(Page, typeof(string), "RefreshScript", ScriptHelper.GetScript(script)); }
private void FieldEditor_OnAfterDefinitionUpdate(object sender, EventArgs e) { if (dci != null) { // State of unigrids may contain where/order by clauses no longer valid after definition update UniGrid.ResetStates(CustomTableItemProvider.GetObjectType(dci.ClassName)); } }
/// <summary> /// Reloads the data in the selector. /// </summary> public void ReloadData() { uniSelector.IsLiveSite = IsLiveSite; uniSelector.DisplayNameFormat = DisplayNameFormat; uniSelector.ReturnColumnName = ReturnColumnName; uniSelector.ObjectType = CustomTableItemProvider.GetObjectType(CustomTable); uniSelector.Reload(false); }
/// <summary> /// Reloads the data in the selector. /// </summary> public void ReloadData() { uniSelector.IsLiveSite = IsLiveSite; uniSelector.DisplayNameFormat = DisplayNameFormat; uniSelector.ReturnColumnName = ReturnColumnName; uniSelector.DropDownSingleSelect.AutoPostBack = HasDependingFields; uniSelector.ObjectType = CustomTableItemProvider.GetObjectType(CustomTable); uniSelector.Reload(false); }
private List <string> GetObjectTypes() { // Get custom tables object types var objectTypes = new List <string>(); DataSet dsTables = CustomTableHelper.GetCustomTableClasses(CurrentSiteID).Column("ClassName"); if (!DataHelper.DataSourceIsEmpty(dsTables)) { DataTable table = dsTables.Tables[0]; foreach (DataRow dr in table.Rows) { objectTypes.Add(CustomTableItemProvider.GetObjectType(dr["ClassName"].ToString())); } } return(objectTypes); }
protected DataSet gridTasks_OnDataReload(string completeWhere, string currentOrder, int currentTopN, string columns, int currentOffset, int currentPageSize, ref int totalRecords) { // Get the tasks string where = "TaskSiteID IS NULL"; string classWhere = string.Empty; // Ensure only data task selection if (string.IsNullOrEmpty(objectType)) { DataSet dsTables = DataClassInfoProvider.GetCustomTableClasses(currentSiteId, null, null, 0, "ClassName"); if (!DataHelper.DataSourceIsEmpty(dsTables)) { foreach (DataRow dr in dsTables.Tables[0].Rows) { classWhere += "N'" + CustomTableItemProvider.GetObjectType(dr["ClassName"].ToString()).Replace("'", "''") + "',"; } classWhere = classWhere.TrimEnd(new char[] { ',' }); } where = SqlHelperClass.AddWhereCondition(where, "TaskObjectType IN (" + classWhere + ")"); } DataSet ds = null; // There are some custom tables assigned to the site, get the data if (!string.IsNullOrEmpty(classWhere) || !string.IsNullOrEmpty(objectType)) { ds = TaskInfoProvider.SelectObjectTaskList(currentSiteId, serverId, objectType, where, currentOrder, 0, columns, currentOffset, currentPageSize, ref totalRecords); } else { totalRecords = -1; } pnlFooter.Visible = (totalRecords > 0); return(ds); }
/// <summary> /// Deletes all tasks. /// </summary> protected void DeleteAll(object parameter) { eventCode = "DELETEALLDATA"; CanceledString = GetString("Tasks.DeletionCanceled"); try { AddLog(GetString("Synchronization.DeletingTasks")); string where = "TaskSiteID IS NULL"; string classWhere = string.Empty; // Ensure only data task selection if (string.IsNullOrEmpty(objectType)) { DataSet dsTables = DataClassInfoProvider.GetCustomTableClasses(currentSiteId, null, null, 0, "ClassName"); if (!DataHelper.DataSourceIsEmpty(dsTables)) { foreach (DataRow dr in dsTables.Tables[0].Rows) { classWhere += "N'" + CustomTableItemProvider.GetObjectType(dr["ClassName"].ToString()).Replace("'", "''") + "',"; } classWhere = classWhere.TrimEnd(new char[] { ',' }); } where = SqlHelperClass.AddWhereCondition(where, "TaskObjectType IN (" + classWhere + ")"); } // Get the tasks DataSet ds = TaskInfoProvider.SelectObjectTaskList(currentSiteId, serverId, objectType, where, "TaskID", 0, "TaskID, TaskTitle"); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow row in ds.Tables[0].Rows) { int taskId = ValidationHelper.GetInteger(row["TaskID"], 0); if (taskId > 0) { string taskTitle = ValidationHelper.GetString(row["TaskTitle"], null); AddLog(string.Format(ResHelper.GetAPIString("deletion.running", "Deleting '{0}' task"), HTMLHelper.HTMLEncode(taskTitle))); // Delete synchronization SynchronizationInfoProvider.DeleteSynchronizationInfo(taskId, serverId, currentSiteId); } } } CurrentInfo = GetString("Tasks.DeleteOK"); AddLog(CurrentInfo); } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state == CMSThread.ABORT_REASON_STOP) { // Canceled by user CurrentInfo = CanceledString; AddLog(CurrentInfo); } else { CurrentError = GetString("Tasks.DeletionFailed"); AddErrorLog(CurrentError); } } catch (Exception ex) { CurrentError = GetString("Tasks.DeletionFailed") + ": " + ex.Message; AddErrorLog(CurrentError); } finally { // Finalize log context FinalizeContext(); } }
/// <summary> /// Complete synchronization. /// </summary> public void SynchronizeComplete(object parameter) { string result = null; eventCode = "SYNCCOMPLETEDATA"; CanceledString = GetString("Tasks.SynchronizationCanceled"); try { int sid = serverId; if (sid <= 0) { sid = SynchronizationInfoProvider.ENABLED_SERVERS; } AddLog(GetString("Synchronization.LoggingTasks")); // Get custom tables object types string objectTypes = string.Empty; DataSet dsTables = DataClassInfoProvider.GetCustomTableClasses(currentSiteId, null, null, 0, "ClassName"); if (!DataHelper.DataSourceIsEmpty(dsTables)) { DataTable table = dsTables.Tables[0]; foreach (DataRow dr in table.Rows) { objectTypes += CustomTableItemProvider.GetObjectType(dr["ClassName"].ToString()) + ";"; } } // Get the tasks List <ISynchronizationTask> tasks = SynchronizationHelper.LogObjectChange(objectTypes.Trim(';'), 0, DateTimeHelper.ZERO_TIME, TaskTypeEnum.UpdateObject, true, false, false, false, false, currentSiteId, sid); AddLog(GetString("Synchronization.RunningTasks")); // Run the synchronization foreach (TaskInfo task in tasks.OfType <TaskInfo>()) { AddLog(string.Format(ResHelper.GetAPIString("synchronization.running", "Processing '{0}' task"), HTMLHelper.HTMLEncode(task.TaskTitle))); result += StagingHelper.RunSynchronization(task.TaskID, serverId, true, currentSiteId); } // Log possible errors if (!string.IsNullOrEmpty(result)) { CurrentError = GetString("Tasks.SynchronizationFailed"); AddErrorLog(CurrentError, null); } else { CurrentInfo = GetString("Tasks.SynchronizationOK"); AddLog(CurrentInfo); } } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state == CMSThread.ABORT_REASON_STOP) { // Canceled by user CurrentInfo = CanceledString; AddLog(CurrentInfo); } else { CurrentError = GetString("Tasks.SynchronizationFailed"); AddErrorLog(CurrentError, result); } } catch (Exception ex) { CurrentError = GetString("Tasks.SynchronizationFailed") + ": " + ex.Message; AddErrorLog(CurrentError); } finally { // Finalize log context FinalizeContext(); } }
/// <summary> /// All items synchronization. /// </summary> protected void SynchronizeAll(object parameter) { string result = string.Empty; eventCode = "SYNCALLDATA"; CanceledString = GetString("Tasks.SynchronizationCanceled"); try { string where = "TaskSiteID IS NULL"; string classWhere = string.Empty; AddLog(GetString("Synchronization.RunningTasks")); // Ensure only data task selection if (string.IsNullOrEmpty(objectType)) { DataSet dsTables = DataClassInfoProvider.GetCustomTableClasses(currentSiteId, null, null, 0, "ClassName"); if (!DataHelper.DataSourceIsEmpty(dsTables)) { foreach (DataRow dr in dsTables.Tables[0].Rows) { classWhere += "N'" + CustomTableItemProvider.GetObjectType(dr["ClassName"].ToString()).Replace("'", "''") + "',"; } classWhere = classWhere.TrimEnd(new char[] { ',' }); } where = SqlHelperClass.AddWhereCondition(where, "TaskObjectType IN (" + classWhere + ")"); } // Get the tasks DataSet ds = TaskInfoProvider.SelectObjectTaskList(currentSiteId, serverId, objectType, where, "TaskID", -1, "TaskID,TaskTitle"); // Run the synchronization result = StagingHelper.RunSynchronization(ds, serverId, true, currentSiteId, AddLog); // Log possible error if (result != string.Empty) { CurrentError = GetString("Tasks.SynchronizationFailed"); AddErrorLog(CurrentError, null); } else { CurrentInfo = GetString("Tasks.SynchronizationOK"); AddLog(CurrentInfo); } } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state == CMSThread.ABORT_REASON_STOP) { // Canceled by user CurrentInfo = CanceledString; AddLog(CurrentInfo); } else { CurrentError = GetString("Tasks.SynchronizationFailed"); AddErrorLog(CurrentError, result); } } catch (Exception ex) { CurrentError = GetString("Tasks.SynchronizationFailed") + ": " + ex.Message; AddErrorLog(CurrentError); } finally { // Finalize log context FinalizeContext(); } }
/// <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.Caption = "GUID"; ffiGuid.DataType = FormFieldDataTypeEnum.GUID; ffiGuid.DefaultValue = ""; ffiGuid.Description = ""; 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.AddFormField(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.UpdateTableBySchema(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.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 = CustomTableItem.New(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) { FieldEditor.ShowError(GetString("customtable.ErrorGUID") + ex.Message); // Log event EventLog.LogEvent("Custom table", "GENERATEGUID", ex); } }