Esempio n. 1
0
    private void BindObject(object obj, TreeNode root)
    {
        int index = 0;

        if (obj is DataRow)
        {
            // DataRow source, bind column names
            DataRow dr = (DataRow)obj;

            // Create tree structure
            foreach (DataColumn col in dr.Table.Columns)
            {
                // Stop on max nodes
                if (index++ >= MacroResolver.MaxMacroNodes)
                {
                    AppendMore(root);
                    break;
                }

                // Add the column
                object childObj = dr[col.ColumnName];
                AppendChild(root, col.ColumnName, childObj, false);
            }
        }
        else if (obj is DataRowView)
        {
            // DataRowView source, bind column names
            DataRowView dr = (DataRowView)obj;

            // Create tree structure
            foreach (DataColumn col in dr.DataView.Table.Columns)
            {
                // Stop on max nodes
                if (index++ >= MacroResolver.MaxMacroNodes)
                {
                    AppendMore(root);
                    break;
                }

                // Add the column
                object childObj = dr[col.ColumnName];
                AppendChild(root, col.ColumnName, childObj, false);
            }
        }
        else if (obj is AbstractContext)
        {
            AbstractContext context = (AbstractContext)obj;

            // Create tree structure
            foreach (string col in context.Properties)
            {
                // Stop on max nodes
                if (index >= MacroResolver.MaxMacroNodes)
                {
                    AppendMore(root);
                    break;
                }

                // Add the property
                object childObj = context.GetProperty(col);
                AppendChild(root, col, childObj, false);
            }
        }
        else if (obj is IHierarchicalObject)
        {
            // Data container source
            IHierarchicalObject hc = (IHierarchicalObject)obj;

            // Create tree structure
            foreach (string col in hc.Properties)
            {
                // Stop on max nodes
                if (index++ >= MacroResolver.MaxMacroNodes)
                {
                    AppendMore(root);
                    break;
                }

                // Add the property
                object childObj = null;
                try
                {
                    hc.TryGetProperty(col, out childObj);
                }
                catch
                {
                }

                AppendChild(root, col, childObj, false);
            }
        }
        else if (obj is IDataContainer)
        {
            // Data container source
            IDataContainer dc = (IDataContainer)obj;

            // Create tree structure
            foreach (string col in dc.ColumnNames)
            {
                // Stop on max nodes
                if (index++ >= MacroResolver.MaxMacroNodes)
                {
                    AppendMore(root);
                    break;
                }

                // Add the column
                object childObj = null;
                dc.TryGetValue(col, out childObj);

                AppendChild(root, col, childObj, false);
            }
        }

        // Enumerable objects
        if ((obj is IEnumerable) && !(obj is string))
        {
            IEnumerable collection = (IEnumerable)obj;
            IEnumerator enumerator = null;

            bool indexByName = false;

            INamedEnumerable namedCol = null;
            if (obj is INamedEnumerable)
            {
                // Collection with name enumerator
                namedCol = (INamedEnumerable)collection;
                if (namedCol.ItemsHaveNames)
                {
                    enumerator  = namedCol.GetNamedEnumerator();
                    indexByName = true;
                }
            }

            if (!indexByName)
            {
                // Standard collection
                enumerator = collection.GetEnumerator();
            }

            int i = 0;

            while (enumerator.MoveNext())
            {
                // Stop on max nodes
                if (index++ >= MacroResolver.MaxMacroNodes)
                {
                    AppendMore(root);
                    break;
                }

                // Add the item
                object item = SqlHelperClass.EncapsulateObject(enumerator.Current);
                if (indexByName)
                {
                    // Convert the name with dot to indexer
                    string name = namedCol.GetObjectName(item);
                    if (!ValidationHelper.IsIdentifier(name))
                    {
                        name = "[\"" + name + "\"]";
                    }

                    AppendChild(root, name, item, false);
                }
                else
                {
                    // Indexed item
                    AppendChild(root, i.ToString(), item, true);
                }

                i++;
            }
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Fills given list with properties of given object.
    /// </summary>
    /// <param name="properties">List to fill</param>
    /// <param name="dataProperties">List of data properties</param>
    /// <param name="obj">Object the properties of which should be added to the list</param>
    private static void FillObjectProperties(List <string> properties, List <string> dataProperties, object obj)
    {
        if (obj != null)
        {
            if (obj is DataRow)
            {
                // DataRow source, bind column names
                DataRow dr = (DataRow)obj;
                foreach (DataColumn col in dr.Table.Columns)
                {
                    properties.Add(col.ColumnName);
                }
            }
            else if (obj is DataRowView)
            {
                // DataRowView source, bind column names
                DataRowView dr = (DataRowView)obj;
                foreach (DataColumn col in dr.DataView.Table.Columns)
                {
                    properties.Add(col.ColumnName);
                }
            }
            else if (obj is AbstractContext)
            {
                AbstractContext context = (AbstractContext)obj;
                properties.AddRange(context.Properties);
            }
            else if (obj is IHierarchicalObject)
            {
                // Data container source
                IHierarchicalObject hc = (IHierarchicalObject)obj;
                properties.AddRange(hc.Properties);
            }
            else if (obj is IDataContainer)
            {
                // Data container source
                IDataContainer dc = (IDataContainer)obj;
                properties.AddRange(dc.ColumnNames);
            }

            // Named enumerable objects
            if (obj is INamedEnumerable)
            {
                INamedEnumerable namedCol = (INamedEnumerable)obj;
                if (namedCol.ItemsHaveNames)
                {
                    IEnumerator enumerator = namedCol.GetNamedEnumerator();
                    while (enumerator.MoveNext())
                    {
                        // Named item
                        string name = namedCol.GetObjectName(enumerator.Current);
                        if (ValidationHelper.IsIdentifier(name))
                        {
                            dataProperties.Add(name);
                        }
                        else
                        {
                            dataProperties.Add("[\"" + name + "\"]");
                        }
                    }
                }
            }

            // Special case for TreeNode and PageInfo - append ediable parts
            if ((obj is CMS.TreeEngine.TreeNode) || (obj is PageInfo))
            {
                EditableItems eItems = null;

                if (obj is CMS.TreeEngine.TreeNode)
                {
                    // TreeNode editable fields
                    CMS.TreeEngine.TreeNode node = (CMS.TreeEngine.TreeNode)obj;
                    eItems = node.DocumentContent;
                }
                else
                {
                    PageInfo pi = (PageInfo)obj;
                    eItems = pi.EditableItems;
                }

                // Editable regions
                foreach (string item in eItems.EditableRegions.Keys)
                {
                    properties.Add(item);
                }

                // Editable webparts
                foreach (string item in eItems.EditableWebParts.Keys)
                {
                    properties.Add(item);
                }
            }
        }
    }
Esempio n. 3
0
    private void BindObject(object obj, TreeNode root, bool isPriorityTree)
    {
        int index = 0;

        try
        {
            if (obj is DataRow)
            {
                // DataRow source, bind column names
                DataRow dr = (DataRow)obj;

                // Create tree structure
                foreach (DataColumn col in dr.Table.Columns)
                {
                    // Stop on max nodes
                    if (index++ >= MacroResolver.MaxMacroNodes)
                    {
                        AppendMore(root);
                        break;
                    }

                    // Add the column
                    object childObj = dr[col.ColumnName];
                    AppendChild(root, col.ColumnName, childObj, false, isPriorityTree);
                }
            }
            else if (obj is DataRowView)
            {
                // DataRowView source, bind column names
                DataRowView dr = (DataRowView)obj;

                // Create tree structure
                foreach (DataColumn col in dr.DataView.Table.Columns)
                {
                    // Stop on max nodes
                    if (index++ >= MacroResolver.MaxMacroNodes)
                    {
                        AppendMore(root);
                        break;
                    }

                    // Add the column
                    object childObj = dr[col.ColumnName];
                    AppendChild(root, col.ColumnName, childObj, false, isPriorityTree);
                }
            }
            else if (obj is IHierarchicalObject)
            {
                // Data container source
                IHierarchicalObject hc = (IHierarchicalObject)obj;

                // Create tree structure
                foreach (string col in hc.Properties)
                {
                    // Stop on max nodes
                    if (index++ >= MacroResolver.MaxMacroNodes)
                    {
                        AppendMore(root);
                        break;
                    }

                    // Add the property
                    object childObj = null;
                    try
                    {
                        ContextResolver.GetObjectValue(hc, col, ref childObj);

                        // Append the child value
                        AppendChild(root, col, childObj, false, isPriorityTree);
                    }
                    catch (Exception ex)
                    {
                        EventLogProvider.LogException("MacroTree", "EXPAND", ex);

                        // Append the exception as child value
                        AppendChild(root, col, ex, false, isPriorityTree);
                    }
                }
            }
            else if (obj is IDataContainer)
            {
                // Data container source
                IDataContainer dc = (IDataContainer)obj;

                // Create tree structure
                foreach (string col in dc.ColumnNames)
                {
                    // Stop on max nodes
                    if (index++ >= MacroResolver.MaxMacroNodes)
                    {
                        AppendMore(root);
                        break;
                    }

                    // Add the column
                    object childObj = null;
                    dc.TryGetValue(col, out childObj);

                    AppendChild(root, col, childObj, false, isPriorityTree);
                }
            }

            // Enumerable objects
            if ((obj is IEnumerable) && !(obj is string))
            {
                IEnumerable collection = (IEnumerable)obj;
                IEnumerator enumerator = null;

                bool indexByName = false;

                INamedEnumerable namedCol = null;
                if (obj is INamedEnumerable)
                {
                    // Collection with name enumerator
                    namedCol = (INamedEnumerable)collection;
                    if (namedCol.ItemsHaveNames)
                    {
                        enumerator  = namedCol.GetNamedEnumerator();
                        indexByName = true;
                    }
                }

                if (!indexByName)
                {
                    // Standard collection
                    enumerator = collection.GetEnumerator();
                }

                int i = 0;

                List <string> addedItems = new List <string>();
                addedItems.Add("trees");
                addedItems.Add("documents");

                while (enumerator.MoveNext())
                {
                    // Stop on max nodes
                    if (index++ >= MacroResolver.MaxMacroNodes)
                    {
                        AppendMore(root);
                        break;
                    }

                    // Add the item
                    object item = SqlHelperClass.EncapsulateObject(enumerator.Current);
                    if (indexByName)
                    {
                        // Convert the name with dot to indexer
                        string name = namedCol.GetObjectName(item);
                        if (!ValidationHelper.IsIdentifier(name))
                        {
                            name = "[\"" + name + "\"]";
                        }

                        string nameToLower = name.ToLowerCSafe();
                        if (!addedItems.Contains(nameToLower))
                        {
                            addedItems.Add(nameToLower);
                            AppendChild(root, name, item, false, isPriorityTree);
                        }
                    }
                    else
                    {
                        // Indexed item
                        AppendChild(root, i.ToString(), item, true, isPriorityTree);
                    }

                    i++;
                }
            }
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("MacroTree", "EXPAND", ex);

            throw ex;
        }
    }
    private void BindObject(object obj, TreeNode root, bool isPriorityTree)
    {
        int index = 0;

        try
        {
            // DataRow source, bind column names
            var dr = obj as DataRow;
            if (dr != null)
            {
                // Create tree structure
                foreach (DataColumn col in dr.Table.Columns)
                {
                    // Stop on max nodes
                    if (index++ >= MacroStaticSettings.MaxMacroNodes)
                    {
                        AppendMore(root);
                        break;
                    }

                    // Add the column
                    object childObj = dr[col.ColumnName];
                    AppendChild(root, col.ColumnName, childObj, false, isPriorityTree);
                }
            }
            else
            {
                // DataRowView source, bind column names
                var drv = obj as DataRowView;
                if (drv != null)
                {
                    // Create tree structure
                    foreach (DataColumn col in drv.DataView.Table.Columns)
                    {
                        // Stop on max nodes
                        if (index++ >= MacroStaticSettings.MaxMacroNodes)
                        {
                            AppendMore(root);
                            break;
                        }

                        // Add the column
                        object childObj = drv[col.ColumnName];
                        AppendChild(root, col.ColumnName, childObj, false, isPriorityTree);
                    }
                }
                else
                {
                    // Hierarchical object source
                    var hc = obj as IHierarchicalObject;
                    if (hc != null)
                    {
                        BaseInfo info = obj as BaseInfo;

                        var props = new List <string>(hc.Properties);

                        var fields = MacroFieldContainer.GetFieldsForObject(hc);
                        if (fields != null)
                        {
                            props.AddRange(fields.Select(x => x.Name));
                        }
                        //props.Sort();

                        if ((info != null) && (info.TypeInfo.SensitiveColumns != null))
                        {
                            props = props.Except(info.TypeInfo.SensitiveColumns).ToList();
                        }

                        // Create tree structure
                        foreach (string col in props)
                        {
                            // Stop on max nodes
                            if (index++ >= MacroStaticSettings.MaxMacroNodes)
                            {
                                AppendMore(root);
                                break;
                            }

                            // Add the property
                            AddProperty(root, isPriorityTree, hc, col);
                        }
                    }
                    else
                    {
                        // Data container source
                        var dc = obj as IDataContainer;
                        if (dc != null)
                        {
                            // Create tree structure
                            foreach (string col in dc.ColumnNames)
                            {
                                // Stop on max nodes
                                if (index++ >= MacroStaticSettings.MaxMacroNodes)
                                {
                                    AppendMore(root);
                                    break;
                                }

                                // Add the column
                                object childObj;
                                dc.TryGetValue(col, out childObj);

                                AppendChild(root, col, childObj, false, isPriorityTree);
                            }
                        }
                    }
                }
            }

            // Enumerable objects
            if ((obj is IEnumerable) && !(obj is string))
            {
                IEnumerable collection = (IEnumerable)obj;
                IEnumerator enumerator = null;

                bool indexByName = false;

                INamedEnumerable namedCol = null;
                if (obj is INamedEnumerable)
                {
                    // Collection with name enumerator
                    namedCol = (INamedEnumerable)collection;
                    if (namedCol.ItemsHaveNames)
                    {
                        enumerator  = namedCol.GetNamedEnumerator <object>();
                        indexByName = true;
                    }
                }

                if (!indexByName)
                {
                    // Standard collection
                    enumerator = collection.GetEnumerator();
                }

                int i = 0;

                List <string> addedItems = new List <string>();
                addedItems.Add("trees");
                addedItems.Add("documents");

                while (enumerator.MoveNext())
                {
                    // Stop on max nodes
                    if (index++ >= MacroStaticSettings.MaxMacroNodes)
                    {
                        AppendMore(root);
                        break;
                    }

                    // Add the item
                    object item = MacroResolver.EncapsulateObject(enumerator.Current);
                    if (indexByName)
                    {
                        // Convert the name with dot to indexer
                        string name = namedCol.GetObjectName(item);
                        if (!ValidationHelper.IsIdentifier(name))
                        {
                            name = "[\"" + name + "\"]";
                        }

                        string nameToLower = name.ToLowerCSafe();
                        if (!addedItems.Contains(nameToLower))
                        {
                            addedItems.Add(nameToLower);
                            AppendChild(root, name, item, false, isPriorityTree);
                        }
                    }
                    else
                    {
                        // Indexed item
                        AppendChild(root, i.ToString(), item, true, isPriorityTree);
                    }

                    i++;
                }
            }
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("MacroTree", "EXPAND", ex);

            throw;
        }
    }