Beispiel #1
0
        protected async System.Threading.Tasks.Task CacheExtensionAsync(Uri uri)
        {
            String uriStr = uri.ToString().ToLower();

            if (uriStr.EndsWith("/", StringComparison.Ordinal))
            {
                uriStr = uriStr.Substring(0, uriStr.Length - 1);
            }
            String fileName = uriStr.Substring(uriStr.LastIndexOf("/", StringComparison.Ordinal));

            if (!(fileName.EndsWith(".xesext", StringComparison.CurrentCulture)))
            {
                fileName = fileName + ".xesext";
            }
            FileStream cacheFile = File.Create(Path.Combine(XRuntimeUtils.GetExtensionCacheFolder(), fileName));
            Stream     fs;

            try
            {
                HttpClient client = new HttpClient();
                fs = await client.GetStreamAsync(uri).ConfigureAwait(false);

                await fs.CopyToAsync(cacheFile);

                cacheFile.Flush();
            }
            catch (Exception e)
            {
                XLogging.Log(e.Message, XLogging.Importance.ERROR);
                throw e;
            }
        }
Beispiel #2
0
        protected void LoadExtensionCache()
        {
            long          minModified = DateTime.Now.Ticks - 2592000000L;
            DirectoryInfo extFolder   = Directory.CreateDirectory(XRuntimeUtils.GetExtensionCacheFolder());

            FileInfo[] extFiles = extFolder.GetFiles();
            if (extFiles == null)
            {
                XLogging.Log("Extension caching disabled (Could not access cache directory)!", XLogging.Importance.WARNING);

                return;
            }
            foreach (FileInfo extFile in extFiles)
            {
                if (!(extFile.FullName.ToLower().EndsWith(".xesext", StringComparison.Ordinal)))
                {
                    continue;
                }

                if (extFile.LastWriteTime.Ticks < minModified)
                {
                    extFile.Delete();
                }
                else
                {
                    try
                    {
                        XExtension extension = XExtensionParser.Instance.Parse(extFile);
                        if (!(this.extensionMap.ContainsKey(extension.Uri)))
                        {
                            this.extensionMap.Add(extension.Uri, extension);
                            this.extensionList.Add(extension);
                            XLogging.Log("Loaded XES extension '" + extension.Uri + "' from cache",
                                         XLogging.Importance.DEBUG);
                        }
                        else
                        {
                            XLogging.Log("Skipping cached XES extension '" + extension.Uri + "' (already defined)",
                                         XLogging.Importance.DEBUG);
                        }
                    }
                    catch (Exception e)
                    {
                        XLogging.Log(e.Message, XLogging.Importance.ERROR);
                        throw e;
                    }
                }
            }
        }