Пример #1
0
        /// <inheritdoc/>
        public virtual async Task <StoragePassword> CreateAsync(string password, string username, string realm = null)
        {
            var arguments = new CreationArgs
            {
                Password = password,
                Username = username,
                Realm    = realm
            };

            return(await this.CreateAsync(arguments.AsEnumerable()).ConfigureAwait(false));
        }
        /// <inheritdoc/>
        public virtual async Task <ServerMessage> CreateAsync(string name, ServerMessageSeverity type, string text)
        {
            var args = new CreationArgs
            {
                Name = name,
                Type = type,
                Text = text
            };

            return(await this.CreateAsync(args.AsEnumerable()).ConfigureAwait(false));
        }
Пример #3
0
        public override void OnGui(SerializedProperty property, GUIContent label)
        {
            var pairsProperty = property.FindPropertyRelative("pairs");
            var errorProperty = property.FindPropertyRelative("error");
            var drawerArgs    = new CreationArgs()
            {
                pairsProperty = pairsProperty,
                errorProperty = errorProperty
            };

            storage.ReturnItem(property, drawerArgs).DoList();
        }
Пример #4
0
        /// <summary>
        /// Asyncrhonously creates the index represented by the current index
        /// </summary>
        /// <param name="coldPath">
        /// Location for storing the cold databases for the current <see cref=
        /// "Index"/>. A value of <c>null</c> or <c>""</c> specifies that the
        /// cold databases should be stored at the default location.
        /// </param>
        /// <param name="homePath">
        /// Location for storing the hot and warm buckets for the current
        /// index. A value of <c>null</c> or <c>""</c> specifies that the hot
        /// and warm buckets should be stored at the default location.
        /// </param>
        /// <param name="thawedPath">
        /// Location for storing the resurrected databases for the current <see
        /// cref="Index"/>. A value of <c>null</c> or <c>""</c> specifies that
        /// the resurrected databases should be stored at the default location.
        /// </param>
        /// <param name="attributes">
        /// Attributes to set on the newly created index.
        /// </param>
        /// <returns></returns>
        public async Task CreateAsync(string coldPath            = null, string homePath = null, string thawedPath = null,
                                      IndexAttributes attributes = null)
        {
            var resourceName = IndexCollection.ClassResourceName;

            var args = new CreationArgs()
            {
                Name = this.Name, ColdPath = coldPath, HomePath = homePath, ThawedPath = thawedPath
            };

            using (var response = await this.Context.PostAsync(this.Namespace, resourceName, args, attributes))
            {
                await response.EnsureStatusCodeAsync(HttpStatusCode.Created);

                await this.UpdateSnapshotAsync(response);
            }
        }
Пример #5
0
        /// <summary>
        /// Asynchronously creates the application represented by the current
        /// instance.
        /// </summary>
        /// <remarks>
        /// This method uses the <a href="http://goo.gl/SzKzNX">POST
        /// apps/local</a> endpoint to create the current <see cref=
        /// "Application"/>.
        /// </remarks>
        public async Task InstallAsync(string path, bool update = false)
        {
            var resourceName = ApplicationCollection.ClassResourceName;

            var args = new CreationArgs()
            {
                ExplicitApplicationName = this.Name,
                Filename = true,
                Name     = path,
                Update   = update
            };

            using (var response = await this.Context.PostAsync(this.Namespace, resourceName, args))
            {
                await response.EnsureStatusCodeAsync(HttpStatusCode.Created);

                await this.UpdateSnapshotAsync(response);
            }
        }
