Exemplo n.º 1
0
 public MachinesService(MarechaiContext context, IStringLocalizer <MachinesService> localizer,
                        GpusService gpusService, ProcessorsService processorsService,
                        SoundSynthsService soundSynthsService)
 {
     _context            = context;
     _l                  = localizer;
     _gpusService        = gpusService;
     _processorsService  = processorsService;
     _soundSynthsService = soundSynthsService;
 }
Exemplo n.º 2
0
 public StorageByMachineService(MarechaiContext context) => _context = context;
Exemplo n.º 3
0

        
Exemplo n.º 4
0
 public PeopleByMagazineService(MarechaiContext context) => _context = context;
Exemplo n.º 5
0
 public InstructionSetsService(MarechaiContext context) => _context = context;
Exemplo n.º 6
0
 public ResolutionsByScreenService(MarechaiContext context) => _context = context;
Exemplo n.º 7
0
 public DocumentCompaniesService(MarechaiContext context) => _context = context;
Exemplo n.º 8
0

        
Exemplo n.º 9
0
 public PeopleByBookService(MarechaiContext context) => _context = context;
Exemplo n.º 10
0
 public NewsService(MarechaiContext context, IStringLocalizer <NewsService> localizer)
 {
     _context = context;
     _l       = localizer;
 }
Exemplo n.º 11
0
 public MemoriesByMachineService(MarechaiContext context) => _context = context;
Exemplo n.º 12
0
 public CompaniesService(MarechaiContext context, IStringLocalizer <CompaniesService> localizer)
 {
     _context = context;
     _l       = localizer;
 }
Exemplo n.º 13
0
 public LicensesService(MarechaiContext context) => _context = context;
Exemplo n.º 14
0
 public DocumentRolesService(MarechaiContext context) => _context = context;
Exemplo n.º 15
0
 public ScreensByMachineService(MarechaiContext context) => _context = context;
Exemplo n.º 16
0
 public DumpsService(MarechaiContext context) => _context = context;
Exemplo n.º 17
0
 public SoftwareVersionsService(MarechaiContext context) => _context = context;
Exemplo n.º 18
0
        // Data files can be found in https://iso639-3.sil.org/code_tables/download_tables
        public static void Seed(MarechaiContext context)
        {
            if (!Directory.Exists("iso639"))
            {
                return;
            }

            IEnumerable <string> files = Directory.EnumerateFiles("iso639", "iso-639-3_*.tab");
            long modified = 0;

            List <Models.Iso639> codes = new();

            foreach (string file in files)
            {
                Console.WriteLine("Importing ISO-639 codes from {0}", file);

                using var fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None);

                using var sr = new StreamReader(fs, Encoding.UTF8);

                string line = sr.ReadLine();

                if (line is null)
                {
                    Console.WriteLine("Invalid data, not proceeding");

                    continue;
                }

                string[] pieces = line.Split('\t');

                if (pieces.Length != 8 ||
                    pieces[0] != "Id" ||
                    pieces[1] != "Part2B" ||
                    pieces[2] != "Part2T" ||
                    pieces[3] != "Part1" ||
                    pieces[4] != "Scope" ||
                    pieces[5] != "Language_Type" ||
                    pieces[6] != "Ref_Name" ||
                    pieces[7] != "Comment")
                {
                    Console.WriteLine("Invalid data, not proceeding");

                    continue;
                }

                line = sr.ReadLine();

                while (line != null)
                {
                    pieces = line.Split('\t');

                    if (pieces.Length != 8)
                    {
                        Console.WriteLine("Invalid data, continuing with next line");
                        line = sr.ReadLine();

                        continue;
                    }

                    for (int p = 1; p < 8; p++)
                    {
                        if (pieces[p] == "")
                        {
                            pieces[p] = null;
                        }
                    }

                    codes.Add(new Models.Iso639
                    {
                        Id            = pieces[0],
                        Part2B        = pieces[1],
                        Part2T        = pieces[2],
                        Part1         = pieces[3],
                        Scope         = pieces[4],
                        Type          = pieces[5],
                        ReferenceName = pieces[6],
                        Comment       = pieces[7]
                    });

                    line = sr.ReadLine();
                }
            }

            if (codes.Count == 0)
            {
                Console.WriteLine("No codes found");

                return;
            }

            List <Models.Iso639> existingCodes = context.Iso639.ToList();
            List <Models.Iso639> newCodes      = new();

            foreach (Models.Iso639 code in codes)
            {
                Models.Iso639 existingCode = existingCodes.FirstOrDefault(c => c.Id == code.Id);

                if (existingCode is null)
                {
                    newCodes.Add(code);
                }
                else
                {
                    bool changed = false;

                    if (code.Part2B != existingCode.Part2B)
                    {
                        existingCode.Part2B = code.Part2B;
                        changed             = true;
                    }

                    if (code.Part2T != existingCode.Part2T)
                    {
                        existingCode.Part2T = code.Part2T;
                        changed             = true;
                    }

                    if (code.Part1 != existingCode.Part1)
                    {
                        existingCode.Part1 = code.Part1;
                        changed            = true;
                    }

                    if (code.Scope != existingCode.Scope)
                    {
                        existingCode.Scope = code.Scope;
                        changed            = true;
                    }

                    if (code.Type != existingCode.Type)
                    {
                        existingCode.Type = code.Type;
                        changed           = true;
                    }

                    if (code.ReferenceName != existingCode.ReferenceName)
                    {
                        existingCode.ReferenceName = code.ReferenceName;
                        changed = true;
                    }

                    if (code.Comment != existingCode.Comment)
                    {
                        existingCode.Comment = code.Comment;
                        changed = true;
                    }

                    if (changed)
                    {
                        modified++;
                    }
                }
            }

            context.Iso639.AddRange(newCodes);

            Console.WriteLine("{0} language codes added", newCodes.Count);
            Console.WriteLine("{0} language codes modified", modified);
        }
