Exemple #1
0
        public Server(Ice.Communicator iceCommunicator, string clientEndpoint, Murmur.ServerPrx proxy, string name)
        {
            Users.CollectionChanged += OnUsersCollectionChanged;
            ServerProxy = proxy;
            Name = name;
            try {
                var servant = new ServerCallback(this);
                var adapter = iceCommunicator.createObjectAdapterWithEndpoints("", clientEndpoint);
                var servantProxy = adapter.addWithUUID(servant);
                ServerCallbackProxy = Murmur.ServerCallbackPrxHelper.checkedCast(servantProxy);
                adapter.activate();

                // TODO: Allow user to provide Ice secret
                var context = new Dictionary<string, string>();
                context["secret"] = "";

                ServerProxy.ice_getConnection().setAdapter(adapter);
                ServerProxy.addCallback(ServerCallbackProxy, context);
                ServerProxy.begin_getUsers().whenCompleted(
                    users => {
                        CompleteGetUsers(users);
                    },
                    e => {
                        System.Diagnostics.Debug.WriteLine("Could not get user dictionary for {0}: {1}", Name, e.ToString());
                    }
                );
            } catch (Ice.Exception e) {
                System.Diagnostics.Debug.WriteLine("Error talking to {0}: {1}", Name, e.ToString());
            }
        }
        // DirectoryI constructor. parent == null indicates root directory.
        public DirectoryI(string name, DirectoryI parent)
        {
            _name = name;
            _parent = parent;
            _id = new Identity();
            _destroyed = false;
            _contents = new Dictionary<string, NodeI>();

            if(parent == null)
            {
                _id.name = "RootDir";
            }
            else
            {
                _id.name = Guid.NewGuid().ToString();
            }
        }
Exemple #3
0
        public void Join(string name, string topic, RoomVersion roomVersion)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentException(Resources.Client_Join_Cannot_be_empty_or_null, "name");

            if (string.IsNullOrEmpty(topic))
                throw new ArgumentException(Resources.Client_Join_Cannot_be_empty_or_null, "topic");

            if (this._lobby == null)
                throw new ApplicationException("Lobby is null");

            ObjectAdapter adapter = this.Communicator.createObjectAdapter(string.Empty);
            this._jobQueue = new JobQueue();
            Listener listener = new ListenerI(this._outputTxtBx, this._jobQueue);
            ObjectPrx listenerPrx = adapter.addWithUUID(listener);
            this._jobQueue.Start();
            adapter.activate();
            this._lobby.ice_getConnection().setAdapter(adapter);

            this._roomAccess = this._lobby.Join(name, topic, listenerPrx.ice_getIdentity());
            this._context = new Dictionary<string, string> { { SESSIONCTXPROP.value, topic }, {AUTHORCTXPROP.value, name} };
        }
Exemple #4
0
 public RoomI(string topic)
 {
     this.Topic = topic;
     this.ListenerPrxs = new Dictionary<string, ListenerPrx>();
 }
Exemple #5
0
 private void CompleteGetUsers(Dictionary<int, Murmur.User> users)
 {
     if (!App.Current.Dispatcher.CheckAccess()) {
         App.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => CompleteGetUsers(users)));
         return;
     }
     foreach (var user in users) {
         CheckedAddUser(user.Value);
     }
 }
        private Dictionary<Identity, ObjectPrx> getPeerProxies(HostAndPort peerHostAndPort, List<Identity> proxyIdentities)
        {
            Dictionary<Identity, ObjectPrx> proxyMap = new Dictionary<Identity, ObjectPrx>();
            if ((proxyIdentities != null) && (proxyIdentities.Count > 0))
            {
                foreach (Identity identity in proxyIdentities)
                {
                    if (identity != null)
                    {
                        ObjectPrx proxy = getPeerProxy(peerHostAndPort, identity);

                        if (proxy != null)
                        {
                            proxyMap.Add(identity, proxy);
                        }
                        else
                        {
                            log("   Ignoring null proxy returned for identity [" + Util.identityToString(identity) + "]");
                        }
                    }
                    else
                    {
                        log("ignoring null identity");
                    }
                }
            }

            return proxyMap;
        }
