Exemple #1
0
        internal static void Bind(List <ContentField> fields, DataRow row, ContentDataItemDecorator item)
        {
            int[] cats = null;
            if (item.Model.Categories != null)
            {
                cats = item.Model.Categories.Select(c => c.ID).ToArray();
            }

            row[DataNames.ID]       = item.ID;
            row[DataNames.ParentID] = item.ParentItemID;
            row[DataNames.Privacy]  = item.Privacy;
            row[DataNames.Created]  = item.Created;
            row[DataNames.Pos]      = item.Pos;
            if (item.Modified.HasValue)
            {
                row[DataNames.Modified] = item.Modified;
            }

            if (item.Published.HasValue)
            {
                row[DataNames.Published] = item.Published;
            }

            row[DataNames.IsPublished]    = item.IsPublished;
            row[DataNames.Modifier]       = item.Modifier;
            row[DataNames.State]          = item.ModerateState;
            row[DataNames.Tags]           = item.Tags;
            row[DataNames.Slug]           = item.Slug;
            row[DataNames.Path]           = item.Path;
            row[DataNames.Categories]     = cats != null ? (string.Join(",", item.Context.Where <Category>(c => cats.Contains(c.ID)).Select(c => c.Name).ToArray())) : "";
            row[DataNames.EnableComments] = item.EnableComments;
            row[DataNames.Owner]          = item.Owner;
            row[DataNames.Ratings]        = item.Ratings;
            row[DataNames.Reads]          = item.Reads;
            row[DataNames.TotalAttachs]   = item.TotalAttachments;
            row[DataNames.TotalVotes]     = item.TotalVotes;
            row[DataNames.TotalComms]     = item.TotalComments;
            row[DataNames.TotalShares]    = item.Parent.AllowResharing ? item.Reshares().Count() : 0;
            row[DataNames.Version]        = item.Version;
            row[DataNames.HasChildren]    = item.Parent.IsHierarchy ? item.Children().Count() > 0 : false;

            foreach (var field in fields)
            {
                var raw = item.Value(field.Name).Raw;
                if (raw == null)
                {
                    row[field.Name] = DBNull.Value;
                }
                else
                {
                    row[field.Name] = raw;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets the data table that contains all data rows
        /// </summary>
        /// <returns></returns>
        private DataTable GetDataTable()
        {
            //if (cacheTable == null)
            //    cacheTable = LoadFromCache();

            if (cacheTable != null)
            {
                cacheTable.DefaultView.Sort      = "";
                cacheTable.DefaultView.RowFilter = "";
                return(cacheTable);
            }

            var netdrive = App.Get().NetDrive;
            var listPath = Parent.DefaultListPath.ToString();
            var dataPath = netdrive.MapPath(new Uri(listPath + "cache/"));

            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }

            var viewDataFile = netdrive.MapPath(new Uri(string.Format(listPath + "cache/view_{0}.xml", this.Name)));
            var schema       = netdrive.MapPath(new Uri(string.Format(listPath + "cache/schema_{0}.xml", this.Name)));

            var dt = new DataTable();

            dt.TableName = this.Name;

            if (!File.Exists(viewDataFile))
            {
                //Generate the view data file
                var items = this.Parent.EnableVersioning ? Context.Where <ContentDataItem>(c => c.ParentID.Equals(this.ParentID) && c.IsCurrentVersion).OrderByDescending(v => v.Modified).ToList() :
                            Context.Where <ContentDataItem>(c => c.ParentID.Equals(this.ParentID)).OrderByDescending(v => v.Modified).ToList();
                var idColumn = new DataColumn(DataNames.ID, typeof(Guid));

                #region add columns

                dt.Columns.Add(idColumn);
                dt.Columns.Add(DataNames.ParentID, typeof(Guid));
                dt.Columns.Add(DataNames.Privacy, typeof(int));
                dt.Columns.Add(DataNames.Created, typeof(DateTime));
                dt.Columns.Add(DataNames.Modified, typeof(DateTime));
                dt.Columns.Add(DataNames.Published, typeof(DateTime));
                dt.Columns.Add(DataNames.Pos, typeof(int));
                dt.Columns.Add(DataNames.State, typeof(int));
                dt.Columns.Add(DataNames.IsPublished, typeof(bool));
                dt.Columns.Add(DataNames.EnableComments, typeof(bool));
                dt.Columns.Add(DataNames.Slug, typeof(string));
                dt.Columns.Add(DataNames.Path, typeof(string));
                dt.Columns.Add(DataNames.Tags, typeof(string));
                dt.Columns.Add(DataNames.Categories, typeof(string));
                dt.Columns.Add(DataNames.Owner, typeof(string));
                dt.Columns.Add(DataNames.Modifier, typeof(string));
                dt.Columns.Add(DataNames.Ratings, typeof(double));
                dt.Columns.Add(DataNames.Reads, typeof(int));
                dt.Columns.Add(DataNames.TotalAttachs, typeof(int));
                dt.Columns.Add(DataNames.TotalVotes, typeof(int));
                dt.Columns.Add(DataNames.TotalComms, typeof(int));
                dt.Columns.Add(DataNames.TotalShares, typeof(int));
                dt.Columns.Add(DataNames.Version, typeof(int));
                dt.Columns.Add(DataNames.HasChildren, typeof(bool));
                dt.PrimaryKey = new DataColumn[] { idColumn };

                #endregion

                var vfs = this.FieldRefs.Count == 0 ? this.Parent.Fields.Select(f => f).ToList() : this.FieldRefs.Select(f => f.Field).ToList();

                foreach (var f in vfs)
                {
                    dt.Columns.Add(f.Name, f.SystemType);
                }

                foreach (var item in items)
                {
                    var   itemWrapper = new ContentDataItemDecorator(item, Context);
                    int[] cats        = null;

                    if (item.Categories != null)
                    {
                        cats = item.Categories.Select(c => c.ID).ToArray();
                    }

                    #region add new row
                    var row = dt.NewRow();
                    row[DataNames.ID]       = item.ID;
                    row[DataNames.ParentID] = item.ParentItemID;
                    row[DataNames.Privacy]  = item.Privacy;
                    row[DataNames.Created]  = item.Created;
                    row[DataNames.Pos]      = item.Pos;
                    if (item.Modified.HasValue)
                    {
                        row[DataNames.Modified] = item.Modified;
                    }

                    if (item.Published.HasValue)
                    {
                        row[DataNames.Published] = item.Published;
                    }

                    row[DataNames.IsPublished]    = item.IsPublished;
                    row[DataNames.Modifier]       = item.Modifier;
                    row[DataNames.State]          = item.ModerateState;
                    row[DataNames.Tags]           = item.Tags;
                    row[DataNames.Slug]           = item.Slug;
                    row[DataNames.Path]           = item.Path;
                    row[DataNames.Categories]     = cats != null ? (string.Join(",", Context.Where <Category>(c => cats.Contains(c.ID)).Select(c => c.Name).ToArray())) : "";
                    row[DataNames.EnableComments] = item.EnableComments;
                    row[DataNames.Owner]          = item.Owner;
                    row[DataNames.Ratings]        = item.Ratings;
                    row[DataNames.Reads]          = item.Reads;
                    row[DataNames.TotalAttachs]   = item.TotalAttachments;
                    row[DataNames.TotalVotes]     = item.TotalVotes;
                    row[DataNames.TotalComms]     = itemWrapper.TotalComments;
                    row[DataNames.TotalShares]    = Parent.AllowResharing ? itemWrapper.Reshares().Count() : 0;
                    row[DataNames.Version]        = itemWrapper.Version;
                    row[DataNames.HasChildren]    = Parent.IsHierarchy ? itemWrapper.Children().Count() > 0 : false;

                    foreach (var v in vfs)
                    {
                        var raw = itemWrapper.Value(v.Name).Raw;
                        if (raw == null)
                        {
                            row[v.Name] = DBNull.Value;
                        }
                        else
                        {
                            row[v.Name] = raw;
                        }
                    }
                    dt.Rows.Add(row);

                    #endregion
                }

                dt.AcceptChanges();
                dt.DefaultView.Sort      = this.Sort;
                dt.DefaultView.RowFilter = FormatFilter(this.Filter);

                //At first we need to apply the first filter for this table
                cacheTable            = dt.DefaultView.ToTable();
                cacheTable.PrimaryKey = new DataColumn[] { cacheTable.Columns[DataNames.ID] };
                cacheTable.WriteXml(viewDataFile);
                cacheTable.WriteXmlSchema(schema, true);
            }
            else
            {
                dt.ReadXmlSchema(schema);
                dt.ReadXml(viewDataFile);
                cacheTable = dt;
            }
            //AddToCache(dt);
            return(cacheTable);
        }