public SPListItem Create(Guid listId)
        {
            var item = new SPListItem();

            try
            {
                item = PublicApi.ListItems.Create(listId, new SPListItemCreateOptions());
            }
            catch (InvalidOperationException ex)
            {
                item.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.InvalidCreateOptions)));
            }
            catch (SPInternalException ex)
            {
                item.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.CannotBeCreated)));
            }
            catch (Exception ex)
            {
                var message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointListItem.Create() method while creating a new listItem in ListId: {1}. The exception message is: {2}", ex.GetType(), listId, ex.Message);
                SPLog.UnKnownError(ex, message);
                item.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.UnknownError)));
            }

            return(item);
        }
        public SPListItem Update(Guid contentId,
                                 [Documentation(Name = "Fields", Description = "A collection of field names and values.", Type = typeof(IDictionary))]
                                 IDictionary options)
        {
            var item = new SPListItem();

            try
            {
                if (options["Fields"] is IDictionary)
                {
                    item = PublicApi.ListItems.Update(EnsureListId(contentId), new SPListItemUpdateOptions(contentId, (IDictionary)options["Fields"]));
                }
            }
            catch (InvalidOperationException ex)
            {
                item.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.InvalidUpdateOptions)));
            }
            catch (SPInternalException ex)
            {
                item.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.CannotBeUpdated)));
            }
            catch (Exception ex)
            {
                var message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointListItem.Update() method ContentId: {1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message);
                SPLog.UnKnownError(ex, message);
                item.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.UnknownError)));
            }

            return(item);
        }
        public PagedList <SPListItem> List(Guid listId)
        {
            var items = new PagedList <SPListItem>();

            try
            {
                items = PublicApi.ListItems.List(listId);
            }
            catch (InvalidOperationException ex)
            {
                items.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.InvalidListId)));
            }
            catch (SPInternalException ex)
            {
                items.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.ListNotFound)));
            }
            catch (Exception ex)
            {
                var message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointListItem.List() method for ListId: {1}. The exception message is: {2}", ex.GetType(), listId, ex.Message);
                SPLog.UnKnownError(ex, message);
                items.Errors.Add(new Error(ex.GetType().ToString(), ex.Message));
            }

            return(items);
        }
        public SPListItem Get(Guid contentId)
        {
            var item = new SPListItem();

            try
            {
                item = PublicApi.ListItems.Get(EnsureListId(contentId), new SPListItemGetOptions(contentId));
            }
            catch (InvalidOperationException ex)
            {
                item.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.InvalidId)));
            }
            catch (SPInternalException ex)
            {
                item.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.NotFound)));
            }
            catch (Exception ex)
            {
                var message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointListItem.Get() method for ContentId: {1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message);
                SPLog.UnKnownError(ex, message);
                item.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.UnknownError)));
            }

            return(item);
        }
        public void Delete(Guid libraryId, DocumentGetOptions options)
        {
            var documentId           = options.Id.HasValue ? options.Id.Value.ToString(CultureInfo.InvariantCulture) : options.ContentId.ToString("N");
            var documentBeforeDelete = Get(libraryId, options);

            if (documentBeforeDelete == null)
            {
                return;
            }

            try
            {
                Events.OnBeforeDelete(documentBeforeDelete);
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the PublicApi.Documents.Events.OnBeforeDelete() method for LibraryId: {1}, DocumentId: {2}. The exception message is: {3}", ex.GetType(), libraryId, documentId, ex.Message);
                SPLog.UnKnownError(ex, message);
            }

            listItemService.Delete(libraryId, options);
            ExpireTags(libraryId);

            try
            {
                Events.OnAfterDelete(documentBeforeDelete);
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the PublicApi.Documents.Events.OnAfterDelete() method for LibraryId: {1}, DocumentId: {2}. The exception message is: {3}", ex.GetType(), libraryId, documentId, ex.Message);
                SPLog.UnKnownError(ex, message);
            }
        }
        public AdditionalInfo Delete(Guid contentId)
        {
            var deleteInfo = new AdditionalInfo();

            try
            {
                PublicApi.ListItems.Delete(EnsureListId(contentId), new SPListItemDeleteOptions(new[] { contentId }));
            }
            catch (InvalidOperationException ex)
            {
                deleteInfo.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.InvalidId)));
            }
            catch (SPInternalException ex)
            {
                deleteInfo.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.NotFoundBecauseDeleted)));
            }
            catch (Exception ex)
            {
                var message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointListItem.Delete() method ContentId: {1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message);
                SPLog.UnKnownError(ex, message);
                deleteInfo.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.UnknownError)));
            }

            return(deleteInfo);
        }
