Ejemplo n.º 1
0
        public void CreateTarget(Target target)
        {
            if (target == null)
                throw new ArgumentNullException("target", "Target cannot be null.");
            if (target.GroupKey == Guid.Empty)
                throw new ArgumentException("Group key cannot be empty.", "target.GroupKey");

            using (var stream = target.Serialise())
            {
                try
                {
                    using (var client = new AmazonS3Client(Context.AwsAccessKeyId, Context.AwsSecretAccessKey))
                    {
                        var groupsController = new Groups(Context);
                        if (!groupsController.GroupExists(target.GroupKey))
                            throw new GroupNotFoundException(String.Format("Group with the key \"{0}\" could not be found.", target.GroupKey));

                        var indexesController = new Internal.Indexes(Context);

                        string indexPath = GetGroupTargetsIndexPath(target.GroupKey);
                        var appIndex = indexesController.LoadIndex(indexPath);
                        if (appIndex.Entries.Any(e => e.Key == target.Key))
                        {
                            throw new DeploymentException("Index already contains entry for given key!");
                        }

                        using (var putResponse = client.PutObject(new PutObjectRequest()
                        {
                            BucketName = Context.BucketName,
                            Key = string.Format("{0}/{1}/{2}", STR_TARGETS_CONTAINER_PATH, target.Key.ToString("N"), STR_INFO_FILE_NAME),
                            InputStream = stream,
                        })) { }

                        appIndex.Entries.Add(new Internal.EntityIndexEntry() { Key = target.Key, Name = target.Name });
                        Internal.Indexes.NameSortIndex(appIndex);
                        indexesController.UpdateIndex(indexPath, appIndex);
                    }
                }
                catch (AmazonS3Exception awsEx)
                {
                    throw new DeploymentException("Failed creating target.", awsEx);
                }
            }
        }
Ejemplo n.º 2
0
        public void UpdateApp(App app)
        {
            if (app == null)
                throw new ArgumentNullException("app", "App cannot be null.");

            var existingApp = GetApp(app.Key);
            // Don't allow moving between groups right now as would have to recursively update references from versions and targets within app.
            app.GroupKey = existingApp.GroupKey;

            using (var stream = app.Serialise())
            {
                try
                {
                    using (var client = new AmazonS3Client(Context.AwsAccessKeyId, Context.AwsSecretAccessKey))
                    {
                        var indexesController = new Internal.Indexes(Context);
                        // This will not currently get called.
                        if (existingApp.GroupKey != app.GroupKey)
                        {
                            var groupsController = new Groups(Context);
                            if (!groupsController.GroupExists(app.GroupKey))
                                throw new GroupNotFoundException(string.Format("Group with key \"{0}\" to move app into cannot be found.", app.GroupKey));
                        }
                        using (var putResponse = client.PutObject(new PutObjectRequest()
                        {
                            BucketName = Context.BucketName,
                            Key = string.Format("{0}/{1}/{2}", STR_APPS_CONTAINER_PATH, app.Key.ToString("N"), STR_INFO_FILE_NAME),
                            InputStream = stream,
                        })) { }

                        // This will not currently get called.
                        if (existingApp.GroupKey != app.GroupKey)
                        {
                            string oldAppIndexPath = GetGroupAppsIndexPath(existingApp.GroupKey);
                            indexesController.DeleteIndexEntry(oldAppIndexPath, app.Key);
                        }

                        string newAppIndexPath = GetGroupAppsIndexPath(app.GroupKey);
                        indexesController.PutIndexEntry(newAppIndexPath, new Internal.EntityIndexEntry() { Key = app.Key, Name = app.Name });
                    }
                }
                catch (AmazonS3Exception awsEx)
                {
                    throw new DeploymentException("Failed updating app.", awsEx);
                }
            }
        }