当前位置: 首页>>代码示例>>C#>>正文


C# ServiceClient.GetFileInfoById方法代码示例

本文整理汇总了C#中ServiceClient.GetFileInfoById方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceClient.GetFileInfoById方法的具体用法?C# ServiceClient.GetFileInfoById怎么用?C# ServiceClient.GetFileInfoById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ServiceClient的用法示例。


在下文中一共展示了ServiceClient.GetFileInfoById方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddTag

        /// <summary>Adds the given tag to the Item with the given Id.</summary>
        /// <param name="tag">The tag text.</param>
        /// <param name="itemId">The Id of the Item which should be tagged.</param>
        public static void AddTag(string tag, int itemId)
        {
            if (_sessionUser == null)
                throw new NotLoggedInException();

            if (tag == null || tag.Length < 3)
                throw new InadequateObjectException();

            using (var client = new ServiceClient())
            {
                Item item = null;

                if (FileExists(itemId))
                    item = client.GetFileInfoById(itemId);

                if (PackageExists(itemId))
                    item = client.GetPackageById(itemId);

                if (item == null)
                    throw new ObjectNotFoundException();

                if (_sessionUser.Type != UserType.admin
                    && !_sessionUser.Email.Equals(item.OwnerEmail)
                    && !HasEditRights(itemId))
                    throw new InsufficientRightsException();

                client.AddTag(tag, itemId);
            }
        }
开发者ID:Crelde,项目名称:ClientBNDN,代码行数:32,代码来源:Controller.cs

示例2: FileExists

        /// <summary>Used to check if there exists a File with a certain id.</summary>
        /// <param name="fileId">The id of the File in question.</param>
        /// <returns>True if there exists such a File, false if not.</returns>
        private static bool FileExists(int fileId)
        {
            using (var client = new ServiceClient())
            {
                try
                {
                    return client.GetFileInfoById(fileId).Id == fileId;
                }
                catch (Exception)
                {
                    return false;
                }

            }
        }
开发者ID:Crelde,项目名称:ClientBNDN,代码行数:18,代码来源:Controller.cs

示例3: GetRight

        /* TODO - It is noted that it should never be called by other than the controller.
         * Do we even need a public method then?
         * If it should only be used by the controller, it can just use client.GetRight(...) as it already does.
         *
        /// <summary>Looks up a Right by the email of the User and the Id of the Item involved.</summary>
        /// <param name="email">The Email of the User whom the Right concerns.</param>
        /// <param name="itemId">The Id of the Item which the Right concerns.</param>
        /// <returns>The Right with the matching email and itemId.</returns>
        private static Right GetRight(string email, int itemId)
        {
            throw new NotImplementedException();
        }
         */
        /// <summary>Updates the exising right that has matching UserEmail and ItemId fields, with the rest of the fields from the given updatedRight.</summary>
        /// <param name="updatedRight">The updated Right object.</param>
        public static void UpdateRight(Right updatedRight)
        {
            if (_sessionUser == null)
                throw new NotLoggedInException();

            if (updatedRight == null || updatedRight.UserEmail == null)
                throw new InadequateObjectException();

            using (var client = new ServiceClient())
            {
                Right right;

                try
                {
                    right = client.GetRight(updatedRight.UserEmail, updatedRight.ItemId);
                }
                catch (Exception)
                {
                    throw new OriginalNotFoundException();
                }

                if(right == null)
                    throw new OriginalNotFoundException();

                Item item = null;

                if (FileExists(updatedRight.ItemId))
                    item = client.GetFileInfoById(updatedRight.ItemId);

                if (PackageExists(updatedRight.ItemId))
                    item = client.GetPackageById(updatedRight.ItemId);

                if(item == null)
                    throw new ObjectNotFoundException();

                if (_sessionUser.Type != UserType.admin
                    && !_sessionUser.Email.Equals(item.OwnerEmail)
                    && !HasEditRights(updatedRight.ItemId))
                    throw new InsufficientRightsException();

                client.UpdateRight(updatedRight);
            }
        }
开发者ID:Crelde,项目名称:ClientBNDN,代码行数:58,代码来源:Controller.cs

示例4: UpdateFileInfo

        /// <summary>Updates the file that matches updatedInfo's Id with the details contained within it.</summary>
        /// <param name="updatedInfo">The FileInfo object that contains the new info.</param>      
        public static void UpdateFileInfo(FileInfo updatedInfo)
        {
            if (_sessionUser == null)
                throw new NotLoggedInException();

            if (updatedInfo.Name == null
                || updatedInfo.Name.Length < 3
                || !updatedInfo.OwnerEmail.Equals(_sessionUser.Email))
                throw new InadequateObjectException();

            if(!FileExists(updatedInfo.Id))
                throw new OriginalNotFoundException();

            using (var client = new ServiceClient())
            {
                if (_sessionUser.Type != UserType.admin
                    && !_sessionUser.Email.Equals(client.GetFileInfoById(updatedInfo.Id).OwnerEmail)
                    && !HasEditRights(updatedInfo.Id))
                    throw new InsufficientRightsException();

                client.UpdateFileInfo(updatedInfo);
            }
        }
开发者ID:Crelde,项目名称:ClientBNDN,代码行数:25,代码来源:Controller.cs

