示例#1
0
 public static void Save(bool SaveAll)
 {
     if (MainWindow.GetSettings().UseDatabase)
     {
         MainWindow.MainForm.GetDatabaseManager().Save(SaveAll);
     }
     else
     {
         // запускаем сохранение в отдельном потоке
         Task.Factory.StartNew(() =>
         {
             if (SaveAll)
             {
                 foreach (Author author in Authors)
                 {
                     author.Changed = false;
                 }
                 Authors.Save(AuthorsFileName);
                 Categories.Save(CategoriesFileName);
             }
             else // запишем только, если есть авторы с изменившимися данными
             {
                 if (Authors.Any(a => a.Changed))
                 {
                     foreach (Author author in Authors)
                     {
                         author.Changed = false;
                     }
                     Authors.Save(AuthorsFileName);
                 }
                 Categories.Save(CategoriesFileName);
             }
         });
     }
 }
示例#2
0
        public IEnumerable <string> Validate()
        {
            if (String.IsNullOrEmpty(Id))
            {
                yield return(String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_RequiredMetadataMissing, "Id"));
            }
            else
            {
                if (Id.Length > PackageIdValidator.MaxPackageIdLength)
                {
                    yield return(String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_IdMaxLengthExceeded));
                }
                else if (!PackageIdValidator.IsValidPackageId(Id))
                {
                    yield return(String.Format(CultureInfo.CurrentCulture, NuGetResources.InvalidPackageId, Id));
                }
            }

            if (Version == null)
            {
                yield return(String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_RequiredMetadataMissing, "Version"));
            }

            if ((Authors == null || !Authors.Any(author => !String.IsNullOrEmpty(author))) && !PackageTypes.Contains(PackageType.SymbolsPackage))
            {
                yield return(String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_RequiredMetadataMissing, "Authors"));
            }

            if (String.IsNullOrEmpty(Description))
            {
                yield return(String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_RequiredMetadataMissing, "Description"));
            }

            if (_licenseUrl == String.Empty)
            {
                yield return(String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_UriCannotBeEmpty, "LicenseUrl"));
            }

            if (_iconUrl == String.Empty)
            {
                yield return(String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_UriCannotBeEmpty, "IconUrl"));
            }

            if (_projectUrl == String.Empty)
            {
                yield return(String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_UriCannotBeEmpty, "ProjectUrl"));
            }

            if (RequireLicenseAcceptance && (string.IsNullOrWhiteSpace(_licenseUrl) && LicenseMetadata == null))
            {
                yield return(NuGetResources.Manifest_RequireLicenseAcceptanceRequiresLicenseUrl);
            }

            if (_licenseUrl != null && LicenseMetadata != null && (string.IsNullOrWhiteSpace(_licenseUrl) || !LicenseUrl.Equals(LicenseMetadata.LicenseUrl)))
            {
                yield return(NuGetResources.Manifest_LicenseUrlCannotBeUsedWithLicenseMetadata);
            }
        }
示例#3
0
 IEnumerable <ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
 {
     if (!CheckISBN())
     {
         yield return(new ValidationResult(
                          "Задан не корректный ISBN",
                          new[] { nameof(ISBN) }));
     }
     if (Authors == null || !Authors.Any())
     {
         yield return(new ValidationResult(
                          "У книги должен быть как минимум один автор",
                          new[] { nameof(Authors) }));
     }
 }