Exemple #7
0
            private int readInstance(int index, ReadValueCallback cb)
            {
                Debug.Assert(index > 0);

                if(index > 1)
                {
                    if(cb != null)
                    {
                        addPatchEntry(index, cb);
                    }
                    return index;
                }

                push(SliceType.ValueSlice);

                //
                // Get the instance ID before we start reading slices. If some
                // slices are skipped, the indirect instance table are still read and
                // might read other instances.
                //
                index = ++_valueIdIndex;

                //
                // Read the first slice header.
                //
                startSlice();
                string mostDerivedId = _current.typeId;
                Ice.Object v = null;
                while(true)
                {
                    bool updateCache = false;

                    if(_current.compactId >= 0)
                    {
                        updateCache = true;

                        //
                        // Translate a compact (numeric) type ID into a class.
                        //
                        if(_compactIdCache == null)
                        {
                            _compactIdCache = new Dictionary<int, Type>(); // Lazy initialization.
                        }
                        else
                        {
                            //
                            // Check the cache to see if we've already translated the compact type ID into a class.
                            //
                            Type cls = null;
                            _compactIdCache.TryGetValue(_current.compactId, out cls);
                            if(cls != null)
                            {
                                try
                                {
                                    Debug.Assert(!cls.IsAbstract && !cls.IsInterface);
                                    v = (Ice.Object)IceInternal.AssemblyUtil.createInstance(cls);
                                    updateCache = false;
                                }
                                catch(Exception ex)
                                {
                                    throw new NoValueFactoryException("no value factory", "compact ID " +
                                                                      _current.compactId, ex);
                                }
                            }
                        }

                        //
                        // If we haven't already cached a class for the compact ID, then try to translate the
                        // compact ID into a type ID.
                        //
                        if(v == null)
                        {
                            _current.typeId = "";
                            if(_compactIdResolver != null)
                            {
                                try
                                {
                                    _current.typeId = _compactIdResolver(_current.compactId);
                                }
                                catch(Ice.LocalException)
                                {
                                    throw;
                                }
                                catch(System.Exception ex)
                                {
                                    throw new Ice.MarshalException("exception in CompactIdResolver for ID " +
                                                                   _current.compactId, ex);
                                }
                            }

                            if(_current.typeId.Length == 0)
                            {
                                _current.typeId = _stream.instance().resolveCompactId(_current.compactId);
                            }
                        }
                    }

                    if(v == null && _current.typeId.Length > 0)
                    {
                        v = newInstance(_current.typeId);
                    }

                    if(v != null)
                    {
                        if(updateCache)
                        {
                            Debug.Assert(_current.compactId >= 0);
                            _compactIdCache.Add(_current.compactId, v.GetType());
                        }

                        //
                        // We have an instance, get out of this loop.
                        //
                        break;
                    }

                    //
                    // If slicing is disabled, stop unmarshaling.
                    //
                    if(!_sliceValues)
                    {
                        throw new NoValueFactoryException("no value factory found and slicing is disabled",
                                                          _current.typeId);
                    }

                    //
                    // Slice off what we don't understand.
                    //
                    skipSlice();

                    //
                    // If this is the last slice, keep the instance as an opaque
                    // UnknownSlicedValue object.
                    //
                    if((_current.sliceFlags & Protocol.FLAG_IS_LAST_SLICE) != 0)
                    {
                        //
                        // Provide a factory with an opportunity to supply the instance.
                        // We pass the "::Ice::Object" ID to indicate that this is the
                        // last chance to preserve the instance.
                        //
                        v = newInstance(Ice.ObjectImpl.ice_staticId());
                        if(v == null)
                        {
                            v = new Ice.UnknownSlicedValue(mostDerivedId);
                        }

                        break;
                    }

                    startSlice(); // Read next Slice header for next iteration.
                }

                //
                // Unmarshal the instance.
                //
                unmarshal(index, v);

                if(_current == null && _patchMap != null && _patchMap.Count > 0)
                {
                    //
                    // If any entries remain in the patch map, the sender has sent an index for an instance, but failed
                    // to supply the instance.
                    //
                    throw new Ice.MarshalException("index for class received, but no instance");
                }

                if(cb != null)
                {
                    cb(v);
                }
                return index;
            }