예제 #7
0
        public PagedList <SPDocumentVersion> GetVersions(Guid contentId)
        {
            var documentVersions = new PagedList <SPDocumentVersion>();

            try
            {
                documentVersions = new PagedList <SPDocumentVersion>(PublicApi.Documents.GetVersions(EnsureLibraryId(contentId), new DocumentGetOptions(contentId)));
            }
            catch (InvalidOperationException ex)
            {
                documentVersions.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.InvalidId, contentId)));
            }
            catch (SPInternalException ex)
            {
                documentVersions.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.NotFound, contentId)));
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointFile.GetVersions() method ContentId: {1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message);
                SPLog.UnKnownError(ex, message);
                documentVersions.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.UnknownError)));
            }

            return(documentVersions);
        }
예제 #8
0
        public AdditionalInfo Delete(Guid libraryId, bool deleteLibrary)
        {
            var errorInfo = new AdditionalInfo();

            try
            {
                var library = PublicApi.Libraries.Get(new LibraryGetOptions(libraryId));
                PublicApi.Libraries.Delete(library, deleteLibrary);
            }
            catch (InvalidOperationException ex)
            {
                errorInfo.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointLibraryExtension.Translations.InvalidId, libraryId)));
            }
            catch (SPInternalException ex)
            {
                // The library has been already deleted
                errorInfo = new AdditionalInfo(new Error(ex.GetType().ToString(), plugin.Translate(SharePointLibraryExtension.Translations.NotFoundBecauseDeleted, libraryId)));
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointLibrary.Delete() method for LibraryId: {1}. The exception message is: {2}", ex.GetType(), libraryId, ex.Message);
                SPLog.UnKnownError(ex, message);
                errorInfo.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointLibraryExtension.Translations.UnknownError)));
            }

            return(errorInfo);
        }
예제 #9
0
        public Folder Delete(string applicationId, string folderPath)
        {
            var folder = new Folder();

            Guid libraryId;

            if (Guid.TryParse(applicationId, out libraryId))
            {
                try
                {
                    folder = ClientApi.Folders.Delete(libraryId, new FolderGetOptions(folderPath));
                }
                catch (InvalidOperationException ex)
                {
                    folder.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFolderExtension.Translations.InvalidLibraryId)));
                }
                catch (SPInternalException ex)
                {
                    folder.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFolderExtension.Translations.NotFoundBecauseDeleted)));
                }
                catch (Exception ex)
                {
                    string message = string.Format("An exception of type {0} occurred in the WidgetApi.V1.SharePointFolder.Delete() method for ApplicationId: {1} FolderPath: '{2}'. The exception message is: {3}",
                                                   ex.GetType(), applicationId, folderPath, ex.Message);
                    SPLog.UnKnownError(ex, message);
                    folder.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFolderExtension.Translations.UnknownError)));
                }
            }
            else
            {
                folder.Errors.Add(new Error(typeof(InvalidOperationException).ToString(), plugin.Translate(SharePointFolderExtension.Translations.InvalidLibraryId, applicationId)));
            }
            return(folder);
        }
        public int GetWSSId(string url, string label)
        {
            using (var context = new SPContext(url, credentials.Get(url)))
            {
                try
                {
                    var taxonomyList = context.Web.Lists.GetByTitle("TaxonomyHiddenList");
                    var taxItems     = taxonomyList.GetItems(CAMLQueryBuilder.GetItemByTitle(label, new[] { "Title", "ID" }));
                    context.Load(taxItems);

                    context.ExecuteQuery();

                    if (taxItems.Any())
                    {
                        return(taxItems[0].Id);
                    }
                }
                catch (Exception ex)
                {
                    SPLog.UnKnownError(ex, ex.Message);
                }
            }

            return(-1);
        }
