Esempio n. 1
0
        /// <summary>
        /// Registers a remote object
        /// </summary>
        /// <returns>An awaitable task.</returns>
        /// <param name="item">The remote item.</param>
        public async Task <bool> RegisterRemoteObjectAsync(long id, IRemoteInstance item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            using (await m_lock.LockAsync())
            {
                if (m_remoteHandles.TryGetValue(id, out var tmp))
                {
                    if (tmp != item)
                    {
                        throw new InvalidOperationException("Attempted to register handle with new instance");
                    }
                    return(false);
                }

                if (m_remoteObjects.TryGetValue(item, out var tmpid) && tmpid != id)
                {
                    throw new InvalidOperationException("Attempted to register handle with new instance");
                }

                m_remoteHandles[id]   = item;
                m_remoteObjects[item] = id;
                return(true);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Attempts to get the handle for the local object
        /// </summary>
        /// <returns><c>true</c>, if get local handle was obtained, <c>false</c> otherwise.</returns>
        /// <param name="item">The item to get the handle for.</param>
        /// <param name="id">The handle for the item.</param>
        public bool TryGetRemoteHandle(IRemoteInstance item, out long id)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            return(m_remoteObjects.TryGetValue(item, out id));
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the handle for a remote object
        /// </summary>
        /// <returns>The remote object handle.</returns>
        /// <param name="item">The object to get the handle for.</param>
        public long GetRemoteHandle(IRemoteInstance item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            return(m_remoteObjects[item]);
        }
Esempio n. 4
0
        /// <summary>
        /// Checks if an object is a remote handle
        /// </summary>
        /// <returns><c>true</c>, if the item is registered as a remote item, <c>false</c> otherwise.</returns>
        /// <param name="item">Item.</param>
        public bool IsRemoteObject(IRemoteInstance item)
        {
            if (item == null)
            {
                return(false);
            }

            return(m_remoteObjects.ContainsKey(item));
        }
Esempio n. 5
0
 /// <summary>
 /// Attempts to get the local object with the given handle
 /// </summary>
 /// <returns><c>true</c>, if get remote object was found, <c>false</c> otherwise.</returns>
 /// <param name="id">The handle for the remote object.</param>
 /// <param name="item">The remote object instance.</param>
 public bool TryGetRemoteObject(long id, out IRemoteInstance item)
 {
     return(m_remoteHandles.TryGetValue(id, out item));
 }