Open topic with navigation

# 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;
               }
           }

© 2018 Micro Focus or one of its affiliates | Send documentation feedback to Micro Focus Close Send documentation feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a web mail client, and send this email to swpdl.idoldocsfeedback@microfocus.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_FT_HTML5_bannerTitle.htm