コード例 #1
0
        internal void ExecuteOperation(ResourceObject resource, ResourceOperationType resourceOpType)
        {
            if (resource == null)
            {
                throw new ArgumentNullException("resource");
            }

            this.ValidateResourceOperationType(resourceOpType);

            switch (this.Operation)
            {
            case AttributeOperationType.None:
                return;

            case AttributeOperationType.Add:
                this.PerformAttributeAdd(resource);
                break;

            case AttributeOperationType.Replace:
                this.PerformAttributeReplace(resource);
                break;

            case AttributeOperationType.Delete:
                this.PerformAttributeDelete(resource);
                break;

            default:
                throw new ArgumentException("Unknown or unsupported operation type");
            }
        }
コード例 #2
0
        private void ValidateResourceOperationType(ResourceOperationType resourceOpType)
        {
            switch (this.Operation)
            {
            case AttributeOperationType.None:
                break;

            case AttributeOperationType.Replace:
            case AttributeOperationType.Delete:
            case AttributeOperationType.Add:
                if (resourceOpType == ResourceOperationType.Delete)
                {
                    throw new ArgumentException("Cannot perform an attribute change on a delete operation");
                }

                break;

            default:
                throw new ArgumentException("Unknown or unsupported AttributeOperationType: " + this.Operation.ToString());
            }
        }
コード例 #3
0
 public static void ST_ResourceX(this Entities db, Guid id, ResourceOperationType operationType, decimal score = 0M)
 {
     var today = DateTime.Today;
     var year = today.Year;
     var month = today.Month;
     var count = db.ResourceStatisticsMonthly.Count(o => o.Year == year && o.Month == month && o.Id == id);
     if (count == 0)
     {
         db.ResourceStatisticsMonthly.Add(new ResourceStatisticsMonthly { Id = id, Year = year, Month = month, TimeStamp = DateTime.Now });
         db.SaveChanges();
     }
     var ops = db.ResourceStatisticsMonthly.First(o => o.Year == year && o.Month == month && o.Id == id);
     switch (operationType)
     {
         case ResourceOperationType.Comment:
             ops.Comment--;
             break;
         case ResourceOperationType.Download:
             ops.Download--;
             break;
         case ResourceOperationType.Favourite:
             ops.Favourite--;
             break;
         case ResourceOperationType.Grade:
             ops.Grade -= score;
             break;
         case ResourceOperationType.Rate:
             ops.Rate--;
             break;
         case ResourceOperationType.View:
             ops.View--;
             break;
     }
 }
コード例 #4
0
 public void UpdateAmount(int difference, int newTotal, ResourceOperationType operationType)
 {
     AmountText.text = newTotal.ToString();
     // TODO: Add animation based on difference and operationType
 }
コード例 #5
0
 private static string ConstructMessage(string message, ResourceOperationType operationType)
 {
     return($"Resource operation: {operationType} - Failure reason: {message}");
 }
コード例 #6
0
 public ResourceOperationException(string message, ResourceOperationType operationType, Exception innerException)
     : base(ConstructMessage(message, operationType), innerException)
 {
 }
コード例 #7
0
 public ResourceOperationException(string message, ResourceOperationType operationType)
     : base(ConstructMessage(message, operationType))
 {
 }