예제 #11
0
        public bool IsInherited(SPList list, SPListItem listItem)
        {
            var inheritance = new Inheritance();

            Validate(inheritance.Errors, list, listItem);
            if (!inheritance.Errors.Any())
            {
                var permissionsGetOptions = new PermissionsGetOptions(list.Id, listItem.ContentId)
                {
                    Url = list.SPWebUrl
                };
                try
                {
                    inheritance = ClientApi.Permissions.GetInheritance(permissionsGetOptions);
                }
                catch (SPInternalException ex)
                {
                    inheritance.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointPermissionsExtension.Translations.ListItemNotFound)));
                }
                catch (Exception ex)
                {
                    string message = string.Format("An exception of type {0} occurred in the WidgetApi.V1.SharePointPermissions.Get() method for ContentId: {1} ListId: {2}. The exception message is: {3}", ex.GetType(), listItem.ContentId, list.Id, ex.Message);
                    SPLog.UnKnownError(ex, message);
                    inheritance.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointPermissionsExtension.Translations.UnknownError)));
                }
            }
            return(inheritance.Enabled);
        }
예제 #12
0
        public Document Update(Guid contentId,
                               [Documentation(Name = "Fields", Description = "A collection of field names and values.", Type = typeof(IDictionary))]
                               IDictionary options)
        {
            var document = new Document();

            try
            {
                if (options["Fields"] is IDictionary)
                {
                    document = PublicApi.Documents.Update(EnsureLibraryId(contentId), new DocumentUpdateOptions(contentId)
                    {
                        Fields = (IDictionary)options["Fields"]
                    });
                }
            }
            catch (InvalidOperationException ex)
            {
                document.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.InvalidUpdateOptions, contentId)));
            }
            catch (SPInternalException ex)
            {
                document.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.CannotBeUpdated, contentId)));
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointFile.Update() method ContetnId:{1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message);
                SPLog.UnKnownError(ex, message);
                document.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.UnknownError)));
            }

            return(document);
        }
예제 #13
0
        public AdditionalInfo UndoCheckOut(Guid contentId)
        {
            var undoCheckOutInfo = new AdditionalInfo();

            try
            {
                PublicApi.Documents.UndoCheckOut(EnsureLibraryId(contentId), new DocumentGetOptions(contentId));
            }
            catch (InvalidOperationException ex)
            {
                undoCheckOutInfo.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.InvalidId, contentId)));
            }
            catch (SPInternalException ex)
            {
                undoCheckOutInfo.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.CannotBeCheckedIn, contentId)));
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointFile.CheckOut() method ContentId: {1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message);
                SPLog.UnKnownError(ex, message);
                undoCheckOutInfo.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.UnknownError)));
            }

            return(undoCheckOutInfo);
        }
예제 #14
0
        public PagedList <Document> List(Guid applicationId,
                                         [Documentation(Name = "FolderPath", Type = typeof(string), Description = "Folder server relative Url"),
                                          Documentation(Name = "PageIndex", Type = typeof(int)),
                                          Documentation(Name = "PageSize", Type = typeof(int)),
                                          Documentation(Name = "SortBy", Type = typeof(string)),
                                          Documentation(Name = "SortOrder", Type = typeof(string), Options = new[] { "Ascending", "Descending" })]
                                         IDictionary options)
        {
            var documents = new PagedList <Document>();

            try
            {
                documents = PublicApi.Documents.List(applicationId, ProcessDocumentListOptions(options));
            }
            catch (InvalidOperationException ex)
            {
                documents.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.InvalidLibraryId, applicationId)));
            }
            catch (SPInternalException ex)
            {
                documents.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.LibraryNotFound, applicationId)));
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointFile.List() method for LibraryId: {1}. The exception message is: {2}", ex.GetType(), applicationId, ex.Message);
                SPLog.UnKnownError(ex, message);
                documents.Errors.Add(new Error(ex.GetType().ToString(), ex.Message));
            }
            return(documents);
        }
