NCache 4.6 - Online Documentation

Sample Implementation of IBridgeConflictResolver Interface

 
The following code is a sample implementation for IBridgeConflictResolver:
 
      To utilize the IBridgeConflictResolver interface, include the following namespace in your application: Alachisoft.NCache.Runtime.Bridge.
 
    public class Resolver : IBridgeConflictResolver
    {
        // If true, logs will be generated
        private bool _enableLogging;
        private TextWriter _textLogger;
 
        public void Dispose()
        {
            if (_enableLogging)
            {
                _textLogger.WriteLine("Closing logger");
                _textLogger.Close();
            }
        }
 
        public void Init(System.Collections.IDictionary parameters)
        {
            //Initialize textWriter
            if (parameters.Contains("logging"))
            {
                _enableLogging = Convert.ToBoolean(parameters["logging"]);
            }
 
            if (_enableLogging)
            {
                _textLogger = new StreamWriter("bridgeResolverLog.txt");
                _textLogger.WriteLine("Initializing bridge Conflict Resolver");
            }
        }
 
        public ConflictResolution Resolve(ProviderBridgeItem oldEntry, ProviderBridgeItem newEntry)
        {
            ConflictResolution conflictResolution = new ConflictResolution();
 
            switch (oldEntry.BridgeItemVersion)
            {
                case BridgeItemVersion.OLD:
                    {
                        conflictResolution.ResolutionAction = ResolutionAction.ReplaceWithNewEntry;
                    }
                    break;
 
                case BridgeItemVersion.LATEST:
                    {
                        conflictResolution.ResolutionAction = ResolutionAction.KeepOldEntry;
                    }
                    break;
 
                case BridgeItemVersion.SAME:
                    {
                        if (oldEntry.OpCode == BridgeItemOpCodes.Remove)
                        {
                            conflictResolution.ResolutionAction = ResolutionAction.ReplaceWithNewEntry;
                        }
                        else
                        {
                            conflictResolution.ResolutionAction = ResolutionAction.KeepOldEntry;
                        }
                    }
                    break;
            }
 
            if (_enableLogging)
                _textLogger.WriteLine("Resolve Key {0} and decision taken {1}", oldEntry.Key, conflictResolution.ResolutionAction.ToString());
 
            return conflictResolution;
        }
    }
 
 
See Also