Exemplo n.º 1
0
        public void EqualsWithObjectResourceTypeNull()
        {
            ResourceType rt          = "Microsoft.Network1/VirtualNetworks2/subnets1";
            object       rightObject = null;

            Assert.IsFalse(rt.Equals(rightObject));

            object sameRt = rt;

            Assert.IsTrue(rt.Equals(sameRt));

            object intRt = 5;

            Assert.IsFalse(rt.Equals(intRt));
        }
Exemplo n.º 2
0
        public void EqualsWithObjectString(bool expected, string left, string right)
        {
            ResourceType rt          = left;
            object       rightObject = right;

            Assert.AreEqual(expected, rt.Equals(rightObject));
        }
Exemplo n.º 3
0
 public bool Equals(StorageItem other)
 {
     if (other == null)
     {
         return(false);
     }
     return(resourceType.Equals(other.resourceType));
 }
Exemplo n.º 4
0
        public void EqualsWithObjectResourceType(bool expected, string left, string right)
        {
            ResourceType rt          = left;
            ResourceType rightRt     = right;
            object       rightObject = rightRt;

            Assert.AreEqual(expected, rt.Equals(rightObject));
            Assert.AreEqual(expected, rt?.GetHashCode() == rightRt?.GetHashCode());

            object sameRt = rt;

            Assert.IsTrue(rt.Equals(sameRt));

            object intRt = 5;

            Assert.IsFalse(rt.Equals(intRt));
        }
    private GameObject SelectRandomResourceNode()
    {
        ResourceType selectedResourceType = SelectRandomResourceType();

        if (selectedResourceType.Equals(ResourceType.Wood))
        {
            int randomIndex = Random.Range(0, woodResourcesNodes.Length);
            return(woodResourcesNodes[randomIndex]);
        }
        else if (selectedResourceType.Equals(ResourceType.Stone))
        {
            int randomIndex = Random.Range(0, stoneResourcesNodes.Length);
            return(stoneResourcesNodes[randomIndex]);
        }
        else
        {
            int randomIndex = Random.Range(0, goldResourcesNodes.Length);
            return(goldResourcesNodes[randomIndex]);
        }
    }
Exemplo n.º 6
0
 public virtual void updateFilter(Filter filter, ProcessEngine engine)
 {
     if (!string.ReferenceEquals(ResourceType, null) && !ResourceType.Equals(filter.ResourceType))
     {
         throw new InvalidRequestException(Status.BAD_REQUEST, "Unable to update filter from resource type '" + filter.ResourceType + "' to '" + ResourceType + "'");
     }
     filter.Name       = Name;
     filter.Owner      = Owner;
     filter.Query      = query.toQuery(engine);
     filter.Properties = Properties;
 }
Exemplo n.º 7
0
    float DepositResource(ResourceType resource, float value, ref ResourceDepositEntity entity)
    {
        float val;

        if (resource.Equals(entity.deposit.Value.Type) && resourceGeneration.TryGetValue(resource, out val))
        {
            float availableSpace = entity.deposit.Value.Capacity.Evaluate(entity.level.Value) - entity.deposit.Value.Amount;
            float depositValue   = Mathf.Min(availableSpace, value);
            entity.deposit.Value.Amount += depositValue;
            return(depositValue);
        }
        else
        {
            return(0f);
        }
    }
Exemplo n.º 8
0
 /// <summary>
 /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
 /// </summary>
 /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
 /// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.</returns>
 public override bool Equals(object obj)
 {
     if (obj is CriteriaGet)
     {
         var c = (CriteriaGet)obj;
         if (!ResourceType.Equals(c.ResourceType))
         {
             return(false);
         }
         if (!UICulture.Equals(c.UICulture))
         {
             return(false);
         }
         return(true);
     }
     return(false);
 }