예제 #15
0
        public Document Get(Guid contentId)
        {
            var libraryId = EnsureLibraryId(contentId);

            if (libraryId == Guid.Empty)
            {
                return(null);
            }

            var document = new Document();

            try
            {
                document = PublicApi.Documents.Get(libraryId, new DocumentGetOptions(contentId));
            }
            catch (InvalidOperationException ex)
            {
                document.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.InvalidId, contentId)));
            }
            catch (SPInternalException ex)
            {
                document.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.NotFound, contentId)));
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointFile.Get() method for ContentId: {1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message);
                SPLog.UnKnownError(ex, message);
                document.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.UnknownError)));
            }

            return(document);
        }
예제 #16
0
        public Library Get(Guid libraryId)
        {
            var library = new Library();

            try
            {
                library = PublicApi.Libraries.Get(new LibraryGetOptions(libraryId));
            }
            catch (InvalidOperationException ex)
            {
                library.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointLibraryExtension.Translations.InvalidId, libraryId)));
            }
            catch (SPInternalException ex)
            {
                library.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointLibraryExtension.Translations.NotFound, libraryId)));
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointLibrary.Get() method for LibraryId: {1}. The exception message is: {2}", ex.GetType(), libraryId, ex.Message);
                SPLog.UnKnownError(ex, message);
                library.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointLibraryExtension.Translations.UnknownError)));
            }

            return(library);
        }
예제 #17
0
        public List <string> LoadSubSiteUrls()
        {
            var webCollection = new List <string>();

            using (var clientContext = new SPContext(siteUrl, auth, runAsServiceAccount: true))
            {
                var webs = clientContext.Web.Webs;
                clientContext.Load(webs);

                try
                {
                    clientContext.ExecuteQuery();
                }
                catch (Exception ex)
                {
                    SPLog.UnKnownError(ex, "An exception in the process of SiteCollection loading of type {0} has been occurred. The exception message is: {1}", ex.GetType().Name, ex.Message);
                    return(webCollection);
                }

                var baseUrl = clientContext.Url.Trim('/');

                foreach (var web in webs)
                {
                    webCollection.Add(MergeUrl(baseUrl, web.ServerRelativeUrl));
                }
            }

            return(webCollection);
        }
예제 #18
0
        public AdditionalInfo Restore(Guid contentId, string version)
        {
            var restoreInfo = new AdditionalInfo();

            try
            {
                PublicApi.Documents.Restore(EnsureLibraryId(contentId), new DocumentRestoreOptions(contentId)
                {
                    Version = version
                });
            }
            catch (InvalidOperationException ex)
            {
                restoreInfo.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.InvalidId, contentId)));
            }
            catch (SPInternalException ex)
            {
                restoreInfo.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.NotFound, contentId)));
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointFile.Restore() method ContentId: {1} Version: {2}. The exception message is: {3}", ex.GetType(), contentId, version, ex.Message);
                SPLog.UnKnownError(ex, message);
                restoreInfo.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.UnknownError)));
            }
            return(restoreInfo);
        }
        public SPList Create(int groupId, string url, string name,
                             [Documentation(Name = "Description", Type = typeof(string)),
                              Documentation(Name = "Template", Type = typeof(string), Description = @"
AdminTasks, Agenda, Announcements, CallTrack, Categories, Circulation, Comments, Contacts, CustomGrid, DataConnectionLibrary,
DataSources, Decision, DiscussionBoard, Events, ExternalList, Facility, GanttTasks, GenericList, HealthReports, HealthRules,
Holidays, HomePageLibrary, IMEDic, IssueTracking, Links, ListTemplateCatalog, MasterPageCatalog, MeetingObjective, Meetings,
MeetingUser, NoCodePublic, NoCodeWorkflows, PictureLibrary, Posts, SolutionCatalog, Survey, Tasks, TextBox, ThemeCatalog,
ThingsToBring, Timecard, UserInformation, WebPageLibrary, WebPartCatalog, ListTemplateCatalog, WebTemplateCatalog, Whereabouts,
WorkflowHistory, WorkflowProcess, XMLForm")]
                             IDictionary options = null)
        {
            var list = new SPList();

            var createOptions = new SPListCreateOptions(groupId)
            {
                SPWebUrl = url,
                Title    = name
            };

            if (options != null)
            {
                if (options["Description"] != null)
                {
                    createOptions.Description = options["Description"].ToString();
                }

                if (options["Template"] != null)
                {
                    createOptions.Template = options["Template"].ToString();
                }
            }

            try
            {
                list = PublicApi.Lists.Create(createOptions);
            }
            catch (InvalidOperationException ex)
            {
                var exType = ex.GetType().ToString();
                ValidateGroupId(groupId, list.Errors, exType);
                ValidateUrl(url, list.Errors, exType);
                if (string.IsNullOrEmpty(name))
                {
                    list.Errors.Add(new Error(exType, plugin.Translate(SharePointListExtension.Translations.NameCannotBeEmpty)));
                }
            }
            catch (SPInternalException ex)
            {
                list.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointListExtension.Translations.CannotBeCreated, groupId, url, name)));
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointList.Create() method while creating list with Title:{1} in SPWebUrl:{2} for GroupId:{3}. The exception message is: {4}", ex.GetType(), name, url, groupId, ex.Message);
                SPLog.UnKnownError(ex, message);
                list.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointListExtension.Translations.UnknownError)));
            }
            return(list);
        }
