### Create FileMakerClip from XML String - C# Source: https://context7.com/fuzzzerd/sharpfm/llms.txt Illustrates initializing a FileMakerClip object directly from an XML string. This method is useful when the XML data is obtained from a file or user input. The constructor handles automatic formatting of the XML for improved readability. The example prints the clip's name, type, and the formatted XML content. ```csharp using SharpFM; // Create clip from XML string (e.g., loaded from file or user input) string rawXml = "User email address"; var clip = new FileMakerClip("Users", "Mac-XMTB", rawXml); Console.WriteLine($"Name: {clip.Name}"); Console.WriteLine($"Type: {clip.ClipboardFormat}"); // XML is automatically formatted for readability Console.WriteLine(clip.XmlData); ``` -------------------------------- ### Folder Service for Directory Selection (C#) Source: https://context7.com/fuzzzerd/sharpfm/llms.txt This snippet shows how to use the FolderService to display a folder picker dialog, allowing users to select a directory for storing clips. It's designed to be used within an Avalonia application context. The service returns the selected path, which can then be used to initialize a ClipRepository for loading clips from that location. Error handling is included for cases where no folder is selected or an invalid path is provided. ```csharp using SharpFM.Services; using Avalonia.Controls; using System; using System.Threading.Tasks; // In Avalonia application context Window mainWindow = new Window(); var folderService = new FolderService(mainWindow); try { // Open folder picker dialog string selectedPath = await folderService.GetFolderAsync(); Console.WriteLine($"Selected folder: {selectedPath}"); // Use the path to load clips from different location var repository = new ClipRepository(selectedPath); repository.LoadClips(); } catch (ArgumentException ex) { Console.WriteLine($"No folder selected or invalid path: {ex.Message}"); } ``` -------------------------------- ### Create FileMakerClip from Binary Data - C# Source: https://context7.com/fuzzzerd/sharpfm/llms.txt Demonstrates creating a FileMakerClip object from raw binary clipboard data. This involves simulating FileMaker's 4-byte length prefix and XML content. The constructor automatically parses the clip name and formats the XML data. It outputs the clip's name, clipboard format, formatted XML, and raw data length. ```csharp using SharpFM; using System.Text; // Simulate FileMaker clipboard data: 4-byte length prefix + XML content string xmlContent = @" "; byte[] xmlBytes = Encoding.UTF8.GetBytes(xmlContent); byte[] lengthPrefix = BitConverter.GetBytes(xmlBytes.Length); byte[] clipboardData = lengthPrefix.Concat(xmlBytes).ToArray(); // Create clip from binary data var clip = new FileMakerClip("new-clip", "Mac-XMSC", clipboardData); Console.WriteLine($"Clip Name: {clip.Name}"); // Output: MyScript Console.WriteLine($"Format: {clip.ClipboardFormat}"); // Output: Mac-XMSC Console.WriteLine($"XML Data:\n{clip.XmlData}"); // Output: Formatted XML Console.WriteLine($"Raw Data Length: {clip.RawData.Length}"); // Can be copied back to clipboard ``` -------------------------------- ### FileMakerClip Supported Clip Types (C#) Source: https://context7.com/fuzzzerd/sharpfm/llms.txt This code illustrates how to access and utilize the static `ClipTypes` property of the `FileMakerClip` class, which provides a list of all supported FileMaker clipboard formats. It shows how to iterate through all available types to display their `KeyId` and `DisplayName`, and how to find a specific clip type by either its `KeyId` or `DisplayName` using LINQ. ```csharp using SharpFM; using System; using System.Linq; // Access all supported clip types foreach (var clipType in FileMakerClip.ClipTypes) { Console.WriteLine($"KeyId: {clipType.KeyId}, Display: {clipType.DisplayName}"); } // Output: // KeyId: Mac-XMSS, Display: ScriptSteps // KeyId: Mac-XML2, Display: Layout // KeyId: Mac-XMTB, Display: Table // KeyId: Mac-XMFD, Display: Field // KeyId: Mac-XMSC, Display: Script // Find format by key var scriptFormat = FileMakerClip.ClipTypes .FirstOrDefault(ct => ct.KeyId == "Mac-XMSC"); Console.WriteLine($"Script format display name: {scriptFormat?.DisplayName}"); // Find format by display name var tableFormat = FileMakerClip.ClipTypes .FirstOrDefault(ct => ct.DisplayName == "Table"); Console.WriteLine($"Table format key: {tableFormat?.KeyId}"); ``` -------------------------------- ### Generate C# Class from Table Clip and Copy to Clipboard (C#) Source: https://context7.com/fuzzzerd/sharpfm/llms.txt This snippet demonstrates how to use the MainWindowViewModel to generate a C# class definition from a FileMaker table clip and copy the resulting code to the system clipboard. It requires the SharpFM library and Microsoft.Extensions.Logging. The input is an XML string representing a FileMaker table structure, which is converted into a FileMakerClip object. ```csharp using SharpFM.ViewModels; using SharpFM; using Microsoft.Extensions.Logging; var logger = LoggerFactory.Create(builder => builder.AddConsole()) .CreateLogger(); var viewModel = new MainWindowViewModel(logger); // Load or create a table clip string tableXml = @" "; var tableClip = new FileMakerClip("Invoice", "Mac-XMTB", tableXml); viewModel.FileMakerClips.Add(new ClipViewModel(tableClip)); viewModel.SelectedClip = viewModel.FileMakerClips[0]; // Generate and copy C# class to clipboard viewModel.CopyAsClass(); // Clipboard now contains: // namespace SharpFM.CodeGen // { // using System; // using System.Runtime.Serialization; // [DataContract] // public class Invoice { ... } // } ``` -------------------------------- ### Manage File Persistence for FileMaker Clips using ClipRepository Source: https://context7.com/fuzzzerd/sharpfm/llms.txt Manages the loading and saving of FileMaker clips as individual files within a specified directory. It handles automatic serialization and deserialization of clip data. The repository is initialized with a path and can load existing clips from disk, add new ones, and save all changes. ```csharp using SharpFM.Models; using System; using System.IO; // Initialize repository with path string clipPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SharpFM", "Clips" ); var repository = new ClipRepository(clipPath); // Load existing clips from disk repository.LoadClips(); Console.WriteLine($"Loaded {repository.Clips.Count} clips from {repository.ClipPath}"); foreach (var clip in repository.Clips) { Console.WriteLine($" {clip.ClipName}.{clip.ClipType}"); } // Add new clip var newClip = new Clip { ClipName = "MyScript", ClipType = "Mac-XMSC", ClipXml = @" " }; repository.Clips.Add(newClip); // Save all clips to disk (creates/updates files: MyScript.Mac-XMSC) repository.SaveChanges(); ``` -------------------------------- ### ClipViewModel Data Binding and Editor Integration (C#) Source: https://context7.com/fuzzzerd/sharpfm/llms.txt This code demonstrates the ClipViewModel, a wrapper for FileMakerClip that enables two-way data binding and integration with text editors like AvaloniaEdit. It shows how to create a ClipViewModel, subscribe to property changes, modify properties, and access the underlying TextDocument for UI binding. Changes to properties like Name, ClipType, or ClipXml automatically update the associated FileMakerClip object. ```csharp using SharpFM.ViewModels; using SharpFM; using AvaloniaEdit.Document; using System.ComponentModel; // Create clip and wrap in view model var clip = new FileMakerClip("MyLayout", "Mac-XML2", ""); var viewModel = new ClipViewModel(clip); // Access properties with change notification viewModel.PropertyChanged += (sender, args) => { Console.WriteLine($"Property changed: {args.PropertyName}"); }; // Modify properties (triggers PropertyChanged) viewModel.Name = "UpdatedLayout"; viewModel.ClipType = "Mac-XML2"; // Access text document for editor binding TextDocument doc = viewModel.XmlDocument; Console.WriteLine($"Document has {doc.LineCount} lines"); // Update XML through property viewModel.ClipXml = ""; // Both viewModel.Clip.XmlData and viewModel.XmlDocument are updated ``` -------------------------------- ### Copy Selected Clip to Clipboard in FileMaker Format Source: https://context7.com/fuzzzerd/sharpfm/llms.txt Converts a selected FileMaker clip back into its binary format and places it onto the system clipboard. This allows users to copy data from the C# application and paste it directly into FileMaker Pro. The process involves creating a FileMakerClip object and then using the ViewModel to handle the clipboard operation. ```csharp using SharpFM.ViewModels; using SharpFM; using System.Threading.Tasks; // Assuming viewModel is initialized and has clips var viewModel = new MainWindowViewModel(logger); // Create or select a clip string scriptXml = @" "; var clip = new FileMakerClip("ProcessOrder", "Mac-XMSC", scriptXml); viewModel.FileMakerClips.Add(new ClipViewModel(clip)); viewModel.SelectedClip = viewModel.FileMakerClips[0]; // Copy to clipboard in FileMaker format await viewModel.CopySelectedToClip(); // Now user can switch to FileMaker and paste (Ctrl+V or Cmd+V) // The script will appear in the script editor ready to be pasted ``` -------------------------------- ### Generate C# Data Contract Classes from FileMaker Table XML Source: https://context7.com/fuzzzerd/sharpfm/llms.txt Generates C# data contract classes from FileMaker table definitions. It automatically maps FileMaker data types to C# types and includes DataContract and DataMember attributes for serialization. Input is an XML string representing the FileMaker table structure. ```csharp using SharpFM; using System; string tableXml = @" "; var clip = new FileMakerClip("Customer", "Mac-XMTB", tableXml); // Generate C# class with DataContract attributes string csharpCode = clip.CreateClass(); Console.WriteLine(csharpCode); ``` -------------------------------- ### Paste FileMaker Clip Data from Clipboard to XML Source: https://context7.com/fuzzzerd/sharpfm/llms.txt Extracts FileMaker data from the system clipboard and converts it into XML clip format. This method is designed to be called within an application context that has access to the clipboard. It scans for FileMaker-specific formats (e.g., 'Mac-*'), creates FileMakerClip objects, and populates a collection. ```csharp using SharpFM.ViewModels; using Avalonia.Controls.ApplicationLifetimes; using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; // In application context with access to clipboard var logger = LoggerFactory.Create(builder => builder.AddConsole()) .CreateLogger(); var viewModel = new MainWindowViewModel(logger); // User copies a script in FileMaker Pro (Ctrl+C or Cmd+C) // Then calls this method to extract it await viewModel.PasteFileMakerClipData(); // The method scans clipboard for Mac-* formats // Creates FileMakerClip objects for each found format // Adds them to FileMakerClips collection // Automatically extracts names and converts binary data to XML foreach (var clip in viewModel.FileMakerClips) { Console.WriteLine($"Captured: {clip.Name} ({clip.ClipType})"); } ``` -------------------------------- ### Extract Field Metadata from FileMakerClip - C# Source: https://context7.com/fuzzzerd/sharpfm/llms.txt Shows how to use the `Fields` property of a FileMakerClip object to extract structured metadata for fields from Table or Layout XML data. The code iterates through the parsed fields, printing details such as name, ID, data type, field type, and validation requirements. It handles cases where comments might be absent. ```csharp using SharpFM; using System; using System.Linq; string tableXml = @" Primary key for products "; var tableClip = new FileMakerClip("Products", "Mac-XMTB", tableXml); // Access parsed field metadata foreach (var field in tableClip.Fields) { Console.WriteLine($"Field: {field.Name}"); Console.WriteLine($" ID: {field.FileMakerFieldId}"); Console.WriteLine($" DataType: {field.DataType}"); Console.WriteLine($" FieldType: {field.FieldType}"); Console.WriteLine($" Required: {field.NotEmpty}"); Console.WriteLine($" Unique: {field.Unique}"); Console.WriteLine($" Comment: {field.Comment ?? "None"}"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.