示例#4
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.AppendLine(new string('-', 20));
            sb.AppendLine($"Name: {Name}");

            if (Version != null)
            {
                sb.AppendLine($"Version: {Version}");
            }

            if (!string.IsNullOrWhiteSpace(Description))
            {
                sb.AppendLine($"Description: {Description}");
            }

            if (Authors != null && Authors.Any())
            {
                sb.AppendLine("Authors:");
                foreach (var i in Authors)
                {
                    sb.AppendLine($" - {i}");
                }
            }

            if (Date != null)
            {
                sb.AppendLine($"Date: {DateTime:F}");
            }

            if (Includes.Any())
            {
                sb.AppendLine("Includes:");
                foreach (var i in Includes)
                {
                    sb.AppendLine($" - '{i.Path}' => '{i.Mount}'");
                }
            }

            if (!string.IsNullOrWhiteSpace(Main))
            {
                sb.AppendLine($"Main: {Main}");
            }

            sb.AppendLine(new string('-', 20));
            return(sb.ToString());
        }
        private void AddNewEntity(object sender)
        {
            using (var context = new BookOrdersContext()) {
                using (DbContextTransaction transaction =
                           context.Database.BeginTransaction(IsolationLevel.RepeatableRead)) {
                    try {
                        if (!Publishers.Any(NewPublisher.Equals))
                        {
                            context.Publishers.Add(NewPublisher);
                        }

                        NewBook.PublisherId = NewPublisher.Id;
                        if (!Books.Any(NewBook.Equals))
                        {
                            context.Books.Add(NewBook);
                        }

                        if (!Authors.Any(NewAuthor.Equals))
                        {
                            NewAuthor.Id = 0;
                            context.Authors.Add(NewAuthor);
                        }

                        NewBookAndAuthor.AuthorId = NewAuthor.Id;
                        NewBookAndAuthor.ISBN     = NewBook.ISBN;
                        context.BooksAndAuthors.Add(NewBookAndAuthor);
                        context.SaveChanges();
                        transaction.Commit();
                    } catch (Exception e) {
                        Exception innerException = e;
                        while (innerException?.InnerException != null)
                        {
                            innerException = innerException.InnerException;
                        }

                        transaction.Rollback();
                        MessageBox.Show(innerException?.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    AddedNewEntity?.Invoke();
                }
            }
        }
        public bool RetrieveSpawnsetList()
        {
            try
            {
                Spawnsets.Clear();
                Authors.Clear();

                string downloadString = string.Empty;
                using (TimeoutWebClient client = new TimeoutWebClient(Timeout))
                    downloadString = client.DownloadString(UrlUtils.ApiGetSpawnsets);
                List <SpawnsetFile> spawnsetFiles = JsonConvert.DeserializeObject <List <SpawnsetFile> >(downloadString);

                Authors.Add(new AuthorListEntry(SpawnsetListHandler.AllAuthors, spawnsetFiles.Count));
                foreach (SpawnsetFile sf in spawnsetFiles)
                {
                    AuthorListEntry author = new AuthorListEntry(sf.Author, spawnsetFiles.Where(s => s.Author == sf.Author).Count());
                    if (!Authors.Any(a => a.Name == author.Name))
                    {
                        Authors.Add(author);
                    }
                }

                foreach (SpawnsetFile spawnsetFile in spawnsetFiles)
                {
                    Spawnsets.Add(new SpawnsetListEntry {
                        SpawnsetFile = spawnsetFile
                    });
                }

                return(true);
            }
            catch (WebException ex)
            {
                App.Instance.ShowError("Error retrieving spawnset list", $"Could not connect to '{UrlUtils.ApiGetSpawnsets}'.", ex);
                return(false);
            }
            catch (Exception ex)
            {
                App.Instance.ShowError("Unexpected error", "An unexpected error occurred.", ex);
                return(false);
            }
        }
示例#7
0
 public void Initialize()
 {
     if (!Categories.Any())
     {
         Categories.Add(new Category {
             Name = "Root"
         });
     }
     SaveChanges();
     if (!Authors.Any())
     {
         Authors.Add(new Author {
             Name = "Administrator"
         });
     }
     SaveChanges();
     if (!Problems.Any())
     {
         Problems.Add(new Problem {
             Name = "abc", Content = "cde", CategoryId = 1, AuthorId = 1
         });
     }
     SaveChanges();
 }
示例#8
0
        public Dictionary <string, Tuple <string, string> > Diff(CalibreBook other)
        {
            var output = new Dictionary <string, Tuple <string, string> >();

            if (Title != other.Title)
            {
                output.Add("Title", Tuple.Create(Title, other.Title));
            }

            if (!Authors.SequenceEqual(other.Authors))
            {
                var oldValue = Authors.Any() ? string.Join(" / ", Authors) : null;
                var newValue = other.Authors.Any() ? string.Join(" / ", other.Authors) : null;

                output.Add("Author", Tuple.Create(oldValue, newValue));
            }

            var oldDate = PubDate.HasValue ? PubDate.Value.ToString("MMM-yyyy") : null;
            var newDate = other.PubDate.HasValue ? other.PubDate.Value.ToString("MMM-yyyy") : null;

            if (oldDate != newDate)
            {
                output.Add("PubDate", Tuple.Create(oldDate, newDate));
            }

            if (Publisher != other.Publisher)
            {
                output.Add("Publisher", Tuple.Create(Publisher, other.Publisher));
            }

            if (!Languages.OrderBy(x => x).SequenceEqual(other.Languages.OrderBy(x => x)))
            {
                output.Add("Languages", Tuple.Create(string.Join(" / ", Languages), string.Join(" / ", other.Languages)));
            }

            if (Comments != other.Comments)
            {
                output.Add("Comments", Tuple.Create(Comments, other.Comments));
            }

            if (Rating != other.Rating)
            {
                output.Add("Rating", Tuple.Create(Rating.ToString(), other.Rating.ToString()));
            }

            if (!Identifiers.Where(x => x.Value != null).OrderBy(x => x.Key).SequenceEqual(
                    other.Identifiers.Where(x => x.Value != null).OrderBy(x => x.Key)))
            {
                output.Add("Identifiers", Tuple.Create(
                               string.Join(" / ", Identifiers.Where(x => x.Value != null).OrderBy(x => x.Key)),
                               string.Join(" / ", other.Identifiers.Where(x => x.Value != null).OrderBy(x => x.Key))));
            }

            if (Series != other.Series)
            {
                output.Add("Series", Tuple.Create(Series, other.Series));
            }

            if (Position != other.Position)
            {
                output.Add("Series Index", Tuple.Create(Position.ToString(), other.Position.ToString()));
            }

            return(output);
        }