Exemplo n.º 1
0
 /// <summary>
 /// Crate an address object from serialized string.
 /// </summary>
 /// <param name="serialized"></param>
 /// <returns></returns>
 public static RemoteObjectAddress Deserialize(string serialized)
 {
     string[] parts = serialized.Split('|');
     ServerAddress serverAddress = ServerAddress.Deserialize(parts[0]);
     int objectID = int.Parse(parts[1]);
     var result = new RemoteObjectAddress(serverAddress, objectID);
     return result;
 }
Exemplo n.º 2
0
        internal static RemoteObjectAddress InternalPublishObject(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (obj is IRemoteObjectProxy)
            {
                var proxy = (IRemoteObjectProxy)obj;
                return proxy.RemoteObjectAddress;
            }

            lock (DataLock)
            {
                if (publishedObjectAdresses.ContainsKey(obj))
                {
                    var result = publishedObjectAdresses[obj];
                    return result;
                }
            }

            if (!isServerRunning)
            {
                StartServer();
            }

            RemoteObjectAddress address;
            lock (DataLock)
            {
                // TODO: This assumes that the objects are never "unpublished"
                // (ie. removed from the collection). In such a case the
                // identifier created this way could collide with an identifier
                // another of another existing published object!
                int objectID = publishedObjectsByID.Count + 1;
                address = new RemoteObjectAddress(ServerAddress, objectID);

                publishedObjectsByID.Add(objectID, obj);
                publishedObjectAdresses.Add(obj, address);
            }

            return address;
        }