Example #1
0
        public IntegrationProviders(String xml)
            : this()
        {
            if (String.IsNullOrEmpty(xml))
            {
                return;
            }

            try
            {
                var doc = new XmlDocument();
                doc.LoadXml(xml);
                var spObjectProviderListXml = doc[ProviderElement];

                if (spObjectProviderListXml == null)
                {
                    return;
                }

                foreach (XmlNode spObjectProviderXml in spObjectProviderListXml.ChildNodes)
                {
                    IntegrationProvider spObjectProvider;
                    if (IntegrationProvider.TryParse(spObjectProviderXml, out spObjectProvider))
                    {
                        Collection.Add(spObjectProvider);
                    }
                }
            }
            catch (Exception ex)
            {
                SPLog.DataProvider(ex, ex.Message);
            }
        }
Example #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);
            }
        }
Example #3
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);
            }
        }
Example #4
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);
        }
        public static bool TryParse(XmlNode xmlNode, out IntegrationProvider manager)
        {
            manager = null;

            try
            {
                manager = new IntegrationProvider(xmlNode);
                return(true);
            }
            catch (Exception ex)
            {
                SPLog.DataProvider(ex, String.Format(IntegrationManagerParseError, ex.GetType().Name, ex.Message));
            }

            return(false);
        }
Example #6
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));
        }
        protected void SaveBtnClick(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            try
            {
                UpdateCurrentProvider(TbSPSiteUrl.Text, AuthenticationHelper.FromHtml(CtAuth));
                ClearTempStore();
            }
            catch (Exception ex)
            {
                SPLog.DataProvider(ex, "Error getting Saving: {0} {1}", ex.Message, ex.StackTrace);
            }
        }
Example #8
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);
            }
        }
Example #9
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);
            }
        }
Example #10
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));
        }
Example #11
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);
        }
Example #12
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);
        }
Example #13
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);
        }
        private void LoadFromXml(XmlNode xmlNode)
        {
            try
            {
                Id         = (xmlNode.Attributes != null) ? xmlNode.Attributes[IdAttr].Value : string.Empty;
                SPSiteName = (xmlNode.Attributes != null) ? xmlNode.Attributes[NameAttr].Value : string.Empty;

                var spSiteUrlElement = xmlNode[SPSiteUrlElement];

                SPSiteURL = spSiteUrlElement != null?HttpUtility.UrlDecode(spSiteUrlElement.InnerText) : String.Empty;

                SPSiteID = spSiteUrlElement != null && spSiteUrlElement.Attributes[SPSiteIDAttribute] != null?Guid.Parse(spSiteUrlElement.Attributes[SPSiteIDAttribute].Value) : Guid.Empty;

                SPWebID = spSiteUrlElement != null && spSiteUrlElement.Attributes[SPWebIDAttribute] != null?Guid.Parse(spSiteUrlElement.Attributes[SPWebIDAttribute].Value) : Guid.Empty;

                var teGroupNameElement = xmlNode[TEGroupNameElement];

                TEGroupName = teGroupNameElement != null ? teGroupNameElement.InnerText : String.Empty;
                TEGroupId   = teGroupNameElement != null && teGroupNameElement.Attributes[IdAttr] != null?int.Parse(teGroupNameElement.Attributes[IdAttr].Value) : -1;

                Authentication = new Anonymous();
                var authenticationElement = xmlNode[AuthenticationElement];

                if (authenticationElement != null)
                {
                    Authentication = AuthenticationHelper.FromQueryString(authenticationElement.InnerText);
                }

                IsDefault = xmlNode.Attributes != null && xmlNode.Attributes[IsDefaultAttr] != null && bool.Parse(xmlNode.Attributes[IsDefaultAttr].Value);

                nextId = Math.Max(nextId, int.Parse(Id) + 1);
            }
            catch (Exception ex)
            {
                SPLog.DataProvider(ex, ex.Message);
            }
        }
Example #15
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);
            }
        }
Example #16
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);
            }
        }