private static void CanOpenAppFile(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e) { Windows.DependencyObject d = sender as Windows.DependencyObject; AppFileManager manager = (d == null ? null : d.GetValue(Windows.FrameworkElement.DataContextProperty) as AppFileManager); AppFileInfo file = e.Parameter as AppFileInfo; e.CanExecute = file != null && manager != null && manager.IsUploading == false; }
private void OnDeleteAppFile(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { AppFileInfo file = e.Parameter as AppFileInfo; DialogResult result = MessageBox.Show(string.Format("确认从版本{0}中移除文件{1}吗?", file.Version, file.OriginName), "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == Windows.Forms.DialogResult.OK) { file.Delete(); } }
private static void OnOpenAppFile(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { AppFileInfo file = e.Parameter as AppFileInfo; OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = "选择文件"; dialog.Filter = "(所有文件)|*.*"; dialog.Multiselect = false; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { file.FileName = dialog.FileName; } }
private void OnRemoveAppFile(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { AppFileInfo file = e.Parameter as AppFileInfo; Windows.DependencyObject d = sender as Windows.DependencyObject; AppFileManager manager = null; while (d != null && manager == null) { manager = (d == null ? null : d.GetValue(Windows.FrameworkElement.DataContextProperty) as AppFileManager); d = System.Windows.Media.VisualTreeHelper.GetParent(d); } if (manager != null) { manager.Items.Remove(file); } }
private void OnAddAppFile(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = "选择文件"; dialog.Filter = "(所有文件)|*.*"; dialog.Multiselect = true; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { Windows.DependencyObject d = sender as Windows.DependencyObject; AppFileManager manager = (d == null ? null : d.GetValue(Windows.FrameworkElement.DataContextProperty) as AppFileManager); try { foreach (string name in dialog.FileNames) { AppFileInfo fileInfo = new AppFileInfo() { Version = FileHelper.GetCurrentVersion(), FileName = name, Status = FileStatus.New, Enterprise = manager.SelectedEnterprise }; int index = manager.Items.IndexOf(fileInfo); if (index > -1) { AppFileInfo current = manager.Items[index] as AppFileInfo; current.FileName = name; continue; } manager.Items.Add(fileInfo); } } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public AppCommandProcessor(IMongoCollection <AppData> apps, GridFSBucket files, RepositoryApi repository, DataTransferManager dataTransfer, IMongoCollection <ToDeleteRevision> toDelete, WorkDistributor <BuildRequest, BuildCompled> workDistributor, IActorRef changeTracker) { _apps = apps; CommandPhase1 <CreateAppCommand>("CreateApp", repository, (command, reporter) => { reporter.Send(DeploymentMessages.RegisterRepository); return(new RegisterRepository(command.TargetRepo) { IgnoreDuplicate = true }); }, (command, reporter, op) => new ContinueCreateApp(op, command, reporter)); CommandPhase2 <ContinueCreateApp, CreateAppCommand, AppInfo>("CreateApp2", (command, result, reporter, data) => { if (!result.Ok) { if (reporter.IsCompled) { return(null); } reporter.Compled(OperationResult.Failure(result.Error ?? BuildErrorCodes.CommandErrorRegisterRepository)); return(null); } if (data != null) { reporter.Compled(OperationResult.Failure(BuildErrorCodes.CommandDuplicateApp)); return(null); } var newData = new AppData(command.AppName, -1, DateTime.UtcNow, DateTime.MinValue, command.TargetRepo, command.ProjectName, ImmutableList <AppFileInfo> .Empty); apps.InsertOne(newData); var info = newData.ToInfo(); changeTracker.Tell(info); return(info); }); CommandPhase1 <PushVersionCommand>("PushVersion", (command, reporter) => { var data = apps.AsQueryable().FirstOrDefault(ad => ad.Name == command.AppName); if (data == null) { reporter.Compled(OperationResult.Failure(BuildErrorCodes.CommandAppNotFound)); } else { BuildRequest.SendWork(workDistributor, reporter, data, repository, BuildEnv.TempFiles.CreateFile()) .PipeTo(Self, success: c => new ContinuePushNewVersion(OperationResult.Success(c), command, reporter), failure: e => new ContinuePushNewVersion(OperationResult.Failure(e.Unwrap()?.Message ?? "Cancel"), command, reporter)); } }); CommandPhase2 <ContinuePushNewVersion, PushVersionCommand, AppBinary>("PushVersion2", (command, result, reporter, data) => { if (data == null) { if (!reporter.IsCompled) { reporter.Compled(OperationResult.Failure(BuildErrorCodes.CommandAppNotFound)); } return(null); } if (!result.Ok) { return(null); } using var transaction = apps.Database.Client.StartSession(new ClientSessionOptions { DefaultTransactionOptions = new TransactionOptions(writeConcern: WriteConcern.Acknowledged) }); var dataFilter = Builders <AppData> .Filter.Eq(ad => ad.Name, data.Name); var(commit, fileName) = ((string, ITempFile))result.Outcome !; using var targetStream = fileName; var newId = files.UploadFromStream(data.Name + ".zip", targetStream.Stream); var newBinary = new AppFileInfo(newId, data.Last + 1, DateTime.UtcNow, false, commit); var newBinarys = data.Versions.Add(newBinary); var definition = Builders <AppData> .Update; var updates = new List <UpdateDefinition <AppData> > { definition.Set(ad => ad.Last, newBinary.Version), definition.Set(ad => ad.Versions, newBinarys) }; var deleteUpdates = new List <ToDeleteRevision>(); if (data.Versions.Count(s => !s.Deleted) > 5) { foreach (var info in newBinarys.OrderByDescending(i => i.CreationTime).Skip(5)) { if (info.Deleted) { continue; } info.Deleted = true; deleteUpdates.Add(new ToDeleteRevision(info.File.ToString())); } } transaction.StartTransaction(); if (deleteUpdates.Count != 0) { toDelete.InsertMany(transaction, deleteUpdates); } if (!apps.UpdateOne(transaction, dataFilter, definition.Combine(updates)).IsAcknowledged) { transaction.AbortTransaction(); reporter.Compled(OperationResult.Failure(BuildErrorCodes.DatabaseError)); return(null); } transaction.CommitTransaction(); changeTracker.Tell(_apps.AsQueryable().FirstOrDefault(ad => ad.Name == command.AppName)); return(new AppBinary(command.AppName, newBinary.Version, newBinary.CreationTime, false, newBinary.Commit, data.Repository)); });
private void CanDeleteAppFiel(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e) { AppFileInfo file = e.Parameter as AppFileInfo; e.CanExecute = file != null && (file.Status == FileStatus.Uploaded || file.Status == FileStatus.Update); }
static IObservable <AppBinary?> UpdateAppData(ContinueData <PushVersionCommand> m) { var(commit, fileName) = ((string, ITempFile))m.Result.Outcome !; return(Observable.Using(() => fileName, file => ( from info in Observable.Return((Commit: commit, File: file, Data: m)) let oldApp = info.Data.AppData ?? AppData.Empty let newVersion = oldApp.Last + 1 let newId = $"{oldApp.Id}-{newVersion}.zip" let newBinary = new AppFileInfo(newId, oldApp.Last + 1, DateTime.UtcNow, false, info.Commit) let newData = oldApp with { Last = newVersion, LastUpdate = DateTime.UtcNow, Versions = info.Data.AppData !.Versions.Add(newBinary) } select(info.Data.State, NewData: newData, NewBinary: newBinary, info.File, ToDelete: newData.Versions.OrderByDescending(i => i.CreationTime).Skip(5) .Where(i => !i.Deleted).ToArray()) ) .Select(i => { using var stream = i.State.Files.GetFile(i.NewBinary.Id).Create(); using var fileStream = i.File.Stream; fileStream.Seek(0, SeekOrigin.Begin); fileStream.CopyTo(stream); var newData = i.ToDelete .Aggregate(i.NewData, (current, appFileInfo) => current !with { Versions = current.Versions .Replace(appFileInfo, appFileInfo with { Deleted = true }) }); i.State.Apps.Update(newData !); i.State.ToDelete.Add(i.ToDelete.Select(e => new ToDeleteRevision(e.Id))); return (Data: newData, i.NewBinary, i.State); })
public string GetFilePath(AppFileInfo f) { string s = Path.Combine(DirectoryPath, MaxRev.S); return(Path.Combine(s, f.FilePath.TrimStart('.').TrimStart(Splitter))); }