static ReceiveReplyDesigner() { AttributeTableBuilder builder = new AttributeTableBuilder(); Type receiveType = typeof(ReceiveReply); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelationInitializers"), PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor))); var categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(CorrelationsCategoryLabelKey)); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelationInitializers"), categoryAttribute, BrowsableAttribute.Yes, PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor))); categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(MiscellaneousCategoryLabelKey)); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("DisplayName"), categoryAttribute); var descriptionAttribute = new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingValueHint", "<Value to bind>")); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("Content"), categoryAttribute, descriptionAttribute, PropertyValueEditor.CreateEditorAttribute(typeof(ReceiveContentPropertyEditor))); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("Request"), categoryAttribute, PropertyValueEditor.CreateEditorAttribute(typeof(ActivityXRefPropertyEditor))); var advancedAttribute = new EditorBrowsableAttribute(EditorBrowsableState.Advanced); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("Action"), advancedAttribute, categoryAttribute); Action = receiveType.GetProperty("Action").Name; Type receiveMessageContentType = typeof(ReceiveMessageContent); Message = receiveMessageContentType.GetProperty("Message").Name; DeclaredMessageType = receiveMessageContentType.GetProperty("DeclaredMessageType").Name; MetadataStore.AddAttributeTable(builder.CreateTable()); Func <Activity, IEnumerable <ArgumentAccessor> > argumentAccessorGenerator = (activity) => new ArgumentAccessor[] { new ArgumentAccessor { Getter = (ownerActivity) => { ReceiveReply receiveReply = (ReceiveReply)ownerActivity; ReceiveMessageContent content = receiveReply.Content as ReceiveMessageContent; return(content != null ? content.Message : null); }, Setter = (ownerActivity, arg) => { ReceiveReply receiveReply = (ReceiveReply)ownerActivity; ReceiveMessageContent content = receiveReply.Content as ReceiveMessageContent; if (content != null) { content.Message = arg as OutArgument; } }, }, }; ActivityArgumentHelper.RegisterAccessorsGenerator(receiveType, argumentAccessorGenerator); }
/// <summary> /// Sends a message to beam, reports back to the specified function. /// </summary> /// <param name="message">The message.</param> /// <param name="replyFunc">The reply function.</param> public static void SendBeamMessage(BeamMessage message, ReceiveReply replyFunc) { message.id = message.GetHashCode(); _dicReplyFunctions.Add(message.id, replyFunc); var jsonMessage = JsonConvert.SerializeObject(message); _websocket.Send(jsonMessage); }
static ReceiveReply CreateReceiveReply(ModelItem target, object context) { ReceiveReply reply = null; ModelItem send = (ModelItem)context; if (null != send) { Send sendInstance = (Send)send.GetCurrentValue(); string name = null; //if no correlation is set - create one if (null == sendInstance.CorrelatesWith) { Variable handleVariable = null; //first, look for root variable scope ModelItemCollection variableScope = VariableHelper.FindRootVariableScope(send).GetVariableCollection(); if (null != variableScope) { ModelItemCollection correlations = send.Properties["CorrelationInitializers"].Collection; bool hasRequestReplyHandle = false; foreach (ModelItem item in correlations) { if (item.ItemType.IsAssignableFrom(typeof(RequestReplyCorrelationInitializer))) { hasRequestReplyHandle = true; break; } } if (!hasRequestReplyHandle) { //create unique variable name name = variableScope.CreateUniqueVariableName("__handle", 1); //create variable handleVariable = Variable.Create(name, typeof(CorrelationHandle), VariableModifiers.None); //add it to the scope variableScope.Add(handleVariable); //setup correlation ImportDesigner.AddImport(CorrelationHandleTypeNamespace, send.GetEditingContext()); VariableValue <CorrelationHandle> expression = new VariableValue <CorrelationHandle> { Variable = handleVariable }; InArgument <CorrelationHandle> handle = new InArgument <CorrelationHandle>(expression); correlations.Add(new RequestReplyCorrelationInitializer { CorrelationHandle = handle }); } } } //create receive reply reply = new ReceiveReply() { DisplayName = string.Format(CultureInfo.CurrentUICulture, "ReceiveReplyFor{0}", send.Properties["DisplayName"].ComputedValue), Request = (Send)send.GetCurrentValue(), }; } else { MessageBox.Show( (string)StringResourceDictionary.Instance["sendActivityCreateReplyErrorLabel"] ?? "Source 'Send' element not found!", (string)StringResourceDictionary.Instance["MessagingActivityTitle"] ?? "Send", MessageBoxButton.OK, MessageBoxImage.Error); } return(reply); }
static ReceiveReply CreateReceiveReply(ModelItem target, object context) { ReceiveReply reply = null; ModelItem send = (ModelItem)context; if (null != send) { Send sendInstance = (Send)send.GetCurrentValue(); string name = null; //if no correlation is set - create one if (null == sendInstance.CorrelatesWith) { Variable handleVariable = null; //first, look for root variable scope ModelItemCollection variableScope = VariableHelper.FindRootVariableScope(send).GetVariableCollection(); if (null != variableScope) { ModelItemCollection correlations = send.Properties["CorrelationInitializers"].Collection; bool hasRequestReplyHandle = false; foreach (ModelItem item in correlations) { if (item.ItemType.IsAssignableFrom(typeof(RequestReplyCorrelationInitializer))) { hasRequestReplyHandle = true; break; } } if (!hasRequestReplyHandle) { //create unique variable name name = variableScope.CreateUniqueVariableName("__handle", 1); //create variable handleVariable = Variable.Create(name, typeof(CorrelationHandle), VariableModifiers.None); //add it to the scope variableScope.Add(handleVariable); //setup correlation ImportDesigner.AddImport(CorrelationHandleTypeNamespace, send.GetEditingContext()); VariableValue<CorrelationHandle> expression = new VariableValue<CorrelationHandle> { Variable = handleVariable }; InArgument<CorrelationHandle> handle = new InArgument<CorrelationHandle>(expression); correlations.Add(new RequestReplyCorrelationInitializer { CorrelationHandle = handle }); } } } //create receive reply reply = new ReceiveReply() { DisplayName = string.Format(CultureInfo.CurrentUICulture, "ReceiveReplyFor{0}", send.Properties["DisplayName"].ComputedValue), Request = (Send)send.GetCurrentValue(), }; } else { MessageBox.Show( (string)StringResourceDictionary.Instance["sendActivityCreateReplyErrorLabel"] ?? "Source 'Send' element not found!", (string)StringResourceDictionary.Instance["MessagingActivityTitle"] ?? "Send", MessageBoxButton.OK, MessageBoxImage.Error); } return reply; }