Пример #1
0
        public ViewModelFiles(IPreferenceService preferenceService,
                              IFileService fileService,
                              IRunNuget runNuget)
        {
            PreferenceService  = preferenceService;
            FileService        = fileService;
            _runNuget          = runNuget;
            BsFiles.DataSource = new List <IFile>();
            PropertyChanged   += async(s, e) => {
                Console.WriteLine(e.PropertyName);
                switch (e.PropertyName)
                {
                case nameof(TextSearch):
                case nameof(CheckCsProj):
                case nameof(CheckVbProj):
                case nameof(CheckNupkg):
                case nameof(CheckSln):
                case nameof(CheckNuspec):
                case nameof(CheckSnupkg):
                    await UpdateFilesData();

                    break;

                case nameof(OptionPack):
                case nameof(OptionRestore):
                case nameof(OptionList):
                    break;

                case nameof(OptionDelete):
                case nameof(OptionAddNupkg):
                    CheckProductionSource = true;
                    break;
                }
            };
            _runNuget.GetCmdStandardOutput += async(s, e) => {
                try {
                    if (e.Contains("Successfully created package"))
                    {
                        var pathLine = e.Split("'".ToArray(), StringSplitOptions.RemoveEmptyEntries).LastOrDefault(x => x.Contains(":\\") && x.Contains(".nupkg"));
                        if (pathLine != null && File.Exists(pathLine))
                        {
                            var createFileInfo = new FileInfo(pathLine);
                            if (CheckDevSource)
                            {
                                var devSourceCopy = await PreferenceService.GetSetting(Settings.NugetLocalDevNugetServer);

                                if (!string.IsNullOrWhiteSpace(devSourceCopy.ValueString))
                                {
                                    var devSourceFileInfo = new FileInfo(Path.Combine(devSourceCopy.ValueString, createFileInfo.Name));
                                    File.Copy(createFileInfo.FullName, devSourceFileInfo.FullName, true);
                                }
                            }
                            try {
                                var newNupkg = new Nupkg()
                                {
                                    Path          = pathLine,
                                    PathSha1      = pathLine.ToSha1(),
                                    ProjectID     = (SelectedFile as Project)?.ID ?? 0,
                                    PackageSha256 = createFileInfo.ToSha256(),
                                }.DetermineNugetInfo();
                                await FileService.WriteFileToStorage(newNupkg);
                            } catch (Exception ex) {
                                MessageBox.Show($"Writing new nuget package to storage failed:\r\n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                } catch (Exception ex) {
                    MessageBox.Show($"ViewModelFiles:\r\n{ex.Message}", "Error: copying to Dev Source", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            };
        }