示例#1
0
        /// <summary>
        /// Connects to a local instance
        /// </summary>
        /// <param name="targetConnector">Target connector</param>
        /// <param name="token">Token</param>
        /// <returns>Client synchronizer if successful, otherwise "null"</returns>
        public static IClientSynchronizer ConnectToLocalInstance(ILocalConnector targetConnector, string token)
        {
            if (targetConnector == null)
            {
                throw new ArgumentNullException(nameof(targetConnector));
            }
            ILocalConnector     connector = new LocalConnector((_) => true);
            IClientSynchronizer ret       = new ClientSynchronizer(connector.ConnectToLocal(targetConnector), token);

            ret.AddConnector(connector);
            return(ret);
        }
        /// <summary>
        /// Connects to a local instance
        /// </summary>
        /// <param name="targetConnector">Target local connector</param>
        /// <returns>Peer</returns>
        public IPeer ConnectToLocal(ILocalConnector targetConnector)
        {
            if (targetConnector == null)
            {
                throw new ArgumentNullException(nameof(targetConnector));
            }
            if (targetConnector == this)
            {
                throw new ArgumentException("Target connector must be of another instance.", nameof(targetConnector));
            }
            if (!(targetConnector is IInternalLocalConnector target_connector))
            {
                throw new ArgumentException($"Target connector does not inherit from \"{ nameof(IInternalLocalConnector) }\".", nameof(target_connector));
            }
            IInternalLocalPeer ret = new LocalPeer(Guid.NewGuid(), this, target_connector);

            target_connector.RegisterConnectingPeer(ret);
            return(ret);
        }