예제 #20
0
        public void Update(SPList list, SPListItem listItem,
                           [Documentation(Name = "PermissionLevelIds", Type = typeof(string), Description = "Permission level id or ifs"),
                            Documentation(Name = "GroupIds", Type = typeof(string), Description = "Group id or ids, separated by comma ','"),
                            Documentation(Name = "UserNames", Type = typeof(string), Description = "User login name or names, separated by comma ','"),
                            Documentation(Name = "IsGranted", Type = typeof(bool), Default = false, Description = "Not removes existing role assignments, when true")]
                           IDictionary options)
        {
            var updateInfo = new AdditionalInfo();

            Validate(updateInfo.Errors, list, listItem);
            if (!updateInfo.Errors.Any())
            {
                var updateOptions = new PermissionsUpdateOptions(list.Id, listItem.ContentId)
                {
                    CopyRoleAssignments = true,
                    ClearSubscopes      = true,
                    Url = list.SPWebUrl
                };

                if (options["PermissionLevelIds"] != null && !String.IsNullOrEmpty(options["PermissionLevelIds"].ToString()))
                {
                    updateOptions.Levels = options["PermissionLevelIds"].ToString().Split(',').Select(int.Parse).ToArray();
                }

                bool isGranted;
                if (options["IsGranted"] != null && !String.IsNullOrEmpty(options["IsGranted"].ToString()) && bool.TryParse(options["IsGranted"].ToString(), out isGranted))
                {
                    updateOptions.Overwrite = !isGranted;
                }

                if (options["GroupIds"] != null && !String.IsNullOrEmpty(options["GroupIds"].ToString()))
                {
                    updateOptions.GroupIds = options["GroupIds"].ToString().Split(',').Select(int.Parse).ToArray();
                }

                if (options["UserNames"] != null && !String.IsNullOrEmpty(options["UserNames"].ToString()))
                {
                    updateOptions.LoginNames = options["UserNames"].ToString().Split(',');
                }

                try
                {
                    ClientApi.Permissions.Update(updateOptions);
                }
                catch (SPInternalException ex)
                {
                    updateInfo.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointPermissionsExtension.Translations.ListItemNotFound)));
                }
                catch (Exception ex)
                {
                    string message = string.Format("An exception of type {0} occurred in the WidgetApi.V1.SharePointPermissions.Update() method for ContentId: {1} ListId: {2}. The exception message is: {3}", ex.GetType(), listItem.ContentId, list.Id, ex.Message);
                    SPLog.UnKnownError(ex, message);
                    updateInfo.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointPermissionsExtension.Translations.UnknownError)));
                }
            }
        }
        public AdditionalInfo Delete(string url, Guid listId,
                                     [Documentation(Name = "itemIds", Description = "Comma delimited list of ListItem IDs or UniqueIds", Type = typeof(string))]
                                     string itemIds)
        {
            var deleteInfo = new AdditionalInfo();
            var counterIds = new List <int>();
            var uniqueIds  = new List <Guid>();
            var ids        = itemIds.Split(',');

            foreach (var contentId in ids)
            {
                int  counterId;
                Guid uniqueId;

                if (Guid.TryParse(contentId, out uniqueId))
                {
                    uniqueIds.Add(uniqueId);
                }
                else if (int.TryParse(contentId, out counterId))
                {
                    counterIds.Add(counterId);
                }
                else
                {
                    deleteInfo.Errors.Add(new Error(typeof(ArgumentException).ToString(), SharePointListItemExtension.Translations.InvalidListId));
                }
            }

            if (!deleteInfo.Errors.Any())
            {
                try
                {
                    PublicApi.ListItems.Delete(listId, new SPListItemDeleteOptions(counterIds, uniqueIds)
                    {
                        Url = url
                    });
                }
                catch (InvalidOperationException ex)
                {
                    deleteInfo.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.InvalidId)));
                }
                catch (SPInternalException ex)
                {
                    deleteInfo.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.NotFoundBecauseDeleted)));
                }
                catch (Exception ex)
                {
                    var message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointListItem.Delete() method itemIds: {1}, ListId: {2} Url: {3}. The exception message is: {4}", ex.GetType(), itemIds, listId, url, ex.Message);
                    SPLog.UnKnownError(ex, message);
                    deleteInfo.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(SharePointListItemExtension.Translations.UnknownError)));
                }
            }

            return(deleteInfo);
        }