Exemplo n.º 9
0
        public static void BuyResource(Player buyer, ResourceType type, int count)
        {
            var validPhase = gameState.CurrentPhase == Phase.BuyResources;

            if (validPhase)
            {
                var validPlayer = gameState.CurrentPlayer.Equals(buyer);
                var validType   = !type.Equals(ResourceType.Mixed);
                if (validPlayer && validType)
                {
                    Player player = gameState.Players.First(x => x.Name.Equals(buyer.Name));

                    for (int i = 0; i < count; i++)
                    {
                        int cost = gameState.ResourceMarket.GetCost(type);
                        if (player.Money >= cost)
                        {
                            player.Money -= cost;
                            player.Resources.AvailableResources[(int)type]++;
                            gameState.ResourceMarket.Resources.AvailableResources[(int)type]--;
                        }
                        else
                        {
                            throw new Exception("invalid count.");
                        }
                    }
                }
                else
                {
                    if (!validPlayer)
                    {
                        throw new Exception("invalid player.");
                    }
                    else
                    {
                        throw new Exception("invalid type.");
                    }
                }
            }
            else
            {
                throw new Exception("invalid phase.");
            }
            SendUpdates();
        }
        public bool Equals([AllowNull] ISearchValue other)
        {
            if (other == null)
            {
                return(false);
            }

            var referenceSearchValueOther = other as ReferenceSearchValue;

            if (referenceSearchValueOther == null)
            {
                return(false);
            }

            return(Kind == referenceSearchValueOther.Kind &&
                   BaseUri == referenceSearchValueOther.BaseUri &&
                   ResourceType.Equals(referenceSearchValueOther.ResourceType, StringComparison.OrdinalIgnoreCase) &&
                   ResourceId.Equals(referenceSearchValueOther.ResourceId, StringComparison.OrdinalIgnoreCase));
        }
 public static List <KitsuneResource> CreateKitsuneResource(List <AssetDetails> resources, string projectId, ResourceType type)
 {
     try
     {
         List <KitsuneResource> kitsuneResources = new List <KitsuneResource>();
         DateTime dateTime;
         foreach (var resource in resources)
         {
             if (resource.NewUrl != null && resource.ResponseStatusCode.Equals(HttpStatusCode.OK))
             {
                 dateTime = DateTime.UtcNow;
                 KitsuneResource newResource = new KitsuneResource
                 {
                     CreatedOn    = dateTime,
                     UpdatedOn    = dateTime,
                     SourcePath   = resource.NewUrl,
                     UrlPattern   = resource.NewUrl,
                     ResourceType = type,
                     Version      = 1,
                     ProjectId    = projectId,
                     IsArchived   = false,
                     IsStatic     = type.Equals(ResourceType.LINK) ? false : true
                 };
                 if (resource.NewUrl.Equals("/index.html"))
                 {
                     newResource.IsDefault = true;
                 }
                 kitsuneResources.Add(newResource);
             }
         }
         return(kitsuneResources);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Exemplo n.º 12
0
        public static bool IsResourceMapType(ResourceType type)
        {
            if (type.Equals(ResourceType.PROCESS_AGENT.ToString()) ||
                type.Equals(ResourceType.CLIENT.ToString()) ||
                type.Equals(ResourceType.RESOURCE_MAPPING.ToString()) ||
                type.Equals(ResourceType.STRING.ToString()) ||
                type.Equals(ResourceType.TICKET_TYPE.ToString()) ||
                type.Equals(ResourceType.GROUP.ToString()) ||
                type.Equals(ResourceType.RESOURCE_TYPE.ToString()))
                return true;

            return false;
        }
Exemplo n.º 13
0
        public override KeyExpressions GetAllExistingKeysOfType(ResourceContainer resourceContainer, ResourceType resourceType)
        {
            if (!this.DataGenerator.Done)
            {
                return this.DataGenerator.GetAllGeneratedKeys(resourceContainer, resourceType);
            }

            bool rightsChanged = false;
            EntitySetRights oldRights = this.DataService.ConfigSettings.GetEntitySetAccessRule(resourceContainer.Name);

            if ((EntitySetRights.ReadMultiple & oldRights) == 0)
            {
                rightsChanged = true;
                this.DataService.ConfigSettings.SetEntitySetAccessRule(resourceContainer.Name, EntitySetRights.All);
            }

            bool resourceTypeUnspecified = resourceType == null;
            if (resourceTypeUnspecified)
            {
                resourceType = resourceContainer.BaseType;
            }

            ExpNode query = Query.From(Exp.Variable(resourceContainer)).Where(Exp.IsOf(null, resourceType));
            if (Versioning.Server.SupportsV2Features && !this.Settings.HasExpandProvider)
            {
                query = ((QueryNode)query).New(resourceType.Properties.Where(p => p.PrimaryKey != null || p.Facets.ConcurrencyModeFixed).Select(p => p.Property()).ToArray());
            }
            else
            {
                query = ((QueryNode)query).Select();
            }
            
            AstoriaRequest request = this.CreateRequest(query);

            AstoriaResponse response = request.GetResponse();

            // When the response is 404 this means no keys were found so return empty
            if(response.ActualStatusCode == HttpStatusCode.NotFound)
            {
                return new KeyExpressions();
            }

            // normal verification doesn't work here safely due to ETags and No-Content responses
            if (response.ActualStatusCode != HttpStatusCode.OK && response.ActualStatusCode != HttpStatusCode.NoContent)
                ResponseVerification.LogFailure(response, new TestFailedException("Unexpected status code"));

            if (rightsChanged)
                this.DataService.ConfigSettings.SetEntitySetAccessRule(resourceContainer.Name, oldRights);

            KeyExpressions allKeys = GetKeyExpressionsFromPayload(resourceContainer, response);

            if (resourceTypeUnspecified)
            {
                return allKeys;
            }

            return new KeyExpressions(allKeys.Where(key => resourceType.Equals(key.ResourceType)));
        }
    private void AssertNoRelationshipsInSparseFieldSets()
    {
        ResourceType resourceType = _resourceGraph.GetResourceType <TResource>();

        // @formatter:wrap_chained_method_calls chop_always
        // @formatter:keep_existing_linebreaks true

        bool hasRelationshipSelectors = _constraintProviders
                                        .SelectMany(provider => provider.GetConstraints())
                                        .Select(expressionInScope => expressionInScope.Expression)
                                        .OfType <SparseFieldTableExpression>()
                                        .Any(fieldTable =>
                                             fieldTable.Table.Keys.Any(targetResourceType => !resourceType.Equals(targetResourceType)) ||
                                             fieldTable.Table.Values.Any(fieldSet => fieldSet.Fields.Any(field => field is RelationshipAttribute)));

        // @formatter:keep_existing_linebreaks restore
        // @formatter:wrap_chained_method_calls restore

        if (hasRelationshipSelectors)
        {
            throw new UnsupportedRelationshipException();
        }
    }