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


C# ServiceClient.GetRight方法代码示例

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


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

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

示例2: HasViewRights

 /// <summary>
 /// Utility method that checks whether the current user has 
 /// viewing rights to the Item which is identified by the given itemId.
 /// NOTE - This only checks if there exists a Right object stating that
 /// the current user has view/edit rights. It does NOT check if the user
 /// is the owner of the Item, which would also permit viewing.
 /// </summary>
 /// <param name="itemId">The id of the Item in question.</param>
 /// <returns>True of the current user can view the item, false if not.</returns>
 public static bool HasViewRights(int itemId)
 {
     using (var client = new ServiceClient())
     {
         var right = client.GetRight(_sessionUser.Email, itemId);
         // NOTE - We're using the current systems datetime.
         // Users can thus regain rights that have run out, by changing their clocks.
         return right != null && (right.Until == null || DateTime.Compare(right.Until.Value, DateTime.Now) > 0);
     }
 }
开发者ID:Crelde,项目名称:ClientBNDN,代码行数:19,代码来源:Controller.cs


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