Пример #6
0
        /// <summary>
        /// Asynchronously creates the current <see cref="Application"/>.
        /// instance.
        /// </summary>
        /// <remarks>
        /// This method uses the <a href="http://goo.gl/SzKzNX">POST
        /// apps/local</a> endpoint to create the current <see cref=
        /// "Application"/>.
        /// </remarks>
        public async Task CreateAsync(string template, ApplicationAttributes attributes = null)
        {
            var resourceName = ApplicationCollection.ClassResourceName;

            var args = new CreationArgs()
            {
                ExplicitApplicationName = this.Name,
                Filename = false,
                Name     = this.Name,
                Template = template
            };

            using (var response = await this.Context.PostAsync(this.Namespace, resourceName, args, attributes))
            {
                await response.EnsureStatusCodeAsync(HttpStatusCode.Created);

                await this.UpdateSnapshotAsync(response);
            }
        }
        /// <inheritdoc/>
        public virtual async Task <Index> CreateAsync(string name, IndexAttributes attributes = null,
                                                      string coldPath = null, string homePath = null, string thawedPath = null)
        {
            var arguments = new CreationArgs()
            {
                Name       = name,
                ColdPath   = coldPath,
                HomePath   = homePath,
                ThawedPath = thawedPath
            }
            .AsEnumerable();

            if (attributes != null)
            {
                arguments = arguments.Concat(attributes);
            }

            return(await this.CreateAsync(arguments).ConfigureAwait(false));
        }
        /// <inheritdoc/>
        public async Task <Application> CreateAsync(string name, string template, ApplicationAttributes attributes = null)
        {
            var arguments = new CreationArgs
            {
                ExplicitApplicationName = name,
                Filename = false,
                Name     = name,
                Template = template
            }
            .AsEnumerable();

            if (attributes != null)
            {
                arguments = arguments.Concat(attributes);
            }

            var resourceEndpoint = await this.CreateAsync(arguments).ConfigureAwait(false);

            return(resourceEndpoint);
        }
        /// <inheritdoc/>
        public async Task <Application> InstallAsync(string path, string name = null, bool update = false)
        {
            var resourceName = ClassResourceName;

            var args = new CreationArgs()
            {
                ExplicitApplicationName = name ?? "",
                Filename = true,
                Name     = path,
                Update   = update
            };

            using (var response = await this.Context.PostAsync(this.Namespace, resourceName, args).ConfigureAwait(false))
            {
                await response.EnsureStatusCodeAsync(HttpStatusCode.Created).ConfigureAwait(false);

                var resourceEndpoint = await Entity <Resource> .CreateAsync <Application>(this.Context, response).ConfigureAwait(false);

                return(resourceEndpoint);
            }
        }
Пример #10
0
        public async Task <IActionResult> Get(CreationArgs args)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (string.IsNullOrEmpty(args.Url))
            {
                return(BadRequest(new { Message = "An url for image access must be provided" }));
            }

            var encodedId  = Convert.ToBase64String(Encoding.UTF8.GetBytes(args.Url));
            var folderPath = Path.Combine(_thumbnailConfig.Path, encodedId);

            if (!string.IsNullOrEmpty(args.Size) && !_thumbnailConfig.SupportedSizes.ContainsKey(args.Size))
            {
                return(BadRequest(new { Message = "Invalid size" }));
            }

            var semaphore = LockDictionary.GetOrAdd(encodedId, new SemaphoreSlim(1));
            await semaphore.WaitAsync();

            try
            {
                var requestedImageFormat = args.Format.GetImageFormat();
                var filePath             = Path.Combine(folderPath, GetFileName(args.Size, args.Mode)) + "." +
                                           requestedImageFormat.FileExtensions.First();
                if (!System.IO.File.Exists(filePath))
                {
                    var client = new HttpClient();
                    client.DefaultRequestHeaders.Add("Authorization", Request.Headers["Authorization"].ToString());
                    var hostUrl = _thumbnailConfig.HostUrl;
                    using (var stream = await client.GetStreamAsync(hostUrl + args.Url))
                    {
                        //Create Directory if it doesn't exist
                        Directory.CreateDirectory(folderPath);

                        if (string.IsNullOrEmpty(args.Size))
                        {
                            //The original image should be returned if the size is empty
                            SaveImage(stream, filePath);
                        }
                        else
                        {
                            var value = _thumbnailConfig.SupportedSizes[args.Size];
                            GenerateThumbnail(args.Mode, stream, filePath, value);
                        }
                    }
                }

                return(File(new FileStream(filePath, FileMode.Open), requestedImageFormat.DefaultMimeType,
                            Path.GetFileName(filePath)));
            }
            catch (HttpRequestException)
            {
                return(NotFound(new { Message = "Image access failed" }));
            }
            catch (NotSupportedException)
            {
                return(BadRequest(new { Message = "The format of the requested image is not supported" }));
            }
            finally
            {
                semaphore.Release();
            }
        }