ConnectorLib .NET 25.2
ConnectorLib .NET SDK Programming Guide

# Sample Code for the Synchronize Action

The following code sample demonstrates a complete `synchronize` action. The sample uses a directory on the file system to represent a repository.

           using System;
           using System.IO;
           using Autonomy.Connector;

           namespace MyConnectorNamespace
           {
               public class MyConnector : ConnectorBase
               {
                   public MyConnector(IConfig config, ILog log) :
                          base("My Connector")
                   {
                   }

                   public override void Synchronize(ISynchronizeTask task)
                   {
                       MySynchronize mySynchronize = new MySynchronize(task);
                       mySynchronize.Synchronize();
                   }

               }

               public class MySynchronize
               {
                   public MySynchronize(ISynchronizeTask task)
                   {
                       _task = task;
                   }

                   public void Synchronize()
                   {
                       _task.Ingester.AddResultHandler(ResultHandler);

                       string directory = _task.TaskConfig.Read(
    					"Directory", "data");
                       string searchPattern = _task.TaskConfig.Read(
    					"SearchPattern", "*");

                       foreach (string file in Directory.GetFiles(directory,
    					searchPattern, SearchOption.AllDirectories))
                       {
                           if (_task.Stopping()) return;

                           using(IDocInfo doc = DocInfo.Create(_task.TaskConfig,
                                                     file, file, false))
                           {
                               _task.Ingester.Add(doc);
                           }
                       }
                   }

    	        private void ResultHandler(IDocInfo docInfo,
    				IngestTaskType type, bool success)
                   {
                       if (success)
                       {
                           _task.Log.WriteLine(LogLevel.Normal, string.Format(
    						"Document {0}, ingest {1} succeeded!",
    					        docInfo.Document.Reference, type));
                       }
                       else
                       {
                           _task.Log.WriteLine(LogLevel.Error, string.Format(
    						"Ingestion failed for {0}",
    						docInfo.Document.Reference));
                       }
                   }

                   private ISynchronizeTask _task;
               }
           }

Copyright 2025 Open Text
Version 25.2 | Last updated April 2025

Send documentation feedback

Close

Send documentation feedback

To send feedback using your default email client, open an email window.

Otherwise, send your feedback and the information below to MFI-swpdl.idoldocsfeedback@opentext.com.

We appreciate your feedback!

Product: Knowledge Discovery ConnectorLib .NET 25.2

Topic Title: Sample Code for the Synchronize Action