private void InitiationChannel(string ip, string port, IMessageCallback callback) { try { Uri address = new Uri($"net.tcp://{ip}:{port}/IServiceMessenger"); NetTcpBinding binding = new NetTcpBinding(); binding.MaxReceivedMessageSize = Int32.MaxValue; EndpointAddress endpoint = new EndpointAddress(address); InstanceContext instanceContext = new InstanceContext(callback); DuplexChannelFactory <IServiceMessenger> factory = new DuplexChannelFactory <IServiceMessenger>(instanceContext, binding, endpoint); factory.Closed += FactoryOnClosed; factory.Faulted += FactoryOnClosed; _channel = factory.CreateChannel(); _timer = new Timer(10000); _timer.Enabled = true; _timer.AutoReset = true; _timer.Elapsed += TimerOnElapsed; _lastConnect = DateTime.Now; } catch (Exception ex) { } }
public void Receive(byte[] data, IHeaders headers, IMessageCallback callback) { var envelope = new Envelope(data, headers, callback); Received.Add(envelope); envelope.Callback.MarkSuccessful(); }
public Task Receive(byte[] data, IDictionary <string, string> headers, IMessageCallback callback) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (headers == null) { throw new ArgumentNullException(nameof(headers)); } if (callback == null) { throw new ArgumentNullException(nameof(callback)); } var envelope = new Envelope(data, headers, callback) { ReceivedAt = _address }; // Do keep this here then. envelope.ContentType = envelope.ContentType ?? _node.DefaultContentType ?? _graph.DefaultContentType; return(_pipeline.Invoke(envelope, _node)); }
public Task Receive(object message, IDictionary <string, string> headers, IMessageCallback callback) { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (headers == null) { throw new ArgumentNullException(nameof(headers)); } if (callback == null) { throw new ArgumentNullException(nameof(callback)); } var envelope = new Envelope(headers) { Message = message, Callback = callback }; envelope.ContentType = envelope.ContentType ?? "application/json"; return(_pipeline.Invoke(envelope)); }
/// <summary> /// Create an Envelope for the given callback and raw data /// </summary> /// <param name="data"></param> /// <param name="callback"></param> /// <returns></returns> internal static Envelope ForData(byte[] data, IMessageCallback callback) { return(new Envelope { Data = data, Callback = callback }); }
public ServiceManager(string ip, string port, IMessageCallback callback) { _ip = ip; _port = port; _callback = callback; InitiationChannel(_ip, _port, _callback); }
/// <summary> /// UnRegister a servicetype. /// </summary> /// <param name="serviceType">The given servicetype.</param> public void UnRegister(EServiceType serviceType) { callback = OperationContext.Current.GetCallbackChannel <IMessageCallback>(); loggerPool.Log(serviceType.ServiceType, new LogContentEntity("Unregister!")); callback.Notify(MessageEntity.NormalInfo(serviceType, " Unregister")); Observers.Remove(serviceType, callback); }
public string processDailyTasks(string pathToTempDir, bool useSeperateThread, IMessageCallback msg) { this.myPathToTempDir = pathToTempDir; string retval = ""; string platform = ""; platform = utility.getParameter("platform"); if (platform == "localhost" | platform == "admin_production") { //not possible right now because DTS package can not be changed //if(Request.QueryString["requestor"] != null) //{ //start task expiration emails send_expiration_emails(); msg.AppendLine("expiration emails sent<br>"); ////start task scheduled reporting queue_scheduled_reports(useSeperateThread); msg.AppendLine("scheduled reports sent<br>"); //start task scheduled Master reporting queue_scheduled_masterreports(useSeperateThread); msg.AppendLine("scheduled Master reports sent<br>"); //start task crm_responses process_crm_records(); msg.AppendLine("crm records processed<br>"); //start task delete-archive empty campaigns delete_archive_empty_campaigns(); msg.AppendLine("delete-archive empty campaigns processed<br>"); //start task cid_responses //process_cid_records(); //} //start task cache_hpframes if (cache_hpframes(msg, useSeperateThread)) msg.AppendLine("caching hpframes finished<br>"); else msg.AppendLine("caching some or all hpframes failed!<br>"); } //Added by Phani on 16-04-2009 for RFG 1.9.2 release CaliberRM #PR126953 delete_old_temp_files(myPathToTempDir); msg.AppendLine("temp folder cleaned up<br>"); retval = msg.ToString(); return retval; }
public WsDualClient(string endpointName, IMessageCallback messageCallback) { Guard.IsNull(endpointName); Guard.IsNull(messageCallback); this.m_EndpointName = endpointName; this.m_MessageCallback = messageCallback; InitChannel(); }
public void Receive(byte[] data, IHeaders headers, IMessageCallback callback) { var envelope = new Envelope(data, headers, callback); lock (_received) { _received.Add(envelope); } envelope.Callback.MarkSuccessful(); }
/// <summary> /// Remove a servicetype & callback. /// </summary> /// <param name="serviceType">The given servicetype.</param> /// <param name="callback">The callback instance.</param> public static void Remove(EServiceType serviceType, IMessageCallback callback) { if (Exist(serviceType, callback)) { lock (lockObject) { var tmp = clientList.Find(zw => zw.ServiceType.Equals(serviceType)); tmp.Callbacks.Remove(callback); } } }
/// <summary> /// Check the given servicetype and callback exists whether or not. /// </summary> /// <param name="serviceType">The given servicetype.</param> /// <param name="callback">The callback instance.</param> /// <returns>return true if exists,otherwise return false.</returns> public static bool Exist(EServiceType serviceType, IMessageCallback callback) { lock (lockObject) { var client = clientList.Find(zw => zw.ServiceType.Equals(serviceType)); if (client != null) { return(client.Callbacks.Contains(callback)); } return(false); } }
public void SetUp() { theGraph = new ChannelGraph(); theNode = new ChannelNode(); theNode.Channel = new InMemoryChannel(new Uri("memory://foo")); theInvoker = new RecordingHandlerPipeline(); theCallback = MockRepository.GenerateMock <IMessageCallback>(); theLogger = new RecordingLogger(); theReceiver = new Receiver(theInvoker, theGraph, theNode); }
/// <summary>Remove message callback.</summary> /// <param name="callback">Callback to remove.</param> public void Remove(IMessageCallback callback) { lock (_callbacks) { for (int i = _callbacks.Count - 1; i >= 0; i--) { if (_callbacks[i].Equals(callback)) { _callbacks.RemoveAt(i); } } } }
private static async Task sendToStaticChannel(IMessageCallback callback, Envelope sending, IChannel channel) { sending.Destination = channel.Destination; sending.ReplyUri = channel.ReplyUri; if (callback == null || !callback.SupportsSend && callback.TransportScheme == sending.Destination.Scheme) { await channel.Send(sending).ConfigureAwait(false); } else { await callback.Send(sending).ConfigureAwait(false); } }
private static async Task sendToDynamicChannel(Uri address, IMessageCallback callback, Envelope sending, ITransport transport) { sending.Destination = address; sending.ReplyUri = transport.DefaultReplyUri(); if (callback == null || !callback.SupportsSend && callback.TransportScheme == sending.Destination.Scheme) { await transport.Send(sending, sending.Destination).ConfigureAwait(false); } else { await callback.Send(sending).ConfigureAwait(false); } }
public void Receive(byte[] data, IHeaders headers, IMessageCallback callback) { if (data == null) throw new ArgumentNullException("data"); if (headers == null) throw new ArgumentNullException("headers"); if (callback == null) throw new ArgumentNullException("callback"); var envelope = new Envelope(data, headers, callback) { ReceivedAt = _address }; envelope.ContentType = envelope.ContentType ?? _node.DefaultContentType ?? _graph.DefaultContentType; _pipeline.Receive(envelope); }
public bool Unsubscribe() { try { IMessageCallback callback = OperationContext.Current.GetCallbackChannel <IMessageCallback>(); if (!subscribers.Contains(callback)) { subscribers.Remove(callback); } return(true); } catch { return(false); } }
public string Send(Envelope envelope, IMessageCallback callback) { prepareEnvelopeForSending(envelope); var channels = _router.FindDestinationChannels(envelope).ToArray(); if (!channels.Any()) { throw new Exception("No channels match this message ({0})".ToFormat(envelope)); } channels .Select(x => x.EnvelopeForSending(envelope, _serializer, envelope.ReplyUri)) .Each(callback.Send); return(envelope.CorrelationId); }
public string Send(Envelope envelope, IMessageCallback callback) { prepareEnvelopeForSending(envelope); var channels = _router.FindDestinationChannels(envelope).ToArray(); if (!channels.Any()) { throw new Exception("No channels match this message ({0})".ToFormat(envelope)); } channels .Select(x => x.EnvelopeForSending(envelope, _serializer, envelope.ReplyUri)) .Each(callback.Send); return envelope.CorrelationId; }
public string Send(Envelope envelope, IMessageCallback callback) { var channels = DetermineDestinationChannels(envelope).ToArray(); if (!channels.Any()) { throw new Exception($"No channels match this message ({envelope})"); } foreach (var channel in channels) { var sent = _channels.Send(envelope, channel, _serializer, callback); Logger.Sent(sent); } return(envelope.CorrelationId); }
public bool Subscribe() { try { //Get the hashCode of the connecting app and store it as a connection IMessageCallback callback = OperationContext.Current.GetCallbackChannel <IMessageCallback>(); if (!subscribers.Contains(callback)) { subscribers.Add(callback); } return(true); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
public bool Subscribe(string name) { try { IMessageCallback callback = OperationContext.Current.GetCallbackChannel <IMessageCallback>(); if (!subscribers.ContainsKey(name) && !subscribers.ContainsValue(callback)) { subscribers.Add(name, callback); onlinesList.Add(name); } return(true); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } }
public bool Subscribe() { osae.AddToLog("Attempting to add a subscriber", true); try { IMessageCallback callback = OperationContext.Current.GetCallbackChannel <IMessageCallback>(); if (!subscribers.Contains(callback)) { subscribers.Add(callback); osae.AddToLog("New subscriber: " + callback.ToString(), true); } return(true); } catch { return(false); } }
public void SetUp() { theTransportRegistry = FubuTransportRegistry.Empty(); theTransportRegistry.Handlers.DisableDefaultHandlerSource(); theTransportRegistry.EnableInMemoryTransport(); TestMessageRecorder.Clear(); _invoker = new Lazy <IChainInvoker>(() => { var container = new Container(); theRuntime = FubuTransport.For(theTransportRegistry).StructureMap(container).Bootstrap(); return(container.GetInstance <IChainInvoker>()); }); theCallback = MockRepository.GenerateMock <IMessageCallback>(); theContextIs(); }
protected sealed override void beforeEach() { theData = new byte[] { 1, 2, 3, 4 }; theMessage = new OneMessage(); theCallback = MockFor <IMessageCallback>(); theHeaders = new NameValueHeaders(); theLogger = new RecordingLogger(); theEnvelope = new Envelope(theData, theHeaders, theCallback) { Message = theMessage }; theEnvelope.Message.ShouldBeTheSameAs(theMessage); Services.Inject <ILogger>(theLogger); Services.PartialMockTheClassUnderTest(); theContextIs(); }
/// <summary> /// Add a servicetype & callback. /// </summary> /// <param name="serviceType">The given servicetype.</param> /// <param name="callback">The callback instance.</param> public static void Add(EServiceType serviceType, IMessageCallback callback) { lock (lockObject) { var tmp = clientList.Find(zw => zw.ServiceType.Equals(serviceType)); if (tmp != null) { tmp.Callbacks.Add(callback); } else { clientList.Add(new Client() { ServiceType = serviceType, Callbacks = new List <IMessageCallback>() { callback } }); } } }
public void SetUp() { theTransportRegistry = new FubuRegistry(); theTransportRegistry.ServiceBus.Enable(true); theTransportRegistry.Handlers.DisableDefaultHandlerSource(); theTransportRegistry.ServiceBus.EnableInMemoryTransport(); TestMessageRecorder.Clear(); _invoker = new Lazy <IChainInvoker>(() => { theRuntime = theTransportRegistry.ToRuntime(); return(theRuntime.Get <IChainInvoker>()); }); theCallback = MockRepository.GenerateMock <IMessageCallback>(); theContextIs(); }
protected override void beforeEach() { theChannel = MockFor <IChannel>(); theChannel.Stub(x => x.Address).Return(address); theNode = new ChannelNode { DefaultContentType = "application/json", Channel = theChannel, Uri = address }; Services.Inject(theNode); MockFor <IChainInvoker>().Stub(x => x.Invoke(null)).IgnoreArguments(); theCallback = MockRepository.GenerateMock <IMessageCallback>(); theData = new byte[] { 1, 2, 3 }; theHeaders = new NameValueHeaders(); theHeaders[Envelope.AttemptsKey] = "2"; ClassUnderTest.Receive(theData, theHeaders, theCallback); }
public bool LeaveGame(string user) { try { registedUser = OperationContext.Current.GetCallbackChannel <IMessageCallback>(); notifyList.Remove(user); subscriber.Remove(user); if (!callbacklist.Contains(registedUser)) { callbacklist.Add(registedUser); } callbacklist.ForEach( delegate(IMessageCallback callback) { callback.NotifyUserLeftTheGame(user, subscriber); }); return(true); } catch (Exception) { return(false); } }
public MessengerViewModel(IMessageCallback callback, AuthorizationResult data) { Chats = new ObservableCollection <ChatModel>(); Chats.CollectionChanged += ChatsOnCollectionChanged; MessengerData = new MessengerModel(); var employee = data.Employee; MessengerModels = new ObservableCollection <MessengerModel>(); var emptyPhotoPath = "Images\\emptyImage.png"; if (File.Exists(emptyPhotoPath)) { _emptyPhoto = ImageHelper.GetImage(emptyPhotoPath); } CurrentUser = new UserModel { Login = employee.Login, Name = employee.Name, Surname = employee.Surname, Patronymic = employee.Patronymic, Email = employee.Email, Guid = employee.Guid, Position = employee.Position }; CurrentUser.EmployeePhoto = ImageHelper.ByteToImageSource(employee.Photo) ?? _emptyPhoto; callback.CallbackMessage -= CallbackOnCallbackMessage; callback.NeedUpdateChats -= CallbackOnNeedUpdateChats; callback.CallbackMessage += CallbackOnCallbackMessage; callback.NeedUpdateChats += CallbackOnNeedUpdateChats; var manager = DIFactory.Resolve <IServiceManager>(); manager.Disconnected += ManagerOnDisconnected; }
public Task Receive(byte[] data, IDictionary <string, string> headers, IMessageCallback callback) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (headers == null) { throw new ArgumentNullException(nameof(headers)); } if (callback == null) { throw new ArgumentNullException(nameof(callback)); } var envelope = new Envelope(data, callback) { ReceivedAt = _address }; envelope.ContentType = envelope.ContentType ?? "application/json"; return(_pipeline.Invoke(envelope)); }
public async Task <string> Send(Envelope envelope, IMessageCallback callback) { if (envelope.Message == null) { throw new ArgumentNullException(nameof(envelope.Message)); } envelope.Source = _settings.NodeId; if (envelope.Destination == null) { var routes = await _router.Route(envelope.Message.GetType()); if (!routes.Any()) { Logger.NoRoutesFor(envelope); if (_settings.NoMessageRouteBehavior == NoRouteBehavior.ThrowOnNoRoutes) { throw new NoRoutesException(envelope); } } foreach (var route in routes) { await sendEnvelope(envelope, route, callback); } } else { var route = await _router.RouteForDestination(envelope); await sendEnvelope(envelope, route, callback); } return(envelope.CorrelationId); }
public void Receive(byte[] data, IHeaders headers, IMessageCallback callback) { if (data == null) { throw new ArgumentNullException("data"); } if (headers == null) { throw new ArgumentNullException("headers"); } if (callback == null) { throw new ArgumentNullException("callback"); } var envelope = new Envelope(data, headers, callback) { ReceivedAt = _address }; envelope.ContentType = envelope.ContentType ?? _node.DefaultContentType ?? _graph.DefaultContentType; _pipeline.Receive(envelope); }
public Envelope(byte[] data, IHeaders headers, IMessageCallback callback) : this(headers) { Data = data; Callback = callback; }
public string Send(Envelope envelope, IMessageCallback callback) { Sent.Add(envelope); return envelope.CorrelationId; }
public bool cache_hpframes(IMessageCallback msg, bool useSeparateThread) { try { bool success = true; List<CountryLanguageDto> countryLanguages = HpFramesFacade.GetListOfCountryLanguages(); Dictionary<string, Pair<string, string>> hpFrameChanges = new Dictionary<string, Pair<string, string>>(); int prevMsgIndex = msg.ToString().Length; foreach (CountryLanguageDto item in countryLanguages) { HpFramesDto hpFrames = HpFramesFacade.GetHpFramesFromService(item.CountryFK, item.LanguageFK); if ((hpFrames != null) && HpFramesFacade.StoreHpFramesToCache(hpFrames, hpFrameChanges)) { msg.AppendLine(String.Format("cached frameparts for ({0}-{1})<br>", item.CountryFK, item.LanguageFK)); } else { msg.AppendLine(String.Format("failed: frameparts for ({0}-{1})<br>", item.CountryFK, item.LanguageFK)); if (!string.IsNullOrEmpty(hpFrames.HeaderError)) { msg.AppendLine(String.Format("{0}<br>", hpFrames.HeaderError)); } if (!string.IsNullOrEmpty(hpFrames.FooterError)) { msg.AppendLine(String.Format("{0}<br>", hpFrames.FooterError)); } msg.AppendLine("<br>"); success = false; } } string cachingLog = msg.ToString().Substring(prevMsgIndex); // sent with E-Mail string path = Path.Combine(this.myPathToTempDir, "hpFrames\\"); if (Directory.Exists(path)) { Directory.Delete(path, true); } msg.AppendLine(String.Format("{0} changes found in frameparts.<br>", hpFrameChanges.Count)); StringCollection files = new StringCollection(); foreach (KeyValuePair<string, Pair<string, string>> item in hpFrameChanges) { string FileName = item.Key + ".txt"; string FileNameOld = item.Key + "_old.txt"; string pathFileName = Path.Combine(path, FileName); string pathFileNameOld = Path.Combine(path, FileNameOld); createDir(Path.GetDirectoryName(pathFileName)); string contentOld = fixHtml(item.Value.First); string contentNew = fixHtml(item.Value.Second); using (StreamWriter sw = File.CreateText(pathFileNameOld)) sw.Write(contentOld); msg.AppendLine(String.Format("create temp file: {0}.<br>", pathFileNameOld)); using (StreamWriter sw = File.CreateText(pathFileName)) sw.Write(contentNew); msg.AppendLine(String.Format("create temp file: {0}.<br>", pathFileName)); files.Add(FileNameOld); files.Add(FileName); } try { mailthread.generate_framepartsemail(path, files, cachingLog, useSeparateThread); msg.AppendLine("frameparts change-notification sent!<br>"); } catch (Exception e) { msg.AppendLine(String.Format("frameparts change-notification failed!<br>" + System.Environment.NewLine + "{0}<br>", e.Message)); } return success; } catch (Exception ex) // We do not throw this exception, as access to frameparts webservice may fail due to changes in webservice - this part is not vital for daily business, so it should not interrupt, just notify... { msg.AppendLine(String.Format("caching frameparts failed completely!<br>" + System.Environment.NewLine + "{0}<br>", ex.Message)); return false; } }