public static OneDriveResultWithData <OneDriveFolder> CreateFolder(GraphServiceClient connection, string newFoldeName, string parentFolderId)
        {
            CheckConnectionOrException(connection);
            OneDriveResultWithData <OneDriveFolder> result = ProcessRequest((Func <OneDriveFolder>)(() =>
            {
                var item = OneDriveUtility.CreateFolderById((GraphServiceClient)connection, (string)newFoldeName, (string)parentFolderId);
                return(new OneDriveFolder((DriveItem)item));
            }));

            return(result);
        }
Beispiel #2
0
        public static OneDriveResultWithData <OneDriveFile> UploadFile(GraphServiceClient connection, string localFilePath, string fileName = null, string parentFolderId = null)
        {
            CheckConnectionOrException(connection);

            OneDriveResultWithData <OneDriveFile> result = ProcessRequest(() =>
            {
                DriveItem item = UploadFileByID(connection, localFilePath, fileName, parentFolderId);
                return(new OneDriveFile(item));
            });

            return(result);
        }
Beispiel #3
0
        public static OneDriveResultWithData <OneDriveFile[]> GetFiles(GraphServiceClient connection, string folderId)
        {
            CheckConnectionOrException(connection);

            OneDriveResultWithData <OneDriveFile[]> result = ProcessRequest(() =>
            {
                var rawList = GetFolderContentFromId(connection, folderId, ItemType.File);
                var list    = rawList.Select((it) => { return(new OneDriveFile(it)); });
                return(list.ToArray());
            });

            return(result);
        }
Beispiel #4
0
        public static OneDriveResultWithData <OneDrivePermission> CreateShareLink(GraphServiceClient connection, string resourceId, OneDriveShareType shareType, OneDriveShareScope shareScope)
        {
            CheckConnectionOrException(connection);

            OneDriveResultWithData <OneDrivePermission> result = ProcessRequest <OneDrivePermission>(() =>
            {
                string type  = Enum.GetName(typeof(OneDriveShareType), shareType).ToLower();
                string scope = Enum.GetName(typeof(OneDriveShareScope), shareScope).ToLower();
                var perm     = CreateShareLinkById(connection, resourceId, type, scope);
                return(CreateOneDrivePermission(perm));
            });

            return(result);
        }
Beispiel #5
0
        public static OneDriveResultWithData <OneDrivePermission[]> GetResourcePermissions(GraphServiceClient connection, string resourceId)
        {
            CheckConnectionOrException(connection);

            OneDriveResultWithData <OneDrivePermission[]> result = ProcessRequest <OneDrivePermission[]>(() =>
            {
                var permissions           = ListPermissionsById(connection, resourceId);
                OneDrivePermission[] data = new OneDrivePermission[permissions.Length];
                for (int i = 0; i < permissions.Length; i++)
                {
                    data[i] = CreateOneDrivePermission(permissions[i]);
                }
                return(data);
            });

            return(result);
        }
        private static OneDriveResultWithData <T> ProcessRequest <T>(System.Func <T> req)
        {
            var result = new OneDriveResultWithData <T>();

            try
            {
                result.Data      = req();
                result.IsSucceed = true;
            }
            catch (Exception exception)
            {
                if (!result.FillFromException(exception))
                {
                    throw;
                }
            }
            return(result);
        }
        public static OneDriveResultWithData <OneDriveResourceType> DoesResourceExist(GraphServiceClient connection, string fileOrFolderId)
        {
            CheckConnectionOrException(connection);
            OneDriveResultWithData <OneDriveResourceType> result = ProcessRequest(() =>
            {
                DriveItem item = OneDriveUtility.GetResourceInfo(connection, fileOrFolderId);
                if (item.Folder != null)
                {
                    return(OneDriveResourceType.Folder);
                }
                else
                {
                    return(OneDriveResourceType.File);
                }
            });

            if (!result.IsSucceed && result.ErrorInfo.HttpErrorCode == HttpStatusCode.NotFound)
            {
                result.Data      = OneDriveResourceType.Unavailable;
                result.IsSucceed = true;
            }
            ;
            return(result);
        }