private void btSendContext_Click(object sender, EventArgs e) { Button bt = (Button)sender; Wrapper wrapper = (Wrapper)bt.Tag; TextBox tb = mContexts[wrapper.Id]; wrapper.NetworkManager.Localhost.PeerContextLock.Lock(); try { NetworkPeerDataContext data = wrapper.NetworkManager.Localhost.PeerContext; if (data == null) { data = new NetworkPeerDataContext(); } PropertyItem pi = null; if (data.PropertyItems.ContainsKey("TEST")) { pi = data.PropertyItems["TEST"]; pi.Value = tb.Text; } else { pi = new PropertyItem("TEST", tb.Text); data.PropertyItems["TEST"] = pi; } wrapper.NetworkManager.Localhost.PeerContext = data; } finally { wrapper.NetworkManager.Localhost.PeerContextLock.Unlock(); } }
protected virtual ServiceProvider CheckServiceAvailable(INetworkPeer peer) { if (peer == null) { ThrowHelper.ThrowArgumentNullException("peer"); } ServiceProvider result = null; NetworkPeerDataContext context = peer.PeerContext; if (context != null && context.PropertyItems.ContainsKey(Id)) { PropertyItem root = context.PropertyItems[Id]; string contextData = root.Value; if (!string.IsNullOrEmpty(contextData)) { string[] values = contextData.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); if (values.Length > 0) { long priority = 0; int port = 0; if (int.TryParse(values[0], out port) && port >= 0 && port <= 65535) { if (values.Length > 1) { long.TryParse(values[1], out priority); } Dictionary <string, PropertyItem> properties = null; if (root.PropertyItems.Count > 0) { properties = new Dictionary <string, PropertyItem>(root.PropertyItems); } if (mPeersVsProviders.ContainsKey(peer)) { result = mPeersVsProviders[peer]; result.Priority = priority; result.Properties = properties; result.RemoteEndPoint = new AddressEndPoint(peer.Id, port); } else { result = new ServiceProvider(peer, new AddressEndPoint(peer.Id, port), priority, properties); mPeersVsProviders.Add(peer, result); } } } } } return(result); }
public override ManagerStateEnum Stop() { if (this.ManagerState == ManagerStateEnum.Started) { if (LOGGER.IsInfoEnabled) { LOGGER.Info(string.Format("{0}, service stopping...", LOG_PREFIX)); } OnStop(ManagerEventStateEnum.Before); Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContextLock.Lock(); try { NetworkPeerDataContext context = Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContext; if (context != null) { context.PropertyItems.Remove(Id); Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContext = context; } } finally { Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContextLock.Unlock(); } if (ServiceBaseServices.IsContractRegistered(typeof(TIServiceProxyType))) { ServiceBaseServices.UnregisterContract(typeof(TIServiceProxyType)); } this.ManagerState = ManagerStateEnum.Stopped; if (LOGGER.IsInfoEnabled) { LOGGER.Info(string.Format("{0}, service successfully stopped.", LOG_PREFIX)); } OnStop(ManagerEventStateEnum.After); } return(this.ManagerState); }
protected virtual void RegisterToPeerContext(Channel channel, long priority, IServiceDescriptor serviceDescriptor) { if (channel == null) { ThrowHelper.ThrowArgumentNullException("channel"); } Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContextLock.Lock(); try { NetworkPeerDataContext context = Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContext; if (context == null) { context = new NetworkPeerDataContext(); } PropertyItem root = new PropertyItem(Id, string.Format("{0};{1}", channel.ServerEndpoints.ToList <AddressEndPoint>()[0].Port.ToString(), priority.ToString())); if (serviceDescriptor != null) { Dictionary <string, PropertyItem> items = serviceDescriptor.CreateServiceProperty(); if (items != null) { foreach (KeyValuePair <string, PropertyItem> kv in items) { root.PropertyItems.Add(kv.Key, kv.Value); } } } context.PropertyItems[Id] = root; Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContext = context; } finally { Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContextLock.Unlock(); } }