예제 #1
0
        public static void ImportStandaloneFeatures(this OGLContext context, bool withZips = true)
        {
            if (context == null || context.Config == null)
            {
                return;
            }
            if (withZips)
            {
                context.FeatureCollections.Clear();
                context.FeatureContainers.Clear();
                context.FeatureCategories.Clear();
                context.Boons.Clear();
                context.Features.Clear();
                context.BoonsSimple.Clear();
            }
            var files = SourceManager.EnumerateFiles(context, context.Config.Features_Directory, withZips);

            foreach (var f in files)
            {
                try
                {
                    using (Stream reader = f.Value.GetReader()) OGLImport.ImportFeatureContainer(reader, f.Value.FullName, f.Value.Source, context, OGLImport.GetPath(f.Value.FullName, SourceManager.AppPath, f.Value.Source));
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error reading " + f.ToString(), e);
                }
            }
        }
        public static async Task ImportStandaloneFeaturesAsync(this OGLContext context, bool withZips = true)
        {
            String basepath = PCLSourceManager.Data.Path;

            if (withZips)
            {
                context.FeatureCollections.Clear();
                context.FeatureContainers.Clear();
                context.FeatureCategories.Clear();
                context.Boons.Clear();
                context.Features.Clear();
                context.BoonsSimple.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.Features_Directory).ConfigureAwait(false);

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

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