public override void OnStartImageLinkProcessing(List <ProcessedNode> imageFigmaNodes) { //not needed in local files Console.WriteLine($"Loading images.."); if (imageFigmaNodes.Count > 0) { foreach (var vector in imageFigmaNodes) { try { var recoveredKey = FigmaResourceConverter.FromResource(vector.FigmaNode.id); string filePath = Path.Combine(ResourcesDirectory, string.Concat(recoveredKey, ImageFormat)); if (!System.IO.File.Exists(filePath)) { throw new FileNotFoundException(filePath); } if (vector.View is IImageView imageView) { var image = AppContext.Current.GetImageFromFilePath(filePath); imageView.Image = image; } } catch (FileNotFoundException ex) { Console.WriteLine("[FIGMA.RENDERER] Resource '{0}' not found.", ex.Message); } catch (Exception ex) { Console.WriteLine(ex); } } } Console.WriteLine("Ended image link processing"); OnImageLinkProcessed(); }
//TODO: Change to async multithread public static void SaveFiles(Models.FigmaFileResponse figmaResponse, string destinationDirectory, string format, Dictionary <string, string> remotefile) { if (!Directory.Exists(destinationDirectory)) { throw new DirectoryNotFoundException(destinationDirectory); } List <Task> downloads = new List <Task>(); foreach (var file in remotefile) { if (file.Value == null) { continue; } var key = FigmaResourceConverter.FromResource(file.Key); var figmaNode = figmaResponse.document.FindNode(s => s.id == file.Key) .FirstOrDefault(); string customNodeName; if (!figmaNode.TryGetNodeCustomName(out customNodeName)) { customNodeName = figmaNode.id; } var fileName = string.Concat(customNodeName, format); var fullPath = Path.Combine(destinationDirectory, fileName); if (File.Exists(fullPath)) { File.Delete(fullPath); } try { using (WebClient client = new WebClient()) { client.DownloadFile(new Uri(file.Value), fullPath); } } catch (Exception ex) { Console.WriteLine(ex); } } ; }
public override void OnStartImageLinkProcessing(List <ProcessedNode> imageFigmaNodes) { Console.WriteLine($"Loading images.."); if (imageFigmaNodes.Count > 0) { foreach (var vector in imageFigmaNodes) { var recoveredKey = FigmaResourceConverter.FromResource(vector.FigmaNode.id); var image = AppContext.Current.GetImageFromManifest(Assembly, recoveredKey); if (image != null && vector.View is IImageView imageView) { imageView.Image = image; } } } Console.WriteLine("Ended image link processing"); OnImageLinkProcessed(); }
//TODO: Change to async multithread public static void SaveFiles(string destinationDirectory, string format, Dictionary <string, string> remotefile) { if (!Directory.Exists(destinationDirectory)) { throw new DirectoryNotFoundException(destinationDirectory); } List <Task> downloads = new List <Task>(); foreach (var file in remotefile) { if (file.Value == null) { continue; } var key = FigmaResourceConverter.FromResource(file.Key); var fileName = string.Concat(Path.GetFileName(key), format); var fullPath = Path.Combine(destinationDirectory, fileName); if (File.Exists(fullPath)) { File.Delete(fullPath); } try { using (WebClient client = new WebClient()) { client.DownloadFile(new Uri(file.Value), fullPath); } } catch (Exception ex) { Console.WriteLine(ex); } } ; }