예제 #22
0
        public Library Add(int groupId, Guid libraryId, string spwebUrl)
        {
            // Check that library was not imported before
            var library = PublicApi.Libraries.Get(new LibraryGetOptions(libraryId));

            if (library != null)
            {
                // Verify the group exists
                var group = Extensibility.Api.Version1.PublicApi.Groups.Get(new GroupsGetOptions {
                    Id = library.GroupId
                });
                if (group != null)
                {
                    // The Library is already in use
                    library.Errors.Add(new Error(typeof(ArgumentException).ToString(), plugin.Translate(SharePointLibraryExtension.Translations.AlreadyInUse)));
                    return(library);
                }
            }

            // Import a library
            library = new Library();
            try
            {
                PublicApi.Libraries.Add(groupId, libraryId, spwebUrl);
                library = PublicApi.Libraries.Get(new LibraryGetOptions(libraryId));
            }
            catch (InvalidOperationException ex)
            {
                var exType = ex.GetType().ToString();
                ValidateGroupId(groupId, library.Errors, exType);
                ValidateLibraryId(libraryId, library.Errors, exType);
                ValidateUrl(spwebUrl, library.Errors, exType);
            }
            catch (ArgumentException ex)
            {
                library.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointLibraryExtension.Translations.NotFound, libraryId)));
            }
            catch (SPInternalException ex)
            {
                var group = TEApi.Groups.Get(new GroupsGetOptions {
                    Id = groupId
                });
                var groupName = group != null ? group.Name : groupId.ToString(CultureInfo.InvariantCulture);
                library.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointLibraryExtension.Translations.CannotBeAdded, groupName, libraryId, spwebUrl)));
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointLibrary.Add() method for LibraryId: {1} GroupId: {2} SPWebUrl: {3}. The exception message is: {4}", ex.GetType(), libraryId, groupId, spwebUrl, ex.Message);
                SPLog.UnKnownError(ex, message);
                library.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointLibraryExtension.Translations.UnknownError)));
            }

            return(library);
        }
 public string SPListItem(Guid contentId)
 {
     try
     {
         return(ClientApi.SharePointUrls.ListItem(contentId));
     }
     catch (SPInternalException) { }
     catch (Exception ex)
     {
         string message = string.Format("An exception of type {0} occurred in the $sharepoint_v1_urls.SPListItem() method ContentId: {1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message);
         SPLog.UnKnownError(ex, message);
     }
     return(null);
 }
예제 #24
0
 public List <SPPermissionsLevel> LevelList(string url, Authentication authentication)
 {
     try
     {
         return(ClientApi.Permissions.Levels(url).ToList());
     }
     catch (SPInternalException) { }
     catch (Exception ex)
     {
         string message = string.Format("An exception of type {0} occurred in the WidgetApi.V1.SharePointPermissions.LevelList() method URL: {1}. The exception message is: {2}", ex.GetType(), url, ex.Message);
         SPLog.UnKnownError(ex, message);
     }
     return(null);
 }
예제 #25
0
        public AdditionalInfo Update(Guid contentId,
                                     [Documentation(Name = "PermissionLevelIds", Type = typeof(string), Description = "Permission level id or ifs"),
                                      Documentation(Name = "GroupIds", Type = typeof(string), Description = "Group id or ids, separated by comma ','"),
                                      Documentation(Name = "UserNames", Type = typeof(string), Description = "User login name or names, separated by comma ','"),
                                      Documentation(Name = "IsGranted", Type = typeof(bool), Default = false, Description = "Not removes existing role assignments, when true")]
                                     IDictionary options)
        {
            var updateOptions = new PermissionsUpdateOptions(EnsureListId(contentId), contentId)
            {
                CopyRoleAssignments = true,
                ClearSubscopes      = true
            };

            if (options["PermissionLevelIds"] != null && !String.IsNullOrEmpty(options["PermissionLevelIds"].ToString()))
            {
                updateOptions.Levels = options["PermissionLevelIds"].ToString().Split(',').Select(int.Parse).ToArray();
            }

            bool isGranted;

            if (options["IsGranted"] != null && !String.IsNullOrEmpty(options["IsGranted"].ToString()) && bool.TryParse(options["IsGranted"].ToString(), out isGranted))
            {
                updateOptions.Overwrite = !isGranted;
            }

            if (options["GroupIds"] != null && !String.IsNullOrEmpty(options["GroupIds"].ToString()))
            {
                updateOptions.GroupIds = options["GroupIds"].ToString().Split(',').Select(int.Parse).ToArray();
            }

            if (options["UserNames"] != null && !String.IsNullOrEmpty(options["UserNames"].ToString()))
            {
                updateOptions.LoginNames = options["UserNames"].ToString().Split(',');
            }

            try
            {
                ClientApi.Permissions.Update(updateOptions);
                return(new AdditionalInfo());
            }
            catch (SPInternalException ex)
            {
                return(new AdditionalInfo(GetItemNotFoundError(ex)));
            }
            catch (Exception ex)
            {
                SPLog.UnKnownError(ex, string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointPermissions.Update() method for ContentId: {1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message));
                return(new AdditionalInfo(GetUnknownError(ex)));
            }
        }
 public string Library(Guid applicationId)
 {
     try
     {
         return(ClientApi.SharePointUrls.BrowseDocuments(applicationId));
     }
     catch (SPInternalException) { }
     catch (Exception ex)
     {
         string message = string.Format("An exception of type {0} occurred in the $sharepoint_v1_urls.Library() method ApplicationId: {1}. The exception message is: {2}", ex.GetType(), applicationId, ex.Message);
         SPLog.UnKnownError(ex, message);
     }
     return(null);
 }
        public AdditionalInfo Remove(Guid contentId,
                                     [Documentation(Name = "FieldName", Type = typeof(string), Description = "\"Attachments\" by default"),
                                      Documentation(Name = "FileNames", Type = typeof(string), Description = "File names to be removed splitted by ';'.")]
                                     IDictionary options)
        {
            var result = new AdditionalInfo();

            string fieldName = "Attachments";

            if (options["FieldName"] != null)
            {
                fieldName = options["FieldName"].ToString();
            }

            string fileNames = null;

            if (options["FileNames"] != null)
            {
                fileNames = options["FileNames"].ToString();
            }
            try
            {
                var files = fileNames != null?fileNames.Split(';') : new string[0];

                if (files.Length > 0)
                {
                    PublicApi.Attachments.Remove(EnsureListId(contentId), new AttachmentsRemoveOptions(contentId, fieldName)
                    {
                        FileNames = files.ToList()
                    });
                }
            }
            catch (InvalidOperationException ex)
            {
                result.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(AttachmentsExtension.Translations.ListItemNotFound, contentId)));
            }
            catch (SPInternalException ex)
            {
                result.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(AttachmentsExtension.Translations.ListItemNotFound, contentId)));
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.AttachmentsEditor.Remove() method for ContentId: {1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message);
                SPLog.UnKnownError(ex, message);
                result.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(AttachmentsExtension.Translations.UnknownError, contentId)));
            }

            return(result);
        }
        public bool CanEdit(Guid listId)
        {
            bool canEdit = false;

            try
            {
                canEdit = PublicApi.Lists.CanEdit(listId);
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointList.CanEdit() method for ListId: {1}. The exception message is: {2}", ex.GetType(), listId, ex.Message);
                SPLog.UnKnownError(ex, message);
            }
            return(canEdit);
        }