Exemple #8
0
            protected Type resolveClass(string typeId)
            {
                Type cls = null;
                if(_typeIdCache == null)
                {
                    _typeIdCache = new Dictionary<string, Type>(); // Lazy initialization.
                }
                else
                {
                    _typeIdCache.TryGetValue(typeId, out cls);
                }

                if(cls == typeof(EncapsDecoder)) // Marker for non-existent class.
                {
                    cls = null;
                }
                else if(cls == null)
                {
                    try
                    {
                        if(_classResolver != null)
                        {
                            cls = _classResolver(typeId);
                            _typeIdCache.Add(typeId, cls != null ? cls : typeof(EncapsDecoder));
                        }
                    }
                    catch(Exception ex)
                    {
                        throw new NoValueFactoryException("no value factory", typeId, ex);
                    }
                }

                return cls;
            }
Exemple #9
0
            protected string readTypeId(bool isIndex)
            {
                if(_typeIdMap == null)
                {
                    _typeIdMap = new Dictionary<int, string>();
                }

                if(isIndex)
                {
                    int index = _stream.readSize();
                    string typeId;
                    if(!_typeIdMap.TryGetValue(index, out typeId))
                    {
                        throw new Ice.UnmarshalOutOfBoundsException();
                    }
                    return typeId;
                }
                else
                {
                    string typeId = _stream.readString();
                    _typeIdMap.Add(++_typeIdIndex, typeId);
                    return typeId;
                }
            }
Exemple #10
0
            protected void addPatchEntry(int index, ReadValueCallback cb)
            {
                Debug.Assert(index > 0);

                //
                // Check if we already unmarshaled the instance. If that's the case,
                // just call the callback and we're done.
                //
                Ice.Object obj;
                if(_unmarshaledMap.TryGetValue(index, out obj))
                {
                    cb(obj);
                    return;
                }

                if(_patchMap == null)
                {
                    _patchMap = new Dictionary<int, LinkedList<ReadValueCallback>>();
                }

                //
                // Add patch entry if the instance isn't unmarshaled yet,
                // the callback will be called when the instance is
                // unmarshaled.
                //
                LinkedList<ReadValueCallback> l;
                if(!_patchMap.TryGetValue(index, out l))
                {
                    //
                    // We have no outstanding instances to be patched for this
                    // index, so make a new entry in the patch map.
                    //
                    l = new LinkedList<ReadValueCallback>();
                    _patchMap.Add(index, l);
                }

                //
                // Append a patch entry for this instance.
                //
                l.AddLast(cb);
            }
Exemple #11
0
 internal EncapsDecoder(InputStream stream, Encaps encaps, bool sliceValues, ValueFactoryManager f,
                        ClassResolver cr)
 {
     _stream = stream;
     _encaps = encaps;
     _sliceValues = sliceValues;
     _valueFactoryManager = f;
     _classResolver = cr;
     _typeIdIndex = 0;
     _unmarshaledMap = new Dictionary<int, Ice.Object>();
 }
Exemple #12
0
 public RoomV2I(string topic)
 {
     this._topic = topic;
     this._listenerPrxs = new Dictionary<string, ListenerPrx>();
 }
Exemple #13
0
 private RoomFactory()
 {
     this._rooms = new Dictionary<string, RoomPrx>();
 }