Ejemplo n.º 1
0
        public void Delete(Guid contentId)
        {
            try
            {
                // Remove from DB
                using (var connection = DataHelpers.GetSqlConnection())
                {
                    using (var command = DataHelpers.CreateSprocCommand("[te_SharePoint_Item_Delete]", connection))
                    {
                        command.Parameters.Add("@ContentId", SqlDbType.UniqueIdentifier).Value = contentId;

                        connection.Open();
                        command.ExecuteNonQuery();
                        connection.Close();
                    }
                }
                // Clear Cache
                cacheService.RemoveByTags(new[] { GetTagId(contentId) }, CacheScope.Context | CacheScope.Process);
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the InternalApi.SPItemDataService.Delete() method for ContentId: {1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message);
                SPLog.DataProvider(ex, message);
                throw new SPDataException(message, ex);
            }
        }
Ejemplo n.º 2
0
        public void UpdateIndexingStatus(Guid[] ids, bool isIndexed)
        {
            if (ids == null || ids.Length <= 0)
            {
                return;
            }

            var applicationIds = string.Join(",", ids);

            try
            {
                using (var connection = DataHelpers.GetSqlConnection())
                {
                    using (var command = DataHelpers.CreateSprocCommand("[te_SharePoint_List_UpdateIsIndexed]", connection))
                    {
                        connection.Open();
                        command.Parameters.Add("@IsIndexed", SqlDbType.Bit).Value           = isIndexed ? 1 : 0;
                        command.Parameters.Add("@ApplicationIds", SqlDbType.NVarChar).Value = applicationIds;

                        command.ExecuteNonQuery();

                        connection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                var message = string.Format("An exception of type {0} occurred in the SPListDataService.ListsToReindex() method for Application Ids: {1}. The exception message is: {2}", ex.GetType(), applicationIds, ex.Message);
                SPLog.DataProvider(ex, message);
                throw new SPDataException(message, ex);
            }
        }
Ejemplo n.º 3
0
        public List <ItemBase> List(Guid applicationId)
        {
            var items = new List <ItemBase>();

            try
            {
                using (var connection = DataHelpers.GetSqlConnection())
                {
                    connection.Open();
                    using (var command = DataHelpers.CreateSprocCommand("[te_SharePoint_Item_List]", connection))
                    {
                        command.Parameters.Add("@ApplicationId", SqlDbType.UniqueIdentifier).Value = applicationId;

                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.HasRows && reader.Read())
                            {
                                var itemBase = GetItemBase(reader);
                                items.Add(itemBase);
                                PutInCache(itemBase);
                            }
                        }
                    }
                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the SPItemDataService.List() method for ApplicationId: {1}. The exception message is: {2}", ex.GetType(), applicationId, ex.Message);
                SPLog.DataProvider(ex, message);
                throw new SPDataException(message, ex);
            }

            return(items);
        }
Ejemplo n.º 4
0
        public PagedList <ItemBase> ListItemsToReindex(int batchSize, Guid[] enabledListIds)
        {
            if (enabledListIds == null || enabledListIds.Length == 0)
            {
                return(new PagedList <ItemBase>());
            }

            var items = new List <ItemBase>();

            int totalCount;
            var applicationIds = string.Join(", ", enabledListIds);

            try
            {
                using (var connection = DataHelpers.GetSqlConnection())
                {
                    using (var command = DataHelpers.CreateSprocCommand("[te_SharePoint_Item_GetToReindex]", connection))
                    {
                        command.Parameters.Add("@EnabledListIds", SqlDbType.NVarChar).Value = string.Join(",", enabledListIds);
                        command.Parameters.Add("@PagingBegin", SqlDbType.Int).Value         = 0;
                        command.Parameters.Add("@PagingEnd", SqlDbType.Int).Value           = batchSize;
                        command.Parameters.Add("@TotalRecords", SqlDbType.Int).Direction    = ParameterDirection.Output;

                        connection.Open();
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.HasRows && reader.Read())
                            {
                                var itemBase = GetItemBase(reader);
                                PutInCache(itemBase);
                                items.Add(itemBase);
                            }
                        }
                        totalCount = (int)command.Parameters["@TotalRecords"].Value;
                        connection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the SPItemDataService.ListItemsToReindex() method for ListIds: {1} batchSize: {2}. The exception message is: {3}", ex.GetType(), applicationIds, batchSize, ex.Message);
                SPLog.DataProvider(ex, message);
                throw new SPDataException(message, ex);
            }

            return(new PagedList <ItemBase>(items, batchSize, 0, totalCount));
        }
Ejemplo n.º 5
0
        public void AddUpdate(ListBase list)
        {
            list.Validate();

            // Make ApplicationKey valid and unique
            if (!string.IsNullOrEmpty(list.ApplicationKey))
            {
                int groupId = list.GroupId;
                list.ApplicationKey = applicationKeyValidator.MakeValid(list.ApplicationKey.ToLowerInvariant(), applicationKey =>
                {
                    // List is duplicate when there is another list with the same application key but different Id
                    var anotherList = Get(applicationKey, groupId);
                    return(anotherList != null && anotherList.Id != Guid.Empty && anotherList.Id != list.Id);
                });
            }

            try
            {
                using (var connection = DataHelpers.GetSqlConnection())
                {
                    using (var command = DataHelpers.CreateSprocCommand("[te_SharePoint_List_AddUpdate]", connection))
                    {
                        command.Parameters.Add("@ApplicationId", SqlDbType.UniqueIdentifier).Value = list.Id;
                        command.Parameters.Add("@ApplicationKey", SqlDbType.NVarChar, 256).Value   = list.ApplicationKey;
                        command.Parameters.Add("@TypeId", SqlDbType.UniqueIdentifier).Value        = list.TypeId;
                        command.Parameters.Add("@GroupId", SqlDbType.Int).Value             = list.GroupId;
                        command.Parameters.Add("@SPWebUrl", SqlDbType.NVarChar, 256).Value  = list.SPWebUrl;
                        command.Parameters.Add("@ViewId", SqlDbType.UniqueIdentifier).Value = list.ViewId;

                        connection.Open();
                        command.ExecuteNonQuery();
                        connection.Close();
                    }
                }

                // Clear Cache
                cacheService.RemoveByTags(new[] { GetTagId(list.Id) }, CacheScope.Context | CacheScope.Process);
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the SPListDataService.AddUpdate() method. The exception message is: {1}", ex.GetType(), ex.Message);
                SPLog.DataProvider(ex, message);
                throw new AddLibraryException(ex.Message, list.SPWebUrl, list.Id, list.GroupId);
            }
        }
Ejemplo n.º 6
0
        public void AddUpdate(ItemBase item)
        {
            item.Validate();

            // Clear Cache
            cacheService.RemoveByTags(new[] { GetTagId(item.UniqueId) }, CacheScope.Context | CacheScope.Process);

            // Make ContentKey valid and unique
            if (!string.IsNullOrEmpty(item.ContentKey))
            {
                var applicationId = item.ApplicationId;
                item.ContentKey = applicationKeyValidator.MakeValid(item.ContentKey.ToLowerInvariant(), contentKey =>
                {
                    // Item is a duplicate when there is another item with the same key but different Id
                    var anotherItem = Get(contentKey, applicationId);
                    return(anotherItem != null && anotherItem.UniqueId != Guid.Empty && anotherItem.UniqueId != item.UniqueId);
                });
            }

            try
            {
                using (var connection = DataHelpers.GetSqlConnection())
                {
                    using (var command = DataHelpers.CreateSprocCommand("[te_SharePoint_Item_AddUpdate]", connection))
                    {
                        command.Parameters.Add("@ApplicationId", SqlDbType.UniqueIdentifier).Value = item.ApplicationId;
                        command.Parameters.Add("@ContentKey", SqlDbType.NVarChar, 256).Value       = item.ContentKey;
                        command.Parameters.Add("@ContentId", SqlDbType.UniqueIdentifier).Value     = item.UniqueId;
                        command.Parameters.Add("@ItemId", SqlDbType.Int).Value    = item.Id;
                        command.Parameters.Add("@IsIndexed", SqlDbType.Int).Value = item.IsIndexable ? 0 : -1;

                        connection.Open();
                        command.ExecuteNonQuery();
                        connection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                var message = string.Format("An exception of type {0} occurred in the SPItemDataService.AddUpdate() method. The exception message is: {1}", ex.GetType(), ex.Message);
                SPLog.DataProvider(ex, message);
                throw new SPDataException(message, ex);
            }
        }
Ejemplo n.º 7
0
        public PagedList <ListBase> ListsToReindex(Guid applicationTypeId, int pageSize, int pageIndex = 0)
        {
            var listCollection = new List <ListBase>();

            int totalCount;

            try
            {
                using (var connection = DataHelpers.GetSqlConnection())
                {
                    using (var command = DataHelpers.CreateSprocCommand("[te_SharePoint_List_GetToReindex]", connection))
                    {
                        command.Parameters.Add("@TypeId", SqlDbType.UniqueIdentifier).Value = applicationTypeId;
                        command.Parameters.Add("@PagingBegin", SqlDbType.Int).Value         = pageIndex * pageSize;
                        command.Parameters.Add("@PagingEnd", SqlDbType.Int).Value           = (pageIndex + 1) * pageSize;
                        command.Parameters.Add("@TotalRecords", SqlDbType.Int).Direction    = ParameterDirection.Output;

                        connection.Open();
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var listBase = GetListBase(reader);
                                PutInCache(listBase);
                                listCollection.Add(listBase);
                            }
                        }
                        connection.Close();

                        totalCount = (int)command.Parameters["@TotalRecords"].Value;
                    }
                }
            }
            catch (Exception ex)
            {
                var message = string.Format("An exception of type {0} occurred in the SPListDataService.ListsToReindex() method for ApplicationTypeId = {1}. The exception message is: {2}", ex.GetType(), applicationTypeId, ex.Message);
                SPLog.DataProvider(ex, message);
                throw new SPDataException(message, ex);
            }
            return(new PagedList <ListBase>(listCollection, pageSize, pageIndex, totalCount));
        }
Ejemplo n.º 8
0
        public ListBase Get(string applicationKey, int groupId)
        {
            var cacheId  = GetCacheId(groupId, applicationKey);
            var listBase = (ListBase)cacheService.Get(cacheId, CacheScope.Context | CacheScope.Process);

            if (listBase != null)
            {
                return(listBase);
            }

            try
            {
                using (var connection = DataHelpers.GetSqlConnection())
                {
                    using (var command = DataHelpers.CreateSprocCommand("[te_SharePoint_List_GetByApplicationKey]", connection))
                    {
                        command.Parameters.Add("@ApplicationKey", SqlDbType.NVarChar, 256).Value = applicationKey;
                        command.Parameters.Add("@GroupId", SqlDbType.Int).Value = groupId;

                        connection.Open();

                        using (var reader = command.ExecuteReader(CommandBehavior.SingleRow | CommandBehavior.CloseConnection))
                        {
                            if (reader.Read())
                            {
                                listBase = GetListBase(reader);
                                PutInCache(listBase);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var message = string.Format("An exception of type {0} occurred in the SPListDataService.Get() method for ApplicationKey: {1}, GroupId: {2}. The exception message is: {3}", ex.GetType(), applicationKey, groupId, ex.Message);
                SPLog.DataProvider(ex, message);
                throw new SPDataException(ex.Message, ex.InnerException);
            }
            return(listBase);
        }
Ejemplo n.º 9
0
        public ItemBase Get(Guid contentId)
        {
            var cacheId  = GetCacheId(contentId);
            var itemBase = (ItemBase)cacheService.Get(cacheId, CacheScope.Context | CacheScope.Process);

            if (itemBase != null)
            {
                return(itemBase);
            }

            try
            {
                using (var connection = DataHelpers.GetSqlConnection())
                {
                    connection.Open();
                    using (var command = DataHelpers.CreateSprocCommand("[te_SharePoint_Item_Get]", connection))
                    {
                        command.Parameters.Add("@ContentId", SqlDbType.UniqueIdentifier).Value = contentId;

                        using (var reader = command.ExecuteReader(CommandBehavior.SingleRow | CommandBehavior.CloseConnection))
                        {
                            if (reader.HasRows && reader.Read())
                            {
                                itemBase = GetItemBase(reader);
                                PutInCache(itemBase);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var message = string.Format("An exception of type {0} occurred in the InternalApi.SPItemDataService.Get() method for ContentId: {1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message);
                SPLog.DataProvider(ex, message);
                throw new SPDataException(message, ex);
            }

            return(itemBase);
        }
Ejemplo n.º 10
0
        public List <ListBase> List(int groupId, Guid typeId)
        {
            var listCollection = new List <ListBase>();

            try
            {
                using (var connection = DataHelpers.GetSqlConnection())
                {
                    using (var command = DataHelpers.CreateSprocCommand("[te_SharePoint_List_ListByGroupIdTypeId]", connection))
                    {
                        command.Parameters.Add("@GroupId", SqlDbType.Int).Value             = groupId;
                        command.Parameters.Add("@TypeId", SqlDbType.UniqueIdentifier).Value = typeId;

                        connection.Open();

                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var listBase = GetListBase(reader);
                                PutInCache(listBase);
                                listCollection.Add(listBase);
                            }
                        }

                        connection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                var message = string.Format("An exception of type {0} occurred in the listDataService.List() method for GroupId: {1} and ApplicationTypeId: {2}. The exception message is: {3}", ex.GetType(), groupId, typeId, ex.Message);
                SPLog.DataProvider(ex, message);
                throw new SPDataException(message, ex);
            }

            return(listCollection);
        }
Ejemplo n.º 11
0
        public void Delete(Guid id)
        {
            try
            {
                using (var connection = DataHelpers.GetSqlConnection())
                {
                    using (var command = DataHelpers.CreateSprocCommand("[te_SharePoint_List_Delete]", connection))
                    {
                        command.Parameters.Add("@ApplicationId", SqlDbType.UniqueIdentifier).Value = id;

                        connection.Open();
                        command.ExecuteNonQuery();
                        connection.Close();
                    }
                }
                cacheService.RemoveByTags(new[] { GetTagId(id) }, CacheScope.Context | CacheScope.Process);
            }
            catch (Exception ex)
            {
                var message = string.Format("An exception of type {0} occurred in the SPListDataService.Delete() method for ApplicationId: {1}. The exception message is: {2}", ex.GetType(), id, ex.Message);
                SPLog.DataProvider(ex, message);
                throw new SPDataException(message, ex);
            }
        }
Ejemplo n.º 12
0
        public void AddUpdate(IEnumerable <ItemBase> items)
        {
            var itemList = items.ToList();

            foreach (var item in itemList)
            {
                item.Validate();

                // Clear Cache
                cacheService.RemoveByTags(new[] { GetTagId(item.UniqueId) }, CacheScope.Context | CacheScope.Process);

                // Make ContentKey valid and unique
                if (!string.IsNullOrEmpty(item.ContentKey))
                {
                    var applicationId = item.ApplicationId;
                    item.ContentKey = applicationKeyValidator.MakeValid(item.ContentKey.ToLowerInvariant(), contentKey =>
                    {
                        // Item is a duplicate when there is another item with the same key but different Id
                        var anotherItem = Get(contentKey, applicationId);
                        return((anotherItem != null && anotherItem.UniqueId != Guid.Empty && anotherItem.UniqueId != item.UniqueId) ||
                               itemList.Any(newItem => newItem != null && newItem.UniqueId != item.UniqueId && newItem.ApplicationId == applicationId && string.Compare(newItem.ContentKey, contentKey, StringComparison.InvariantCultureIgnoreCase) == 0));
                    });
                }
            }

            try
            {
                using (var connection = DataHelpers.GetSqlConnection())
                {
                    using (var command = DataHelpers.CreateSprocCommand("[te_SharePoint_Item_AddBatch]", connection))
                    {
                        var xitems = new XDocument(
                            new XDeclaration("1.0", "utf-8", "yes"),
                            new XElement("items",
                                         itemList.Select(item => new XElement("item",
                                                                              new XAttribute("applicationId", item.ApplicationId),
                                                                              new XAttribute("id", item.Id),
                                                                              new XAttribute("contentId", item.UniqueId),
                                                                              new XAttribute("contentKey", item.ContentKey ?? string.Empty),
                                                                              new XAttribute("isIndexed", item.IsIndexable ? 0 : -1)))
                                         )
                            );

                        var itemsXml = new StringBuilder();
                        using (TextWriter writer = new StringWriter(itemsXml))
                        {
                            xitems.Save(writer);
                        }

                        command.Parameters.Add("@ItemsXml", SqlDbType.Xml).Value = itemsXml.ToString();

                        connection.Open();
                        command.ExecuteNonQuery();
                        connection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                var message = string.Format("An exception of type {0} occurred in the SPItemDataService.AddUpdate() method. The exception message is: {1}", ex.GetType(), ex.Message);
                SPLog.DataProvider(ex, message);
                throw new SPDataException(message, ex);
            }
        }