예제 #29
0
        public PagedList <SPPermissions> List(SPList list, SPListItem listItem,
                                              [Documentation(Name = "PageSize", Type = typeof(int)),
                                               Documentation(Name = "PageIndex", Type = typeof(int))]
                                              IDictionary options)
        {
            var permissionsList = new PagedList <SPPermissions>();

            Validate(permissionsList.Errors, list, listItem);
            if (!permissionsList.Errors.Any())
            {
                var permissionsListOptions = new PermissionsListOptions(list.Id, listItem.ContentId)
                {
                    Url       = list.SPWebUrl,
                    PageSize  = DefaultPageSize,
                    PageIndex = 0
                };
                if (options != null)
                {
                    int pageSize;
                    if (options["PageSize"] != null && int.TryParse(options["PageSize"].ToString(), out pageSize))
                    {
                        permissionsListOptions.PageSize = pageSize;
                    }

                    int pageIndex;
                    if (options["PageIndex"] != null && int.TryParse(options["PageIndex"].ToString(), out pageIndex))
                    {
                        permissionsListOptions.PageIndex = pageIndex;
                    }
                }

                try
                {
                    permissionsList = ClientApi.Permissions.List(permissionsListOptions);
                }
                catch (SPInternalException ex)
                {
                    permissionsList.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointPermissionsExtension.Translations.ListItemNotFound)));
                }
                catch (Exception ex)
                {
                    string message = string.Format("An exception of type {0} occurred in the WidgetApi.V1.SharePointPermissions.List() method for ContentId: {1} ListId: {2}. The exception message is: {3}", ex.GetType(), listItem.ContentId, list.Id, ex.Message);
                    SPLog.UnKnownError(ex, message);
                    permissionsList.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointPermissionsExtension.Translations.UnknownError)));
                }
            }
            return(permissionsList);
        }
