Esempio n. 1
0
        private string resourceToFilePath(string resourcePath)
        {
            return(_installedFonts.GetOrAdd(resourcePath, _ =>
            {
                string filePath = _resources.FindFilePath(resourcePath);
                if (filePath != null && _device.FileSystem.FileExists(filePath))
                {
                    return filePath;
                }
                var resource = _resources.LoadResource(resourcePath);
                if (resource == null)
                {
                    throw new NullReferenceException(string.Format("Failed to find font in path: {0}", resourcePath));
                }
                filePath = Path.Combine(_device.FileSystem.StorageFolder, Path.GetFileName(resourcePath));
                if (_device.FileSystem.FileExists(filePath))
                {
                    _device.FileSystem.Delete(filePath);
                }

                using (Stream fileStream = _device.FileSystem.Create(filePath))
                    using (resource.Stream)
                    {
                        resource.Stream.CopyTo(fileStream);
                    }

                return filePath;
            }));
        }