예제 #1
0
        private static string GetDataSourceName(IDataItem item)
        {
            string dataSourceName = null;

            if (item != null && item is DynamicContent)
            {
                var moduleProvider = ModuleBuilderManager.GetManager().Provider;
                var itemType       = item.GetType().FullName;

                var dynamicContentType = moduleProvider.GetDynamicModules()
                                         .Where(m => m.Status == DynamicModuleStatus.Active)
                                         .Join(moduleProvider.GetDynamicModuleTypes().Where(t => string.Concat(t.TypeNamespace, ".", t.TypeName) == itemType), m => m.Id, t => t.ParentModuleId, (m, t) => t)
                                         .FirstOrDefault();

                if (dynamicContentType != null)
                {
                    dataSourceName = dynamicContentType.ModuleName;
                }
            }
            else if (item != null)
            {
                Type managerType;
                if (ManagerBase.TryGetMappedManagerType(item.GetType(), out managerType))
                {
                    dataSourceName = managerType.FullName;
                }
            }

            return(dataSourceName);
        }
예제 #2
0
        public static MvcHtmlString CommentsCount(this HtmlHelper helper, string navigateUrl, IDataItem item)
        {
            if (item == null)
                return MvcHtmlString.Empty;

            var contentItem = item as Content;
            bool? allowComments = contentItem != null ? contentItem.AllowComments : null;
            var threadKey = ControlUtilities.GetLocalizedKey(item.Id, null, CommentsBehaviorUtilities.GetLocalizedKeySuffix(item.GetType().FullName));
            var itemTypeFullName = item.GetType().FullName;

            return CommentsHelpers.CommentsCount(helper, navigateUrl, threadKey, itemTypeFullName, allowComments);
        }
