public void RegisterFeedProviderNullResolverFailureTest() { DataBus db = new DataBus(); const Func <string, IObservable <int> > feedResolver = null; db.RegisterFeedProvider("test", feedResolver); }
private void buttonStartTrace_Click(object sender, EventArgs e) { using (DataBus dataBus = GetDataBus()) { debugEntity = new DebugEntity(); debugEntity.OnTraceChanged += new TraceChangedHandler(DoTraceChanged); debugEntity.InitStack(dataBus); treeViewTraces.Nodes.Clear(); treeViewTraces.Nodes.Add(new TreeNode()); ShowTrace(debugEntity.TopRAD, treeViewTraces.Nodes[0]); currentRADNode = treeViewTraces.Nodes[0]; //Set the current RAD node to the leaf node. while (currentRADNode.Nodes.Count > 0) { currentRADNode = currentRADNode.Nodes[0]; } treeViewTraces.SelectedNode = currentRADNode; clientEverHeld = false; needHoldSMClient = false; if (dataSyncThread.ThreadState == System.Threading.ThreadState.Suspended) { dataSyncThread.Resume(); } } }
public LoginAction(DataBus bus) : base("execute", bus) { IsGzip = true; eventId = 0; type = "detail"; }
static void Main(string[] args) { DataBus bus = null; DependencyResolver.SetDependencyResolver(new NinjectBusDependencyResolver()); try { EndpointConvention.Map <TestMessage>(new Uri("rabbitmq://localhost/testmessage_queue")); MessageCorrelation.UseCorrelationId <TestMessage>(x => x.CorrelationId); bus = new DataBus("domer"); bus.Start(); for (int i = 0; i < MessageCount; i++) { bus.Publish <TestMessage>(new TestMessage() { Message = $"Hello World{i}" }).Wait(); } //Thread.Sleep(TimeSpan.FromSeconds(20)); Console.WriteLine($"Количество обработанных сообщений: {TestMessageHandler.Counter}"); Console.WriteLine($"Время затрачено: {TestMessageHandler.WorkTime}"); Console.ReadLine(); } finally { bus?.Stop(); } }
public void ExceptionHandlingTest() { DataBus db = new DataBus(); db.RegisterFeedProvider <string, string>("channel", context => Observable.Interval(TimeSpan.FromMilliseconds(50)).Select(i => context + i)); ManualResetEvent ev = new ManualResetEvent(false); DataBusUnhandledExceptionEventArgs eventArgs = null; db.UnhandledException += (sender, args) => { eventArgs = args; ev.Set(); }; var ex = new Exception("message"); using (db.Channel <string>("channel").Feed("test").Subscribe(s => { throw ex; })) { Assert.IsTrue(ev.WaitOne(500), "Exception was not handled"); Assert.IsNotNull(eventArgs); Assert.AreEqual("channel", eventArgs.ChannelName, "Channel name was not captured."); Assert.AreEqual(ex, eventArgs.Exception, "Exception was not captured."); } }
public void Invoke(OutgoingContext context, Action next) { if (context.OutgoingLogicalMessage.IsControlMessage()) { next(); return; } var timeToBeReceived = context.OutgoingLogicalMessage.Metadata.TimeToBeReceived; var message = context.OutgoingLogicalMessage.Instance; foreach (var property in Conventions.GetDataBusProperties(message)) { var propertyValue = property.GetValue(message, null); if (propertyValue == null) { continue; } using (var stream = new MemoryStream()) { var dataBusProperty = propertyValue as IDataBusProperty; if (dataBusProperty != null) { propertyValue = dataBusProperty.GetValue(); } DataBusSerializer.Serialize(propertyValue, stream); stream.Position = 0; string headerValue; using (new TransactionScope(TransactionScopeOption.Suppress)) { headerValue = DataBus.Put(stream, timeToBeReceived); } string headerKey; if (dataBusProperty != null) { dataBusProperty.Key = headerValue; //we use the headers to in order to allow the infrastructure (eg. the gateway) to modify the actual key headerKey = headerValue; } else { property.SetValue(message, null, null); headerKey = String.Format("{0}.{1}", message.GetType().FullName, property.Name); } //we use the headers to in order to allow the infrastructure (eg. the gateway) to modify the actual key context.OutgoingLogicalMessage.Headers["NServiceBus.DataBus." + headerKey] = headerValue; } } next(); }
public ExecuteAction(DataBus bus) : base("execute", bus) { IsGzip = true; formName = bus.FormName; ThreadId = bus.ThreadId; }
void TransmittDataBusProperties(string remoteUrl, NameValueCollection headers) { var headersToSend = new NameValueCollection { headers }; foreach (string headerKey in headers.Keys) { if (headerKey.Contains(DATABUS_PREFIX)) { if (DataBus == null) { throw new InvalidOperationException("Can't send a message with a databus property without a databus configured"); } headersToSend[GatewayHeaders.DatabusKey] = headerKey; using (var stream = DataBus.Get(headers[headerKey])) { var buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); MakeHttpRequest(remoteUrl, CallType.DatabusProperty, headersToSend, buffer); } } } }
public T Run <T>(DataBus dataBus, string code) where T : class { //string serializedCode = SerializeCode(code); string serializedCode = code; DebugAction debugAction = new DebugAction(dataBus); debugAction.CommandLine = serializedCode; //string.Format(codeFormat, serializedCode); HttpResponseMessage response = debugAction.DoAction(); Execute excuteObject = debugAction.ResponseData as Execute; ActionUtil.StoreMessages(excuteObject.ClientRequestEntity); while (excuteObject.ClientRequestEntity.Messages.Rearm) { //Get messages MessageResponseAction messageResponseAction = new MessageResponseAction(dataBus); response = messageResponseAction.DoAction(); excuteObject = messageResponseAction.ResponseData as Execute; ActionUtil.StoreMessages(excuteObject.ClientRequestEntity); } if (typeof(T) == typeof(JsonRaw)) { JsonRaw jsonRaw = new JsonRaw(); jsonRaw.Text = excuteObject.ClientRequestEntity.Messages[0].Text; //response. GetContent(); return(jsonRaw as T); } string resultStr = excuteObject.ClientRequestEntity.Messages[0].Text; return(JsonToObject <T>(resultStr)); }
protected override void Init() { Kernel.Register(Component.For <IDataBus>().ImplementedBy <DataBus>().Named("DataBus")); m_Bus = Kernel.Resolve <DataBus>("DataBus"); Kernel.ComponentModelBuilder.AddContributor(new ChannelContributer(m_Bus)); Kernel.Resolver.AddSubResolver(new ChannelResolver(m_Bus)); }
void HandleDatabusProperty(CallInfo callInfo) { if (DataBus == null) { throw new InvalidOperationException("Databus transmission received without a databus configured"); } //todo TimeSpan timeToBeReceived = TimeSpan.FromDays(1); string newDatabusKey; using (var stream = new MemoryStream(callInfo.Buffer)) newDatabusKey = DataBus.Put(stream, timeToBeReceived); using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted, Timeout = TimeSpan.FromSeconds(30) })) { persister.UpdateHeader(callInfo.ClientId, callInfo.Headers[GatewayHeaders.DatabusKey], newDatabusKey); scope.Complete(); } }
public void RegisterFeedProvider_MismatchWithPreviouselyRegisteredChannel_FailureTest() { DataBus db = new DataBus(); db.RegisterFeedProvider <long, string>("test", context => Observable.Empty <long>()); db.RegisterFeedProvider <int, string>("test", context => Observable.Empty <int>()); }
//TODO: replace IKernel with factory public FeedProviderProxy(IKernel container, string key) { _container = container; _key = key; _bus = container.Resolve <DataBus>("DataBus"); container.ComponentDestroyed += KernelOnComponentDestroyed; }
public void Should_not_throw_propertyType_is_not_serializable_if_a_IDataBusSerializer_is_already_registered() { if (!Debugger.IsAttached) { Assert.Ignore("This only work in debug mode."); } var builder = new BusConfiguration(); builder.EndpointName("xyz"); builder.TypesToScan(new[] { typeof(MessageWithNonSerializableDataBusProperty) }); builder.Conventions().DefiningDataBusPropertiesAs(p => p.Name.EndsWith("DataBus")); builder.RegisterComponents(c => { c.RegisterSingleton <IDataBus>(new InMemoryDataBus()); c.ConfigureComponent <IDataBusSerializer>(() => new MyDataBusSerializer(), DependencyLifecycle.SingleInstance); }); var config = builder.BuildConfiguration(); var feature = new DataBus(); Assert.DoesNotThrow(() => feature.CheckPrerequisites(new FeatureConfigurationContext(config))); }
public void InitStack(DataBus dataBus) { DebugAction debugAction = new DebugAction(dataBus); debugAction.CommandLine = "stack"; HttpResponseMessage response = debugAction.DoAction(); Execute excuteObject = debugAction.ResponseData as Execute; //ActionUtil.StoreMessages(excuteObject.ClientRequestEntity); ClientRequest clientRequest = excuteObject.ClientRequestEntity; if (clientRequest != null) { DebugTraceRADCall parentRadCall = new DebugTraceRADCall(); parentRadCall.RADName = clientRequest.Messages.Messages[0].Text; topRAD = parentRadCall; DebugTraceRADCall childRadCall = parentRadCall; for (int i = 1; i < clientRequest.Messages.Messages.Count; i++) { childRadCall = new DebugTraceRADCall(); childRadCall.RADName = clientRequest.Messages.Messages[i].Text; childRadCall.Parent = parentRadCall; parentRadCall.Traces.Add(childRadCall); parentRadCall = childRadCall; } currentRAD = childRadCall; foreach (MessageItem messageItem in clientRequest.Messages.Messages) { radStack.Push(messageItem.Text); } } }
public void MultipleInitializationsRaceConditionTest() { var transportResolver = new TransportResolver(new Dictionary <string, TransportInfo> { { "tr1", new TransportInfo("host", "guest", "guest", null, "InMemory") }, { "tr2", new TransportInfo("host", "guest", "guest", null, "InMemory") } }); var messagingEngine = new MessagingEngine(transportResolver, new ITransportFactory[] { new InMemoryTransportFactory() }); messagingEngine.SerializationManager.RegisterSerializer("txt", typeof(string), new FakeStringSerializer()); var fp1 = new FeedProvider1(messagingEngine); var consoleLogger = new ConsoleLogger(); fp1.Logger = consoleLogger; var fp2 = new FeedProvider2(messagingEngine); fp2.Logger = consoleLogger; var databus = new DataBus(); databus.RegisterFeedProvider("FP1", fp1); databus.RegisterFeedProvider("FP2", fp2); var disposable1 = databus.Channel <string>("FP1").Feed("context1").Subscribe(Console.WriteLine); var disposable2 = databus.Channel <string>("FP2").Feed("context2").Subscribe(Console.WriteLine); Thread.Sleep(10000); disposable1.Dispose(); disposable2.Dispose(); }
public void StatusFlowRepeatsCurrentStatusOnSubscribeTest() { var feedProvider = MockRepository.GenerateMock <IFeedProvider <long, string> >(); feedProvider.Expect(provider => provider.CanProvideFor("context")).IgnoreArguments().Return(true); var feedSource = new Subject <long>(); feedProvider.Expect(provider => provider.CreateFeed("context")).IgnoreArguments() .Return(Observable.Defer(() => feedSource)); var db = new DataBus(200); db.RegisterFeedProvider("feed", feedProvider); var feed = db.Channel <long>("feed").Feed("context"); FeedStatus? latestStatusFlowValue = null; ManualResetEvent statusHandlerCalled = new ManualResetEvent(false); using (feed.Subscribe()) { feedSource.OnNext(1); using (feed.StatusFlow.Subscribe(status => { latestStatusFlowValue = status; statusHandlerCalled.Set(); Console.WriteLine(status); })) { Assert.IsTrue(statusHandlerCalled.WaitOne(200), "Value was not pushed on subscrbe to StatusFlow"); Assert.AreEqual(FeedStatus.Available, latestStatusFlowValue, "Wrong value was pushed on subscrbe to StatusFlow"); } } }
public T RunJSCode <T>(DataBus dataBus, string jscode) where T : class { const string codeFormat = "x js(\"{0}\")"; string serializedCode = SerializeCode(jscode); string formatedCode = string.Format(codeFormat, serializedCode); return(Run <T>(dataBus, formatedCode)); }
internal ChannelDescriptor(DataBus bus, string channelName) { _channelName = string.IsNullOrEmpty(channelName) ? _channelName = typeof(TData).FullName : channelName; _bus = bus; }
private void CreatePackage() { try { if (currentConnectionInfo != null) { SessionCache sessionCache = new SessionCache(); ConnectionSession connectionSession = sessionCache[currentConnectionInfo]; DataBus dataBus = connectionSession.GetDataBus(); if (needCreateAuditlog) { //Generate audit log file. AuditLogInfo auditInfo = GetAuditInfo(dataBus, releaseManagerName); auditInfo.Author = currentConnectionInfo.UserName; auditInfo.Title = auditFileTitle; GenerateAuditLog(auditInfo, auditFileName); } //Create unload record if (needCreateUnloadRecord) { CreateUnloadFile(dataBus, releaseManagerName, unloadName); } //Generate move instruction doc. if (needCreateMoveInstruction) { dataBus = connectionSession.GetDataBus(); //Generate unload script file UnloadScriptFile unloadScriptFile = new UnloadScriptFile(); unloadScriptFile.FileLocation = fileDir; unloadScriptFile.UnloadScriptName = unloadName; unloadScriptFile.GenerateUnloadScript(dataBus); //Create move instruction. MoveInstructionInfo moveInstructionInfo = new MoveInstructionInfo(); moveInstructionInfo.UnloadFileLocation = unloadScriptFile.FileLocation; moveInstructionInfo.Title = textBoxMoveInstructionLocation.Text.Trim(); moveInstructionInfo.Author = currentConnectionInfo.UserName; moveInstructionInfo.Entity = GetUnloadEntity(connectionSession.GetDataBus(), unloadScriptFile.UnloadScriptName); GenerateMoveInstructions(moveInstructionInfo, moveInstructionFileLocation); } } Invoke(new UpdateUI(delegate() { MessageBox.Show("Package Created"); EnableControls(); })); } catch { Invoke(new UpdateUI(delegate() { MessageBox.Show("Create Package Failed, please try again"); EnableControls(); })); } }
private void CreateUnloadFile(DataBus dataBus, string releaseName, string unloadName) { JSCodeRunner codeRunner = new JSCodeRunner(); codeRunner.Include("JSCode\\JsonEncode.js"); codeRunner.Include("JSCode\\CreateUnloadRecord.js"); string codeToRun = " return CreateUnloadRecord(\"" + unloadName + "\",\"" + releaseName + "\");"; JsonRaw unloadEntity = codeRunner.Run <JsonRaw>(dataBus, codeToRun); }
public DataBusTests(ITestOutputHelper output) { // Fixture Setup this.container = TestComponentryContainer.Create(output); this.receiver = new MockComponent(this.container, "1"); this.dataBus = new DataBus <Tick>(this.container); this.receiver.RegisterHandler <Tick>(this.receiver.OnMessage); this.dataBus.Start().Wait(); }
public T RunJSCodeFromFile <T>(DataBus dataBus, string filePath) where T : class { using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { StreamReader reader = new StreamReader(fileStream); string jsCode = reader.ReadToEnd(); reader.Close(); return(RunJSCode <T>(dataBus, jsCode)); } }
public PolicemanViewForm() { InitializeComponent(); this.Text = "Полицейский: " + DataSingleton.GetInstance().CurrentPoliceman.FirstName + " " + DataSingleton.GetInstance().CurrentPoliceman.LastName; pictureAvatar.SizeMode = PictureBoxSizeMode.Zoom; pictureAvatar.Image = DataBus.GetPolicemanImage(DataSingleton.GetInstance().CurrentPoliceman.Rank); textBoxFName.Text = DataSingleton.GetInstance().CurrentPoliceman.FirstName; textBoxLName.Text = DataSingleton.GetInstance().CurrentPoliceman.LastName; textBoxRank.Text = DataSingleton.GetInstance().Ranks[DataSingleton.GetInstance().CurrentPoliceman.Rank]; }
private UnloadEntity GetUnloadEntity(DataBus dataBus, string unloadName) { JSCodeRunner codeRunner = new JSCodeRunner(); codeRunner.Include("JSCode\\JsonEncode.js"); codeRunner.Include("JSCode\\GetUnloadEntity.js"); string codeToRun = " return GetUnloadEntity(\"" + unloadName + "\");"; UnloadEntity unloadEntity = codeRunner.Run <UnloadEntity>(dataBus, codeToRun); return(unloadEntity); }
private Collection <EventMapFieldValue> GetEventValues(DataBus dataBus, string fileName, string queryString, string eventMapName) { JSCodeRunner codeRunner = new JSCodeRunner(); codeRunner.Include("JSCode\\JsonEncode.js"); codeRunner.Include("JSCode\\GetEventInFieldValues.js"); string codeToRun = " return generateEventInFieldValues(\"" + fileName + "\",\"" + queryString + "\",\"" + eventMapName + "\");"; Collection <EventMapFieldValue> fieldValues = codeRunner.Run <Collection <EventMapFieldValue> >(dataBus, codeToRun); return(fieldValues); }
public void Databus_should_not_be_activated_if_no_databus_property_is_found() { var builder = new BusConfiguration(); builder.EndpointName("xyz"); builder.TypesToScan(new[] { typeof(MessageWithoutDataBusProperty) }); var feature = new DataBus(); Assert.False(feature.CheckPrerequisites(new FeatureConfigurationContext(builder.BuildConfiguration())).IsSatisfied); }
public void FeedProvidersRegisteredTwiceFailureTest() { DataBus db = new DataBus(); MyFeedProvider feedProvider1 = new MyFeedProvider(); db.RegisterFeedProvider("MyChannel", feedProvider1); db.RegisterFeedProvider("MyChannel", feedProvider1); db.Channel <string>("MyChannel").Feed(1); }
private AuditLogInfo GetAuditInfo(DataBus dataBus, string releaseName) { JSCodeRunner codeRunner = new JSCodeRunner(); codeRunner.Include("JSCode\\JsonEncode.js"); codeRunner.Include("JSCode\\GetAuditInfo.js"); string codeToRun = " return GetAuditInfo(\"" + releaseName + "\");"; AuditLogInfo auditLogInfo = codeRunner.Run <AuditLogInfo>(dataBus, codeToRun); return(auditLogInfo); }
private Format GetFormatInfo(string formatName, string language) { using (DataBus dataBus = GetDataBus()) { JSCodeRunner codeRunner = new JSCodeRunner(); codeRunner.Include("JSCode\\JsonEncode.js"); codeRunner.Include("JSCode\\GetFormatInfo.js"); string codeToRun = " return GetFormatInfo(\"" + formatName + "\",\"" + language + "\");"; Format format = codeRunner.Run <Format>(dataBus, codeToRun); return(format); } }