static void Main(string[] args) { Observer mediator = new Observer(); IClassA outputManager = new ClassA(); mediator.SubscribeToObserver(outputManager, outputManager.MessageFromObserver); IClassB dbManager = new ClassB(); mediator.SubscribeToObserver(dbManager, dbManager.MessageFromObserver); IObservableAction observedAction = new ObservableAction(); MessageAction action = new MessageAction { targetByName = nameof(ClassB), command_action = TypeOfObservableAction.InsertData }; observedAction.Actions.Add(action); mediator.TransmitMessage(observedAction); /* * * Equation equation1 = new Equation("$B1", "Sqrt($A1) + Cos($A2)"); * * SpreadsheetInJson ss = new SpreadsheetInJson(); * ss.calcInfo += equation1.ParseExpression; * * ss.RegisterEquation(equation1); * * //Invokes the delegate * ss.NewValue("$A1", 4); * ss.NewValue("$A2", 4); * * Console.WriteLine("{0}",equation1.GetExpression()); * Console.WriteLine("{0}", ss.GetValue("$B1")); */ //Console.WriteLine("{0}", ss.Squared(4)); /* * StringTypes mystring = new StringTypes(new StringBuilderType()); * mystring.Append("Hello World"); * mystring.Append("Hello Boise"); * * Console.WriteLine(mystring.ToString()); * * StringTypes myString2 = new StringTypes(new charType()); * myString2.Append('a'); * myString2.Append('b'); * myString2.Append('c'); * * Console.WriteLine(myString2.ToString()); * * MDArray.MultidimensionalArray(); */ Console.ReadLine(); }
private void DoRegister(ObservableAction action, IActor actor) { if (action.Equals(ObservableAction.Register)) { fCollection.Add(actor); } else { fCollection.Remove(actor); } }
public Task RecordObservableActionAsync(ObservableAction action, Func <Dictionary <string, object> >?getData = null) { if (_targetActions == null || !_targetActions.Contains(action)) { return(Task.CompletedTask); } var data = getData?.Invoke() ?? new Dictionary <string, object>(); data["action"] = action.ToString(); data["instanceId"] = this.Host.GetInstanceId(); data["start"] = this.Host.GetStartTime(); data["name"] = this.Workflow.Name; data["version"] = this.Workflow.Version; data["data"] = this.Data.ToString(); if (!string.IsNullOrWhiteSpace(this.Workflow.Description)) { data["description"] = this.Workflow.Description; } return(this.Host.OnObservableEventAsync(data)); }
public async Task TestObserver() { InvoiceModule invMod = new InvoiceModule(); ContractInvoiceModule contractInvoiceMod = new ContractInvoiceModule(); Customer customer = await invMod.Customer.Query().GetEntityById(9); AddressBook addressBookCustomer = await invMod.AddressBook.Query().GetEntityById(customer?.AddressId); NextNumber nextNumber = await invMod.Invoice.Query().GetNextNumber(); TaxRatesByCode taxRatesByCode = await invMod.TaxRatesByCode.Query().GetEntityById(1); InvoiceView invoiceView = new InvoiceView(); invoiceView.InvoiceDocument = "Inv-99"; invoiceView.InvoiceDate = DateTime.Parse("8/10/2018"); invoiceView.Amount = 1500.0M; invoiceView.CustomerId = customer?.CustomerId; invoiceView.CustomerName = addressBookCustomer?.Name; invoiceView.Description = "VNW Fixed Asset project"; invoiceView.PaymentTerms = "Net 30"; invoiceView.TaxAmount = 0; invoiceView.CompanyId = 1; invoiceView.TaxRatesByCodeId = taxRatesByCode.TaxRatesByCodeId; invoiceView.InvoiceNumber = nextNumber.NextNumberValue; Invoice newInvoice = await invMod.Invoice.Query().MapToEntity(invoiceView); Observer mediator = new Observer(); mediator.SubscribeToObserver(invMod, invMod.MessageFromObserver); mediator.SubscribeToObserver(contractInvoiceMod, contractInvoiceMod.MessageFromObserver); IObservableAction observedAction = new ObservableAction(); MessageAction action = new MessageAction { targetByName = nameof(Invoice), command_action = TypeOfObservableAction.InsertData, Invoice = newInvoice }; observedAction.Actions.Add(action); NextNumber nextNumberContractInvoice = await invMod.ContractInvoice.Query().GetNextNumber(); ContractInvoiceView contractInvoiceView = new ContractInvoiceView { InvoiceId = 5, ContractId = 1, ContractInvoiceNumber = nextNumberContractInvoice.NextNumberValue }; ContractInvoice contractInvoice = await invMod.ContractInvoice.Query().MapToEntity(contractInvoiceView); MessageAction actionContractInvoice = new MessageAction { targetByName = nameof(ContractInvoice), command_action = TypeOfObservableAction.InsertData, ContractInvoice = contractInvoice }; observedAction.Actions.Add(actionContractInvoice); mediator.TransmitMessage(observedAction); if (observedAction.Actions.Count() > 0) { Assert.True(false); } Invoice lookupInvoice = await invMod.Invoice.Query().GetEntityByNumber(invoiceView.InvoiceNumber); lookupInvoice.Amount = 9999; ContractInvoice lookupContractInvoice = await contractInvoiceMod.ContractInvoice.Query().GetEntityByNumber(contractInvoiceView.ContractInvoiceNumber); //*******Contract Invoice MessageAction actionInvoiceUpdate = new MessageAction { targetByName = nameof(Invoice), command_action = TypeOfObservableAction.UpdateData, Invoice = lookupInvoice }; observedAction.Actions.Add(actionInvoiceUpdate); MessageAction actionInvoiceDelete = new MessageAction { targetByName = nameof(Invoice), command_action = TypeOfObservableAction.DeleteData, Invoice = lookupInvoice }; observedAction.Actions.Add(actionInvoiceDelete); MessageAction actionContractInvoiceDelete = new MessageAction { targetByName = nameof(ContractInvoice), command_action = TypeOfObservableAction.DeleteData, ContractInvoice = lookupContractInvoice }; observedAction.Actions.Add(actionContractInvoiceDelete); mediator.TransmitMessage(observedAction); if (observedAction.Actions.Count() > 0) { Assert.True(false); } await Task.Yield(); Assert.True(true); }