示例5: UpdateFileData

        /// <summary>Updates the File with the matching fileId with the givne updatedData.</summary>
        /// <param name="updatedData">The updated data.</param>
        /// <param name="fileId">The Id of the file which data should be updated.</param>
        public static void UpdateFileData(byte[] updatedData, int fileId)
        {
            if (_sessionUser == null)
                throw new NotLoggedInException();

            if (updatedData == null)
                throw new InadequateObjectException();

            if (!FileExists(fileId))
                throw new OriginalNotFoundException();

            using (var client = new ServiceClient())
            {
                if (_sessionUser.Type != UserType.admin
                    && !_sessionUser.Email.Equals(client.GetFileInfoById(fileId).OwnerEmail)
                    && !HasEditRights(fileId))
                    throw new InsufficientRightsException();

                client.UpdateFileData(updatedData, fileId);
            }
        }
开发者ID:Crelde,项目名称:ClientBNDN,代码行数:24,代码来源:Controller.cs

示例6: GrantRight

        /// <summary>Adds the given Right to the service.</summary>
        /// <param name="newRight">The Right that should be created on the service.</param>
        public static void GrantRight(Right newRight)
        {
            if(_sessionUser == null)
                throw new NotLoggedInException();

            if(newRight == null
                || newRight.UserEmail == null
                || !(FileExists(newRight.ItemId)
                || PackageExists(newRight.ItemId))
                || !UserExists(newRight.UserEmail))
                throw new InadequateObjectException();

            using (var client = new ServiceClient())
            {
                Item item = null;

                if (FileExists(newRight.ItemId))
                    item = client.GetFileInfoById(newRight.ItemId);

                if (PackageExists(newRight.ItemId))
                    item = client.GetPackageById(newRight.ItemId);

                if(item == null)
                    throw new ObjectNotFoundException();

                if(_sessionUser.Type != UserType.admin
                    && !_sessionUser.Email.Equals(item.OwnerEmail)
                    && !HasEditRights(newRight.ItemId))
                    throw new InsufficientRightsException();

                client.GrantRight(newRight);
            }
        }
开发者ID:Crelde,项目名称:ClientBNDN,代码行数:35,代码来源:Controller.cs

示例7: GetTagsByItemId

        /// <summary>Returns the tags that the Item with the given Id has.</summary>
        /// <param name="itemId">The Id of the Item whose tags should be returned.</param>
        /// <returns>The tags of the matching Item.</returns>
        public static string[] GetTagsByItemId(int itemId)
        {
            if (_sessionUser == null)
                throw new NotLoggedInException();

            using (var client = new ServiceClient())
            {
                Item item = null;

                if (FileExists(itemId))
                    item = client.GetFileInfoById(itemId);

                if (PackageExists(itemId))
                    item = client.GetFileInfoById(itemId);

                if (item == null)
                    throw new ObjectNotFoundException();

                if (_sessionUser.Type != UserType.admin
                    && !_sessionUser.Email.Equals(item.OwnerEmail)
                    && !HasViewRights(itemId))
                    throw new InsufficientRightsException();

                return client.GetTagsByItemId(itemId);
            }
        }
开发者ID:Crelde,项目名称:ClientBNDN,代码行数:29,代码来源:Controller.cs

示例8: GetFileInfoById

        /// <summary>Looks up the info of a file by its Id.</summary>
        /// <param name="fileId">The Id of the file whose info should be returned.</param>
        /// <returns>The FileInfo of the file whose Id property matched the given fileId.</returns>
        /// <exception cref="NotLoggedInException">Thrown if you are not logged in.</exception>
        /// <exception cref="InsufficientRightsException">Thrown if you are logged in, but don't have the required rights.</exception>
        /// <exception cref="ObjectNotFoundException">Thrown if the requested object could not be retrieved.</exception>
        public static FileInfo GetFileInfoById(int fileId)
        {
            if (_sessionUser == null)
                throw new NotLoggedInException();

            if (!FileExists(fileId))
                throw new ObjectNotFoundException();

            using (var client = new ServiceClient())
            {
                var info = client.GetFileInfoById(fileId);

                if (_sessionUser.Type != UserType.admin
                    && !_sessionUser.Email.Equals(info.OwnerEmail)
                    && !HasViewRights(fileId))
                    throw new InsufficientRightsException();

                return info;
            }
        }
开发者ID:Crelde,项目名称:ClientBNDN,代码行数:26,代码来源:Controller.cs

示例9: DeleteFileById

        /// <summary>Deletes the File with the matching fileId.</summary>
        /// <param name="fileId">The Id of the file which should be deleted.</param>
        public static void DeleteFileById(int fileId)
        {
            if (_sessionUser == null)
                throw new NotLoggedInException();

            if (!FileExists(fileId))
                throw new ObjectNotFoundException();

            using (var client = new ServiceClient())
            {
                if (_sessionUser.Type != UserType.admin
                    && !_sessionUser.Email.Equals(client.GetFileInfoById(fileId).OwnerEmail)
                    && !HasEditRights(fileId))
                    throw new InsufficientRightsException();

                client.DeleteFileById(fileId);
            }
        }
开发者ID:Crelde,项目名称:ClientBNDN,代码行数:20,代码来源:Controller.cs


注:本文中的ServiceClient.GetFileInfoById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。