void CreateChannel(EndpointAddress address, Uri listenUri) { Exception exception = null; try { this.innerChannel = this.discoveryClientChannelBase.innerChannelFactory.CreateChannel( address, listenUri); } catch (ArgumentException argumentException) { exception = argumentException; } catch (InvalidOperationException invalidOperationException) { exception = invalidOperationException; } catch (CommunicationException communicationException) { exception = communicationException; this.CompleteOnce(communicationException); } finally { if (exception != null && TD.InnerChannelCreationFailedIsEnabled()) { TD.InnerChannelCreationFailed(address.ToString(), listenUri.ToString(), exception); } } }
public void OnGUI() { GUILayout.BeginVertical(); if (GUILayout.Button("Connect", GUILayout.Width(200))) { m_TChannel = (TChannel)m_TService.ConnectChannel(NetHelper.ToIPEndPoint("127.0.0.1", 2500)); } if (GUILayout.Button("Send", GUILayout.Width(200))) { using (var mem = new MemoryStream()) { var word_byts = Encoding.UTF8.GetBytes("Hello Udp!"); mem.Write(word_byts, 0, word_byts.Length); mem.Position = 0; m_TChannel.Send(mem); } } if (GUILayout.Button("DisConnect", GUILayout.Width(200))) { m_TChannel.DisConnect(); } if (GUILayout.Button("Dispose", GUILayout.Width(200))) { m_TChannel.Dispose(); } GUILayout.EndVertical(); }
public bool ChannelSave(TChannel Channel) { if (Channel.Id == default) { //执行添加 Channel.Id = Guid.NewGuid(); var userid = Guid.Parse(HttpContext.Session.GetString("userId")); Channel.CreateTime = DateTime.Now; Channel.CreateUserId = userid; Channel.IsDelete = false; db.TChannel.Add(Channel); } else { //执行修改 var dbChannel = db.TChannel.Where(t => t.Id == Channel.Id).FirstOrDefault(); dbChannel.Name = Channel.Name; dbChannel.Remarks = Channel.Remarks; dbChannel.Sort = Channel.Sort; } db.SaveChanges(); return(true); }
public static TChannel OpenPeerChannel <TService, TChannel>() where TChannel : IClientChannel { var portnumber = DeNSo.Configuration.Extensions.P2P().NetworkPort; NetPeerTcpBinding binding = new NetPeerTcpBinding() { Port = portnumber, Name = GetURI().OriginalString + "@" + portnumber, }; binding.Security.Mode = SecurityMode.None; EndpointAddress address = new EndpointAddress(GetURI().OriginalString); ChannelFactory <TChannel> sourceFactory = new ChannelFactory <TChannel>(binding, address); //sourceFactory.Credentials.Peer.MeshPassword = DeNSo.Configuration.Extensions.P2P().NetworkPassword; TChannel sourceProxy = (TChannel)sourceFactory.CreateChannel(); MessagePropagationFilter remoteOnlyFilter = new MessagePropagationFilter(); PeerNode peerNode = ((IClientChannel)sourceProxy).GetProperty <PeerNode>(); //peerNode.MessagePropagationFilter = remoteOnlyFilter; sourceProxy.Open(); return(sourceProxy); }
/// <summary> /// Initializes a new instance of the <see cref="UaChannelAsyncResult"/> class. /// </summary> /// <param name="channel">The channel.</param> /// <param name="callback">The callback.</param> /// <param name="callbackData">The callback data.</param> public UaChannelAsyncResult( TChannel channel, AsyncCallback callback, object callbackData) : base(callback, callbackData, 0) { m_channel = channel; }
/// <summary> /// 断开连接 /// </summary> public void DisconnectServer() { State = ENetworkState.Disconnect; if (_channel != null) { _server.ReleaseChannel(_channel); _channel = null; } }
/// <summary> /// Initializes a new instance of the <see cref="Channel"/> class. /// </summary> /// <param name="channel">The channel.</param> public Channel(TChannel channel) { _applicationId = channel.Id; FirstName = channel.FirstName; LastName = channel.LastName; Username = channel.Title; IsSolo = channel.Type == ChatType.Private; Application = TelegramApplication.Application.Instance; }
/// <summary> /// Initializes a new instance of the <see cref="Channel"/> class. /// </summary> /// <param name="channel">The channel.</param> public Channel(TChannel channel) { ApplicationId = channel.ID; FirstName = channel.Name; LastName = channel.Topic; Username = channel.Parent.Name; IsSolo = false; _application = DiscordApplication.Application.Instance; }
private static Channel Parse(TChannel chat) { var appChat = new Channel() { Id = chat.Id, Title = chat.Title, CreateDate = Instant.FromUnixTimeSeconds(chat.Date).ToDateTimeUtc() }; return(appChat); }
private void OnConnectServer(TChannel channel, SocketError error) { LogSystem.Log(ELogType.Log, $"Server connect result : {error}"); if (error == SocketError.Success) { _channel = channel; State = ENetworkState.Connected; } else { State = ENetworkState.Disconnect; } }
public TChannel CreateLocalChannel <TChannel>() { ChannelFactory <TChannel> channelFactory = new ChannelFactory <TChannel>(localBinding, localWorkflowAddress); TChannel channel = channelFactory.CreateChannel(); IDictionary <string, string> context = ContextManager.DepersistContext(contextFileName); if (context != null && context.Count > 0) { ContextManager.ApplyContextToChannel(context, (IClientChannel)channel); recoveredContext = true; // register handlers to cleanup context file when Workflow completes or terminates. this.Description.Behaviors.Find <WorkflowRuntimeBehavior>().WorkflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { ContextManager.DeleteContext(contextFileName); }; this.Description.Behaviors.Find <WorkflowRuntimeBehavior>().WorkflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { ContextManager.DeleteContext(contextFileName); }; } return(channel); }
/// <summary> /// 创建一个指定类型的通道 /// </summary> /// <typeparam name="TChannel">WCF接口类型</typeparam> /// <returns></returns> public static TChannel GetChannel <TChannel>() { try { string endPointConfigName = typeof(TChannel).Name; if (Channels.ContainsKey(endPointConfigName)) { return((TChannel)Channels[endPointConfigName]); } ChannelFactory <TChannel> channelFactory = new ChannelFactory <TChannel>(endPointConfigName); TChannel channel = channelFactory.CreateChannel(); Channels.Add(endPointConfigName, channel); return(channel); } catch (Exception ex) { throw ex; } }
public CloseAsyncResult(TChannel innerChannel, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { this.innerChannel = innerChannel; if (this.innerChannel != null) { IAsyncResult closeResult = this.innerChannel.BeginClose( timeout, PrepareAsyncCompletion(new AsyncCompletion(OnCloseCompleted)), this); if (closeResult.CompletedSynchronously && OnCloseCompleted(closeResult)) { this.Complete(true); } } else { this.Complete(true); } }
public TcpSocketChannelConfig(TChannel channel, Socket javaSocket) : base(channel, javaSocket) { CalculateMaxBytesPerGatheringWrite(); }
/// <summary> /// Initializes a new instance of the <see cref="WcfChannelAsyncResult"/> class. /// </summary> /// <param name="channel">The channel.</param> /// <param name="callback">The callback.</param> /// <param name="callbackData">The callback data.</param> public WcfChannelAsyncResult( TChannel channel, AsyncCallback callback, object callbackData) : base(callback, callbackData, 0) { m_channel = channel; }
public TransientErrorCallbackStrategy(TChannel channel, Func <Exception, bool> transientCheckFunc) { this.channel = channel; this.transientCheckFunc = transientCheckFunc; }
internal static async Task SendMessage(TMessage message, List <ChannelConnection> c, TChannel chan) { foreach (var conn in c) { Queue.Enqueue(new MessageQueue { Message = message, C = conn, Chan = chan }); } if (!isProcessing) { StartProcessing(); } }
public virtual void Initialize(IChannel channel) { _channel = (TChannel)channel; _ = Interlocked.Exchange(ref _outboundBuffer, new ChannelOutboundBuffer(channel)); }
internal static async Task SendMessage(TMessage message, ChannelConnection c, TChannel chan) { try { //var channel = Client.Guilds.First(x => x.TextChannels.Any(t => t.Id == c.DiscordChannelId)).TextChannels.FirstOrDefault(x => x.Id == c.DiscordChannelId); var text = ""; if (c.ShowName) { text = chan.Title + " posted:" + Environment.NewLine; } text += message.Message; if (message.Entities?.Any(x => x is TMessageEntityTextUrl) ?? false) { var urls = message.Entities.Where(x => x is TMessageEntityTextUrl).Cast <TMessageEntityTextUrl>().OrderByDescending(x => x.Offset); foreach (var u in urls) { text = text.Insert(u.Offset + u.Length, $" ({(u.Url.StartsWith("http") ? u.Url : "http://" + u.Url)}) "); } } if (message.Entities?.Any(x => x is TMessageEntityUrl) ?? false) { var urls = message.Entities.Where(x => x is TMessageEntityUrl).Cast <TMessageEntityUrl>().OrderByDescending(x => x.Offset); foreach (var u in urls) { //get original text var tu = message.Message.Substring(u.Offset, u.Length); if (!tu.StartsWith("http")) { text = text.Replace(tu, "http://" + tu); } } } if (message.Entities?.Any(x => x is TMessageEntityTextUrl || x is TMessageEntityUrl) ?? false) { if (!c.AllowUrls) { Log.WriteLine("Message has a link: " + text + "\r\nnot sending"); return; } } if (message.Media == null || message.Media is TMessageMediaWebPage) { Log.WriteLine("Posting " + text + " to " + c.DiscordChannelName); //using (var w = new DiscordWebhookClient(c.DiscordHookId, c.DiscordHookToken, new DiscordRestConfig { LogLevel = LogSeverity.Verbose })) //{ await Post((c.Everyone ? "@everyone " : "") + text, c.DiscordHookToken, c.DiscordHookId); //await w.SendMessageAsync((c.Everyone ? "@everyone " : "") + text, options: new RequestOptions { RetryMode = RetryMode.AlwaysRetry }); //} //await channel.SendMessageAsync((c.Everyone ? "@everyone " : "") + text); } else { if (message.Media is TMessageMediaPhoto mp) { try { Log.WriteLine("Message is photo"); var p = mp.Photo as TPhoto; var s = p.Sizes.Where(x => x is TPhotoSize).Cast <TPhotoSize>().OrderByDescending(x => x.Size).First(); var l = s.Location as TFileLocation; byte[] file = null; var tries = 1; while (file == null && tries <= 5) { try { file = await Telegram.clientApi.FileService.DownloadFullFileAsync(new TInputFileLocation { LocalId = l.LocalId, Secret = l.Secret, VolumeId = l.VolumeId }); } catch (Exception e) { while (e.InnerException != null) { e = e.InnerException; } Log.WriteLine("Error downloading photo, trying again....\r\n" + e.Message); await Task.Delay(1000); tries++; } } if (tries == 5 || file == null) { Log.WriteLine($"Attempted {tries} tries to download the file, unable. Skipping."); return; } var name = $"photo_{DateTime.Now:yyyy-MM-dd_hh-mm-ss}.jpg"; Log.WriteLine($"Posting photo {name} to {c.DiscordChannelName} with text {text}"); //var w = new DiscordWebhookClient(c.DiscordHookId, c.DiscordHookToken); await Post((c.Everyone ? "@everyone " : "") + text, c.DiscordHookToken, c.DiscordHookId, new MemoryStream(file), name); //await w.SendFileAsync(new MemoryStream(file), name, text, options: new RequestOptions { RetryMode = RetryMode.AlwaysRetry }); //await channel.SendFileAsync(new MemoryStream(file), name, (c.Everyone ? "@everyone " : "") + text); } catch (AggregateException e) { Log.WriteLine(e.InnerException.Message); //MessageBox.Show(e.InnerException.Message); } catch (Exception e) { Log.WriteLine(e.Message); //MessageBox.Show(e.InnerException.Message); } } } } catch (AggregateException e) { Log.WriteLine($"ERROR!!\r\n{e.InnerException.Message}\r\n{e.InnerException.StackTrace}"); } catch (Exception e) { Log.WriteLine($"ERROR!!\r\n{e.Message}\r\n{e.StackTrace}"); } }
private void DownloadChannel(TChannel channel) { channel.DownloadCompleted += new EventHandler <ItemsDownloadedEventArgs>(Channel_DownloadCompleted); channel.DownloadItemsAsync(); }
public RpcChannelWrapper(RpcChannel <TChannel> rpcChannel, TChannel channel) { _rpcChannel = rpcChannel; _channel = channel; }