Esempio n. 1
0
        void HandleNewServerConnected(Connection connection)
        {
            IDomainOfInterest       doi = null;
            IDomainOfResponsibility dor = null;
            Guid syncID = Guid.Empty;

            connection["serverSync.getDoR"]().OnSuccess <string>(delegate(string serializedDoR) {
                dor = StringSerialization.DeserializeObject <IDomainOfResponsibility>(serializedDoR);
                if (doi != null && syncID != Guid.Empty)
                {
                    AddRemoteServer(connection, dor, doi, syncID);
                }
            });

            connection["serverSync.getDoI"]().OnSuccess <string>(delegate(string serializedDoI)
            {
                doi = StringSerialization.DeserializeObject <IDomainOfInterest>(serializedDoI);
                if (dor != null && syncID != Guid.Empty)
                {
                    AddRemoteServer(connection, dor, doi, syncID);
                }
            });

            connection["serverSync.getSyncID"]().OnSuccess <Guid>(delegate(Guid remoteSyncID)
            {
                syncID = remoteSyncID;
                if (dor != null && doi != null)
                {
                    AddRemoteServer(connection, dor, doi, remoteSyncID);
                }
            });
        }
Esempio n. 2
0
        void AddRemoteServer(Connection connection, IDomainOfResponsibility dor, IDomainOfInterest doi, Guid syncID)
        {
            if (syncID == ServerSync.LocalServer.SyncID)
            {
                return;
            }

            var newServer = new RemoteServerImpl(connection, doi, dor, syncID);

            lock (remoteServers)
                remoteServers.Add(connection, newServer);

            if (AddedServer != null)
            {
                AddedServer(this, new ServerEventArgs(newServer));
            }

            connection.Closed += delegate(object sender, EventArgs args)
            {
                lock (remoteServers)
                    remoteServers.Remove(connection);

                if (RemovedServer != null)
                {
                    RemovedServer(this, new ServerEventArgs(newServer));
                }
            };
        }
Esempio n. 3
0
        void HandleNewServerConnected(Connection connection)
        {
            IDomainOfInterest       doi = null;
            IDomainOfResponsibility dor = null;
            Guid syncID = Guid.Empty;

            AttemptedConnections.Add(connection);

            connection["serverSync.getDoR"]().OnSuccess <string>(delegate(string serializedDoR)
            {
                dor = StringSerialization.DeserializeObject <IDomainOfResponsibility>(serializedDoR);
                if (doi != null && syncID != Guid.Empty)
                {
                    AddRemoteServer(connection, dor, doi, syncID);
                }
            }).OnError(m => { Console.WriteLine("Could not retrieve DoR of remote server, reason: " + m); });

            connection["serverSync.getDoI"]().OnSuccess <string>(delegate(string serializedDoI)
            {
                doi = StringSerialization.DeserializeObject <IDomainOfInterest>(serializedDoI);
                if (dor != null && syncID != Guid.Empty)
                {
                    AddRemoteServer(connection, dor, doi, syncID);
                }
            }).OnError(m => { Console.WriteLine("Could not retrieve DoI of remote server, reason: " + m); });;

            connection["serverSync.getSyncID"]().OnSuccess <string>(delegate(string remoteSyncID)
            {
                syncID = new Guid(remoteSyncID);
                if (dor != null && doi != null)
                {
                    AddRemoteServer(connection, dor, doi, syncID);
                }
            }).OnError(m => { Console.WriteLine("Could not retrieve SyncID of remote server, reason: " + m); });;
        }
Esempio n. 4
0
 /// <summary>
 /// Constructs a remote server object.
 /// </summary>
 /// <param name="connection">An established connection to the remote server.</param>
 /// <param name="doi">Remote server's DoI.</param>
 /// <param name="dor">Remote server's DoR.</param>
 /// <param name="syncID">Remote server's SyncID.</param>
 public RemoteServerImpl(Connection connection, IDomainOfInterest doi, IDomainOfResponsibility dor, Guid syncID)
 {
     this.connection = connection;
     this.doi        = doi;
     this.dor        = dor;
     this.syncID     = syncID;
 }
 /// <summary>
 /// Constructs a remote server object.
 /// </summary>
 /// <param name="connection">An established connection to the remote server.</param>
 /// <param name="doi">Remote server's DoI.</param>
 /// <param name="dor">Remote server's DoR.</param>
 /// <param name="syncID">Remote server's SyncID.</param>
 public RemoteServerImpl(Connection connection, IDomainOfInterest doi, IDomainOfResponsibility dor, Guid syncID)
 {
     this.connection = connection;
     this.doi = doi;
     this.dor = dor;
     this.syncID = syncID;
 }
        /// <summary>
        /// Constructs a LocalServerImpl object.
        /// </summary>
        public LocalServerImpl()
        {
            dor = new EmptyDoR();
            doi = new EmptyDoI();
            syncID = Guid.NewGuid();

            server = new KIARAServer(KIARAServerManager.Instance.ServerURI,
                KIARAServerManager.Instance.ServerPort,
                "/serversync/",
                "serverSync.kiara");

            Configuration serverSyncConfig = ConfigurationManager.OpenExeConfiguration(this.GetType().Assembly.Location);
            int syncPort = int.Parse(serverSyncConfig.AppSettings.Settings["serverSyncPort"].Value);
            service = server.StartService(KIARAServerManager.Instance.ServerURI, syncPort, "/", "ws", "fives-json");
            service.OnNewClient += ServerSyncTools.ConfigureJsonSerializer;

            RegisterSyncIDAPI(service);
        }
        void AddRemoteServer(Connection connection, IDomainOfResponsibility dor, IDomainOfInterest doi, Guid syncID)
        {
            if (syncID == ServerSync.LocalServer.SyncID)
                return;

            var newServer = new RemoteServerImpl(connection, doi, dor, syncID);

            lock (remoteServers)
                remoteServers.Add(connection, newServer);

            if (AddedServer != null)
                AddedServer(this, new ServerEventArgs(newServer));

            connection.Closed += delegate(object sender, EventArgs args)
            {
                lock (remoteServers)
                    remoteServers.Remove(connection);

                if (RemovedServer != null)
                    RemovedServer(this, new ServerEventArgs(newServer));
            };
        }