/// <summary> /// Add a client to subscription list /// </summary> /// <param name="clientId"></param> /// <returns></returns> public AsyncMethodResponse Subscribe(Guid clientId) { try { Guid newClientId = clientId; if (newClientId == Guid.Empty) { newClientId = Guid.NewGuid(); } IServerAdminCallback callback = OperationContext.Current.GetCallbackChannel <IServerAdminCallback>(); ClientProxy clientProxy = new ClientProxy(newClientId, callback); lock (subscribers) { ClientProxy existingClientProxy; if (clientId != Guid.Empty) { subscribers.TryGetValue(clientId, out existingClientProxy); } else { existingClientProxy = null; } if (existingClientProxy == null) { subscribers[newClientId] = clientProxy; } else { existingClientProxy.AssignNewCallback(callback); List <KeyValuePair <PublishEventArgs, PublishEventHandler> > pendingList = existingClientProxy.PopPendingMessageList(); if (pendingList != null) { Dictionary <Guid, ClientProxy> targetClientProxyMap = new Dictionary <Guid, ClientProxy>(); targetClientProxyMap[existingClientProxy.ClientId] = existingClientProxy; foreach (KeyValuePair <PublishEventArgs, PublishEventHandler> pair in pendingList) { Publish(targetClientProxyMap, true, pair.Key, pair.Value); } } } } AsyncMethodResponse response = new AsyncMethodResponse(newClientId, null); return(response); } catch (Exception ex) { AsyncMethodResponse errorResponse = new AsyncMethodResponse(clientId, null); errorResponse.AddError(ex.Message, ErrorCode.Fatal); return(errorResponse); } }
public IServerAdminApi GetServerAdminApi(IServerAdminCallback callback) { _adminCallback = callback; return(_marshaller.Get <IServerAdminApi>()); }
/// <summary> /// /// </summary> /// <param name="callback"></param> public void AssignNewCallback(IServerAdminCallback callback) { this.CallBack = callback; }
//message sequenceId /// <summary> /// /// </summary> /// <param name="clientId"></param> /// <param name="callBack"></param> public ClientProxy(Guid clientId, IServerAdminCallback callBack) { this.ClientId = clientId; this.CallBack = callBack; this.pendingMessageList = new List <KeyValuePair <PublishEventArgs, PublishEventHandler> >(); }