예제 #1
0
        public void Delete(string name)
        {
            client.VerifyAccess();

            CollectionEntry entry = null;

            if (this.TryGetValue(name, out entry))
            {
                DeleteCollection(entry, Source.Client);
            }
            else
            {
                // If we have no local record of a collection it may still exist. Send Delete payload
                Payload eventData = new CollectionDeletedPayload(name, this.client.ClientId);
                client.SendPublishEvent(eventData);
            }
        }
예제 #2
0
        /// <summary>
        /// Opens an object with the specified name
        /// </summary>
        /// <param name="name">The object to open</param>
        /// <param name="mode">An ObjectMode value that specifies whether an object is created if one does not exist, and determines whether the contents of existing object is retained or overwritten.</param>
        /// <returns>A shared object with the specified name</returns>
        public T Open <T>(string name, ObjectMode mode, Action <ObjectConnectedEventArgs> callback) where T : INotifyPropertyChanged, new()
        {
            client.VerifyAccess();

            if (mode == ObjectMode.Create || mode == ObjectMode.Truncate)
            {
                throw new ArgumentException("mode", "Create and Truncate are not supported ObjectModes for named objects");
            }

            if (!this.client.IsConnected)
            {
                throw new InvalidOperationException("Cannot open object before the Client is connected");
            }

            if (this.pendingOpenOperations.ContainsKey(name))
            {
                throw new InvalidOperationException("The specified named object is already in the process of being opened");
            }

            ObjectEntry entry = null;

            if (this.ContainsKey(name))
            {
                if (mode != ObjectMode.Open && mode != ObjectMode.OpenOrCreate)
                {
                    throw new ArgumentException("Invalid ObjectMode. Specified object has already been opened on this client. Try using ObjectMode.Open", "mode");
                }

                entry = this[name];
                // Make sure type of object matches T
                if (entry.Type != typeof(T))
                {
                    throw new ArgumentException("Specified type does not match that of existing collection");
                }

                if (callback != null)
                {
                    // If callback was provided, call the opened callback
                    callback(new ObjectConnectedEventArgs(entry.Object, entry.Name, false));
                }
            }
            else
            {
                entry = new ObjectEntry(this.client, name, typeof(T));
                // Add to internal dictionary tracking all the pending open operations
                this.pendingOpenOperations[entry.Name] = new OpenOperation()
                {
                    Entry = entry, Callback = callback
                };

                Payload eventData = new ObjectOpenedPayload(entry.ToPayload(), mode, this.client.ClientId);
                this.client.SendPublishEvent(eventData);

                entry.AddParent(new ParentEntry(this.client.Id, 0));
            }

            return((T)entry.Object);
        }