예제 #3
0
        /// <summary>
        /// Process a message and put it into the correct bucket
        /// </summary>
        /// <param name="packet"></param>
        public bool ProcessMessage(string packet)
        {
            try
            {
                //create our type
                IDataItem item = Activator.CreateInstance(Table.DataType) as IDataItem;

                //get the fields of packet
                string[] fields = packet.Split(Table.ColumnDelimiters, StringSplitOptions.None);

                //parse the fields
                for (int x = 0; x < fields.Length; x++)
                {
                    //get the column
                    var column = Table.ColumnsMetadata.Values.FirstOrDefault(c => c.OrdinalPosition == x);

                    //ILineProcessor is here
                    var value = Convert.ChangeType(fields[x], column.ColumnType);

                    //put in our object
                    item.GetType().GetField(column.FieldMapping).SetValue(item, value);
                }
                //action to take for message
                ProcessMessageAction(packet, item);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
            return(false);
        }
예제 #4
0
        /// <summary>
        /// delete an item given its catalog table
        /// </summary>
        /// <param name="item"></param>
        /// <param name="table"></param>
        public void DeleteItem(IDataItem item, bool HardDelete)
        {
            //the table to call delete item with
            IReferenceDataTable delete_table = null;

            //check if this is a reference table
            if (TableMetadata.ReferenceTable)
            {
                //get the reference table
                delete_table = (IReferenceDataTable)this;
            }
            else
            {
                //get the mod field
                IColumnMetadata column = TableMetadata.ColumnsMetadata[TableMetadata.ModField];

                //get the value to mode
                object obj = item.GetType().GetField(column.FieldMapping).GetValue(item);
                Int64  id  = Convert.ToInt64(obj);

                //mod to get the bucket index
                Int64 bucket = id % TableMetadata.CatalogMetadata.Catalog.ComputeNode.GlobalBucketCount;

                //get the bucket table
                delete_table = TableMetadata.CatalogMetadata.Catalog.Buckets[bucket].BucketDataTables[TableMetadata.TableName];
            }
            //call delete
            if (delete_table != null)
            {
                DeleteItem(item, delete_table, HardDelete);
            }
        }
예제 #5
0
        private void TypeSwitchConvert(byte[] message, IDataItem dataItem)
        {
            switch (dataItem)
            {
            case IDataItem <bool> di:
                di.Value = message[0] == 1;
                break;

            case IDataItem <short> di:
                di.Value = (short)(message[0] << 8 | message[1]);
                break;

            case IDataItem <int> di:
                di.Value = message[0] << 24 | message[1] << 16 | message[2] << 8 | message[3];
                break;

            case IDataItem <float> di:
                di.Value = 0;
                break;

            case IDataItem <string> di:
                di.Value = Encoding.ASCII.GetString(message);
                break;

            default:
                throw new ArgumentException($"Type {dataItem.GetType()} not supported.");
            }
        }
예제 #6
0
        internal virtual string GetDefaultCanonicalUrl(IDataItem item)
        {
            IManager manager = null;

            if (!ManagerBase.TryGetMappedManager(item.GetType(), string.Empty, out manager))
            {
                return(null);
            }

            var locationsService = SystemManager.GetContentLocationService();

            if (item is ILifecycleDataItemGeneric lifecycleDataItem &&
                lifecycleDataItem.Status != GenericContent.Model.ContentLifecycleStatus.Master &&
                manager is ILifecycleManager lifecycleManager)
            {
                item = lifecycleManager.Lifecycle.GetMaster(lifecycleDataItem);
            }

            var location = locationsService.GetItemDefaultLocation(item);

            if (location != null)
            {
                return(location.ItemAbsoluteUrl);
            }

            var page         = this.HttpContext.CurrentHandler.GetPageHandler();
            var pageNode     = SiteMapBase.GetActualCurrentNode();
            var canonicalUrl = page.GetCanonicalUrlForPage(pageNode);

            return(canonicalUrl);
        }
        /// <summary>
        /// Gets the database context.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns>DbContext.</returns>
        /// <exception cref="NotSupportedException">Items of type {item.GetType()}</exception>
        public DbContext GetDbContext(IDataItem item)
        {
            if (_dbContext.ContextSupports(item))
            {
                return(_dbContext);
            }

            throw new NotSupportedException($"Items of type {item.GetType()} are not supported by this DataContextProvider");
        }
예제 #8
0
 /// <summary>
 /// Creates an instance of the item view model by given data item.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns></returns>
 protected ItemViewModel CreateItemViewModelInstance(IDataItem item)
 {
     if (item.GetType() == typeof(SitefinityProfile))
     {
         return(new SitefinityProfileItemViewModel(item));
     }
     else
     {
         return(new ItemViewModel(item));
     }
 }
예제 #9
0
 public static IEnumerable <string> GetPropertyNames(this IDataItem dataItem)
 {
     if (dataItem != null)
     {
         var type = dataItem.GetType();
         foreach (var propName in type.GetProperties(BindingFlags.Public).Select(pi => pi.Name))
         {
             yield return(propName);
         }
     }
 }
예제 #10
0
        public static MvcHtmlString CommentsCount(this HtmlHelper helper, string navigateUrl, IDataItem item)
        {
            if (item == null)
            {
                return(MvcHtmlString.Empty);
            }

            var  contentItem      = item as Content;
            bool?allowComments    = contentItem != null ? contentItem.AllowComments : null;
            var  threadKey        = ControlUtilities.GetLocalizedKey(item.Id, null, CommentsBehaviorUtilities.GetLocalizedKeySuffix(item.GetType().FullName));
            var  itemTypeFullName = item.GetType().FullName;

            return(CommentsHelpers.CommentsCount(helper, navigateUrl, threadKey, itemTypeFullName, allowComments));
        }
예제 #11
0
        public static object GetPropertyValue(this IDataItem dataItem, string name)
        {
            if (dataItem == null)
            {
                throw new ArgumentNullException("dataItem");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            var type = dataItem.GetType();
            var pi   = type.GetProperty(name);

            return(pi.GetValue(dataItem));
        }
예제 #12
0
        /// <summary>
        /// Distinguish the currently opened content item and other content items on the same page that are in details mode.
        /// The current navigated URL is a canonical URL for an item. We take its meta properties.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        internal virtual bool IsURLMatch(IDataItem item)
        {
            IManager manager = null;

            if (!ManagerBase.TryGetMappedManager(item.GetType(), string.Empty, out manager))
            {
                return(true);
            }

            var locationsService = SystemManager.GetContentLocationService();
            var locations        = locationsService.GetItemLocations(item);
            var currentNode      = (PageSiteNode)SystemManager.CurrentHttpContext.Items[SiteMapBase.CurrentNodeKey];
            var itemUrl          = HyperLinkHelpers.GetDetailPageUrl(item, currentNode.Id);

            // TODO: compare urls better
            return(locations.Any(location => location.ItemAbsoluteUrl == itemUrl));
        }
예제 #13
0
        public T Create<T>(IDataItem source)
        {
            if (source == null) return default(T);

            if (typeof(T).IsAssignableFrom(source.GetType()))
                return (T)source;

            // need to unproxy otherwise Mapper won't recognize the type (nhibernate proxy class)
            T result = Mapper.Map<T>(NHibernateUtility.Unproxy(Session, source));

            foreach (var injection in _injections)
            {
                result.InjectFrom(injection, source);
            }

            return result;
        }
예제 #14
0
        internal virtual string GetDefaultCanonicalUrl(IDataItem item)
        {
            IManager manager = null;

            if (!ManagerBase.TryGetMappedManager(item.GetType(), string.Empty, out manager))
            {
                return(null);
            }

            var locationsService = SystemManager.GetContentLocationService();
            var location         = locationsService.GetItemDefaultLocation(item);

            if (location != null)
            {
                return(location.ItemAbsoluteUrl);
            }

            return(null);
        }
예제 #15
0
        private static MvcHtmlString GetCommentsList(HtmlHelper helper, IDataItem item, string title)
        {
            if (SystemManager.GetModule("Comments") == null || item == null)
            {
                return(MvcHtmlString.Empty);
            }

            var itemTypeFullName = item.GetType().FullName;
            var itemProviderName = item.GetProviderName();

            var itemThreadKey = ControlUtilities.GetLocalizedKey(item.Id, null, CommentsBehaviorUtilities.GetLocalizedKeySuffix(itemTypeFullName));
            var itemGroupKey  = ControlUtilities.GetUniqueProviderKey(GetDataSourceName(item), itemProviderName);

            var routeDictionary = new System.Web.Routing.RouteValueDictionary()
            {
                { "AllowComments", GetAllowComments(item) },
                { "ThreadKey", itemThreadKey },
                { "ThreadTitle", title },
                { "ThreadType", itemTypeFullName },
                { "GroupKey", itemGroupKey },
                { "DataSource", itemProviderName }
            };

            var controllerName = itemThreadKey.EndsWith(ReviewsSuffix, StringComparison.Ordinal) ? CommentsHelpers.ReviewsControllerName : CommentsHelpers.CommentsControllerName;

            MvcHtmlString result;

            try
            {
                result = helper.Action(CommentsHelpers.IndexActionName, controllerName, routeDictionary);
            }
            catch (HttpException)
            {
                result = MvcHtmlString.Empty;
            }
            catch (NullReferenceException)
            {
                //// Telerik.Sitefinity.Mvc.SitefinityMvcRoute GetOrderedParameters() on line 116 controllerType.GetMethods() throws null reference exception (controllerType is null).
                result = MvcHtmlString.Empty;
            }

            return(result);
        }
예제 #16
0
        /// <summary>
        /// put this item in the correct tables
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        protected override bool ProcessMessageAction(string packet, IDataItem item)
        {
            try
            {
                //get the mod field
                long mod    = (long)Convert.ChangeType(item.GetType().GetField(Table.ModField).GetValue(item), typeof(long));
                long bucket = mod % ComputeNode.GlobalBucketCount;

                //send the packet along
                Catalog.Buckets[bucket].BucketDataTables[Table.TableName].AddOrUpdate(item.PrimaryKey, item);
                Catalog.CatalogDataTables[Table.TableName].AddOrUpdate(item.PrimaryKey, item);

                return(true);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
            return(false);
        }
예제 #17
0
        /// <summary>
        /// put this item in the correct tables
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        protected override bool ProcessMessageAction(string packet, IDataItem item)
        {
            try
            {
                //get the mod field
                long mod = (long)Convert.ChangeType(item.GetType().GetField(Table.ModField).GetValue(item), typeof(long));
                long bucket = mod % ComputeNode.GlobalBucketCount;
                
                //send the packet along
                Catalog.Buckets[bucket].BucketDataTables[Table.TableName].AddOrUpdate(item.PrimaryKey, item);
                Catalog.CatalogDataTables[Table.TableName].AddOrUpdate(item.PrimaryKey, item);

                return true;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
            return false;
        }
예제 #18
0
        /// <summary>
        /// send this packet along to the correct bermuda node to be saved
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        protected override bool ProcessMessageAction(string packet, IDataItem item)
        {
            try
            {
                //get the mod field
                long   mod      = (long)Convert.ChangeType(item.GetType().GetField(Table.ModField).GetValue(item), typeof(long));
                long   bucket   = mod % ComputeNode.GlobalBucketCount;
                long   instance = bucket % AddressMap.Count;
                string address  = AddressMap[instance];

                //send the packet along
                Client.Send(packet, address);

                return(true);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
            return(false);
        }
예제 #19
0
        /// <summary>
        /// send this packet along to the correct bermuda node to be saved
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        protected override bool ProcessMessageAction(string packet, IDataItem item)
        {
            try
            {
                //get the mod field
                long mod = (long)Convert.ChangeType(item.GetType().GetField(Table.ModField).GetValue(item), typeof(long));
                long bucket = mod % ComputeNode.GlobalBucketCount;
                long instance = bucket % AddressMap.Count;
                string address = AddressMap[instance];

                //send the packet along
                Client.Send(packet, address);

                return true;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
            return false;
        }
예제 #20
0
        public static JsonCacheTypes.Item ToCacheJsonItem(IDataItem item)
        {
            switch (item)
            {
            case DataNode modelNode:
                return(new JsonCacheTypes.Item {
                    Node = ToCacheJsonNode(modelNode)
                });

            case DataLink modelLink:
                return(new JsonCacheTypes.Item {
                    Link = ToJsonLink(modelLink)
                });

            case DataLine modelLine:
                return(new JsonCacheTypes.Item {
                    Line = ToCacheJsonLine(modelLine)
                });

            default:
                throw Asserter.FailFast($"Unsupported item {item?.GetType()}");
            }
        }
        internal virtual string GetDefaultCanonicalUrl(IDataItem item)
        {
            IManager manager = null;

            if (!ManagerBase.TryGetMappedManager(item.GetType(), string.Empty, out manager))
            {
                return(null);
            }

            var locationsService = SystemManager.GetContentLocationService();
            var location         = locationsService.GetItemDefaultLocation(item);

            if (location != null)
            {
                return(location.ItemAbsoluteUrl);
            }

            var page         = this.HttpContext.CurrentHandler.GetPageHandler();
            var pageNode     = SiteMapBase.GetActualCurrentNode();
            var canonicalUrl = page.GetCanonicalUrlForPage(pageNode);

            return(canonicalUrl);
        }
예제 #22
0
        private bool CanDisplayItem(IDataItem item)
        {
            bool isParentSelected = true;
            var  modelProperty    = this.Controller.GetType().GetProperty("Model");

            if (modelProperty != null)
            {
                var model = modelProperty.GetValue(this.Controller);
                if (item is IHasParent)
                {
                    var serializedSelectedParentsIdsProperty = model.GetType().GetProperty("SerializedSelectedParentsIds");
                    if (serializedSelectedParentsIdsProperty != null)
                    {
                        var serializedSelectedParentsIds = serializedSelectedParentsIdsProperty.GetValue(model);
                        if (serializedSelectedParentsIds != null)
                        {
                            isParentSelected = serializedSelectedParentsIds.ToString().Contains((item as IHasParent).Parent.Id.ToString());

                            if (!isParentSelected)
                            {
                                var folderIdProperty = item.GetType().GetProperty("FolderId");
                                if (folderIdProperty != null)
                                {
                                    var folderId = folderIdProperty.GetValue(item);
                                    if (folderId != null)
                                    {
                                        isParentSelected = serializedSelectedParentsIds.ToString().Contains(folderId.ToString());
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(isParentSelected);
        }
예제 #23
0
        /// <summary>
        /// add data item to the table
        /// </summary>
        /// <param name="item"></param>
        public bool AddItem(IDataItem item)
        {
            object obj;
            bool   bRet = false;

            //check if table type to handle relations
            if (this is RelationshipDataTable)
            {
                //parse the table's relationships
                RelationshipDataTable rel_table = this as RelationshipDataTable;

                //get the fields
                long parent_id = Convert.ToInt64(item.GetType().GetField(rel_table.RelationshipMetadata.ParentRelationshipField).GetValue(item));
                long child_id  = Convert.ToInt64(item.GetType().GetField(rel_table.RelationshipMetadata.ChildRelationshipField).GetValue(item));

                //lock the resource
                lock (rel_table.RelationshipParentLookup)
                {
                    //add the relation
                    //if (ReferenceEquals(AddOrUpdate(item.PrimaryKey, item), item))
                    {
                        //look for the parent item
                        IBucketDataTable bucket_table = rel_table.Bucket.BucketDataTables[rel_table.RelationshipMetadata.ParentTable.TableName];
                        IDataItem        parent_item;
                        if (bucket_table.TryGetValue(parent_id, bucket_table.TableMetadata.DataType, out obj))
                        {
                            //add to the parent item
                            parent_item = (IDataItem)obj;
                            //List<long> list = (List<long>)parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).GetValue(parent_item);
                            List <Tuple <List <long>, long> > list = (List <Tuple <List <long>, long> >)parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).GetValue(parent_item);
                            lock (parent_item)
                            {
                                try
                                {
                                    //check the list to init
                                    if (list == null)
                                    {
                                        list = new List <Tuple <List <long>, long> >();
                                    }

                                    //check for no items
                                    if (list.Count == 0)
                                    {
                                        List <long> sub_list = new List <long>();
                                        sub_list.Add(item.PrimaryKey);
                                        list.Add(new Tuple <List <long>, long>(sub_list, child_id));
                                        bRet = true;
                                    }
                                    else
                                    {
                                        //get the sub list
                                        var tuple = list.FirstOrDefault(t => t.Item2 == child_id);
                                        if (tuple == null)
                                        {
                                            List <long> sub_list = new List <long>();
                                            sub_list.Add(item.PrimaryKey);
                                            list.Add(new Tuple <List <long>, long>(sub_list, child_id));
                                            bRet = true;
                                        }
                                        else
                                        {
                                            //is this a distinct relationship
                                            if (rel_table.RelationshipMetadata.DistinctRelationship)
                                            {
                                                //check if item is already added
                                                if (!tuple.Item1.Contains(item.PrimaryKey))
                                                {
                                                    tuple.Item1.Add(item.PrimaryKey);
                                                    bRet = true;
                                                }
                                            }
                                            else
                                            {
                                                if (!list.Any(t => t.Item1.Contains(item.PrimaryKey)))
                                                {
                                                    List <long> sub_list = new List <long>();
                                                    sub_list.Add(item.PrimaryKey);
                                                    list.Add(new Tuple <List <long>, long>(sub_list, child_id));
                                                    bRet = true;
                                                }
                                            }
                                        }
                                    }
                                    //check if should update the field
                                    if (bRet)
                                    {
                                        parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).SetValue(parent_item, list);
                                    }


                                    //if (!list.Any(t => t.Item2 == child_id))
                                    //{
                                    //    List<long> sub_list = new List<long>();
                                    //    sub_list.Add(item.PrimaryKey);
                                    //    list.Add(new Tuple<List<long>, long>(sub_list, child_id));
                                    //    if (rel_table.RelationshipMetadata.DistinctRelationship)
                                    //        parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).SetValue(parent_item, list);
                                    //    bRet = true;
                                    //}
                                }
                                catch (Exception ex)
                                {
                                    System.Diagnostics.Trace.WriteLine(ex.ToString());
                                }
                            }
                        }
                        else
                        {
                            //update the lookup
                            //rel_table.RelationshipParentLookup.AddOrUpdate
                            //    (
                            //            parent_id,
                            //            new ConcurrentDictionary<long, long>
                            //                (
                            //                new KeyValuePair<long, long>[]
                            //                {
                            //                    new KeyValuePair<long, long>
                            //                        (
                            //                            item.PrimaryKey,
                            //                            child_id
                            //                        )
                            //                }
                            //            ),
                            //        (x, y) =>
                            //        {
                            //            y.AddOrUpdate
                            //                (
                            //                    item.PrimaryKey,
                            //                    child_id,
                            //                    (j, k) => { return k; }
                            //                );
                            //            return y;
                            //        }
                            //    );
                        }
                    }
                }
                ////update the parent collection
                //IBucketDataTable bucket_table = rel_table.Bucket.BucketDataTables[rel_table.RelationshipMetadata.ParentTable.TableName];
                //IDataItem parent_item;
                //if (bucket_table.TryGetValue(parent_id, bucket_table.TableMetadata.DataType, out obj))
                //{
                //    parent_item = (IDataItem)obj;
                //    parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).SetValue(parent_item, rel_table.GetChildList(parent_id));
                //}
            }
            else if (this is BucketDataTable)
            {
                //cast the table
                BucketDataTable bucket_table = this as BucketDataTable;

                //add the bucket reference
                object objItem = AddOrUpdate(item.PrimaryKey, item);
                if (ReferenceEquals(objItem, item))
                {
                    //parse the table's relationships
                    //foreach (RelationshipMetadata rel in this.TableMetadata.CatalogMetadata.Relationships.Where(r => r.Value.ParentTable.TableName == TableMetadata.TableName).Select(r => r.Value))
                    //{
                    //    //get the relationship table
                    //    RelationshipDataTable rel_table = bucket_table.Bucket.BucketDataTables[rel.RelationTable.TableName] as RelationshipDataTable;

                    //    //lock the resource
                    //    lock (rel_table.RelationshipParentLookup)
                    //    {
                    //        //remove the lookup
                    //        ConcurrentDictionary<long, long> lookup;
                    //        if (rel_table.RelationshipParentLookup.TryGetValue(item.PrimaryKey, out lookup))
                    //        {
                    //            //set the child collection
                    //            item.GetType().GetField(rel.ParentChildCollection).SetValue(item, rel_table.GetChildList(item.PrimaryKey));

                    //            //remove the list
                    //            rel_table.RelationshipParentLookup.TryRemove(item.PrimaryKey, out lookup);
                    //        }
                    //    }
                    //}
                    bRet = true;
                }
                else
                {
                    bRet = false;
                    //parse the table's relationships
                    //foreach (RelationshipMetadata rel in this.TableMetadata.CatalogMetadata.Relationships.Where(r => r.Value.ParentTable.TableName == TableMetadata.TableName).Select(r => r.Value))
                    //{
                    //    //get the relationship table
                    //    RelationshipDataTable rel_table = bucket_table.Bucket.BucketDataTables[rel.RelationTable.TableName] as RelationshipDataTable;

                    //    //lock the resource
                    //    lock (rel_table.RelationshipParentLookup)
                    //    {
                    //        //copy the collection
                    //        item.GetType().GetField(rel.ParentChildCollection).SetValue(item, objItem.GetType().GetField(rel.ParentChildCollection).GetValue(objItem));
                    //    }
                    //}
                }
                //update our catalog
                var catalog_table = this.TableMetadata.CatalogMetadata.Catalog.CatalogDataTables[this.TableMetadata.TableName];
                catalog_table.AddOrUpdate(item.PrimaryKey, item);
            }
            else
            {
                string test = "test";
            }

            return(bRet);
        }
예제 #24
0
        private static MvcHtmlString GetCommentsList(HtmlHelper helper, IDataItem item, string title)
        {
            if (SystemManager.GetModule("Comments") == null || item == null)
            {
                return MvcHtmlString.Empty;
            }

            var itemTypeFullName = item.GetType().FullName;
            var itemProviderName = item.GetProviderName();

            var itemThreadKey = ControlUtilities.GetLocalizedKey(item.Id, null, CommentsBehaviorUtilities.GetLocalizedKeySuffix(itemTypeFullName));
            var itemGroupKey = ControlUtilities.GetUniqueProviderKey(GetDataSourceName(item), itemProviderName);

            var routeDictionary = new System.Web.Routing.RouteValueDictionary()
            {
                { "AllowComments", GetAllowComments(item) },
                { "ThreadKey", itemThreadKey },
                { "ThreadTitle", title },
                { "ThreadType", itemTypeFullName },
                { "GroupKey", itemGroupKey },
                { "DataSource", itemProviderName }
            };

            var controllerName = itemThreadKey.EndsWith(ReviewsSuffix, StringComparison.Ordinal) ? CommentsHelpers.ReviewsControllerName : CommentsHelpers.CommentsControllerName;

            MvcHtmlString result;
            try
            {
                result = helper.Action(CommentsHelpers.IndexActionName, controllerName, routeDictionary);
            }
            catch (HttpException)
            {
                result = MvcHtmlString.Empty;
            }
            catch (NullReferenceException)
            {
                //// Telerik.Sitefinity.Mvc.SitefinityMvcRoute GetOrderedParameters() on line 116 controllerType.GetMethods() throws null reference exception (controllerType is null).
                result = MvcHtmlString.Empty;
            }

            return result;
        }
예제 #25
0
        private static string GetDataSourceName(IDataItem item)
        {
            string dataSourceName = null;

            if (item != null && item is DynamicContent)
            {
                var moduleProvider = ModuleBuilderManager.GetManager().Provider;
                var itemType = item.GetType().FullName;

                var dynamicContentType = moduleProvider.GetDynamicModules()
                    .Where(m => m.Status == DynamicModuleStatus.Active)
                    .Join(moduleProvider.GetDynamicModuleTypes().Where(t => string.Concat(t.TypeNamespace, ".", t.TypeName) == itemType), m => m.Id, t => t.ParentModuleId, (m, t) => t)
                    .FirstOrDefault();

                if (dynamicContentType != null)
                {
                    dataSourceName = dynamicContentType.ModuleName;
                }
            }
            else if (item != null)
            {
                Type managerType;
                if (ManagerBase.TryGetMappedManagerType(item.GetType(), out managerType))
                {
                    dataSourceName = managerType.FullName;
                }
            }

            return dataSourceName;
        }
예제 #26
0
        public IDataItem GetItemByUrl(string url, Type itemType, string provider, out string redirectUrl)
        {
            var manager = this.ResolveManager(itemType, provider);

            if (manager == null)
            {
                redirectUrl = null;
                return(null);
            }

            var itemIdFromQueryParam = (SystemManager.CurrentHttpContext.Request.ParamsGet("sf-itemId") ?? SystemManager.CurrentHttpContext.Items["sf-itemId"]) as string;

            if (!itemIdFromQueryParam.IsNullOrEmpty())
            {
                Guid itemIdGuid;
                if (Guid.TryParse(itemIdFromQueryParam, out itemIdGuid))
                {
                    redirectUrl = null;
                    return(manager.GetItem(itemType, itemIdGuid) as IDataItem);
                }
            }

            IDataItem item = null;

            if (manager is IContentManager || manager is DynamicModuleManager)
            {
                try
                {
                    item = this.GetItemFromUrl(manager, itemType, url, out redirectUrl);
                }
                catch (System.UnauthorizedAccessException e)
                {
                    redirectUrl = null;
                    ItemAccessException access = new ItemAccessException(e.Message, e.InnerException);
                    access.Data["ItemType"] = itemType.Name;

                    throw access;
                }

                if (item != null)
                {
                    var type = item.GetType();
                    if (!type.Equals(itemType) && !(type.Module != null && type.Module.ScopeName == "OpenAccessDynamic" && type.BaseType != null && type.BaseType.Equals(itemType)))
                    {
                        item = null;
                    }
                }
            }
            else
            {
                item = ((IUrlProvider)manager.Provider).GetItemFromUrl(itemType, url, out redirectUrl);
            }

            var lifecycleItem    = item as ILifecycleDataItem;
            var lifecycleManager = manager as ILifecycleManager;

            if (lifecycleItem != null && lifecycleManager != null)
            {
                ContentLifecycleStatus requestedStatus = ContentLocatableViewExtensions.GetRequestedItemStatus();
                if (lifecycleItem.Status != requestedStatus)
                {
                    item = lifecycleManager.Lifecycle.GetLive(lifecycleItem);
                }

                object requestedItem;
                if (ContentLocatableViewExtensions.TryGetItemWithRequestedStatus(lifecycleItem, lifecycleManager, out requestedItem))
                {
                    item = requestedItem as IDataItem;
                }
            }

            return(item);
        }
예제 #27
0
        /// <summary>
        /// the saturate data table routine
        /// </summary>
        /// <param name="obj"></param>
        private void SaturateDataTable(object obj)
        {
            //get the parameter
            SaturateDataTableData data = (SaturateDataTableData)obj;

            try
            {
                //the parent query for relations
                string parent_query = data.table.ConstructQuery();

                //check if we can saturate this table
                if (!data.table.CanSaturate())
                {
                    return;
                }

                //get the mod value
                Int64 mod = -1;
                if (data.table is BucketDataTable)
                {
                    mod = (data.table as BucketDataTable).Bucket.BucketMod;
                }

                //list of items
                List <IDataItem> list = new List <IDataItem>();

                //connect to db
                using (IDbConnection connection = DBFactory.CreateConnection(
                           data.table.Catalog.ConnectionString, data.table.Catalog.ConnectionType))
                {
                    //open the connection
                    connection.Open();

                    //create the command
                    using (IDbCommand command = DBFactory.CreateCommand(
                               parent_query, connection, data.table.Catalog.ConnectionType))
                    {
                        //set timeout
                        command.CommandTimeout = 5 * 60;

                        //execute the reader
                        using (IDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                        {
                            //parse the results
                            while (dr.Read())
                            {
                                //create the data item
                                try
                                {
                                    IDataItem item = (IDataItem)Activator.CreateInstance(data.table.TableMetadata.DataType);
                                    if (item != null)
                                    {
                                        //set the IDataItem with row info
                                        ProcessRow(dr, item, data.table, false);

                                        //add items to the list
                                        list.Add(item);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    System.Diagnostics.Trace.WriteLine(ex.ToString());
                                }
                            }
                        }
                    }
                    //close the connection for chad
                    connection.Close();
                }
                //process the parent items
                bool table_saturated = true;
                foreach (var item in list)
                {
                    //process the item
                    if (ProcessItem(item, data.table))
                    {
                        table_saturated = false;
                    }

                    //get the update field
                    object update = item.GetType().GetField(data.table.TableMetadata.SaturationUpdateField).GetValue(item);
                    data.table.UpdateLastValue(update);
                }
                //set table saturation
                data.table.Saturated = table_saturated;

                //report status
                ReportStatus(
                    data.table.Catalog.CatalogName,
                    mod,
                    data.table.TableMetadata.TableName,
                    list.Count,
                    data.table.DataItems.Count,
                    data.table.Catalog.CatalogDataTables[data.table.TableMetadata.TableName].DataItems.Count);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }
            finally
            {
                data.table.LastSaturation = DateTime.UtcNow;
                data.table.Saturating     = false;
                data.eventDone.Set();
            }
        }
예제 #28
0
        /// <summary>
        /// delete an item and its references
        /// </summary>
        /// <param name="item"></param>
        /// <param name="table"></param>
        private void DeleteItem(IDataItem item, IReferenceDataTable table, bool HardDelete)
        {
            //remove from table
            object objTable;
            object objCatalog;
            IDataItem removed;
            
            //check we need to handle relationship
            if (table is RelationshipDataTable)
            {
                //parse the table's relationships
                RelationshipDataTable rel_table = table as RelationshipDataTable;

                //get the fields
                long parent_id = Convert.ToInt64(item.GetType().GetField(rel_table.RelationshipMetadata.ParentRelationshipField).GetValue(item));
                long child_id = Convert.ToInt64(item.GetType().GetField(rel_table.RelationshipMetadata.ChildRelationshipField).GetValue(item));

                //lock the resource
                lock (rel_table.RelationshipParentLookup)
                {
                    //remove the item
                    if (table.TryRemove(item.PrimaryKey, table.TableMetadata.DataType, out objTable))
                    {
                        removed = (IDataItem)objTable;
                    }
                    //check if this is a hard delete
                    //HardDelete removes the relations
                    //SoftDelete leave the references
                    if (HardDelete)
                    {
                        //remove this relation
                        ConcurrentDictionary<long, long> lookup;
                        if (rel_table.RelationshipParentLookup.TryGetValue(parent_id, out lookup))
                        {
                            //remove all lookup entries for association
                            long id;
                            bool found = true;
                            while (found)
                                found = lookup.TryRemove(item.PrimaryKey, out id);

                            if (lookup.Count == 0)
                            {
                                //remove the lookup for this parent
                                if (rel_table.RelationshipParentLookup.TryRemove(parent_id, out lookup))
                                {
                                    //lookup.Clear();
                                    //lookup = null;
                                }
                            }
                        }
                        //get the parent item
                        object objParent;
                        IDataItem parent_item;
                        //dynamic parent_item;
                        IBucketDataTable parent_table = rel_table.Bucket.BucketDataTables[rel_table.RelationshipMetadata.ParentTable.TableName];
                        if (parent_table.TryGetValue(parent_id, parent_table.TableMetadata.DataType, out objParent))
                        {
                            parent_item = (IDataItem)objParent;
                            //parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).SetValue(parent_item, rel_table.GetChildList(parent_id));
                            var list = (List<Tuple<List<long>,long>>)parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).GetValue(parent_item);
                            if (rel_table.RelationshipMetadata.DistinctRelationship)
                            {
                                var rel_item = list.FirstOrDefault(t => t.Item2 == child_id);
                                if (rel_item != null)
                                {
                                    if (rel_item.Item1.Contains(item.PrimaryKey))
                                        rel_item.Item1.Remove(item.PrimaryKey);
                                    if (rel_item.Item1.Count == 0)
                                        list.Remove(rel_item);
                                }
                            }
                            else
                            {
                                var rel_item = list.FirstOrDefault(t => t.Item1.Any(l => l == item.PrimaryKey));
                                if (rel_item != null)
                                    list.Remove(rel_item);
                            }
                            
                        }
                    }
                }
                //if(rel_table.DataItems.Count % 1000 == 0)
                //{
                //    System.Diagnostics.Trace.WriteLine(
                //    string.Format(
                //        "Lookup Status - Catalog:{0}, Table:{1}, TableCount:{2}, LookupCount:{3}",
                //        rel_table.TableMetadata.CatalogMetadata.Catalog.CatalogName,
                //        rel_table.TableMetadata.TableName,
                //        rel_table.DataItems.Count,
                //        rel_table.RelationshipParentLookup.Count));
                //}
            }
            else if (table is BucketDataTable)
            {
                //remove the item
                if (table.TryRemove(item.PrimaryKey, table.TableMetadata.DataType, out objTable))
                {
                    removed = (IDataItem)objTable;
                }
                //parse the table's relationships
                BucketDataTable bucket_table = table as BucketDataTable;
                foreach (RelationshipMetadata rel in table.Catalog.CatalogMetadata.Relationships.Where(r => r.Value.ParentTable.TableName == table.TableMetadata.TableName).Select(r => r.Value))
                {
                    //get the relationship table
                    RelationshipDataTable rel_table = bucket_table.Bucket.BucketDataTables[rel.RelationTable.TableName] as RelationshipDataTable;

                    //lock the resource
                    lock (rel_table.RelationshipParentLookup)
                    {
                        //remove the lookup for this parent
                        ConcurrentDictionary<long, long> lookup;
                        if (rel_table.RelationshipParentLookup.TryRemove(item.PrimaryKey, out lookup))
                        {
                            lookup.Clear();
                            lookup = null;
                        }
                    }
                }
            }
            //remove from catalog
            if (table.Catalog.CatalogDataTables[table.TableMetadata.TableName].TryRemove(item.PrimaryKey, table.TableMetadata.DataType, out objCatalog))
            {
                removed = (IDataItem)objCatalog;
            }
        }
예제 #29
0
        /// <summary>
        /// delete an item and its references
        /// </summary>
        /// <param name="item"></param>
        /// <param name="table"></param>
        private void DeleteItem(IDataItem item, IReferenceDataTable table, bool HardDelete)
        {
            //remove from table
            object    objTable;
            object    objCatalog;
            IDataItem removed;

            //check we need to handle relationship
            if (table is RelationshipDataTable)
            {
                //parse the table's relationships
                RelationshipDataTable rel_table = table as RelationshipDataTable;

                //get the fields
                long parent_id = Convert.ToInt64(item.GetType().GetField(rel_table.RelationshipMetadata.ParentRelationshipField).GetValue(item));
                long child_id  = Convert.ToInt64(item.GetType().GetField(rel_table.RelationshipMetadata.ChildRelationshipField).GetValue(item));

                //lock the resource
                lock (rel_table.RelationshipParentLookup)
                {
                    //remove the item
                    if (table.TryRemove(item.PrimaryKey, table.TableMetadata.DataType, out objTable))
                    {
                        removed = (IDataItem)objTable;
                    }
                    //check if this is a hard delete
                    //HardDelete removes the relations
                    //SoftDelete leave the references
                    if (HardDelete)
                    {
                        //remove this relation
                        ConcurrentDictionary <long, long> lookup;
                        if (rel_table.RelationshipParentLookup.TryGetValue(parent_id, out lookup))
                        {
                            //remove all lookup entries for association
                            long id;
                            bool found = true;
                            while (found)
                            {
                                found = lookup.TryRemove(item.PrimaryKey, out id);
                            }

                            if (lookup.Count == 0)
                            {
                                //remove the lookup for this parent
                                if (rel_table.RelationshipParentLookup.TryRemove(parent_id, out lookup))
                                {
                                    //lookup.Clear();
                                    //lookup = null;
                                }
                            }
                        }
                        //get the parent item
                        object    objParent;
                        IDataItem parent_item;
                        //dynamic parent_item;
                        IBucketDataTable parent_table = rel_table.Bucket.BucketDataTables[rel_table.RelationshipMetadata.ParentTable.TableName];
                        if (parent_table.TryGetValue(parent_id, parent_table.TableMetadata.DataType, out objParent))
                        {
                            parent_item = (IDataItem)objParent;
                            //parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).SetValue(parent_item, rel_table.GetChildList(parent_id));
                            var list = (List <Tuple <List <long>, long> >)parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).GetValue(parent_item);
                            if (rel_table.RelationshipMetadata.DistinctRelationship)
                            {
                                var rel_item = list.FirstOrDefault(t => t.Item2 == child_id);
                                if (rel_item != null)
                                {
                                    if (rel_item.Item1.Contains(item.PrimaryKey))
                                    {
                                        rel_item.Item1.Remove(item.PrimaryKey);
                                    }
                                    if (rel_item.Item1.Count == 0)
                                    {
                                        list.Remove(rel_item);
                                    }
                                }
                            }
                            else
                            {
                                var rel_item = list.FirstOrDefault(t => t.Item1.Any(l => l == item.PrimaryKey));
                                if (rel_item != null)
                                {
                                    list.Remove(rel_item);
                                }
                            }
                        }
                    }
                }
                //if(rel_table.DataItems.Count % 1000 == 0)
                //{
                //    System.Diagnostics.Trace.WriteLine(
                //    string.Format(
                //        "Lookup Status - Catalog:{0}, Table:{1}, TableCount:{2}, LookupCount:{3}",
                //        rel_table.TableMetadata.CatalogMetadata.Catalog.CatalogName,
                //        rel_table.TableMetadata.TableName,
                //        rel_table.DataItems.Count,
                //        rel_table.RelationshipParentLookup.Count));
                //}
            }
            else if (table is BucketDataTable)
            {
                //remove the item
                if (table.TryRemove(item.PrimaryKey, table.TableMetadata.DataType, out objTable))
                {
                    removed = (IDataItem)objTable;
                }
                //parse the table's relationships
                BucketDataTable bucket_table = table as BucketDataTable;
                foreach (RelationshipMetadata rel in table.Catalog.CatalogMetadata.Relationships.Where(r => r.Value.ParentTable.TableName == table.TableMetadata.TableName).Select(r => r.Value))
                {
                    //get the relationship table
                    RelationshipDataTable rel_table = bucket_table.Bucket.BucketDataTables[rel.RelationTable.TableName] as RelationshipDataTable;

                    //lock the resource
                    lock (rel_table.RelationshipParentLookup)
                    {
                        //remove the lookup for this parent
                        ConcurrentDictionary <long, long> lookup;
                        if (rel_table.RelationshipParentLookup.TryRemove(item.PrimaryKey, out lookup))
                        {
                            lookup.Clear();
                            lookup = null;
                        }
                    }
                }
            }
            //remove from catalog
            if (table.Catalog.CatalogDataTables[table.TableMetadata.TableName].TryRemove(item.PrimaryKey, table.TableMetadata.DataType, out objCatalog))
            {
                removed = (IDataItem)objCatalog;
            }
        }
예제 #30
0
 /// <summary>
 /// Creates an instance of the item view model by given data item.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns></returns>
 protected ItemViewModel CreateItemViewModelInstance(IDataItem item)
 {
     if (item.GetType() == typeof(SitefinityProfile))
     {
         return new SitefinityProfileItemViewModel(item);
     }
     else
     {
         return new ItemViewModel(item);
     }
 }
예제 #31
0
        /// <summary>
        /// process a row
        /// </summary>
        /// <param name="dr"></param>
        /// <param name="item"></param>
        /// <param name="table_metadata"></param>
        private void ProcessRow(IDataReader dr, IDataItem item, IReferenceDataTable table, bool update_last_update)
        {
            //get the data
            List<Tuple<string,object>> data = new List<Tuple<string,object>>();
            for (int x = 0; x < dr.FieldCount; x++)
            {
                //get the column metadata
                string column_name = dr.GetName(x);
                IColumnMetadata col = null;
                if(table.TableMetadata.ColumnsMetadata.ContainsKey(column_name))
                    col = table.TableMetadata.ColumnsMetadata[column_name];

                if (col != null)
                {
                    //get the value
                    object value = dr[x];
                    data.Add(new Tuple<string, object>(column_name, value));

                    try
                    {
                        //check if the column is a collection
                        if (col.ColumnType == typeof(List<Tuple<List<long>, long>>))
                        {
                            string string_value = value.ToString();
                            List<Tuple<List<long>, long>> list = new List<Tuple<List<long>, long>>();
                            
                            //get the relationship for this field
                            var rel = table.Catalog.CatalogMetadata.Relationships.Values.FirstOrDefault(r => r.ParentChildCollection == column_name);

                            //check if null
                            if (!dr.IsDBNull(x))
                            {
                                foreach (var s in string_value.Split(','))
                                {
                                    string[] tuple = s.Split('|');
                                    if (tuple.Length == 2)
                                    {
                                        long item1;
                                        long item2;
                                        if (Int64.TryParse(tuple[0], out item1))
                                        {
                                            if (Int64.TryParse(tuple[1], out item2))
                                            {
                                                if (rel != null && rel.DistinctRelationship)
                                                {
                                                    var existing = list.FirstOrDefault(t => t.Item2 == item2);
                                                    if (existing == null)
                                                    {
                                                        List<long> sub_list = new List<long>();
                                                        sub_list.Add(item1);
                                                        list.Add(new Tuple<List<long>, long>(sub_list, item2));
                                                    }
                                                    else
                                                    {
                                                        existing.Item1.Add(item1);
                                                    }
                                                }
                                                else
                                                {
                                                    List<long> sub_list = new List<long>();
                                                    sub_list.Add(item1);
                                                    list.Add(new Tuple<List<long>, long>(sub_list, item2));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            //List<long> list = string_value.Split(',').Select(t => TryParseInt64(t))
                            //                                  .Where(i => i.HasValue)
                            //                                  .Select(i => i.Value)
                            //                                  .ToList();
                            item.GetType().GetField(col.FieldMapping).SetValue(item, list);
                        }
                        else
                        {
                            //check if null
                            if (!dr.IsDBNull(x))
                            {
                                //set the value with reflection
                                item.GetType().GetField(col.FieldMapping).SetValue(item, value);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Trace.WriteLine(ex.ToString());
                    }
                        
                    //update the last update value
                    if (column_name == table.TableMetadata.SaturationUpdateField && update_last_update)
                        table.UpdateLastValue(value);
                }
            }
            if (item is Mention)
            {
                if ((item as Mention).Tags == null)
                {
                    System.Diagnostics.Trace.WriteLine("NO");
                }
            }
        }
예제 #32
0
        /// <summary>
        /// delete an item given its catalog table
        /// </summary>
        /// <param name="item"></param>
        /// <param name="table"></param>
        public void DeleteItem(IDataItem item, bool HardDelete)
        {
            //the table to call delete item with
            IReferenceDataTable delete_table = null;

            //check if this is a reference table
            if (TableMetadata.ReferenceTable)
            {
                //get the reference table
                delete_table = (IReferenceDataTable)this;
            }
            else
            {
                //get the mod field
                IColumnMetadata column = TableMetadata.ColumnsMetadata[TableMetadata.ModField];

                //get the value to mode
                object obj = item.GetType().GetField(column.FieldMapping).GetValue(item);
                Int64 id = Convert.ToInt64(obj);

                //mod to get the bucket index
                Int64 bucket = id % TableMetadata.CatalogMetadata.Catalog.ComputeNode.GlobalBucketCount;

                //get the bucket table
                delete_table = TableMetadata.CatalogMetadata.Catalog.Buckets[bucket].BucketDataTables[TableMetadata.TableName];
            }
            //call delete
            if (delete_table != null)
                DeleteItem(item, delete_table, HardDelete);
        }
예제 #33
0
        /// <summary>
        /// add data item to the table
        /// </summary>
        /// <param name="item"></param>
        public bool AddItem(IDataItem item)
        {
            object obj;
            bool bRet = false;

            //check if table type to handle relations
            if (this is RelationshipDataTable)
            {
                //parse the table's relationships
                RelationshipDataTable rel_table = this as RelationshipDataTable;

                //get the fields
                long parent_id = Convert.ToInt64(item.GetType().GetField(rel_table.RelationshipMetadata.ParentRelationshipField).GetValue(item));
                long child_id = Convert.ToInt64(item.GetType().GetField(rel_table.RelationshipMetadata.ChildRelationshipField).GetValue(item));

                //lock the resource
                lock (rel_table.RelationshipParentLookup)
                {
                    //add the relation
                    //if (ReferenceEquals(AddOrUpdate(item.PrimaryKey, item), item))
                    {
                        //look for the parent item
                        IBucketDataTable bucket_table = rel_table.Bucket.BucketDataTables[rel_table.RelationshipMetadata.ParentTable.TableName];
                        IDataItem parent_item;
                        if (bucket_table.TryGetValue(parent_id, bucket_table.TableMetadata.DataType, out obj))
                        {
                            //add to the parent item
                            parent_item = (IDataItem)obj;
                            //List<long> list = (List<long>)parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).GetValue(parent_item);
                            List<Tuple<List<long>, long>> list = (List<Tuple<List<long>, long>>)parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).GetValue(parent_item);
                            lock (parent_item)
                            {
                                try
                                {
                                    //check the list to init
                                    if(list == null)
                                        list = new List<Tuple<List<long>, long>>();
                                    
                                    //check for no items
                                    if (list.Count == 0)
                                    {
                                        List<long> sub_list = new List<long>();
                                        sub_list.Add(item.PrimaryKey);
                                        list.Add(new Tuple<List<long>,long>(sub_list, child_id));
                                        bRet = true;
                                    }
                                    else
                                    {
                                        //get the sub list
                                        var tuple = list.FirstOrDefault(t => t.Item2 == child_id);
                                        if (tuple == null)
                                        {
                                            List<long> sub_list = new List<long>();
                                            sub_list.Add(item.PrimaryKey);
                                            list.Add(new Tuple<List<long>, long>(sub_list, child_id));
                                            bRet = true;
                                        }
                                        else
                                        {
                                            //is this a distinct relationship
                                            if (rel_table.RelationshipMetadata.DistinctRelationship)
                                            {
                                                //check if item is already added
                                                if (!tuple.Item1.Contains(item.PrimaryKey))
                                                {
                                                    tuple.Item1.Add(item.PrimaryKey);
                                                    bRet = true;
                                                }
                                            }
                                            else
                                            {
                                                if (!list.Any(t => t.Item1.Contains(item.PrimaryKey)))
                                                {
                                                    List<long> sub_list = new List<long>();
                                                    sub_list.Add(item.PrimaryKey);
                                                    list.Add(new Tuple<List<long>, long>(sub_list, child_id));
                                                    bRet = true;
                                                }
                                            }
                                        }
                                    }
                                    //check if should update the field
                                    if(bRet)
                                        parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).SetValue(parent_item, list);


                                    //if (!list.Any(t => t.Item2 == child_id))
                                    //{
                                    //    List<long> sub_list = new List<long>();
                                    //    sub_list.Add(item.PrimaryKey);
                                    //    list.Add(new Tuple<List<long>, long>(sub_list, child_id));
                                    //    if (rel_table.RelationshipMetadata.DistinctRelationship)
                                    //        parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).SetValue(parent_item, list);
                                    //    bRet = true;
                                    //}
                                }
                                catch (Exception ex)
                                {
                                    System.Diagnostics.Trace.WriteLine(ex.ToString());
                                }
                            }
                        }
                        else
                        {
                            //update the lookup
                            //rel_table.RelationshipParentLookup.AddOrUpdate
                            //    (
                            //            parent_id,
                            //            new ConcurrentDictionary<long, long>
                            //                (
                            //                new KeyValuePair<long, long>[] 
                            //                { 
                            //                    new KeyValuePair<long, long>
                            //                        (
                            //                            item.PrimaryKey, 
                            //                            child_id
                            //                        ) 
                            //                }
                            //            ),
                            //        (x, y) =>
                            //        {
                            //            y.AddOrUpdate
                            //                (
                            //                    item.PrimaryKey,
                            //                    child_id,
                            //                    (j, k) => { return k; }
                            //                );
                            //            return y;
                            //        }
                            //    );
                        }
                    }
                }
                ////update the parent collection
                //IBucketDataTable bucket_table = rel_table.Bucket.BucketDataTables[rel_table.RelationshipMetadata.ParentTable.TableName];
                //IDataItem parent_item;
                //if (bucket_table.TryGetValue(parent_id, bucket_table.TableMetadata.DataType, out obj))
                //{
                //    parent_item = (IDataItem)obj;
                //    parent_item.GetType().GetField(rel_table.RelationshipMetadata.ParentChildCollection).SetValue(parent_item, rel_table.GetChildList(parent_id));
                //}
            }
            else if (this is BucketDataTable)
            {
                //cast the table
                BucketDataTable bucket_table = this as BucketDataTable;

                //add the bucket reference
                object objItem = AddOrUpdate(item.PrimaryKey, item);
                if (ReferenceEquals(objItem, item))
                {
                    //parse the table's relationships
                    //foreach (RelationshipMetadata rel in this.TableMetadata.CatalogMetadata.Relationships.Where(r => r.Value.ParentTable.TableName == TableMetadata.TableName).Select(r => r.Value))
                    //{
                    //    //get the relationship table
                    //    RelationshipDataTable rel_table = bucket_table.Bucket.BucketDataTables[rel.RelationTable.TableName] as RelationshipDataTable;

                    //    //lock the resource
                    //    lock (rel_table.RelationshipParentLookup)
                    //    {
                    //        //remove the lookup
                    //        ConcurrentDictionary<long, long> lookup;
                    //        if (rel_table.RelationshipParentLookup.TryGetValue(item.PrimaryKey, out lookup))
                    //        {
                    //            //set the child collection
                    //            item.GetType().GetField(rel.ParentChildCollection).SetValue(item, rel_table.GetChildList(item.PrimaryKey));

                    //            //remove the list
                    //            rel_table.RelationshipParentLookup.TryRemove(item.PrimaryKey, out lookup);
                    //        }
                    //    }
                    //}
                    bRet = true;
                }
                else
                {
                    bRet = false;
                    //parse the table's relationships
                    //foreach (RelationshipMetadata rel in this.TableMetadata.CatalogMetadata.Relationships.Where(r => r.Value.ParentTable.TableName == TableMetadata.TableName).Select(r => r.Value))
                    //{
                    //    //get the relationship table
                    //    RelationshipDataTable rel_table = bucket_table.Bucket.BucketDataTables[rel.RelationTable.TableName] as RelationshipDataTable;

                    //    //lock the resource
                    //    lock (rel_table.RelationshipParentLookup)
                    //    {
                    //        //copy the collection
                    //        item.GetType().GetField(rel.ParentChildCollection).SetValue(item, objItem.GetType().GetField(rel.ParentChildCollection).GetValue(objItem));
                    //    }
                    //}
                }
                //update our catalog
                var catalog_table = this.TableMetadata.CatalogMetadata.Catalog.CatalogDataTables[this.TableMetadata.TableName];
                catalog_table.AddOrUpdate(item.PrimaryKey, item);
            }
            else
            {
                string test = "test";
            }

            return bRet;
        }
예제 #34
0
 /// <summary>
 /// An IDataItem extension method that gets a manager.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns>
 /// The manager.
 /// </returns>
 public static IManager GetManager(this IDataItem item)
 {
     return(ManagerBase.GetMappedManager(item.GetType()));
 }
예제 #35
0
        /// <summary>
        /// process a row
        /// </summary>
        /// <param name="dr"></param>
        /// <param name="item"></param>
        /// <param name="table_metadata"></param>
        private void ProcessRow(IDataReader dr, IDataItem item, IReferenceDataTable table, bool update_last_update)
        {
            //get the data
            List <Tuple <string, object> > data = new List <Tuple <string, object> >();

            for (int x = 0; x < dr.FieldCount; x++)
            {
                //get the column metadata
                string          column_name = dr.GetName(x);
                IColumnMetadata col         = null;
                if (table.TableMetadata.ColumnsMetadata.ContainsKey(column_name))
                {
                    col = table.TableMetadata.ColumnsMetadata[column_name];
                }

                if (col != null)
                {
                    //get the value
                    object value = dr[x];
                    data.Add(new Tuple <string, object>(column_name, value));

                    try
                    {
                        //check if the column is a collection
                        if (col.ColumnType == typeof(List <Tuple <List <long>, long> >))
                        {
                            string string_value = value.ToString();
                            List <Tuple <List <long>, long> > list = new List <Tuple <List <long>, long> >();

                            //get the relationship for this field
                            var rel = table.Catalog.CatalogMetadata.Relationships.Values.FirstOrDefault(r => r.ParentChildCollection == column_name);

                            //check if null
                            if (!dr.IsDBNull(x))
                            {
                                foreach (var s in string_value.Split(','))
                                {
                                    string[] tuple = s.Split('|');
                                    if (tuple.Length == 2)
                                    {
                                        long item1;
                                        long item2;
                                        if (Int64.TryParse(tuple[0], out item1))
                                        {
                                            if (Int64.TryParse(tuple[1], out item2))
                                            {
                                                if (rel != null && rel.DistinctRelationship)
                                                {
                                                    var existing = list.FirstOrDefault(t => t.Item2 == item2);
                                                    if (existing == null)
                                                    {
                                                        List <long> sub_list = new List <long>();
                                                        sub_list.Add(item1);
                                                        list.Add(new Tuple <List <long>, long>(sub_list, item2));
                                                    }
                                                    else
                                                    {
                                                        existing.Item1.Add(item1);
                                                    }
                                                }
                                                else
                                                {
                                                    List <long> sub_list = new List <long>();
                                                    sub_list.Add(item1);
                                                    list.Add(new Tuple <List <long>, long>(sub_list, item2));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            //List<long> list = string_value.Split(',').Select(t => TryParseInt64(t))
                            //                                  .Where(i => i.HasValue)
                            //                                  .Select(i => i.Value)
                            //                                  .ToList();
                            item.GetType().GetField(col.FieldMapping).SetValue(item, list);
                        }
                        else
                        {
                            //check if null
                            if (!dr.IsDBNull(x))
                            {
                                //set the value with reflection
                                item.GetType().GetField(col.FieldMapping).SetValue(item, value);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Trace.WriteLine(ex.ToString());
                    }

                    //update the last update value
                    if (column_name == table.TableMetadata.SaturationUpdateField && update_last_update)
                    {
                        table.UpdateLastValue(value);
                    }
                }
            }
            if (item is Mention)
            {
                if ((item as Mention).Tags == null)
                {
                    System.Diagnostics.Trace.WriteLine("NO");
                }
            }
        }