Exemplo n.º 19
0

        
Exemplo n.º 20
0
 public CurrencyInflationService(MarechaiContext context) => _context = context;
Exemplo n.º 21
0
        // Lists from https://www.currency-iso.org/en/home/tables/table-a1.html
        public static void Seed(MarechaiContext context)
        {
            if (!Directory.Exists("iso4217"))
            {
                return;
            }

            var codes = new Iso4217Xml.Root();

            try
            {
                if (File.Exists(Path.Combine("iso4217", "list_one.xml")))
                {
                    using var sr = new StreamReader(Path.Combine("iso4217", "list_one.xml"));
                    var xs      = new XmlSerializer(typeof(Iso4217Xml.Root));
                    var listOne = (Iso4217Xml.Root)xs.Deserialize(sr);

                    if (listOne.Published > codes.Published)
                    {
                        codes.Published = listOne.Published;
                    }

                    codes.Current = listOne.Current;
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Exception trying to read list one.");
            }

            try
            {
                if (File.Exists(Path.Combine("iso4217", "list_three.xml")))
                {
                    using var sr = new StreamReader(Path.Combine("iso4217", "list_three.xml"));
                    var xs        = new XmlSerializer(typeof(Iso4217Xml.Root));
                    var listThree = (Iso4217Xml.Root)xs.Deserialize(sr);

                    if (listThree.Published > codes.Published)
                    {
                        codes.Published = listThree.Published;
                    }

                    codes.Historical = listThree.Historical;
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Exception trying to read list three.");
            }

            if (codes.Current is null &&
                codes.Historical is null)
            {
                Console.WriteLine("No ISO-4217 codes could be read.");

                return;
            }

            Dictionary <string, Models.Iso4217> existingCodes = context.Iso4217.ToDictionary(c => c.Code);
            Dictionary <string, Models.Iso4217> newCodes      = new();

            long modified = 0;

            codes.Current ??= new Iso4217Xml.Currency[0];
            codes.Historical ??= new Iso4217Xml.Currency[0];

            foreach (Iso4217Xml.Currency currency in codes.Historical)
            {
                bool     changed = false;
                byte     minorUnits;
                DateTime withdrawn;

                if (currency.Code is null)
                {
                    continue;
                }

                if (!existingCodes.TryGetValue(currency.Code, out Models.Iso4217 existing))
                {
                    var newCode = new Models.Iso4217
                    {
                        Code    = currency.Code,
                        Name    = currency.Name,
                        Numeric = currency.Number
                    };

                    if (byte.TryParse(currency.MinorUnits, out minorUnits))
                    {
                        newCode.MinorUnits = minorUnits;
                    }

                    if (DateTime.TryParseExact(currency.Withdrawn, "yyyy'-'MM", CultureInfo.InvariantCulture,
                                               DateTimeStyles.AssumeUniversal, out withdrawn))
                    {
                        newCode.Withdrawn = withdrawn;
                    }

                    newCodes[currency.Code]      = newCode;
                    existingCodes[currency.Code] = newCode;

                    continue;
                }

                if (existing.Code != currency.Code)
                {
                    existing.Code = currency.Code;
                    changed       = true;
                }

                if (existing.Name != currency.Name)
                {
                    existing.Name = currency.Name;
                    changed       = true;
                }

                if (byte.TryParse(currency.MinorUnits, out minorUnits) &&
                    existing.MinorUnits != minorUnits)
                {
                    existing.MinorUnits = minorUnits;
                    changed             = true;
                }

                if (DateTime.TryParseExact(currency.Withdrawn, "yyyy'-'MM", CultureInfo.InvariantCulture,
                                           DateTimeStyles.AssumeUniversal, out withdrawn) &&
                    existing.Withdrawn != withdrawn)
                {
                    existing.Withdrawn = withdrawn;
                    changed            = true;
                }

                if (changed)
                {
                    modified++;
                }
            }

            foreach (Iso4217Xml.Currency currency in codes.Current)
            {
                bool changed = false;
                byte minorUnits;

                if (currency.Code is null)
                {
                    continue;
                }

                if (!existingCodes.TryGetValue(currency.Code, out Models.Iso4217 existing))
                {
                    var newCode = new Models.Iso4217
                    {
                        Code    = currency.Code,
                        Name    = currency.Name,
                        Numeric = currency.Number
                    };

                    if (byte.TryParse(currency.MinorUnits, out minorUnits))
                    {
                        newCode.MinorUnits = minorUnits;
                    }

                    newCodes[currency.Code]      = newCode;
                    existingCodes[currency.Code] = newCode;

                    continue;
                }

                if (existing.Code != currency.Code)
                {
                    existing.Code = currency.Code;
                    changed       = true;
                }

                if (existing.Name != currency.Name)
                {
                    existing.Name = currency.Name;
                    changed       = true;
                }

                if (byte.TryParse(currency.MinorUnits, out minorUnits) &&
                    existing.MinorUnits != minorUnits)
                {
                    existing.MinorUnits = minorUnits;
                    changed             = true;
                }

                if (existing.Withdrawn != null)
                {
                    existing.Withdrawn = null;
                    changed            = true;
                }

                if (changed)
                {
                    modified++;
                }
            }

            context.Iso4217.AddRange(newCodes.Values);

            Console.WriteLine("{0} currency codes added", newCodes.Count);
            Console.WriteLine("{0} currency codes modified", modified);
        }
Exemplo n.º 22
0
 public GpusService(MarechaiContext context) => _context = context;
Exemplo n.º 23
0
 public DocumentsByMachineService(MarechaiContext context) => _context = context;
Exemplo n.º 24
0
        public static void ImportCompanyLogos(MarechaiContext context)
        {
            if (!Directory.Exists("wwwroot/assets/incoming"))
            {
                return;
            }

            foreach (string file in Directory.GetFiles("wwwroot/assets/incoming", "company_*.svg",
                                                       SearchOption.TopDirectoryOnly))
            {
                string filename = Path.GetFileNameWithoutExtension(file);

                if (!filename.StartsWith("company_", StringComparison.InvariantCulture))
                {
                    continue;
                }

                string[] pieces = filename.Split('_');

                if (pieces.Length != 3)
                {
                    continue;
                }

                var guid = Guid.NewGuid();

                if (!int.TryParse(pieces[1], out int companyId))
                {
                    continue;
                }

                if (!int.TryParse(pieces[2], out int year))
                {
                    continue;
                }

                try
                {
                    context.CompanyLogos.Add(new CompanyLogo
                    {
                        CompanyId = companyId,
                        Year      = year,
                        Guid      = guid
                    });

                    context.SaveChanges();
                }
                catch (Exception)
                {
                    continue;
                }

                SKSvg svg = null;

                foreach (int minSize in new[]
                {
                    256, 32
                })
                {
                    foreach (string format in new[]
                    {
                        "png", "webp"
                    })
                    {
                        string outDir = minSize == 32 ? Path.Combine("wwwroot/assets/logos/thumbs", format)
                                            : Path.Combine("wwwroot/assets/logos", format);

                        if (!Directory.Exists(outDir))
                        {
                            Directory.CreateDirectory(outDir);
                        }

                        SKEncodedImageFormat skFormat;

                        switch (format)
                        {
                        case "webp":
                            skFormat = SKEncodedImageFormat.Webp;

                            break;

                        default:
                            skFormat = SKEncodedImageFormat.Png;

                            break;
                        }

                        foreach (int multiplier in new[]
                        {
                            1, 2, 3
                        })
                        {
                            string outPath = Path.Combine(outDir, $"{multiplier}x");

                            if (!Directory.Exists(outPath))
                            {
                                Directory.CreateDirectory(outPath);
                            }

                            string rendered = Path.Combine(outPath, $"{guid}.{format}");

                            if (File.Exists(rendered))
                            {
                                continue;
                            }

                            Console.WriteLine("Rendering {0}", rendered);

                            if (svg == null)
                            {
                                svg = new SKSvg();
                                svg.Load(file);
                            }

                            var outFs = new FileStream(rendered, FileMode.CreateNew);
                            RenderSvg(svg, outFs, skFormat, minSize, multiplier);
                            outFs.Close();
                        }
                    }
                }

                File.Move(file, $"wwwroot/assets/logos/{guid}.svg");
            }
        }
Exemplo n.º 25
0
 public ProcessorsService(MarechaiContext context) => _context = context;
Exemplo n.º 26
0

        
Exemplo n.º 27
0

        
Exemplo n.º 28
0
 public Iso4217Service(MarechaiContext context) => _context = context;
Exemplo n.º 29
0
 public MagazineIssuesService(MarechaiContext context) => _context = context;
Exemplo n.º 30
0
 public MagazineScansService(MarechaiContext context) => _context = context;