### Call Zome Function Example Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Example of calling a Zome function asynchronously using the HoloNET client. ```APIDOC ## Call Zome Function ### Description Demonstrates calling a Zome function with specific parameters. ### Method `CallZomeFunctionAsync` ### Endpoint `/oasis/create_entry_avatar` ### Parameters #### Request Body - **id** (int) - Required - Identifier for the entry. - **first_name** (string) - Required - The first name of the individual. - **last_name** (string) - Required - The last name of the individual. - **email** (string) - Required - The email address of the individual. - **dob** (string) - Required - The date of birth in MM/DD/YYYY format. ### Request Example ```json { "id": 1, "first_name": "David", "last_name": "Ellams", "email": "davidellams@hotmail.com", "dob": "11/07/1980" } ``` ``` -------------------------------- ### Start Holochain Conductor (C#) Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Initiates the Holochain conductor process based on settings defined in the HoloNETConfig. This method is available in both asynchronous and synchronous versions. ```csharp public async Task StartHolochainConductorAsync() public async Task StartHolochainConductor() ``` -------------------------------- ### Instantiate HoloNETClient Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Create a new instance of the HoloNETClient by passing the Holochain websocket URI to the constructor. This is the first step to establishing a connection. ```csharp HoloNETClient holoNETClient = new HoloNETClient("ws://localhost:8888"); ``` -------------------------------- ### Signal Callback Handler Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Handles incoming signals from the Holochain conductor and logs relevant information. ```APIDOC ## Signal Callback ### Description This event handler is triggered when the Holochain conductor sends signals. ### Method `OnSignalCallBack` event handler ### Parameters #### SignalCallBackEventArgs - **EndPoint** (string) - The URI EndPoint of the Holochain conductor. - **Id** (string) - The id that made the request. - **AgentPubKey** (string) - The Agent Public Key of the hApp that is running in the Holochain Conductor. - **DnaHash** (string) - The DNA Hash of the hApp that is running in the Holochain Conductor. - **SignalType** (SignalType enum) - An enum containing the SignalType, can be either App or System. - **SignalData** (object) - The Signal Data decoded into a dictionary with keyvalue pairs. - **SignalDataAsString** (string) - The Signal Data decoded into a string with keyvalue pairs. - **RawSignalData** (object) - The Raw Signal Data returned from the conductor decoded into a HoloNETSignalData object containing a CellData (contains a 2 dimensional array containing the AgentPubKey & DnaHash) & SignalData binary array. - **RawBinaryData** (byte[]) - The raw binary data returned from the Holochain conductor. - **RawBinaryDataAsString** (string) - The raw binary data returned from the Holochain conductor formatted as a string (useful for debugging/logging etc). - **RawBinaryDataDecoded** (string) - The raw binary data returned from the Holochain conductor decoded into a string using UTF8 encoding. - **RawBinaryDataAfterMessagePackDecode** (object) - The raw binary data after it has been decoded by MessagePack. - **RawBinaryDataAfterMessagePackDecodeAsString** (string) - The raw binary data after it has been decoded by MessagePack formatted as a string (useful for debugging/logging etc). - **RawBinaryDataAfterMessagePackDecodeDecoded** (string) - The raw binary data after it has been decoded by MessagePack decoded into a string using UTF8 encoding. - **RawJSONData** (string) - The raw JSON data returned from the Holochain conductor. - **WebSocketResult** (object) - Contains more detailed technical information of the underlying websocket. This includes the number of bytes received, whether the message was fully received & whether the message is UTF-8 or binary. Please see here for more info. - **IsError** (bool) - True if there was an error during the initialization, false if not. - **Message** (string) - If there was an error this will contain the error message, this normally includes a stacktrace to help you track down the cause. If there was no error it can contain any other message such as status etc or will be blank. ### Response Example ```csharp private static void HoloNETClient_OnSignalCallBack(object sender, SignalCallBackEventArgs e) { Console.WriteLine(string.Concat("TEST HARNESS: SIGINALS CALLBACK EVENT HANDLER: EndPoint: ", e.EndPoint, ", Id: ", e.Id, ", Data: ", e.RawJSONData, ", AgentPubKey = ", e.AgentPubKey, ", DnaHash = ", e.DnaHash, ", Signal Type: ", Enum.GetName(typeof(SignalType), e.SignalType), ", Signal Data: ", e.SignalDataAsString)); Console.WriteLine(""); } ``` ``` -------------------------------- ### Initialize Method Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Synchronously initializes the HoloNETEntryBaseClass and HoloNET client, raising the OnInitialized event upon completion. It also manages the connection and retrieval of AgentPubKey and DnaHash. ```APIDOC ## POST /websites/nuget_packages_nextgensoftware_holochain_holonet_orm/Initialize ### Description Initializes the HoloNETEntryBaseClass and HoloNET client synchronously. This method will also call the Connect and RetrieveAgentPubKeyAndDnaHash methods on the HoloNET client. Once the HoloNET client has successfully connected to the Holochain Conductor, retrieved the AgentPubKey & DnaHash & then raised the OnReadyForZomeCalls event it will raise the OnInitialized event. See also the IsInitializing and the IsInitialized properties. ### Method POST ### Endpoint /websites/nuget_packages_nextgensoftware_holochain_holonet_orm/Initialize ### Parameters #### Query Parameters - **retrieveAgentPubKeyAndDnaHashFromConductor** (bool) - Optional - Set this to true for HoloNET to automatically retrieve the AgentPubKey & DnaHash from the Holochain Conductor after it has connected. This defaults to true. - **retrieveAgentPubKeyAndDnaHashFromSandbox** (bool) - Optional - Set this to true if you wish HoloNET to automatically retrieve the AgentPubKey & DnaHash from the hc sandbox after it has connected. This defaults to true. - **automaticallyAttemptToRetrieveFromConductorIfSandBoxFails** (bool) - Optional - If this is set to true it will automatically attempt to get the AgentPubKey & DnaHash from the Holochain Conductor if it fails to get them from the HC Sandbox command. This defaults to true. - **automaticallyAttemptToRetrieveFromSandBoxIfConductorFails** (bool) - Optional - If this is set to true it will automatically attempt to get the AgentPubKey & DnaHash from the HC Sandbox command if it fails to get them from the Holochain Conductor. This defaults to true. - **updateConfigWithAgentPubKeyAndDnaHashOnceRetrieved** (bool) - Optional - Set this to true (default) to automatically update the HoloNETConfig once it has retrieved the DnaHash & AgentPubKey. ### Request Example ```json { "retrieveAgentPubKeyAndDnaHashFromConductor": true, "retrieveAgentPubKeyAndDnaHashFromSandbox": true, "automaticallyAttemptToRetrieveFromConductorIfSandBoxFails": true, "automaticallyAttemptToRetrieveFromSandBoxIfConductorFails": true, "updateConfigWithAgentPubKeyAndDnaHashOnceRetrieved": true } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the initialization. #### Response Example ```json { "status": "Initialized successfully" } ``` ``` -------------------------------- ### InitializeAsync Method Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Initializes the HoloNETEntryBaseClass, HoloNET client, and raises the OnInitialized event. It also connects to the Holochain Conductor and retrieves AgentPubKey and DnaHash. ```APIDOC ## POST /websites/nuget_packages_nextgensoftware_holochain_holonet_orm/InitializeAsync ### Description This method will Initialize the HoloNETEntryBaseClass along with the internal HoloNET Client and will raise the OnInitialized event once it has finished initializing. This will also call the Connect and RetrieveAgentPubKeyAndDnaHash methods on the HoloNET client. Once the HoloNET client has successfully connected to the Holochain Conductor, retrieved the AgentPubKey & DnaHash & then raised the OnReadyForZomeCalls event it will raise the OnInitialized event. See also the IsInitializing and the IsInitialized properties. ### Method POST ### Endpoint /websites/nuget_packages_nextgensoftware_holochain_holonet_orm/InitializeAsync ### Parameters #### Query Parameters - **connectedCallBackMode** (ConnectedCallBackMode) - Optional - If set to `WaitForHolochainConductorToConnect` (default) it will await until it is connected before returning, otherwise it will return immediately and then call the OnConnected event once it has finished connecting. - **retrieveAgentPubKeyAndDnaHashMode** (RetrieveAgentPubKeyAndDnaHashMode) - Optional - If set to `Wait` (default) it will await until it has finished retrieving the AgentPubKey & DnaHash before returning, otherwise it will return immediately and then call the OnReadyForZomeCalls event once it has finished retrieving the DnaHash & AgentPubKey. - **retrieveAgentPubKeyAndDnaHashFromConductor** (bool) - Optional - Set this to true for HoloNET to automatically retrieve the AgentPubKey & DnaHash from the Holochain Conductor after it has connected. This defaults to true. - **retrieveAgentPubKeyAndDnaHashFromSandbox** (bool) - Optional - Set this to true if you wish HoloNET to automatically retrieve the AgentPubKey & DnaHash from the hc sandbox after it has connected. This defaults to true. - **automaticallyAttemptToRetrieveFromConductorIfSandBoxFails** (bool) - Optional - If this is set to true it will automatically attempt to get the AgentPubKey & DnaHash from the Holochain Conductor if it fails to get them from the HC Sandbox command. This defaults to true. - **automaticallyAttemptToRetrieveFromSandBoxIfConductorFails** (bool) - Optional - If this is set to true it will automatically attempt to get the AgentPubKey & DnaHash from the HC Sandbox command if it fails to get them from the Holochain Conductor. This defaults to true. - **updateConfigWithAgentPubKeyAndDnaHashOnceRetrieved** (bool) - Optional - Set this to true (default) to automatically update the HoloNETConfig once it has retrieved the DnaHash & AgentPubKey. ### Request Example ```json { "connectedCallBackMode": "WaitForHolochainConductorToConnect", "retrieveAgentPubKeyAndDnaHashMode": "Wait", "retrieveAgentPubKeyAndDnaHashFromConductor": true, "retrieveAgentPubKeyAndDnaHashFromSandbox": true, "automaticallyAttemptToRetrieveFromConductorIfSandBoxFails": true, "automaticallyAttemptToRetrieveFromSandBoxIfConductorFails": true, "updateConfigWithAgentPubKeyAndDnaHashOnceRetrieved": true } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the initialization. #### Response Example ```json { "status": "Initialized successfully" } ``` ``` -------------------------------- ### Call Zome Function (Overloads) Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Provides details on how to call zome functions using different overloads of the CallZomeFunction and CallZomeFunctionAsync methods. ```APIDOC ## CallZomeFunction / CallZomeFunctionAsync ### Description These methods allow for synchronous and asynchronous calls to zome functions within Holochain. Various overloads are provided to accommodate different parameter requirements, including instance IDs, callbacks, and caching options. ### Method POST (Implied by the nature of calling functions) ### Endpoint `/call_zome_function` (Hypothetical endpoint for illustrative purposes) ### Parameters Parameters vary based on the overload. Common parameters include: #### Path Parameters None #### Query Parameters - **id** (string) - Optional - The unique identifier for a specific instance of a zome function. - **zome** (string) - Required - The name of the zome to call. - **function** (string) - Required - The name of the function within the zome to execute. - **paramsObject** (object) - Optional - An object containing the parameters to pass to the zome function. - **entryDataObjectTypeReturnedFromZome** (Type) - Optional - Specifies the type of entry data expected to be returned from the zome function. - **zomeResultCallBackMode** (ZomeResultCallBackMode) - Optional - Determines how the result of the zome function call is handled (e.g., wait for response). - **callback** (ZomeFunctionCallBack) - Optional - A callback function to be executed when the zome function completes. - **cachReturnData** (bool) - Optional - If true, the return data will be cached. - **matchIdToInstanceZomeFuncInCallback** (bool) - Optional - If true, the provided ID will be matched to the instance zome function within the callback. ### Request Example ```json { "zome": "my_zome", "function": "my_function", "paramsObject": { "key": "value" } } ``` ### Response #### Success Response (200) - **ZomeFunctionCallBackEventArgs** (object) - Contains information about the result of the zome function call, including success status, returned data, and any errors. #### Response Example ```json { "Success": true, "Data": { "result": "some data" }, "Error": null } ``` ``` -------------------------------- ### Calling a Holochain Zome Function Asynchronously in C# Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Demonstrates how to asynchronously call a zome function on the Holochain conductor using the `_holoNETClient`. This example shows calling the `create_entry_avatar` function with specific parameters. ```csharp await _holoNETClient.CallZomeFunctionAsync("oasis", "create_entry_avatar", ZomeCallback, new { id = 1, first_name = "David", last_name = "Ellams", email = "davidellams@hotmail.com", dob = "11/07/1980" }); ``` -------------------------------- ### Connect to Holochain Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Initiate the connection to Holochain using the Connect method. This method can optionally retrieve AgentPubKey and DnaHash from the conductor or sandbox. ```csharp await holoNETClient.Connect(); ``` -------------------------------- ### HoloNETEntryBaseClass Constructor - Basic Configuration Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Initializes the HoloNETEntryBaseClass with core zome function names, logging options, and Holochain connection details. Supports optional version and audit tracking. ```csharp public HoloNETEntryBaseClass(string zomeName, string zomeLoadEntryFunction, string zomeCreateEntryFunction, string zomeUpdateEntryFunction, string zomeDeleteEntryFunction, IEnumerable loggers, bool alsoUseDefaultLogger = false, bool isVersionTrackingEnabled = true, bool isAuditTrackingEnabled = true, bool isAuditAgentCreateModifyDeleteFieldsEnabled = true, bool autoCallInitialize = true, string holochainConductorURI = "ws://localhost:8888", HoloNETConfig holoNETConfig = null, ConnectedCallBackMode connectedCallBackMode = ConnectedCallBackMode.WaitForHolochainConductorToConnect, RetrieveAgentPubKeyAndDnaHashMode retrieveAgentPubKeyAndDnaHashMode = RetrieveAgentPubKeyAndDnaHashMode.Wait, bool retrieveAgentPubKeyAndDnaHashFromConductor = true, bool retrieveAgentPubKeyAndDnaHashFromSandbox = true, bool automaticallyAttemptToRetrieveFromConductorIfSandBoxFails = true, bool automaticallyAttemptToRetrieveFromSandBoxIfConductorFails = true, bool updateConfigWithAgentPubKeyAndDnaHashOnceRetrieved = true) ``` -------------------------------- ### HoloNETEntryBaseClass Constructor with HoloNETConfig (C#) Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Initializes the HoloNETEntryBaseClass using a provided HoloNETConfig object and specifies zome function names. This constructor simplifies setup by encapsulating configuration within a single object and offers control over initialization and Holochain connection behavior. It's suitable when a pre-configured HoloNET environment is available. ```csharp public HoloNETEntryBaseClass(string zomeName, string zomeLoadEntryFunction, string zomeCreateEntryFunction, string zomeUpdateEntryFunction, string zomeDeleteEntryFunction, HoloNETConfig holoNETConfig, bool autoCallInitialize = true, ConnectedCallBackMode connectedCallBackMode = ConnectedCallBackMode.WaitForHolochainConductorToConnect, RetrieveAgentPubKeyAndDnaHashMode retrieveAgentPubKeyAndDnaHashMode = RetrieveAgentPubKeyAndDnaHashMode.Wait, bool retrieveAgentPubKeyAndDnaHashFromConductor = true, bool retrieveAgentPubKeyAndDnaHashFromSandbox = true, bool automaticallyAttemptToRetrieveFromConductorIfSandBoxFails = true, bool automaticallyAttemptToRetrieveFromSandBoxIfConductorFails = true, bool updateConfigWithAgentPubKeyAndDnaHashOnceRetrieved = true) ``` -------------------------------- ### SaveAsync Method Example in C# Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Demonstrates how to use the SaveAsync method in C# to save an entry. It shows how to disable specific Holochain fields and include custom data in the Zome function call. The method returns a Task of ZomeFunctionCallBackEventArgs. ```csharp public override Task SaveAsync(Dictionary customDataKeyValuePair = null, Dictionary holochainFieldsIsEnabledKeyValuePair = null, bool cachePropertyInfos = true, useReflectionToMapKeyValuePairResponseOntoEntryDataObject = true) { //Example of how to disable various holochain fields/ properties so the data is omitted from the data sent to the zome function. if (holochainFieldsIsEnabledKeyValuePair == null) holochainFieldsIsEnabledKeyValuePair = new Dictionary(); holochainFieldsIsEnabledKeyValuePair["DOB"] = false; holochainFieldsIsEnabledKeyValuePair["Email"] = false; //Below is an example of how you can send custom data to the zome function: if (customDataKeyValuePair == null) customDataKeyValuePair = new Dictionary(); customDataKeyValuePair["dynamic data"] = "dynamic"; customDataKeyValuePair["some other data"] = "data"; return base.SaveAsync(customDataKeyValuePair, holochainFieldsIsEnabledKeyValuePair, cachePropertyInfos, useReflectionToMapKeyValuePairResponseOntoEntryDataObject); } ``` -------------------------------- ### HoloNETEntryBaseClass Constructor - HoloNETClient Provided Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Initializes the HoloNETEntryBaseClass using an active HoloNETClient instance, allowing direct use of an established connection. Supports version and audit tracking. ```csharp public HoloNETEntryBaseClass(string zomeName, string zomeLoadEntryFunction, string zomeCreateEntryFunction, string zomeUpdateEntryFunction, string zomeDeleteEntryFunction, HoloNETClient holoNETClient, bool isVersionTrackingEnabled = true, bool isAuditTrackingEnabled = true, bool isAuditAgentCreateModifyDeleteFieldsEnabled = true, bool autoCallInitialize = true, ConnectedCallBackMode connectedCallBackMode = ConnectedCallBackMode.WaitForHolochainConductorToConnect, RetrieveAgentPubKeyAndDnaHashMode retrieveAgentPubKeyAndDnaHashMode = RetrieveAgentPubKeyAndDnaHashMode.Wait, bool retrieveAgentPubKeyAndDnaHashFromConductor = true, bool retrieveAgentPubKeyAndDnaHashFromSandbox = true, bool automaticallyAttemptToRetrieveFromConductorIfSandBoxFails = true, bool automaticallyAttemptToRetrieveFromSandBoxIfConductorFails = true, bool updateConfigWithAgentPubKeyAndDnaHashOnceRetrieved = true) ``` -------------------------------- ### WaitTillReadyForZomeCallsAsync API Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Asynchronously waits until HoloNET is prepared to execute zome calls, ensuring connection and necessary data retrieval. ```APIDOC ## WaitTillReadyForZomeCallsAsync ### Description This method will wait (non blocking) until HoloNET is ready to make zome calls after it has connected to the Holochain Conductor and retrived the AgentPubKey & DnaHash. It will then return to the caller with the AgentPubKey & DnaHash. This method will return the same time the OnReadyForZomeCalls event is raised. Unlike all the other methods, this one only contains an async version because the non async version would block all other threads including any UI ones etc. ### Method `public async Task WaitTillReadyForZomeCallsAsync()` ### Endpoint N/A (Method call) ### Response #### Success Response (200) - **ReadyForZomeCallsEventArgs** (object) - Contains the AgentPubKey and DnaHash once HoloNET is ready for zome calls. ### Response Example ```json { "agentPubKey": "agentId", "dnaHash": "dnaId" } ``` ``` -------------------------------- ### Entry Fields Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Defines the common fields for Holochain entries, including creation and modification timestamps, author information, deletion status, and versioning. ```APIDOC ## Entry Structure ### Description Represents a standard Holochain entry with metadata. ### Fields - **created_date** (DateTime) - The date the entry was created. - **created_by** (string) - The AgentId who created the entry. - **modified_date** (DateTime) - The date the entry was last modified. - **modified_by** (string) - The AgentId who modified the entry. - **deleted_date** (DateTime) - The date the entry was soft deleted. - **deleted_by** (string) - The AgentId who deleted the entry. - **is_active** (bool) - Flag showing whether this entry is active or not. - **version** (int) - The current version of the entry. ``` -------------------------------- ### Manually Set AgentPubKey and DnaHash Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Manually configure the AgentPubKey and DnaHash if automatic retrieval fails. This is useful for specific deployment scenarios or when not using default Holochain configurations. ```csharp //Use this if you to manually pass in the AgentPubKey &DnaHash(otherwise it will be automatically queried from the conductor or sandbox). _holoNETClient.Config.AgentPubKey = "YOUR KEY"; _holoNETClient.Config.DnaHash = "YOUR HASH"; await _holoNETClient.Connect(false, false); ``` -------------------------------- ### Wait for HoloNET Initialization Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Waits until the HoloNET client is ready to receive zome calls. This method is useful to ensure that the HoloNET instance has completed its initialization process before attempting to interact with zomes. ```csharp public async Task WaitTillHoloNETInitializedAsync() ``` -------------------------------- ### HoloNETEntryBaseClass Constructor - HoloNETConfig Provided Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Initializes the HoloNETEntryBaseClass using an existing HoloNETConfig object, simplifying configuration when a config object is already available. Supports version and audit tracking. ```csharp public HoloNETEntryBaseClass(string zomeName, string zomeLoadEntryFunction, string zomeCreateEntryFunction, string zomeUpdateEntryFunction, string zomeDeleteEntryFunction, HoloNETConfig holoNETConfig, bool isVersionTrackingEnabled = true, bool isAuditTrackingEnabled = true, bool isAuditAgentCreateModifyDeleteFieldsEnabled = true, bool autoCallInitialize = true, ConnectedCallBackMode connectedCallBackMode = ConnectedCallBackMode.WaitForHolochainConductorToConnect, RetrieveAgentPubKeyAndDnaHashMode retrieveAgentPubKeyAndDnaHashMode = RetrieveAgentPubKeyAndDnaHashMode.Wait, bool retrieveAgentPubKeyAndDnaHashFromConductor = true, bool retrieveAgentPubKeyAndDnaHashFromSandbox = true, bool automaticallyAttemptToRetrieveFromConductorIfSandBoxFails = true, bool automaticallyAttemptToRetrieveFromSandBoxIfConductorFails = true, bool updateConfigWithAgentPubKeyAndDnaHashOnceRetrieved = true) ``` -------------------------------- ### Subscribe to HoloNET Events Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Subscribe to various events emitted by the HoloNETClient to handle different connection and data states. This allows for asynchronous handling of Holochain interactions. ```csharp holoNETClient.OnConnected += HoloNETClient_OnConnected; holoNETClient.OnAppInfoCallBack += HoloNETClient_OnAppInfoCallBack; holoNETClient.OnReadyForZomeCalls += HoloNETClient_OnReadyForZomeCalls; holoNETClient.OnDataReceived += HoloNETClient_OnDataReceived; holoNETClient.OnZomeFunctionCallBack += HoloNETClient_OnZomeFunctionCallBack; holoNETClient.OnSignalCallBack += HoloNETClient_OnSignalsCallBack; holoNETClient.OnDisconnected += HoloNETClient_OnDisconnected; holoNETClient.OnError += HoloNETClient_OnError; holoNETClient.OnConductorDebugCallBack += HoloNETClient_OnConductorDebugCallBack; holoNETClient.OnHolochainConductorsShutdownComplete += _holoNETClient_OnHolochainConductorsShutdownComplete; holoNETClient.OnHoloNETShutdownComplete += _holoNETClient_OnHoloNETShutdownComplete; ``` -------------------------------- ### Handling Holochain Signals in C# Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Sets up a callback for receiving signals from the Holochain conductor. The `HoloNETClient_OnSignalCallBack` method processes and logs detailed information about each incoming signal, including its source and data. ```csharp holoNETClient.OnSignalCallBack += HoloNETClient_OnSignalCallBack; private static void HoloNETClient_OnSignalCallBack(object sender, SignalCallBackEventArgs e) { Console.WriteLine(string.Concat("TEST HARNESS: SIGINALS CALLBACK EVENT HANDLER: EndPoint: ", e.EndPoint, ", Id: ", e.Id, ", Data: ", e.RawJSONData, ", AgentPubKey = ", e.AgentPubKey, ", DnaHash = ", e.DnaHash, ", Signal Type: ", Enum.GetName(typeof(SignalType), e.SignalType), ", Signal Data: ", e.SignalDataAsString)); Console.WriteLine(""); } ``` -------------------------------- ### OnDataReceived Event Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index This event is fired when any data is received from the Holochain conductor. It provides access to the raw data, whether JSON or binary. ```APIDOC ## OnDataReceived Event ### Description Fired when any data is received from the Holochain conductor. This returns the raw data. ### Method Event Handler ### Parameters #### Event Arguments (HoloNETDataReceivedEventArgs) - **EndPoint** (string) - The URI EndPoint of the Holochain conductor. - **Id** (string) - The id that made the request. - **InstalledAppId** (string) - The InstalledAppId for the hApp. - **RawBinaryData** (byte[]) - The raw binary data returned from the Holochain conductor. - **RawBinaryDataAsString** (string) - The raw binary data returned from the Holochain conductor formatted as a string (useful for debugging/logging etc). - **RawBinaryDataDecoded** (string) - The raw binary data returned from the Holochain conductor decoded into a string using UTF8 encoding. - **RawBinaryDataAfterMessagePackDecode** (byte[]) - The raw binary data after it has been decoded by MessagePack. - **RawBinaryDataAfterMessagePackDecodeAsString** (string) - The raw binary data after it has been decoded by MessagePack formatted as a string (useful for debugging/logging etc). - **RawBinaryDataAfterMessagePackDecodeDecoded** (string) - The raw binary data after it has been decoded by MessagePack decoded into a string using UTF8 encoding. - **RawJSONData** (string) - The raw JSON data returned from the Holochain conductor. - **WebSocketResult** (object) - Contains more detailed technical information of the underlying websocket. This includes the number of bytes received, whether the message was fully received & whether the message is UTF-8 or binary. Please see here for more info. - **IsError** (bool) - True if there was an error during the initialization, false if not. - **Message** (string) - If there was an error this will contain the error message, this normally includes a stacktrace to help you track down the cause. If there was no error it can contain any other message such as status etc or will be blank. ### Example Usage ```csharp holoNETClient.OnDataReceived += HoloNETClient_OnDataReceived; private static void HoloNETClient_OnDataReceived(object sender, HoloNETDataReceivedEventArgs e) { if (!e.IsError) { Console.WriteLine(string.Concat("\nTEST HARNESS: DATA RECEIVED EVENT HANDLER: EndPoint: ", e.EndPoint, ", Raw JSON Data: ", e.RawJSONData, ", Raw Binary Data: ", e.RawBinaryData)); Console.WriteLine(""); } } ``` ``` -------------------------------- ### OnReadyForZomeCalls Event Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index This event is fired when the HoloNET client has successfully connected and retrieved the AgentPubKey and DnaHash. This indicates the client is ready to make zome calls to the Holochain conductor. ```APIDOC ## OnReadyForZomeCalls Event ### Description Fired when the client has successfully connected and retrieved the AgentPubKey & DnaHash, meaning it is ready to make zome calls to the holochain conductor. ### Method Event Handler ### Parameters #### Event Arguments (ReadyForZomeCallsEventArgs) - **EndPoint** (string) - The URI EndPoint of the Holochain conductor. - **AgentPubKey** (string) - The AgentPubKey for the hApp. - **DnaHash** (string) - The DnaHash for the hApp. ### Example Usage ```csharp private async static void _holoNETClient_OnReadyForZomeCalls(object sender, ReadyForZomeCallsEventArgs e) { Console.WriteLine(string.Concat("TEST HARNESS: READY FOR ZOME CALLS EVENT HANDLER: EndPoint: ", e.EndPoint, ", AgentPubKey: ", e.AgentPubKey, ", DnaHash: ", e.DnaHash)); Console.WriteLine(""); Console.WriteLine("Calling Test Zome...\n"); await _holoNETClient.CallZomeFunctionAsync("1", "numbers", "add_ten", ZomeCallback, new { number = 10 }); } ``` ``` -------------------------------- ### Handle HoloNET Client Connection Event (C#) Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index This snippet shows how to subscribe to and handle the `OnConnected` event. This event fires when the HoloNET client successfully establishes a connection to the Holochain conductor. The `ConnectedEventArgs` provide the `EndPoint` of the conductor. ```csharp holoNETClient.OnConnected += HoloNETClient_OnConnected; private static void HoloNETClient_OnConnected(object sender, ConnectedEventArgs e) { Console.WriteLine(string.Concat("TEST HARNESS: CONNECTED CALLBACK: Connected to ", e.EndPoint)); Console.WriteLine(""); } ``` -------------------------------- ### HoloNETClient Constructors Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Defines various constructors for the HoloNETClient, allowing customization of the Holochain Conductor URI, logging behavior (console, file, colors, custom loggers), and log file paths/names. It supports injecting custom ILogger implementations. ```csharp public HoloNETClient(string holochainConductorURI = "ws://localhost:8888", bool logToConsole = true, bool logToFile = true, string releativePathToLogFolder = "Logs", string logFileName = "HoloNET.log", bool addAdditionalSpaceAfterEachLogEntry = false, bool showColouredLogs = true, ConsoleColor debugColour = ConsoleColor.White, ConsoleColor infoColour = ConsoleColor.Green, ConsoleColor warningColour = ConsoleColor.Yellow, ConsoleColor errorColour = ConsoleColor.Red) public HoloNETClient(ILogger logger, bool alsoUseDefaultLogger = false, string holochainConductorURI = "ws://localhost:8888") public HoloNETClient(ILogger logger, bool alsoUseDefaultLogger = false, string holochainConductorURI = "ws://localhost:8888", bool logToConsole = true, bool logToFile = true, string releativePathToLogFolder = "Logs", string logFileName = "HoloNET.log", bool addAdditionalSpaceAfterEachLogEntry = false, bool showColouredLogs = true, ConsoleColor debugColour = ConsoleColor.White, ConsoleColor infoColour = ConsoleColor.Green, ConsoleColor warningColour = ConsoleColor.Yellow, ConsoleColor errorColour = ConsoleColor.Red) public HoloNETClient(IEnumerable loggers, bool alsoUseDefaultLogger = false, string holochainConductorURI = "ws://localhost:8888") public HoloNETClient(IEnumerable loggers, bool alsoUseDefaultLogger = false, string holochainConductorURI = "ws://localhost:8888", bool logToConsole = true, bool logToFile = true, string releativePathToLogFolder = "Logs", string logFileName = "HoloNET.log", bool addAdditionalSpaceAfterEachLogEntry = false, bool showColouredLogs = true, ConsoleColor debugColour = ConsoleColor.White, ConsoleColor infoColour = ConsoleColor.Green, ConsoleColor warningColour = ConsoleColor.Yellow, ConsoleColor errorColour = ConsoleColor.Red) ``` -------------------------------- ### Connect to Holochain Conductor (C#) Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Establishes a connection to the Holochain conductor and optionally retrieves agent public key and DNA hash. Supports asynchronous and synchronous operations with configurable retrieval modes and fallback mechanisms. ```csharp public async Task ConnectAsync(ConnectedCallBackMode connectedCallBackMode = ConnectedCallBackMode.WaitForHolochainConductorToConnect, RetrieveAgentPubKeyAndDnaHashMode retrieveAgentPubKeyAndDnaHashMode = RetrieveAgentPubKeyAndDnaHashMode.Wait, bool retrieveAgentPubKeyAndDnaHashFromConductor = true, bool retrieveAgentPubKeyAndDnaHashFromSandbox = true, bool automaticallyAttemptToRetrieveFromConductorIfSandBoxFails = true, bool automaticallyAttemptToRetrieveFromSandBoxIfConductorFails = true, bool updateConfigWithAgentPubKeyAndDnaHashOnceRetrieved = true) public void Connect(bool retrieveAgentPubKeyAndDnaHashFromConductor = true, bool retrieveAgentPubKeyAndDnaHashFromSandbox = false, bool automaticallyAttemptToRetrieveFromConductorIfSandBoxFails = true, bool automaticallyAttemptToRetrieveFromSandBoxIfConductorFails = true, bool updateConfigWithAgentPubKeyAndDnaHashOnceRetrieved = true) ``` -------------------------------- ### RetrieveAgentPubKeyAndDnaHash Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Retrieves the AgentPubKey & DnaHash from either the Holochain Conductor or HC Sandbox. It defaults to retrieving from the Conductor first and calls internal methods for conductor and sandbox retrieval. ```APIDOC ## GET /websites/nuget_packages_nextgensoftware_holochain_holonet_orm/RetrieveAgentPubKeyAndDnaHash ### Description This method retrieves the AgentPubKey & DnaHash from either the Holochain Conductor or HC Sandbox based on the provided parameters. It defaults to checking the Conductor first and internally calls methods to retrieve from both the Conductor and Sandbox. ### Method GET ### Endpoint /websites/nuget_packages_nextgensoftware_holochain_holonet_orm/RetrieveAgentPubKeyAndDnaHash ### Parameters #### Query Parameters - **retrieveAgentPubKeyAndDnaHashMode** (enum: Wait, Immediate) - Optional - If set to `Wait` (default), it will await the retrieval completion before returning. If set to `Immediate`, it returns immediately and raises the `OnReadyForZomeCalls` event upon completion. - **retrieveAgentPubKeyAndDnaHashFromConductor** (boolean) - Optional - Set to true to automatically retrieve the AgentPubKey & DnaHash from the Holochain Conductor after connection. Defaults to true. - **retrieveAgentPubKeyAndDnaHashFromSandbox** (boolean) - Optional - Set to true to automatically retrieve the AgentPubKey & DnaHash from the hc sandbox after connection. Defaults to true. - **automaticallyAttemptToRetrieveFromConductorIfSandBoxFails** (boolean) - Optional - If true, it will attempt to retrieve from the Conductor if retrieval from the HC Sandbox fails. Defaults to true. - **automaticallyAttemptToRetrieveFromSandBoxIfConductorFails** (boolean) - Optional - If true, it will attempt to retrieve from the HC Sandbox if retrieval from the Holochain Conductor fails. Defaults to true. - **updateConfigWithAgentPubKeyAndDnaHashOnceRetrieved** (boolean) - Optional - Set to true to automatically update the HoloNETConfig once the DnaHash & AgentPubKey have been retrieved. Defaults to true. ### Request Example ```json { "retrieveAgentPubKeyAndDnaHashMode": "Wait", "retrieveAgentPubKeyAndDnaHashFromConductor": true, "retrieveAgentPubKeyAndDnaHashFromSandbox": true, "automaticallyAttemptToRetrieveFromConductorIfSandBoxFails": true, "automaticallyAttemptToRetrieveFromSandBoxIfConductorFails": true, "updateConfigWithAgentPubKeyAndDnaHashOnceRetrieved": true } ``` ### Response #### Success Response (200) - **AgentPubKey** (string) - The public key of the agent. - **DnaHash** (string) - The hash of the DNA. #### Response Example ```json { "AgentPubKey": "someAgentPubKey", "DnaHash": "someDnaHash" } ``` **NOTE:** If both `retrieveAgentPubKeyAndDnaHashFromConductor` and `retrieveAgentPubKeyAndDnaHashFromSandbox` are true, it will first attempt retrieval from the Conductor. If that fails, it will then attempt retrieval from the hc sandbox command, even if `retrieveAgentPubKeyAndDnaHashFromSandbox` is set to false. ``` -------------------------------- ### Call Zome Function with Type Mapping in C# Source: https://www.nuget.org/packages/NextGenSoftware.Holochain.HoloNET.ORM/index Demonstrates calling a zome function using CallZomeFunctionAsync, specifying the target zome and function, a callback, a return hash, and the C# type for mapping the returned entry data. ```csharp _holoNETClient.CallZomeFunctionAsync("oasis", "get_entry_avatar", ZomeCallback, e.ZomeReturnHash, true, false, typeof(Avatar)); ```