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


C# ServiceClient.GetPackageById方法代码示例

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


在下文中一共展示了ServiceClient.GetPackageById方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: AddToPackage

        /// <summary>Adds some Files to a Package.</summary>
        /// <param name="fileIds">The Ids of the Files that should be added to the Pacakge.</param>
        /// <param name="packageId">The Id of the Package to which the Files should be added.</param>
        public static void AddToPackage(int[] fileIds, int packageId)
        {
            if (_sessionUser == null)
                throw new NotLoggedInException();

            if (fileIds == null || fileIds.Length == 0 || fileIds.Any(fileId => !FileExists(fileId)))
                throw new InadequateObjectException();

            if (!PackageExists(packageId))
                throw new ObjectNotFoundException();

            using (var client = new ServiceClient())
            {
                var package = client.GetPackageById(packageId);

                if (_sessionUser.Type != UserType.admin
                    && !_sessionUser.Email.Equals(package.OwnerEmail)
                    && !HasEditRights(packageId)
                    || fileIds.Any(fileId => !HasEditRights(fileId) && !IsOwnerOf(fileId)))
                    throw new InsufficientRightsException();

                client.AddToPackage(fileIds, packageId);
            }
        }
开发者ID:Crelde,项目名称:ClientBNDN,代码行数:27,代码来源:Controller.cs

示例3: PackageExists

 /// <summary>Used to check if there exists a Package with a certain id.</summary>
 /// <param name="packageId">The id of the Package in question.</param>
 /// <returns>True if there exists such a Package, false if not.</returns>
 private static bool PackageExists(int packageId)
 {
     using (var client = new ServiceClient())
     {
         try
         {
             return client.GetPackageById(packageId).Id == packageId;
         }
         catch (Exception)
         {
             return false;
         }
     }
 }
开发者ID:Crelde,项目名称:ClientBNDN,代码行数:17,代码来源:Controller.cs

示例4: 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

示例5: 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

示例6: GetPackageById

        /// <summary>Look up a Package by its Id.</summary>
        /// <param name="packageId">The Id of the Package that should be returned.</param>
        /// <returns>The Package with the matching packageId.</returns>
        public static Package GetPackageById(int packageId)
        {
            if (_sessionUser == null)
                throw new NotLoggedInException();

            if (!PackageExists(packageId))
                throw new ObjectNotFoundException();

            using (var client = new ServiceClient())
            {
                var package = client.GetPackageById(packageId);

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

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

示例7: DeletePackageById

        /// <summary>Deletes a Package by its Id.</summary>
        /// <param name="packageId">The Id of the Package which should be deleted.</param>
        public static void DeletePackageById(int packageId)
        {
            if (_sessionUser == null)
                throw new NotLoggedInException();

            if (!PackageExists(packageId))
                throw new ObjectNotFoundException();

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

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


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