Exemplo n.º 1
0
        public void Add(ResourceJson resource, int order)
        {
            var key = GetResourcesJsonIndicesKey(resource);

            if (!this.ResourcesJsonIndices.ContainsKey(key))
            {
                this.ResourcesJsonIndices.Add(key, order);
            }
        }
        private FilePath _assetKey; // needed for deletion (in case file is missing)

        public UpdateResource(FilePath assetKey, ResourceJson resource, FileEntry file)
        {
            _name     = resource.Name;
            _file     = file;
            _assetKey = assetKey;
            _resource = resource;

            Contract.Assert(assetKey != null);
            Contract.Assert(file == null || file.Name.Equals(assetKey));
        }
Exemplo n.º 3
0
        public void TestAssetFileRename()
        {
            var doc       = new CanvasDocument();
            var resource1 = new ResourceJson()
            {
                Name         = "Image", // Capital
                Path         = "Assets\\Images\\Image.png",
                FileName     = "Image.png",
                ResourceKind = ResourceKind.LocalFile,
                Content      = ContentKind.Image,
            };

            doc._assetFiles.Add(new FilePath("Images", "Image.png"), new FileEntry());

            var resource2 = new ResourceJson()
            {
                Name         = "image", // Lowercase
                Path         = "Assets\\Images\\image.png",
                FileName     = "image.png",
                ResourceKind = ResourceKind.LocalFile,
                Content      = ContentKind.Image,
            };

            doc._assetFiles.Add(new FilePath("Images", "image.png"), new FileEntry());

            var resource3 = new ResourceJson()
            {
                Name         = "image_1",
                Path         = "Assets\\Images\\image_1.png",
                FileName     = "image_1.png",
                ResourceKind = ResourceKind.LocalFile,
                Content      = ContentKind.Image,
            };

            doc._assetFiles.Add(new FilePath("Images", "image_1.png"), new FileEntry());

            doc._resourcesJson = new ResourcesJson()
            {
                Resources = new ResourceJson[] { resource1, resource2, resource3 }
            };

            var errorContainer = new ErrorContainer();

            doc.StabilizeAssetFilePaths(errorContainer);

            var newFileNames = doc._resourcesJson.Resources.Select(resource => resource.Name);

            Assert.IsTrue(newFileNames.Contains("Image"));
            Assert.IsTrue(newFileNames.Contains("image_1"));
            Assert.IsTrue(newFileNames.Contains("image_2"));
        }
Exemplo n.º 4
0
        public string Serialize(Stack stack)
        {
            var stackJson = new StackJson
            {
                AWSTemplateFormatVersion = stack.AWSTemplateFormatVersion,
                Transform   = stack.Transform,
                Description = stack.Description
            };

            if (stack.Parameters != null && stack.Parameters.Any())
            {
                stackJson.Parameters = stack.Parameters;
            }

            if (stack.Mappings != null && stack.Mappings.Any())
            {
                stackJson.Mappings = stack.Mappings;
            }

            if (stack.Outputs != null && stack.Outputs.Any())
            {
                stackJson.Outputs = stack.Outputs;
            }

            if (stack.Conditions != null && stack.Conditions.Any())
            {
                stackJson.Conditions = stack.Conditions;
            }

            if (stack.TemplateMetadata != null && stack.TemplateMetadata.Any())
            {
                stackJson.Metadata = stack.TemplateMetadata;
            }

            if (stack.Resources != null && stack.Resources.Any())
            {
                stackJson.Resources = new Dictionary <string, ResourceJson>();

                foreach (KeyValuePair <string, Resource> kvp in stack.Resources)
                {
                    var resource = kvp.Value;

                    var typeInfo = kvp.Value.GetType();
                    Debug.Assert(typeInfo.Namespace != null);

                    var condition = stack.GetCondition(kvp.Key);
                    var dependsOn = stack.GetDependsOn(kvp.Key);

                    var creationPolicy = stack.GetCreationPolicy(kvp.Key);
                    var updatePolicy   = stack.GetUpdatePolicy(kvp.Key);
                    var deletionPolicy = stack.GetDeletionPolicy(kvp.Key);
                    var metadata       = stack.GetMetadata(kvp.Key);

                    var resourceJson = new ResourceJson
                    {
                        Type           = resource.AWSTypeName,
                        Condition      = condition,
                        Properties     = resource,
                        DependsOn      = dependsOn,
                        CreationPolicy = creationPolicy,
                        UpdatePolicy   = updatePolicy,
                        DeletionPolicy = deletionPolicy,
                        Metadata       = metadata
                    };

                    stackJson.Resources.Add(kvp.Key, resourceJson);
                }
            }

            var result = JsonConvert.SerializeObject(stackJson, settings);

            return(result);
        }
Exemplo n.º 5
0
 // Using the name of the resource combined with the content kind as a key to avoid collisions across different resource types.
 public string GetResourcesJsonIndicesKey(ResourceJson resource)
 {
     return(resource.Content + "-" + resource.Name);
 }
 public AddResource(string name, ResourceJson resource)
 {
     _file     = null;
     _resource = resource;
     _name     = name;
 }
 public AddResource(string name, ResourceJson resource, FileEntry file)
 {
     _file     = file;
     _resource = resource;
     _name     = name;
 }