예제 #30
0
        public AdditionalInfo Update(Guid libraryId,
                                     [Documentation(Name = "Title", Type = typeof(string)),
                                      Documentation(Name = "Description", Type = typeof(string)),
                                      Documentation(Name = "DefaultViewId", Type = typeof(Guid))]
                                     IDictionary options)
        {
            var result = new AdditionalInfo();

            if (options == null)
            {
                return(result);
            }

            var updateOptions = new LibraryUpdateOptions(libraryId);

            if (options["Title"] != null)
            {
                updateOptions.Title = options["Title"].ToString();
            }
            if (options["Description"] != null)
            {
                updateOptions.Description = options["Description"].ToString();
            }
            if (options["DefaultViewId"] is Guid)
            {
                updateOptions.DefaultViewId = (Guid)options["DefaultViewId"];
            }
            if (updateOptions.Title != null ||
                updateOptions.Description != null ||
                updateOptions.DefaultViewId != Guid.Empty)
            {
                try
                {
                    PublicApi.Libraries.Update(updateOptions);
                }
                catch (SPInternalException ex)
                {
                    result.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointLibraryExtension.Translations.CannotBeUpdated)));
                }
                catch (Exception ex)
                {
                    string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointLibrary.Update() method while updating library with Id: {1}. The exception message is: {2}", ex.GetType(), libraryId, ex.Message);
                    SPLog.UnKnownError(ex, message);
                    result.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointLibraryExtension.Translations.UnknownError)));
                }
            }
            return(result);
        }