예제 #1
0
        public static void ImportRaces(this OGLContext context, bool withZips = true)
        {
            if (context == null || context.Config == null)
            {
                return;
            }
            if (withZips)
            {
                context.Races.Clear();
                context.RacesSimple.Clear();
            }
            var files = SourceManager.EnumerateFiles(context, context.Config.Races_Directory, withZips, SearchOption.TopDirectoryOnly);

            foreach (var f in files)
            {
                try
                {
                    using (Stream reader = f.Value.GetReader()) OGLImport.ImportRace(reader, f.Value.FullName, f.Value.Source, context);
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error reading " + f.ToString(), e);
                }
            }
        }
        public async static Task ImportRacesAsync(this OGLContext context, bool withZips = true)
        {
            if (withZips)
            {
                context.Races.Clear();
                context.RacesSimple.Clear();
                foreach (IFile z in PCLSourceManager.Zips)
                {
                    String s = System.IO.Path.ChangeExtension(z.Name, null);
                    if (context.ExcludedSources.Contains(s, StringComparer.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    using (ZipFile zf = new ZipFile(await z.OpenAsync(FileAccess.Read)))
                    {
                        var zfiles = await PCLSourceManager.EnumerateZipFilesAsync(zf, s, context.Config.Races_Directory).ConfigureAwait(false);

                        foreach (var f in zfiles)
                        {
                            try { using (Stream reader = zf.GetInputStream(f.Value)) OGLImport.ImportRace(reader, f.Key, s, context); }
                            catch (Exception e) { ConfigManager.LogError("Error reading " + Path(f.Key), e); }
                        }
                    }
                }
            }
            var files = await PCLSourceManager.EnumerateFilesAsync(context, context.Config.Races_Directory).ConfigureAwait(false);

            foreach (var f in files)
            {
                try
                {
                    using (Stream reader = await f.Key.OpenAsync(FileAccess.Read).ConfigureAwait(false)) OGLImport.ImportRace(reader, f.Key.Path, f.Value, context);
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error reading " + Path(f.Key.Path), e);
                }
            }
        }