public BaseCmd GetCmd(CommandModel model, SendContent receviContent) { Type type = Type.GetType(combinTypeName(model.CustomerCmd.ToString())); BaseCmd baseCmd = (BaseCmd)(Activator.CreateInstance(type, _service, receviContent)); return(baseCmd); }
/// <summary> /// 消息输入框 回车 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { SendContent_Click(sender, e); SendContent.Focus(); } }
public bool Send(string phone, string sms, SmsFormat format) { lock (lockItem) { MakeSureConnection(); sms = sms.Replace("\r\n", ""); string[] contentSet = CutMessageFromContent(sms); if (ChinaMobile && contentSet.Length > 1) { return(SendMobile(phone, sms, format)); } for (int i = 0; i < contentSet.Length; i++) { string content = contentSet[i]; var messageFromat = new SetSmsFromatCommand(format); AbstractCommand resultCommand = Send(messageFromat); if (!resultCommand.Success) { return(false); } var cmgsCommand = new CmgsCommand(); if (format == SmsFormat.Pdu) { var info = new SmsInfo(ServiceCenterNumber, phone, content); int smsLen = 0; content = info.EncodingSMS(out smsLen); cmgsCommand.Argument = string.Format(smsLen.ToString("D2")); } else { cmgsCommand.Argument = phone; } resultCommand = Send(cmgsCommand); if (!resultCommand.Success) { return(false); } var directCommand = new SendContent { Content = content }; resultCommand = Send(directCommand); if (!resultCommand.Success) { return(false); } Thread.Sleep(1000); } Thread.Sleep(1000); } return(true); }
public List <string> SendContentMethod(List <string> strList, string targetId, CustomerCommand command, string message = null, string fromId = null) { SendContent CtoC = new SendContent() { Target = targetId, Message = PublicMethod.JsonSerialize <ReceiveModel>(new ReceiveModel() { Command = command, Message = message, FromId = fromId }), From = Connector.HubToken }; strList.Add(PublicMethod.JsonSerialize <SendContent>(CtoC)); return(strList); }
static WorkflowService GetService() { Variable <string> incomingMessage = new Variable <string> { Name = "inmessage" }; Variable <int> outgoingMessage = new Variable <int> { Name = "outmessage" }; Receive receiveSecureData = new Receive { OperationName = "AskQuestion", ServiceContractName = "ISecuredService", CanCreateInstance = true, Content = ReceiveContent.Create(new OutArgument <string>(incomingMessage)) }; Sequence SecuredWorkFlow = new Sequence() { Variables = { incomingMessage, outgoingMessage }, Activities = { receiveSecureData, new WriteLine { Text = new InArgument <string>(env => ("Message received: " + incomingMessage.Get(env))) }, new SendReply { Request = receiveSecureData, Content = SendContent.Create(new InArgument <int>(4)) } } }; WorkflowService service = new WorkflowService { Name = "SecuredService", Body = SecuredWorkFlow, ConfigurationName = "SecuredService" }; return(service); }
internal List<string> ReNewList(List<string> strList) { var List = _service.Clients.Where(x => x.ClientType == ClientType.List).ToList(); if (List.Count > 0) { foreach (var list in List) { SendContent CtoL = new SendContent() { Target = list.Id, Message = PublicMethod.JsonSerialize<ReceiveModel>(new ReceiveModel() { Command = CustomerCommand.Reload }), From = _service.Connector.HubToken }; strList.Add(PublicMethod.JsonSerialize<SendContent>(CtoL)); } } return strList; }
private bool SendMobile(string phone, string sms, SmsFormat format) { int rem = 0; int count = Math.DivRem(sms.Length, maxSmsLength, out rem); if (rem > 0) { count++; } var messageFromat = new SetSmsFromatCommand(format); AbstractCommand resultCommand = Send(messageFromat); this._log.Debug("Set format command is " + resultCommand.Success); if (!resultCommand.Success) { return(false); } sms = PDUdecoding.EncodingOther(sms); this._log.Debug("send long sms's length " + count); for (int i = 0; i < count; i++) { _log.Info("Send the " + i); string length; string sendMessage = PDUdecoding.EncodingSMS(ServiceCenterNumber, phone, count, i + 1, sms, out length); var cmgs = new CmgsCommand { Argument = length }; Send(cmgs); var directCommand = new SendContent { Content = sendMessage }; var s = Send(directCommand); } return(true); }
static WorkflowService GetService() { Variable <Customer> customer = new Variable <Customer>(); Variable <Order> order = new Variable <Order>(); Variable <string> drug = new Variable <string>(); Variable <double> adjustedCost = new Variable <double>(); Variable <int> percentagePaidByInsurance = new Variable <int>(); Variable <CorrelationHandle> customerHandle = new Variable <CorrelationHandle>(); Variable <CorrelationHandle> orderHandle = new Variable <CorrelationHandle>(); XPathMessageContext pathContext = new XPathMessageContext(); pathContext.AddNamespace("psns", Constants.PharmacyServiceNamespace); // <Snippet2> MessageQuerySet GetOrderQuerySet = new MessageQuerySet { { "OrderID", new XPathMessageQuery("//psns:Order/psns:OrderID", pathContext) } }; // </Snippet2> MessageQuerySet GetOrderIDQuerySet = new MessageQuerySet { { "OrderID", new XPathMessageQuery("//ser:guid", pathContext) } }; MessageQuerySet customerQuerySet = new MessageQuerySet { { "CustomerID", new XPathMessageQuery("//psns:GetBaseCost/psns:Customer/psns:CustomerID", pathContext) } }; MessageQuerySet customerIDQuerySet = new MessageQuerySet { { "CustomerID", new XPathMessageQuery("//ser:guid", pathContext) } }; // This will use implicit correlation within the workflow using the WorkflowServiceHost's default CorrelationHandle // <Snippet3> Receive prescriptionRequest = new Receive { DisplayName = "Request Perscription", OperationName = "GetBaseCost", ServiceContractName = Constants.PharmacyServiceContractName, CanCreateInstance = true, //CorrelatesWith = customerHandle, -- add this line for explicit correlation CorrelatesOn = customerQuerySet, Content = new ReceiveParametersContent { Parameters = { { "Customer", new OutArgument <Customer>(customer) }, { "Drug", new OutArgument <string>(drug) }, } } }; // </Snippet3> // This will use implicit correlation within the workflow using the WorkflowServiceHost's default CorrelationHandle Receive GetInsurancePaymentPercentageRequest = new Receive { DisplayName = "Get Insurance Coverage", ServiceContractName = Constants.PharmacyServiceContractName, OperationName = "GetInsurancePaymentPercentage", CanCreateInstance = true, //CorrelatesWith = customerHandle, -- add this line for explicit correlation CorrelatesOn = customerIDQuerySet, Content = ReceiveContent.Create(new OutArgument <Guid>()) }; // This will explicitly correlate with the SendReply action after the prescriptionRequest using the OrderID (stored in the orderHandle) Receive GetAdjustedCostRequest = new Receive { DisplayName = "Get Adjusted Cost", OperationName = "GetAdjustedCost", ServiceContractName = Constants.PharmacyServiceContractName, CanCreateInstance = true, CorrelatesOn = GetOrderIDQuerySet, CorrelatesWith = orderHandle, Content = ReceiveContent.Create(new OutArgument <Guid>()) }; Activity PrescriptonWorkflow = new Sequence() { Variables = { customer, order, drug, percentagePaidByInsurance, adjustedCost, customerHandle, orderHandle }, Activities = { new WriteLine { Text = "Beginning Workflow" }, new Parallel { Branches = { new Sequence { Activities = { GetInsurancePaymentPercentageRequest, new Assign <int> { To = new OutArgument <int>((e) => percentagePaidByInsurance.Get(e)), Value = new InArgument <int>((e) => new Random().Next(0, 100)) }, new SendReply { DisplayName = "Return Percentage", Request = GetInsurancePaymentPercentageRequest, Content = SendContent.Create(new InArgument <int>((e) => percentagePaidByInsurance.Get(e))) } } }, new Sequence { Activities = { prescriptionRequest, new WriteLine { Text = new InArgument <string>(env => (string.Format("{0}, {1}\t{2}",customer.Get(env).LastName, customer.Get(env).FirstName, customer.Get(env).CustomerID.ToString()))) }, new Assign <Order> { To = new OutArgument <Order>(order), Value = new InArgument <Order>((e) => new Order() { CustomerID = customer.Get(e).CustomerID,Drug = drug.Get(e), OrderID = Guid.NewGuid() }) }, new WriteLine { Text = new InArgument <string>(env => (string.Format("OrderID: {0}",order.Get(env).OrderID.ToString()))) }, new Assign <int> { To = new OutArgument <int>((e) => order.Get(e).Cost), Value = new InArgument <int>((e) => new Random().Next(20, 50)) }, // <Snippet0> new SendReply { DisplayName = "Send Adjusted Cost", Request = prescriptionRequest, // Initialize the orderHandle using the MessageQuerySet to correlate with the final GetAdjustedCost request CorrelationInitializers = { // <Snippet1> new QueryCorrelationInitializer { CorrelationHandle = orderHandle, MessageQuerySet = GetOrderQuerySet } // </Snippet1> }, Content = SendContent.Create(new InArgument <Order>((e) => order.Get(e))) } // </Snippet0> } } } }, new Assign <double> { To = new OutArgument <double>((e) => adjustedCost.Get(e)), Value = new InArgument <double>((e) => order.Get(e).Cost *(100 - percentagePaidByInsurance.Get(e)) * .01) }, new WriteLine { Text = new InArgument <string>(env => (string.Format("Base Cost: ${0}", order.Get(env).Cost.ToString()))) }, new WriteLine { Text = new InArgument <string>(env => (string.Format("Insurance Coverage: {0}%", percentagePaidByInsurance.Get(env).ToString()))) }, new WriteLine { Text = new InArgument <string>(env => (string.Format("Adjusted Cost: ${0}", decimal.Round(Convert.ToDecimal(adjustedCost.Get(env)), 2)))) }, GetAdjustedCostRequest, new SendReply { Request = GetAdjustedCostRequest, Content = SendContent.Create(new InArgument <double>((e) => adjustedCost.Get(e))) }, new WriteLine { Text = "Workflow Completed" } } }; WorkflowService service = new WorkflowService { Name = "PharmacyService", Body = PrescriptonWorkflow, ConfigurationName = "PharmacyService" }; return(service); }
static Activity GetServiceWorkflow() { Variable <PurchaseOrder> po = new Variable <PurchaseOrder>(); Variable <Customer> customer = new Variable <Customer>(); Variable <CorrelationHandle> poidHandle = new Variable <CorrelationHandle>(); Variable <CorrelationHandle> custidHandle = new Variable <CorrelationHandle>(); Variable <bool> complete = new Variable <bool>() { Default = false }; Receive submitPO = new Receive { CanCreateInstance = true, ServiceContractName = Constants.POContractName, OperationName = Constants.SubmitPOName, Content = ReceiveContent.Create(new OutArgument <PurchaseOrder>(po)) // creates a ReceiveMessageContent }; return(new Sequence { Variables = { po, customer, poidHandle, custidHandle, complete }, Activities = { submitPO, new WriteLine { Text = "Received PurchaseOrder" }, new Assign <int> { To = new OutArgument <int>((e) => po.Get(e).Id), Value = new InArgument <int>((e) => new Random().Next()) }, // <Snippet2> new SendReply { Request = submitPO, Content = SendContent.Create(new InArgument <int>((e) => po.Get(e).Id)),// creates a SendMessageContent CorrelationInitializers = { new QueryCorrelationInitializer { // initializes a correlation based on the PurchaseOrder Id sent in the reply message and stores it in the handle CorrelationHandle = poidHandle, MessageQuerySet = new MessageQuerySet { // int is the name of the parameter being sent in the outgoing response { "PoId", new XPathMessageQuery("sm:body()/ser:int",Constants.XPathMessageContext) } } } } }, // </Snippet2> new Parallel { CompletionCondition = complete, Branches = { new While { Condition = true, Body = new Receive { ServiceContractName = Constants.POContractName, OperationName = Constants.UpdatePOName, CorrelatesWith = poidHandle, // identifies that the UpdatePO operation is waiting on the PurchaseOrderId that was used to initialize this handle CorrelatesOn = new MessageQuerySet // the query that is used on an incoming message to find the requisite PurchaseOrderId specified in the correlation { // Id is the name of the incoming parameter within the PurchaseOrder { "PoId", new XPathMessageQuery("sm:body()/defns:PurchaseOrder/defns:Id",Constants.XPathMessageContext) } }, Content = ReceiveContent.Create(new OutArgument <PurchaseOrder>(po)) // creates a ReceiveMessageContent } }, new Sequence { Activities = { new Receive { ServiceContractName = Constants.POContractName, OperationName = Constants.AddCustomerInfoName, Content = ReceiveContent.Create(new OutArgument <PurchaseOrder>(po)), // creates a ReceiveMessageContent CorrelatesWith = poidHandle, // identifies that the AddCustomerInfo operation is waiting on the PurchaseOrderId that was used to initialize this handle CorrelatesOn = new MessageQuerySet // the query that is used on an incoming message to find the requisite PurchaseOrderId specified in the correlation { // Id is the name of the incoming parameter within the PurchaseOrder { "PoId", new XPathMessageQuery("sm:body()/defns:PurchaseOrder/defns:Id", Constants.XPathMessageContext)} }, CorrelationInitializers = { new QueryCorrelationInitializer { // initializes a new correlation based on the CustomerId parameter in the message and stores it in the handle CorrelationHandle = custidHandle, MessageQuerySet = new MessageQuerySet { // CustomerId is the name of the incoming parameter within the PurchaseOrder { "CustId", new XPathMessageQuery("sm:body()/defns:PurchaseOrder/defns:CustomerId", Constants.XPathMessageContext)} } } } }, new WriteLine { Text = "Got CustomerId" }, new Receive { ServiceContractName = Constants.POContractName, OperationName = Constants.UpdateCustomerName, Content = ReceiveContent.Create(new OutArgument <Customer>(customer)), // creates a ReceiveMessageContent CorrelatesWith = custidHandle, // identifies that the UpdateCustomerName operation is waiting on the CustomerId that was used to initialize this handle CorrelatesOn = new MessageQuerySet // the query that is used on an incoming message to find the requisite CustomerId specified in the correlation { // Id is the name of the incoming parameter within the Customer type { "CustId", new XPathMessageQuery("sm:body()/defns:Customer/defns:Id", Constants.XPathMessageContext)} } }, new Assign <bool> { To = new OutArgument <bool>(complete), Value = new InArgument <bool>(true) } } } } }, new WriteLine { Text = new InArgument <string>((e) => string.Format("Workflow completed for PurchaseOrder {0}: {1} {2}s",po.Get(e).Id, po.Get(e).Quantity, po.Get(e).PartName)) }, new WriteLine { Text = new InArgument <string>((e) => string.Format("Order will be shipped to {0} as soon as possible",customer.Get(e).Name)) } } }); }
private static Activity GetApproveExpense(Variable <Expense> expense, Variable <bool> reply) { Receive approveExpense = new Receive { OperationName = "ApproveExpense", CanCreateInstance = true, ServiceContractName = "FinanceService", SerializerOption = SerializerOption.DataContractSerializer, Content = ReceiveContent.Create(new OutArgument <Expense>(expense)) }; approveExpense.KnownTypes.Add(typeof(Travel)); approveExpense.KnownTypes.Add(typeof(Meal)); Activity workflow = new CorrelationScope() { Body = new Sequence { Variables = { expense, reply }, Activities = { approveExpense, new WriteLine { Text = new InArgument <string>(env => ("Expense approval request received")) }, new If { Condition = new InArgument <bool> (env => (expense.Get(env).Amount <= 100)), Then = new Assign <bool> { Value = true, To = new OutArgument <bool>(reply) }, Else = new Assign <bool> { Value = false, To = new OutArgument <bool>(reply) }, }, new If { Condition = new InArgument <bool> (reply), Then = new WriteLine { Text = new InArgument <string>("Expense Approved") }, Else = new WriteLine { Text = new InArgument <string>("Expense Cannot be Approved") }, }, new SendReply { Request = approveExpense, Content = SendContent.Create(new InArgument <bool>(reply)), }, }, } }; return(workflow); }
static Activity GetClientWorkflow() { // <Snippet0> Variable <PurchaseOrder> po = new Variable <PurchaseOrder>(); Variable <Customer> customer = new Variable <Customer>(); Endpoint clientEndpoint = new Endpoint { Binding = Constants.Binding, AddressUri = new Uri(Constants.ServiceAddress) }; Send submitPO = new Send { Endpoint = clientEndpoint, ServiceContractName = Constants.POContractName, OperationName = Constants.SubmitPOName, Content = new SendMessageContent(new InArgument <PurchaseOrder>(po)) }; // </Snippet0> // <Snippet3> return(new Sequence { Variables = { po, customer }, Activities = { new Assign <PurchaseOrder> { To = po, Value = new InArgument <PurchaseOrder>((e) => new PurchaseOrder() { PartName = "Widget", Quantity = 150 }) }, new Assign <Customer> { To = customer, Value = new InArgument <Customer>((e) => new Customer() { Id = 12345678, Name = "John Smith" }) }, new WriteLine { Text = new InArgument <string>((e) => string.Format("Submitting new PurchaseOrder for {0} {1}s", po.Get(e).Quantity, po.Get(e).PartName)) }, new CorrelationScope { Body = new Sequence { Activities = { submitPO, new ReceiveReply { Request = submitPO, Content = ReceiveContent.Create(new OutArgument <int>((e) => po.Get(e).Id)) } } } }, new WriteLine { Text = new InArgument <string>((e) => string.Format("Received ID for new PO: {0}", po.Get(e).Id)) }, new Assign <int> { To = new OutArgument <int>((e) => po.Get(e).Quantity), Value = 250 }, new WriteLine { Text = "Updated PO with new quantity: 250. Resubmitting updated PurchaseOrder based on POId." }, // <Snippet1> new Send { Endpoint = clientEndpoint, ServiceContractName = Constants.POContractName, OperationName = Constants.UpdatePOName, Content = SendContent.Create(new InArgument <PurchaseOrder>(po)) }, // </Snippet1> new Assign <int> { To = new OutArgument <int>((e) => po.Get(e).CustomerId), Value = new InArgument <int>((e) => customer.Get(e).Id) }, new WriteLine { Text = "Updating customer data based on CustomerId." }, new Send { Endpoint = clientEndpoint, ServiceContractName = Constants.POContractName, OperationName = Constants.AddCustomerInfoName, Content = SendContent.Create(new InArgument <PurchaseOrder>(po)) }, new Send { Endpoint = clientEndpoint, ServiceContractName = Constants.POContractName, OperationName = Constants.UpdateCustomerName, Content = SendContent.Create(new InArgument <Customer>(customer)) }, new WriteLine { Text = "Client completed." } } }); // </Snippet3> }
static Activity GetClientWorkflow() { Variable <PurchaseOrder> po = new Variable <PurchaseOrder>(); Variable <OrderStatus> orderStatus = new Variable <OrderStatus>(); Endpoint clientEndpoint = new Endpoint { Binding = Constants.Binding, AddressUri = new Uri(Constants.ServiceAddress) }; Send submitPO = new Send { Endpoint = clientEndpoint, ServiceContractName = Constants.POContractName, OperationName = Constants.SubmitPOName, Content = SendContent.Create(new InArgument <PurchaseOrder>(po)) }; return(new Sequence { Variables = { po, orderStatus }, Activities = { new WriteLine { Text = "Sending order for 150 widgets." }, new Assign <PurchaseOrder> { To = po, Value = new InArgument <PurchaseOrder>((e) => new PurchaseOrder() { PartName = "Widget", Quantity = 150 }) }, new CorrelationScope { Body = new Sequence { Activities = { submitPO, new ReceiveReply { Request = submitPO, Content = ReceiveContent.Create(new OutArgument <int>((e) => po.Get(e).Id)) } } } }, new WriteLine { Text = new InArgument <string>((e) => string.Format("Got PoId: {0}", po.Get(e).Id)) }, new Assign <OrderStatus> { To = orderStatus, Value = new InArgument <OrderStatus>((e) => new OrderStatus() { Id = po.Get(e).Id, Confirmed = true }) }, new Send { Endpoint = clientEndpoint, ServiceContractName = Constants.POContractName, OperationName = Constants.ConfirmPurchaseOrder, Content = SendContent.Create(new InArgument <OrderStatus>(orderStatus)) }, new WriteLine { Text = "The order was confirmed." }, new WriteLine { Text = "Client completed." } } }); }
private static Activity GetApprovePO(Variable <PurchaseOrder> po, Variable <bool> replyPO) { Receive approvePO = new Receive { OperationName = "ApprovePurchaseOrder", CanCreateInstance = true, ServiceContractName = "FinanceService", SerializerOption = SerializerOption.XmlSerializer, Content = ReceiveContent.Create(new OutArgument <PurchaseOrder>(po)) }; Activity workflow = new CorrelationScope() { Body = new Sequence { Variables = { po, replyPO }, Activities = { approvePO, new WriteLine { Text = new InArgument <string>(env => ("Purchase order approval request received")) }, new If { Condition = new InArgument <bool> (env => (po.Get(env).RequestedAmount <= 100)), Then = new Assign <bool> { Value = true, To = new OutArgument <bool>(replyPO) }, Else = new Assign <bool> { Value = false, To = new OutArgument <bool>(replyPO) }, }, new If { Condition = new InArgument <bool> (replyPO), Then = new WriteLine { Text = new InArgument <string>("Purchase Order Approved") }, Else = new WriteLine { Text = new InArgument <string>("Purchase Order Cannot be Approved") }, }, new SendReply { Request = approvePO, Content = SendContent.Create(new InArgument <bool>(replyPO)), }, } } }; return(workflow); }
private static Activity GetPropertyWorkflow() { // Correlation handle used to link operations together Variable <CorrelationHandle> operationHandle = new Variable <CorrelationHandle>(); // The generated property Id Variable <Guid> propertyId = new Variable <Guid>(); // Variable used to indicate that the workflow should finish Variable <bool> finished = new Variable <bool>("Finished", false); Variable <string> address = new Variable <string>(); Variable <string> owner = new Variable <string>(); Variable <double> askingPrice = new Variable <double>(); // Initial receive - this kicks off the workflow Receive receive = new Receive { CanCreateInstance = true, OperationName = "UploadPropertyInformation", ServiceContractName = XName.Get("IProperty", ns), Content = new ReceiveParametersContent { Parameters = { { "address", new OutArgument <string>(address) }, { "owner", new OutArgument <string>(owner) }, { "askingPrice", new OutArgument <double>(askingPrice) } } } }; // Define the local namespace XPathMessageContext messageContext = new XPathMessageContext(); messageContext.AddNamespace("local", ns); // Extracts the guid sent back to the client on the initial response MessageQuerySet extractGuid = new MessageQuerySet { { "PropertyId", new XPathMessageQuery("sm:body()/ser:guid", messageContext) } }; // Extracts the guid sent up with the property image MessageQuerySet extractGuidFromUploadRoomInformation = new MessageQuerySet { { "PropertyId", new XPathMessageQuery(@"sm:body()/local:UploadRoomInformation/local:propertyId", messageContext) } }; // Receive used to indicate that the upload is complete Receive receiveDetailsComplete = new Receive { OperationName = "DetailsComplete", ServiceContractName = XName.Get("IProperty", ns), CorrelatesWith = operationHandle, CorrelatesOn = extractGuid, Content = ReceiveContent.Create(new OutArgument <Guid>(propertyId)) }; Variable <string> roomName = new Variable <string>(); Variable <double> width = new Variable <double>(); Variable <double> depth = new Variable <double>(); // Receive room information Receive receiveRoomInfo = new Receive { OperationName = "UploadRoomInformation", ServiceContractName = XName.Get("IProperty", ns), CorrelatesWith = operationHandle, CorrelatesOn = extractGuidFromUploadRoomInformation, Content = new ReceiveParametersContent { Parameters = { { "propertyId", new OutArgument <Guid>() }, { "roomName", new OutArgument <string>(roomName) }, { "width", new OutArgument <double>(width) }, { "depth", new OutArgument <double>(depth) }, } } }; return(new Sequence { Variables = { propertyId, operationHandle, finished, address, owner, askingPrice }, Activities = { receive, new WriteLine { Text = "Assigning a unique ID" }, new Assign <Guid> { To = new OutArgument <Guid> (propertyId), Value = new InArgument <Guid> (Guid.NewGuid()) }, new WriteLine { Text = new InArgument <string> (env => string.Format("{0} is selling {1} for {2}.\r\nAssigned unique id {3}.",owner.Get(env), address.Get(env), askingPrice.Get(env), propertyId.Get(env))) }, new SendReply { Request = receive, Content = SendContent.Create(new InArgument <Guid> (env => propertyId.Get(env))), CorrelationInitializers = { new QueryCorrelationInitializer { CorrelationHandle = operationHandle, MessageQuerySet = extractGuid } } }, new While { Condition = ExpressionServices.Convert <bool>(env => !finished.Get(env)), Body = new Pick { Branches = { new PickBranch { Variables = { roomName, width,depth }, Trigger = receiveRoomInfo, Action = new WriteLine{ Text = new InArgument <string> (env => string.Format("Room '{0}' uploaded, dimensions {1}W x {2}D",roomName.Get(env), width.Get(env), depth.Get(env))) }, }, new PickBranch { Trigger = receiveDetailsComplete, Action = new Sequence { Activities = { new Assign <bool> { To = new OutArgument <bool>(finished), Value = new InArgument <bool>(true) }, new WriteLine { Text = "Property Details Complete" } } } } } } }, new WriteLine { Text = "Finished!" } } }); }
static Sequence VendorApprovalRequest(Endpoint endpoint) { Variable <VendorRequest> vendor = new Variable <VendorRequest> { Name = "vendor", }; Variable <VendorResponse> result = new Variable <VendorResponse> { Name = "result" }; Send approvedVendor = new Send { ServiceContractName = XName.Get("FinanceService", "http://tempuri.org/"), Endpoint = endpoint, OperationName = "ApprovedVendor", Content = SendContent.Create(new InArgument <VendorRequest>(vendor)), }; Sequence workflow = new Sequence { Variables = { vendor, result }, Activities = { new Assign <VendorRequest> { Value = new InArgument <VendorRequest>((e) => new VendorRequest{ Name = "Vendor1", requestingDepartment = "HR" }), To = new OutArgument <VendorRequest>(vendor) }, new WriteLine { Text = new InArgument <string>("Hello") }, approvedVendor, new ReceiveReply { Request = approvedVendor, Content = ReceiveContent.Create(new OutArgument <VendorResponse>(result)) }, new If { Condition = new InArgument <bool> (env => result.Get(env).isPreApproved), Then = new WriteLine { Text = new InArgument <string>("Vendor Approved") }, Else = new WriteLine { Text = new InArgument <string>("Vendor is not Approved") }, }, } }; return(workflow); }
private Activity InternalImplementation() { Variable <string> requestMessage = new Variable <string> { Name = "requestString" }; Variable <string> replyMessage = new Variable <string> { Name = "replyString" }; Receive receive = new Receive { OperationName = "StartSample", CanCreateInstance = true, Content = ReceiveContent.Create(new OutArgument <string>(requestMessage)), ServiceContractName = "ITransactedReceiveService", }; return(new Sequence { Activities = { new WriteLine { Text = "Service workflow begins." }, new System.ServiceModel.Activities.TransactedReceiveScope { Variables = { requestMessage, replyMessage }, Request = receive, Body = new Sequence { Activities = { new WriteLine { Text = new InArgument <string>("Server side: Receive complete.") }, new WriteLine { Text = new InArgument <string>(new VisualBasicValue <string>() { ExpressionText = "\"Server side: Received = '\" + requestString.toString() + \"'\"" }) }, new PrintTransactionInfo(), new Assign <string> { Value = new InArgument <string>("Server side: Sending reply."), To = new OutArgument <string>(replyMessage) }, new WriteLine { Text = new InArgument <string>("Server side: Begin reply.") }, new SendReply { Request = receive, Content = SendContent.Create(new InArgument <string>(replyMessage)), }, new WriteLine { Text = new InArgument <string>("Server side: Reply sent.") }, }, }, }, new WriteLine { Text = "Server workflow ends." }, }, }); }
public TransHandleCmd(ISupportService service, SendContent receivContent) : base(service, receivContent) { }
public GetQusetionTypeCmd(ISupportService service, SendContent receivContent) : base(service, receivContent) { }
public ReloadCmd(ISupportService service, SendContent receivContent) : base(service, receivContent) { }
public BaseCmd(ISupportService service, SendContent receiveContent) { _service = service as SupportService; _receiveContent = receiveContent; _receiveCmd = PublicMethod.JsonDeSerialize<CommandModel>(_receiveContent.Message); }
public RequirementCmd(ISupportService service, SendContent receivContent) : base(service, receivContent) { }
private static Activity GetApprovedVendor(Variable <VendorRequest> vendor, Variable <VendorResponse> replyVendor) { Receive approvedVendor = new Receive { OperationName = "ApprovedVendor", CanCreateInstance = true, ServiceContractName = "FinanceService", Content = ReceiveContent.Create(new OutArgument <VendorRequest>(vendor)) }; Activity workflow = new CorrelationScope() { Body = new Sequence { Variables = { vendor, replyVendor }, Activities = { approvedVendor, new WriteLine { Text = new InArgument <string>(env => ("Query for approved vendor received")) }, new If { Condition = new InArgument <bool> (env => ((vendor.Get(env).requestingDepartment == "Finance")) || Constants.vendors.Contains(vendor.Get(env).Name)), Then = new Assign <VendorResponse> { Value = new InArgument <VendorResponse>((e) => new VendorResponse { isPreApproved = true }), To = new OutArgument <VendorResponse>(replyVendor) }, Else = new Assign <VendorResponse> { Value = new InArgument <VendorResponse>((e) => new VendorResponse { isPreApproved = false }), To = new OutArgument <VendorResponse>(replyVendor) }, }, new If { Condition = new InArgument <bool> (env => replyVendor.Get(env).isPreApproved), Then = new WriteLine { Text = new InArgument <string>("Vendor is pre-approved") }, Else = new WriteLine { Text = new InArgument <string>("Vendor is not pre-approved") }, }, new SendReply { Request = approvedVendor, Content = SendContent.Create(new InArgument <VendorResponse>(replyVendor)), }, } } }; return(workflow); }
private void GetContent(string text) { SendContent?.Invoke(new { }, text); }
public CloseCmd(ISupportService service, SendContent receivContent) : base(service, receivContent) { }
public Task Send(string content, string connectionId = null) { SendContent value = PublicMethod.JsonDeSerialize <SendContent>(content); if (value == null) { return(Task.CompletedTask); } value.Deliver = String.IsNullOrEmpty(value.Deliver) ? PublicMethod.CombinationString(_baseconnectionHub.HubToken, selfUrl) : value.Deliver; string newContent = PublicMethod.JsonSerialize(value); string[] info = PublicMethod.SplitString(value.Deliver); CacheInfo cache = String.IsNullOrEmpty(connectionId) ? null : HubSelector(value.Target); List <ClientInfo> clients = ClientSelector(info[0], value.Target); if (clients.Count > 0 && !String.IsNullOrEmpty(value.Target)) { foreach (ClientInfo client in clients) { switch (client.ConnectionType) { case ConnectionType.Client: case ConnectionType.Hub: case ConnectionType.Service: sendSignal(newContent, client); break; case ConnectionType.Group: sendGroup(newContent, client, connectionId); break; } } } else if (cache != null) { if (cache.ClientToken != value.From) { ConnectionInfo connection = SubConnection(cache).Result; connection.HubConnection.InvokeAsync("Send", newContent); } } else if (!String.IsNullOrEmpty(value.Target)) { } else { broadcast(newContent, connectionId); } if (_cacheList.Where(x => x.ClientToken == value.From).FirstOrDefault() == null && _List.Where(x => x.ClientToken == value.From).FirstOrDefault() == null && _List.Where(x => x.ClientToken == info[0]).FirstOrDefault() == null) { _cacheList.Add(new CacheInfo() { ClientToken = value.From, Token = info[0], Url = info[1] + "?connectionType=SubHub" }); } return(Task.CompletedTask); }
static Activity GetServiceWorkflow() { Variable <PurchaseOrder> po = new Variable <PurchaseOrder>(); Variable <OrderStatus> orderStatus = new Variable <OrderStatus>(); Variable <CorrelationHandle> poidHandle = new Variable <CorrelationHandle>(); Variable <bool> complete = new Variable <bool>() { Default = false }; Receive submitPO = new Receive { CanCreateInstance = true, ServiceContractName = Constants.POContractName, OperationName = Constants.SubmitPOName, Content = ReceiveContent.Create(new OutArgument <PurchaseOrder>(po)) // creates a ReceiveMessageContent }; return(new Sequence { Variables = { po, orderStatus, poidHandle, complete }, Activities = { submitPO, new WriteLine { Text = "Received Purchase Order" }, new Assign <int> { To = new OutArgument <int>((e) => po.Get(e).Id), Value = new InArgument <int>((e) => new Random().Next()) }, new SendReply { Request = submitPO, Content = SendContent.Create(new InArgument <int>((e) => po.Get(e).Id)),// creates a SendMessageContent CorrelationInitializers = { new QueryCorrelationInitializer { // initializes a correlation based on the PurchaseOrder Id sent in the reply message and stores it in the handle CorrelationHandle = poidHandle, MessageQuerySet = new MessageQuerySet { // Here we use our custom LinqMessageQuery for correlatoin // int is the name of the parameter being sent in the outgoing response { "PoId", new LinqMessageQuery(XName.Get("int",Constants.SerializationNamespace)) } } } } }, new Assign <OrderStatus> { To = orderStatus, Value = new InArgument <OrderStatus>((e) => new OrderStatus() { Confirmed = false }) }, new While // Continue the workflow until the PurchaseOrder is confirmed { Condition = ExpressionServices.Convert <bool>(env => orderStatus.Get(env).Confirmed), Body = new Receive { ServiceContractName = Constants.POContractName, OperationName = Constants.ConfirmPurchaseOrder, CorrelatesWith = poidHandle, // identifies that the ConfirmPurchaseOrder operation is waiting on the PurchaseOrderId that was used to initialize this handle CorrelatesOn = new MessageQuerySet // the query that is used on an incoming message to find the requisite PurchaseOrderId specified in the correlation { // Id is the name of the incoming parameter within the OrderStatus { "PoId",new LinqMessageQuery(XName.Get("Id", Constants.DefaultNamespace)) } }, Content = ReceiveContent.Create(new OutArgument <OrderStatus>(orderStatus)) // creates a ReceiveMessageContent } }, new WriteLine { Text = "Purchase Order confirmed." }, new WriteLine { Text = new InArgument <string>((e) => string.Format("Workflow completed for PurchaseOrder {0}: {1} {2}s",po.Get(e).Id, po.Get(e).Quantity, po.Get(e).PartName)) }, } }); }
static Sequence PurchaseOrderRequest(Endpoint endpoint) { Variable <PurchaseOrder> po = new Variable <PurchaseOrder> { Name = "po" }; Variable <bool> result = new Variable <bool> { Name = "result" }; Send approveExpense = new Send { ServiceContractName = XName.Get("FinanceService", "http://tempuri.org/"), Endpoint = endpoint, OperationName = "ApprovePurchaseOrder", Content = SendContent.Create(new InArgument <PurchaseOrder>(po)), SerializerOption = SerializerOption.XmlSerializer }; Sequence workflow = new Sequence { Variables = { po, result }, Activities = { new Assign <PurchaseOrder> { Value = new InArgument <PurchaseOrder>((e) => new PurchaseOrder{ RequestedAmount = 500, Description = "New PC" }), To = new OutArgument <PurchaseOrder>(po) }, new WriteLine { Text = new InArgument <string>("Hello") }, approveExpense, new ReceiveReply { Request = approveExpense, Content = ReceiveContent.Create(new OutArgument <bool>(result)) }, new If { Condition = new InArgument <bool> (result), Then = new WriteLine { Text = new InArgument <string>("Purchase order Approved") }, Else = new WriteLine { Text = new InArgument <string>("Purchase order Cannot be Approved") }, }, } }; return(workflow); }
public HistoryCmd(ISupportService service, SendContent receivContent) : base(service, receivContent) { }
static Sequence ExpenseRequest(Endpoint endpoint) { Variable <Expense> mealExpense = new Variable <Expense> { Name = "mealExpense", }; Variable <bool> result = new Variable <bool> { Name = "result" }; Send approveExpense = new Send { ServiceContractName = XName.Get("FinanceService", "http://tempuri.org/"), Endpoint = endpoint, OperationName = "ApproveExpense", Content = SendContent.Create(new InArgument <Expense>(mealExpense)) }; approveExpense.KnownTypes.Add(typeof(Travel)); approveExpense.KnownTypes.Add(typeof(Meal)); //<Snippet1> Sequence workflow = new Sequence { Variables = { mealExpense, result }, Activities = { new Assign <Expense> { Value = new InArgument <Expense>((e) => new Meal{ Amount = 50, Location = "Redmond", Vendor = "KFC" }), To = new OutArgument <Expense>(mealExpense) }, new WriteLine { Text = new InArgument <string>("Hello") }, approveExpense, new ReceiveReply { Request = approveExpense, Content = ReceiveContent.Create(new OutArgument <bool>(result)) }, new If { Condition = new InArgument <bool> (result), Then = new WriteLine { Text = new InArgument <string>("Expense Approved") }, Else = new WriteLine { Text = new InArgument <string>("Expense Cannot be Approved") }, }, } }; //</Snippet1> return(workflow); }
public SelectSolutionCmd(ISupportService service, SendContent receivContent) : base(service, receivContent) { }