示例#1
0
 private void AddKeyToInternalMapping(IKey localKey, IKey generatedKey)
 {
     if (localhost.GetKeyKind(localKey) == KeyKind.Temporary)
     {
         mapper.Remap(localKey.ResourceId, generatedKey.WithoutVersion());
     }
     else
     {
         mapper.Remap(localKey.ToString(), generatedKey.WithoutVersion());
     }
 }
        public ValueExpression GetNormalizedReferenceValue(ValueExpression originalValue, string resourceType)
        {
            if (originalValue == null)
            {
                return(null);
            }
            var value = originalValue.ToString();

            if (string.IsNullOrWhiteSpace(value))
            {
                return(originalValue);
            }
            if (!value.Contains("/") && !string.IsNullOrWhiteSpace(resourceType))
            {
                return(new StringValue($"{resourceType}/{value}"));
            }
            if (Uri.TryCreate(value, UriKind.RelativeOrAbsolute, out var uri))
            {
                var key = KeyExtensions.ExtractKey(uri);
                if (_localhost.GetKeyKind(key) != KeyKind.Foreign) // Don't normalize external references (https://github.com/FirelyTeam/spark/issues/244).
                {
                    var refUri = _localhost.RemoveBase(uri);
                    return(new StringValue(refUri.ToString().TrimStart('/')));
                }
            }
            return(originalValue);
        }
示例#3
0
        void InternalizeKey(Interaction interaction)
        {
            if (interaction.IsDeleted)
            {
                return;
            }

            Key key = interaction.Key.Clone();

            switch (localhost.GetKeyKind(key))
            {
            case KeyKind.Foreign:
            {
                interaction.Key = Remap(key);
                return;
            }

            case KeyKind.Temporary:
            {
                interaction.Key = Remap(key);
                return;
            }

            case KeyKind.Local:
            case KeyKind.Internal:
            {
                if (interaction.Method == Bundle.HTTPVerb.PUT)
                {
                    interaction.Key = RemapHistoryOnly(key);
                }
                else
                {
                    interaction.Key = Remap(key);
                }
                return;
            }

            default:
            {
                // switch can never get here.
                throw Error.Internal("Unexpected key for resource: " + interaction.Key.ToString());
            }
            }
        }
示例#4
0
        private static Bundle.HTTPVerb DetermineMethod(ILocalhost localhost, IKey key)
        {
            if (key == null) return Bundle.HTTPVerb.DELETE; // probably...

            switch (localhost.GetKeyKind(key))
            {
                case KeyKind.Foreign: return Bundle.HTTPVerb.POST;
                case KeyKind.Temporary: return Bundle.HTTPVerb.POST;
                case KeyKind.Internal: return Bundle.HTTPVerb.PUT;
                case KeyKind.Local: return Bundle.HTTPVerb.PUT;
                default: return Bundle.HTTPVerb.PUT;
            }
        }
示例#5
0
        private static Bundle.HTTPVerb DetermineMethod(ILocalhost localhost, IKey key)
        {
            if (key == null)
            {
                return(Bundle.HTTPVerb.DELETE); // probably...
            }

            return(localhost.GetKeyKind(key) switch
            {
                KeyKind.Foreign => Bundle.HTTPVerb.POST,
                KeyKind.Temporary => Bundle.HTTPVerb.POST,
                KeyKind.Internal => Bundle.HTTPVerb.PUT,
                KeyKind.Local => Bundle.HTTPVerb.PUT,
                _ => Bundle.HTTPVerb.PUT
            });
示例#6
0
        private static Bundle.HTTPVerb DetermineMethod(ILocalhost localhost, IKey key)
        {
            if (key == null)
            {
                return(Bundle.HTTPVerb.DELETE);             // probably...
            }
            switch (localhost.GetKeyKind(key))
            {
            case KeyKind.Foreign: return(Bundle.HTTPVerb.POST);

            case KeyKind.Temporary: return(Bundle.HTTPVerb.POST);

            case KeyKind.Internal: return(Bundle.HTTPVerb.PUT);

            case KeyKind.Local: return(Bundle.HTTPVerb.PUT);

            default: return(Bundle.HTTPVerb.PUT);
            }
        }
示例#7
0
        private void AddMappingsForOperation(
            Mapper <string, IKey> mapper,
            ResourceManipulationOperation operation,
            IList <Entry> interactions)
        {
            if (mapper == null || interactions.Count != 1)
            {
                return;
            }

            var entry = interactions[0];

            if (!entry.Key.Equals(operation.OperationKey))
            {
                mapper.Remap(
                    _localhost.GetKeyKind(operation.OperationKey) == KeyKind.Temporary
                        ? operation.OperationKey.ResourceId
                        : operation.OperationKey.ToString(),
                    entry.Key.WithoutVersion());
            }
        }
示例#8
0
 private void AddMappingsForOperation(Mapper <string, IKey> mapper, ResourceManipulationOperation operation, IList <Entry> interactions)
 {
     if (mapper == null)
     {
         return;
     }
     if (interactions.Count() == 1)
     {
         Entry entry = interactions.First();
         if (!entry.Key.Equals(operation.OperationKey))
         {
             if (localhost.GetKeyKind(operation.OperationKey) == KeyKind.Temporary)
             {
                 mapper.Remap(operation.OperationKey.ResourceId, entry.Key.WithoutVersion());
             }
             else
             {
                 mapper.Remap(operation.OperationKey.ToString(), entry.Key.WithoutVersion());
             }
         }
     }
 }