예제 #1
0
        private bool CreateKeyedResourceInstance(ResourceContainer container, ResourceType resourceType, out KeyExpression key, out KeyedResourceInstance newResource)
        {
            int retryCount = 5;

            if (!_existingKeyMap.Keys.Contains(container))
            {
                _existingKeyMap.Add(container, new KeyExpressions());
            }

            newResource = resourceType.CreateRandomResource(container, new KeyExpressions(), false); // should not make request
            key         = newResource.ResourceInstanceKey.CreateKeyExpression(container, resourceType);

            while (_existingKeyMap[container].Contains(key) && retryCount > 0)
            {
                newResource.ResourceInstanceKey = ResourceInstanceUtil.CreateUniqueKey(container, resourceType, new KeyExpressions(), new KeyExpressions());
                key = newResource.ResourceInstanceKey.CreateKeyExpression(container, resourceType);
                retryCount--;
            }

            if (retryCount == 0)
            {
                newResource = null;
                key         = null;
                return(false);
            }

            _existingKeyMap[container].Add(key);
            _existingEntityMap[key] = newResource;
            return(true);
        }
예제 #2
0
        public static AstoriaRequest BuildInsert(Workspace workspace, ResourceContainer container, ResourceType type,
                                                 HttpStatusCode expectedStatusCode, SerializationFormatKind format, out KeyExpression createdKey)
        {
            KeyedResourceInstance newResource = type.CreateRandomResource(container);

            if (newResource == null)
            {
                newResource = ResourceInstanceUtil.CreateKeyedResourceInstanceByClone(container, type);

                if (newResource == null)
                {
                    createdKey = null;
                    return(null);
                }
            }

            QueryNode query;

            if (!type.Key.Properties.Any(p => p.Facets.ServerGenerated) && newResource.ResourceInstanceKey != null)
            {
                createdKey = newResource.ResourceInstanceKey.CreateKeyExpression(container, type);
                query      = ContainmentUtil.BuildCanonicalQuery(createdKey, true);
            }
            else
            {
                createdKey = null;
                // the key is unknown, must be server generated
                // in this case, lets hope that containment is a non-issue
                query =
                    Query.From(Exp.Variable(container))
                    .Select();
                if (!container.Facets.TopLevelAccess && expectedStatusCode == HttpStatusCode.Created)
                {
                    expectedStatusCode = HttpStatusCode.BadRequest;
                }
            }

            AstoriaRequest request = workspace.CreateRequest();

            request.Verb               = RequestVerb.Post;
            request.Query              = query;
            request.UpdateTree         = newResource;
            request.ExpectedStatusCode = expectedStatusCode;
            request.Format             = format;

            return(request);
        }
예제 #3
0
        public static AstoriaRequest BuildInsert(Workspace workspace, ResourceContainer container, ResourceType type,
            HttpStatusCode expectedStatusCode, SerializationFormatKind format, out KeyExpression createdKey)
        {
            KeyedResourceInstance newResource = type.CreateRandomResource(container);
            if (newResource == null)
            {
                newResource = ResourceInstanceUtil.CreateKeyedResourceInstanceByClone(container, type);

                if(newResource == null)
                {
                    createdKey = null;
                    return null;
                }
            }

            QueryNode query;
            if (!type.Key.Properties.Any(p => p.Facets.ServerGenerated) && newResource.ResourceInstanceKey != null)
            {
                createdKey = newResource.ResourceInstanceKey.CreateKeyExpression(container, type);
                query = ContainmentUtil.BuildCanonicalQuery(createdKey, true);
            }
            else
            {
                createdKey = null;
                // the key is unknown, must be server generated
                // in this case, lets hope that containment is a non-issue
                query =
                    Query.From(Exp.Variable(container))
                    .Select();
                if (!container.Facets.TopLevelAccess && expectedStatusCode == HttpStatusCode.Created)
                    expectedStatusCode = HttpStatusCode.BadRequest;
            }

            AstoriaRequest request = workspace.CreateRequest();

            request.Verb = RequestVerb.Post;
            request.Query = query;
            request.UpdateTree = newResource;
            request.ExpectedStatusCode = expectedStatusCode;
            request.Format = format;

            return request;
        }
예제 #4
0
        private bool CreateKeyedResourceInstance(ResourceContainer container, ResourceType resourceType, out KeyExpression key, out KeyedResourceInstance newResource)
        {
            int retryCount = 5;

            if (!_existingKeyMap.Keys.Contains(container))
                _existingKeyMap.Add(container, new KeyExpressions());

            newResource = resourceType.CreateRandomResource(container, new KeyExpressions(), false); // should not make request
            key = newResource.ResourceInstanceKey.CreateKeyExpression(container, resourceType);

            while (_existingKeyMap[container].Contains(key) && retryCount > 0)
            {
                newResource.ResourceInstanceKey = ResourceInstanceUtil.CreateUniqueKey(container, resourceType, new KeyExpressions(), new KeyExpressions());
                key = newResource.ResourceInstanceKey.CreateKeyExpression(container, resourceType);
                retryCount--;
            }

            if (retryCount == 0)
            {
                newResource = null;
                key = null;
                return false;
            }

            _existingKeyMap[container].Add(key);
            _existingEntityMap[key] = newResource;
            return true;
        }