public async Task Upload() { try { this.CancelTokenSource = new CancellationTokenSource(); this.SelectedApp.PrepareUpload(); AppInfo appInfo = this.SelectedApp.AppInfo; UploadStrategy uploadStrategy = UploadStrategy.GetStrategy(appInfo); await uploadStrategy.Upload(this.SelectedApp.FileToUpload, this._activeUserConfiguration, ReportProgress, _cancelTokenSource.Token); string publicWebSite = this._activeUserConfiguration.ApiBase; publicWebSite = publicWebSite.Substring(0, publicWebSite.Length - 6); System.Diagnostics.Process.Start(publicWebSite + "apps/" + appInfo.PublicID); this.Close(); } catch (TaskCanceledException) { //do nothing } catch (Exception ex) { IWindowManager wm = IoC.Get <IWindowManager>(); wm.ShowMetroMessageBox("Error while creating a new version:\n" + ex.Message); } finally { this.CancelTokenSource = null; } }
public void RepopulateQueue() { if (App.CustomConfigurationSettings.UploadStrategy != _uploadStrategy) { _hotsApiProcessingQueue.Clear(); _hotsweekProcessingQueue.Clear(); if (App.CustomConfigurationSettings.UploadStrategy == UploadStrategy.UploadAll) { Files.Where(x => x.NeedHotsApiUpdate()).Reverse().Map(x => _hotsApiProcessingQueue[x] = ProcessingStatus.None); Files.Where(x => x.NeedHotsweekUpdate()).Reverse().Map(x => _hotsweekProcessingQueue[x] = ProcessingStatus.None); } } else { if (_uploadToHotsApi != UploadToHotsApi) { _hotsApiProcessingQueue.Clear(); Files.Where(x => x.NeedHotsApiUpdate()).Reverse().Map(x => _hotsApiProcessingQueue[x] = ProcessingStatus.None); } if (_uploadToHotsweek != UploadToHotsweek) { _hotsweekProcessingQueue.Clear(); Files.Where(x => x.NeedHotsweekUpdate()).Reverse().Map(x => _hotsweekProcessingQueue[x] = ProcessingStatus.None); } } _uploadStrategy = App.CustomConfigurationSettings.UploadStrategy; _uploadToHotsApi = UploadToHotsApi; _uploadToHotsweek = UploadToHotsweek; OnStatusChanged(); }
/// <summary> /// 文件上传 /// </summary> /// <param name="parentId">上传至的文件夹id</param> /// <param name="name">文件名称,文件名称必须是1到222个字符,并且不能含有/ ? : * \" > \</param> /// <param name="uploadFilePath">待上传的文件本地路径</param> /// <param name="strategy">文件名冲突时的处理策略</param> /// <returns>通用文件对象</returns> public YfyFile Upload(long parentId, string name, string uploadFilePath, UploadStrategy strategy = UploadStrategy.Rename) { var stream = File.OpenRead(uploadFilePath); var file = this.Upload(parentId, name, stream, strategy); stream.Close(); return(file); }
public UploadFileArg(long parentId, string name, UploadStrategy strategy = UploadStrategy.Rename, UploadType uploadType = UploadType.api) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("name should not be null or empty", nameof(name)); } this.ParentId = parentId; this.UploadType = uploadType; this.Name = name; this.IsCovered = strategy == UploadStrategy.Overwrite; }
/// <summary> /// Start uploading and watching for new replays /// </summary> public void Start() { if (_initialized) { return; } _initialized = true; _bpHelperUploader = new BpHelperUploader(_restApi); _hotsApiUploader = new HotsApiUploader(); _analyzer = new Analyzer(); _monitor = new Monitor(); var replays = ScanReplays(); Files.AddRange(replays.OrderByDescending(l => l.Created)); if (replays.Any()) { Monitor.LatestReplayTime = replays.Max(l => l.Created); } _uploadStrategy = App.CustomConfigurationSettings.UploadStrategy; _uploadToHotsApi = UploadToHotsApi; _uploadToHotsweek = UploadToHotsweek; if (App.CustomConfigurationSettings.UploadStrategy == UploadStrategy.UploadAll) { replays.Where(x => x.NeedHotsApiUpdate()).Reverse().Map(x => _hotsApiProcessingQueue[x] = ProcessingStatus.None); replays.Where(x => x.NeedHotsweekUpdate()).Reverse().Map(x => _hotsweekProcessingQueue[x] = ProcessingStatus.None); } _monitor.ReplayAdded += async(_, e) => { await EnsureFileAvailable(e.Data, 3000); var replay = new ReplayFile(e.Data); Files.Insert(0, replay); _hotsApiProcessingQueue[replay] = ProcessingStatus.None; _hotsweekProcessingQueue[replay] = ProcessingStatus.None; OnReplayFileStatusChanged(new EventArgs <ReplayFile>(replay)); OnStatusChanged(); }; _monitor.Start(); _analyzer.MinimumBuild = Const.ReplayMinimumBuild; Task.Run(UploadHotsApiLoop).Forget(); Task.Run(UploadHotsweekLoop).Forget(); }
/// <summary> /// 获取新文件上传地址 /// </summary> /// <param name="parentId">上传至的文件夹id</param> /// <param name="name">文件名称,文件名称必须是1到222个字符,并且不能含有/ ? : * \" > \ </param> /// <param name="strategy">文件名冲突时的处理策略</param> /// <returns>上传链接,接下来往该链接上传即可上传文件,上传链接的有效时间为1个小时,且只能被使用一次</returns> public string GetUploadUrl(long parentId, string name, UploadStrategy strategy = UploadStrategy.Rename) { var requestArg = new UploadFileArg(parentId, name, strategy); return(this._transport.SendRpcRequest <UploadFileArg, PreSignatureUploadUrl>(requestArg, UriHelper.UploadNewFileUri()).PresignUrl); }
/// <summary> /// 文件上传 /// </summary> /// <param name="parentId">上传至的文件夹id</param> /// <param name="name">文件名称,文件名称必须是1到222个字符,并且不能含有/ ? : * \" > \</param> /// <param name="stream">待上传的文件流</param> /// <param name="strategy">文件名冲突时的处理策略</param> /// <returns>通用文件对象</returns> public YfyFile Upload(long parentId, string name, Stream stream, UploadStrategy strategy = UploadStrategy.Rename) { var uploadUrl = GetUploadUrl(parentId, name, strategy); return(this._transport.SendUploadRequest <string, YfyFile>(name, new Uri(uploadUrl), stream)); }
static void Main(string[] args) { new CrashHandler(); string exeFile = System.Reflection.Assembly.GetEntryAssembly().Location; string exePath = Path.GetDirectoryName(exeFile); var tmp = System.Configuration.ConfigurationManager.OpenExeConfiguration(exePath + @"\HockeyUpload.exe"); System.Configuration.KeyValueConfigurationCollection col = tmp.AppSettings.Settings; HockeyApp.AppLoader.Model.Configuration c = HockeyApp.AppLoader.Model.Configuration.Instance; if (Environment.CommandLine.ToUpper().Contains("/HELP")) { HockeyApp.AppLoader.Model.CommandLineArgs.WriteHelp(Console.Out, "HOCH"); } else if (Environment.GetCommandLineArgs().Count() > 1) { try { _args = Args.Configuration.Configure <HockeyApp.AppLoader.Model.CommandLineArgs>().CreateAndBind(Environment.GetCommandLineArgs()); } catch { HockeyApp.AppLoader.Model.CommandLineArgs.WriteHelp(Console.Out, "HOCH"); return; } string errMsg = ""; if (!_args.IsValid(out errMsg)) { LogToConsole("Wrong parameter: " + errMsg); return; } try { AppInfoMatcher matcher = new AppInfoMatcher(); Task <List <AppInfo> > t = matcher.GetMatchingApps(_args); t.Wait(); List <AppInfo> list = t.Result; if (list.Count == 0) { LogToConsole("No matching application found. Please check the configuration information!"); return; } else if (list.Count > 1) { LogToConsole("More than one apps are matching. Please change parameter!"); LogToConsole("Matching apps: " + list.Select(p => p.Title).Aggregate((a, b) => a + "," + b)); return; } UploadStrategy uploader = UploadStrategy.GetStrategy(list.First()); LogToConsole(""); DateTime start = DateTime.Now; Task task = uploader.Upload(_args.Package, matcher.ActiveUserConfiguration, ProgressHandler, CancellationToken.None); task.Wait(); DateTime end = DateTime.Now; TimeSpan sp = end.Subtract(start); FileInfo fi = new FileInfo(_args.Package); long length = fi.Length; length = length / 8; LogToConsole(""); LogToConsole(string.Format("Uploaded {0}KB in {1}sec", length.ToString("###,###,###"), sp.Seconds.ToString("d"))); } catch (Exception ex) { LogToConsole("Error: " + ex.Message); } } else { HockeyApp.AppLoader.Model.CommandLineArgs.WriteHelp(Console.Out, "HOCH"); } }