Ejemplo n.º 1
0
        public FileCallbackResult(string contentType, FileCallback callback)
            : base(contentType)
        {
            Guard.NotNull(callback, nameof(callback));

            Callback = callback;
        }
Ejemplo n.º 2
0
        public IActionResult GetImage(string app)
        {
            if (App.Image == null)
            {
                return(NotFound());
            }

            var etag = App.Image.Etag;

            Response.Headers[HeaderNames.ETag] = etag;

            var callback = new FileCallback(async(body, range, ct) =>
            {
                var resizedAsset = $"{App.Id}_{etag}_Resized";

                try
                {
                    await assetStore.DownloadAsync(resizedAsset, body, ct: ct);
                }
                catch (AssetNotFoundException)
                {
                    await ResizeAsync(resizedAsset, App.Image.MimeType, body, ct);
                }
            });

            return(new FileCallbackResult(App.Image.MimeType, callback)
            {
                ErrorAs404 = true
            });
        }
Ejemplo n.º 3
0
        public IActionResult GetImage(string app)
        {
            if (App.Image == null)
            {
                return(NotFound());
            }

            var etag = App.Image.Etag;

            Response.Headers[HeaderNames.ETag] = etag;

            var callback = new FileCallback(async(body, range, ct) =>
            {
                var resizedAsset = $"{App.Id}_{etag}_Resized";

                try
                {
                    await assetStore.DownloadAsync(resizedAsset, body, ct: ct);
                }
                catch (AssetNotFoundException)
                {
                    using (Profiler.Trace("Resize"))
                    {
                        using (var sourceStream = GetTempStream())
                        {
                            using (var destinationStream = GetTempStream())
                            {
                                using (Profiler.Trace("ResizeDownload"))
                                {
                                    await appImageStore.DownloadAsync(App.Id, sourceStream);
                                    sourceStream.Position = 0;
                                }

                                using (Profiler.Trace("ResizeImage"))
                                {
                                    await assetThumbnailGenerator.CreateThumbnailAsync(sourceStream, destinationStream, ResizeOptions);
                                    destinationStream.Position = 0;
                                }

                                using (Profiler.Trace("ResizeUpload"))
                                {
                                    await assetStore.UploadAsync(resizedAsset, destinationStream);
                                    destinationStream.Position = 0;
                                }

                                await destinationStream.CopyToAsync(body, ct);
                            }
                        }
                    }
                }
            });

            return(new FileCallbackResult(App.Image.MimeType, callback)
            {
                ErrorAs404 = true
            });
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Scans the directory and all subdirectories, running the callback for each found file.
 /// </summary>
 /// <param name="basePath">Base directory to scan for matching files.</param>
 /// <param name="extensions">Array of extension names to match. Do not include dots.</param>
 /// <param name="callback">Callback for each found file.</param>
 static void ScanDirectories(string basePath, string[] extensions, FileCallback callback)
 {
     foreach (var file in Directory.EnumerateFiles(basePath, "*", SearchOption.AllDirectories))
     {
         FileInfo fi = new FileInfo(file);
         if (extensions.Contains(fi.Extension.ToLower()))
         {
             callback(fi);
         }
     }
 }
Ejemplo n.º 5
0
 public void Initialize(DirectoryInfo starting_directory, ValidateFile validation_method, FileCallback fileCallback, DirectoryCallback directoryCallback)
 {
     NGUITools.SetActive(gameObject, true);
     SelectedFileText.text = "";
     dragPanel.ResetPosition();
     validate_method      = validation_method;
     current_directory    = starting_directory;
     callback_function    = fileCallback;
     directory_callback   = directoryCallback;
     directory_label.text = starting_directory.Name;
     LoadData();
 }
Ejemplo n.º 6
0
        public IActionResult GetLogFile(string token)
        {
            var appId = DomainId.Create(dataProtector.Unprotect(token));

            var today = DateTime.UtcNow.Date;

            var fileName = $"Usage-{today:yyy-MM-dd}.csv";

            var callback = new FileCallback((body, range, ct) =>
            {
                return(appLogStore.ReadLogAsync(appId, today.AddDays(-30), today, body, ct));
            });

            return(new FileCallbackResult("text/csv", callback)
            {
                FileDownloadName = fileName
            });
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Scans the directory and all subdirectories, running the callback for each found file.
        /// </summary>
        /// <param name="basePath">Base directory to scan for matching files.</param>
        /// <param name="extensions">Array of extension names to match. Do not include dots.</param>
        /// <param name="callback">Callback for each found file.</param>
        private static void ScanDirectories(string basePath, string[] extensions, FileCallback callback)
        {
            foreach (var file in Directory.EnumerateFiles(basePath, "*", SearchOption.AllDirectories))
            {
                FileInfo fi = new FileInfo(file);

                string extension = fi.Extension.ToLowerInvariant();
                if (extension.StartsWith("."))
                {
                    extension = extension.Substring(1);
                }

                if (extensions.Contains(extension))
                {
                    callback(fi);
                }
            }
        }
        public async Task <IActionResult> GetBackupContent(string app, string id)
        {
            var backup = await backupservice.GetBackupAsync(AppId, id);

            if (backup == null || backup.Status != JobStatus.Completed)
            {
                return(NotFound());
            }

            var fileName = $"backup-{app}-{backup.Started:yyyy-MM-dd_HH-mm-ss}.zip";

            var callback = new FileCallback((body, range, ct) =>
            {
                return(backupArchiveStore.DownloadAsync(id, body, ct));
            });

            return(new FileCallbackResult("application/zip", callback)
            {
                FileDownloadName = fileName
            });
        }
Ejemplo n.º 9
0
        public bool BeginGetFileDetails(string path, FileCallback callback)
        {
            path = PathUtil.CleanPath(path);

            var file = GetFile(path);

            if (file != null)
            {
                callback(file);
                return(true);
            }

            // If file is local and wasn't found, throw error.
            var parts = path.Split('/');

            if (parts.Length > 1 && parts[1] == "local")
            {
                throw new Exception("File does not exist");
            }

            // If remote file, request it!

            lock (remoteFileCallbacks) {
                if (!remoteFileCallbacks.ContainsKey(path))
                {
                    remoteFileCallbacks.Add(path, new List <FileCallback>());
                }
                var list = remoteFileCallbacks[path];
                list.Add(callback);
            }

            var network = PathUtil.GetNetwork(core, path);

            network.RequestFileDetails(path);
            return(false);
        }
Ejemplo n.º 10
0
 public void File(FileCallback successCallback, FileErrorCallback errorCallback)
 {
 }
Ejemplo n.º 11
0
        private async Task <IActionResult> DeliverAssetAsync(IAssetEntity?asset, AssetContentQueryDto query)
        {
            query ??= new AssetContentQueryDto();

            if (asset == null)
            {
                return(NotFound());
            }

            if (asset.IsProtected && !Resources.CanReadEvents)
            {
                return(StatusCode(403));
            }

            if (query.Version > EtagVersion.Any && asset.Version != query.Version)
            {
                asset = await assetLoader.GetAsync(asset.Id, query.Version);
            }

            var resizeOptions = query.ToResizeOptions(asset);

            FileCallback callback;

            Response.Headers[HeaderNames.ETag] = asset.FileVersion.ToString();

            if (query.CacheDuration > 0)
            {
                Response.Headers[HeaderNames.CacheControl] = $"public,max-age={query.CacheDuration}";
            }

            var contentLength = (long?)null;

            if (asset.Type == AssetType.Image && resizeOptions.IsValid)
            {
                callback = new FileCallback(async(bodyStream, range, ct) =>
                {
                    var resizedAsset = $"{asset.Id}_{asset.FileVersion}_{resizeOptions}";

                    if (query.ForceResize)
                    {
                        await ResizeAsync(asset, bodyStream, resizedAsset, resizeOptions, true, ct);
                    }
                    else
                    {
                        try
                        {
                            await assetStore.DownloadAsync(resizedAsset, bodyStream);
                        }
                        catch (AssetNotFoundException)
                        {
                            await ResizeAsync(asset, bodyStream, resizedAsset, resizeOptions, false, ct);
                        }
                    }
                });
            }
            else
            {
                contentLength = asset.FileSize;

                callback = new FileCallback(async(bodyStream, range, ct) =>
                {
                    await assetFileStore.DownloadAsync(asset.Id, asset.FileVersion, bodyStream, range, ct);
                });
            }

            return(new FileCallbackResult(asset.MimeType, callback)
            {
                EnableRangeProcessing = contentLength > 0,
                ErrorAs404 = true,
                FileDownloadName = asset.FileName,
                FileSize = contentLength,
                LastModified = asset.LastModified.ToDateTimeOffset(),
                SendInline = query.Download != 1
            });
        }
Ejemplo n.º 12
0
	public  void file(FileCallback successCallback, ErrorCallback errorCallback) {}
Ejemplo n.º 13
0
 public void BrowseForFile(DirectoryInfo starting_directory, FileCallback fileCallback)
 {
     Initialize(starting_directory, ValidateEverything, fileCallback, null);
     SetErrorText("Could Not Open File");
 }
Ejemplo n.º 14
0
	public  void file(FileCallback successCallback) {}
Ejemplo n.º 15
0
    // Upload File to Firebase Storage
    public IEnumerator UploadToFirebaseStorage(byte[] data, string fileName, string folder, FileCallback Callback)
    {
        StorageReference images = storage_ref.Child(folder);

#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2 || UNITY_5_3 || UNITY_5_4
        var task = reference.PutBytesAsync(Encoding.UTF8.GetBytes(data), null, null,
                                           default(System.Threading.CancellationToken), null);
#else
        var task = images.Child(fileName).PutBytesAsync(data);
#endif
        yield return(new WaitUntil(() => task.IsCompleted));

        if (task.IsFaulted)
        {
            Callback(null, "Error Uploading Enemy Image");
            DebugLog(task.Exception.ToString());
            throw task.Exception;
        }
        else
        {
            Callback(task.Result.DownloadUrl.ToString(), "Enemy Image Uploaded Succesfully");
            DebugLog("Finished uploading... Download Url: " + task.Result.DownloadUrl.ToString());
        }
    }
Ejemplo n.º 16
0
 public void File(FileCallback successCallback)
 {
 }
Ejemplo n.º 17
0
 public void File(FileCallback successCallback, FileErrorCallback errorCallback) { }
 public TorrentParser(string path, FileCallback readNotify)
 {
     _rCallback = readNotify;
     Process(path);
 }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            if (args.Length < 2 || args.Length > 3)
            {
                WaitAndClose("Improper usage. Expected:" +
                             "\nSpawnableItemFetcher.exe <asset_path> <output_file>" +
                             "\n<asset_path>: Absolute path to unpacked assets." +
                             "\n<output_file>: Absolute path to file to write results to." +
                             "\nOutput file should be /yourMod/sipCustomItems.json.patch");
            }

            basePath = args[0];
            string outputFile = args[1];

            if (args.Length > 2)
            {
                resultType = ResultType.Normal;
            }

            if (basePath.LastIndexOf("\\") == basePath.Length - 1)
            {
                basePath = basePath.Substring(0, basePath.Length - 1);
            }

            // Confirm asset path
            if (!Directory.Exists(basePath))
            {
                WaitAndClose("Asset directory '" + basePath + "' not found. Invalid directory given.");
            }

            // Confirm overwriting
            if (File.Exists(outputFile))
            {
                Console.WriteLine("Output file '" + outputFile + "' already exists!\n1. Overwrite file\n2. Cancel");

                ConsoleKeyInfo cki = Console.ReadKey(true);
                switch (cki.Key)
                {
                default:
                    WaitAndClose("Cancelling task.");
                    break;

                case ConsoleKey.D1:
                case ConsoleKey.NumPad1:
                    Console.WriteLine("Output file will be overwritten.");
                    break;
                }
            }

            result = new JArray();
            FileCallback fc = new FileCallback(AddItem);

            // Scan all folders and subfolders. Adds all found items to result.
            ScanDirectories(basePath, extensions, fc);

            // Write results to selected file.
            Newtonsoft.Json.Formatting format = resultType == ResultType.Patch ? Newtonsoft.Json.Formatting.Indented : Newtonsoft.Json.Formatting.None;
            File.WriteAllText(outputFile, result.ToString(format));

            Console.WriteLine("Done fetching items!\nPress any key to exit...");
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            WriteColoredLine(ConsoleColor.White, "= Spawnable Item Fetcher");

            if (args.Length == 0)
            {
                args = PromptArgs();
            }

            if (args.Length != 2)
            {
                WaitAndClose("Improper usage. Expected:" +
                             "\nSpawnableItemFetcher.exe <asset_path> <output_file>" +
                             "\n<asset_path>: Absolute path to unpacked assets." +
                             "\n<output_file>: Absolute path to file to write results to.");
            }

            basePath = args[0];
            string outputFile = args[1];

            if (basePath.LastIndexOf("\\") == basePath.Length - 1)
            {
                basePath = basePath.Substring(0, basePath.Length - 1);
            }

            // Show paths
            Console.Write("Asset Path:  ");
            WriteColoredLine(ConsoleColor.Cyan, basePath);
            Console.Write("Output File: ");
            WriteColoredLine(ConsoleColor.Cyan, outputFile);
            Console.WriteLine();

            // Confirm asset path
            if (!Directory.Exists(basePath))
            {
                WaitAndClose("Asset directory '" + basePath + "' not found.");
            }

            // Confirm overwriting
            if (File.Exists(outputFile))
            {
                Console.WriteLine("Overwrite existing output file?");
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("[1] Overwrite file. [2] Cancel.");
                Console.ResetColor();

                ConsoleKeyInfo cki = Console.ReadKey(true);
                switch (cki.Key)
                {
                default:
                    WaitAndClose("Cancelled.");
                    break;

                case ConsoleKey.D1:
                case ConsoleKey.NumPad1:
                    Console.WriteLine("The file will be overwritten.");
                    break;
                }
                Console.WriteLine();
            }

            // Get result type.
            resultType = PromptResultType();

            if (resultType == ResultType.Patch && !outputFile.EndsWith(".patch"))
            {
                Console.WriteLine("You're trying to make a patch file, but the output file does not end with '.patch'!");
            }
            Console.WriteLine();

            // Start scan
            Console.WriteLine("Starting to scan assets. This can take a while...");

            result = new JArray();
            FileCallback fc = new FileCallback(AddItem);

            // Scan all folders and subfolders. Adds all found items to result.
            ScanDirectories(basePath, extensions, fc);

            // Write results to selected file.
            Newtonsoft.Json.Formatting format = Newtonsoft.Json.Formatting.None;

            Directory.CreateDirectory(Path.GetDirectoryName(outputFile));
            File.WriteAllText(outputFile, result.ToString(format));

            WaitAndClose("Done fetching items!");
        }
Ejemplo n.º 21
0
 public TorrentParser(string TPath, FileCallback ReadNotify)
 {
     _rCallback = ReadNotify;
     Process(TPath);
 }
Ejemplo n.º 22
0
 public void BrowseForImage(DirectoryInfo starting_directory, FileCallback fileCallback)
 {
     Initialize(starting_directory, ValidateImage, fileCallback, null);
     SetErrorText("Invalid Image File");
 }
Ejemplo n.º 23
0
 public void file(FileCallback successCallback, ErrorCallback errorCallback)
 {
 }