Inheritance: MonoBehaviour
 public bool DeleteReceive(Receive entity)
 {
     if (entity == null) return false;
     _unitOfWork.ReceiveRepository.Delete(entity);
     _unitOfWork.Save();
     return true;
 }
Ejemplo n.º 2
0
 static void Main()
 {
     // mimics Arduino calling structure
     var receive = new Receive {RunLoop = true};
     receive.Setup();
     while (receive.RunLoop) receive.Loop();
     receive.Exit();
 }
Ejemplo n.º 3
0
 protected override bool AroundReceive(Receive receive, object message)
 {
     if (message is TestRequest)
     {
         Sender.Tell(_testValue);
         return true;
     }
     else return base.AroundReceive(receive, message);
 }
Ejemplo n.º 4
0
        public SynChatThinclient()
        {
            InitializeComponent();

            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);   // Create the Socket
            // Try to connect and send the port request command
            _socket.Connect(IPAddress.Parse(RemoteAddress), port);

            Thread lis = new Thread(new ThreadStart(Listener));
            lis.IsBackground = true;
            lis.Start();

            OnReceive += new Receive(Received_msg);
        }
Ejemplo n.º 5
0
        private string RemoteAddress = Properties.Settings.Default.server_ip; // Define Network Propertys (ServerIP and commandport)

        #endregion Fields

        #region Constructors

        public SynChat()
        {
            InitializeComponent();
            // Clear all indices in chat marker array
            for(int i=0; i < 10; i++)
            {
                freechats[i] = true;
                chatbuddies[i] = "";
            }

            // Marrie the delegates with their events (needed for invokes)
            OnReceiveBuddy += new Buddy(ReceiveBuddy);
            EnableItems += new Enable(Enable_Items);
            OnReceive += new Receive(OpenChat);
            OnStatusChange += new BuddyStatus(StatusChange);
            OnStatusReceived += new RequestedStatusReceived(RequestedStatusReceive);
            OnStatusSend += new StatusSend(SendStatus);

            Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);   // Create the Socket
            try
            {
                // Try to connect and send the port request command
                Client.Connect(IPAddress.Parse(RemoteAddress), port);
            }
            catch (SocketException)
            {
                // If that fails -> Show a error and close the Application
                MessageBox.Show("Konnte keine Verbindung zum Server herstellen!");
                debugFile.Write("Server unavaliable\r\n");
                this.Close();
            }

            // Create the Thread for the Listener and put it in the background
            Thread lis = new Thread(new ThreadStart(Listener));
            lis.IsBackground = true;
            lis.Start();

            // Remove menu entry for clearing chatlogs if chatlogs are disabled
            if (Properties.Settings.Default.client_log_conversations)
            {
                alleMitschnitteLöschenToolStripMenuItem.Visible = true;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Causes the Actor to become a different kind of actor.
        /// This has little if any use with the current design
        /// because messages are delivered to individual OnReceive()
        /// methods.
        /// </summary>
        /// <param name="receive">the Receive to which messages are dispatched</param>
        /// <param name="discardOld">the bool that if set causes an Unbecome() before the Become()</param>
        public void Become(Receive receive, bool discardOld = true)
        {
            if (discardOld)
            {
                Unbecome();
            }

            Receive = receive;

            Receivers.Push(receive);

            Channel.ClearSubscribers();

            Channel.Subscribe(Fiber, GetOnReceiveDelegate());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Generates the receive model.
        /// </summary>
        /// <param name="receive">The receive.</param>
        /// <param name="user">The user.</param>
        /// <returns></returns>
        public static ReceiveViewModel GenerateReceiveModel(Receive receive, List<Commodity> commodities, List<CommodityGrade> commodityGrades, List<Transporter> transporters, List<CommodityType> commodityTypes,
            List<CommoditySource> commoditySources, List<Program> programs, List<Donor> donors, List<Hub> hubs, UserProfile user,List<Unit> units )
        {
            ReceiveViewModel model = new ReceiveViewModel();
            model._UserProfile = user;

            model.InitalizeViewModel(commodities, commodityGrades, transporters, commodityTypes,
             commoditySources, programs, donors, hubs, user,units);
            model.IsEditMode = true;
            model.ReceiveID = receive.ReceiveID;
            model.DriverName = receive.DriverName;
            model.GRN = receive.GRN;
            model.PlateNo_Prime = receive.PlateNo_Prime;
            model.PlateNo_Trailer = receive.PlateNo_Trailer;

            model.TransporterID = receive.TransporterID;
            model.HubID = receive.HubID;

            ReceiveDetail receiveDetail = receive.ReceiveDetails.FirstOrDefault();//p=>p.QuantityInMT>0);
            Transaction receiveDetailtransaction = null;
            if (receiveDetail != null)
                foreach (Transaction transaction in receiveDetail.TransactionGroup.Transactions)
                {
                    var negTransaction = receiveDetail.TransactionGroup.Transactions.FirstOrDefault(p => p.QuantityInMT < 0);
                    if (negTransaction != null)
                        model.SourceHubID = negTransaction.Account.EntityID;
                    receiveDetailtransaction = transaction;
                    break;
                }
            if (receiveDetailtransaction != null)
            {
                model.SINumber = receiveDetailtransaction.ShippingInstruction != null ? receiveDetailtransaction.ShippingInstruction.Value : "";

                model.ProjectNumber = receiveDetailtransaction.ProjectCode != null ? receiveDetailtransaction.ProjectCode.Value : "";

                model.ProgramID = receiveDetailtransaction.Program != null ? receiveDetailtransaction.Program.ProgramID : default(int);

                model.StoreID = receiveDetailtransaction.Store != null ? receiveDetailtransaction.Store.StoreID : default(int);

                model.StackNumber = receiveDetailtransaction.Stack.HasValue ? receiveDetailtransaction.Stack.Value : default(int);

            }
            else
            {
                model.SINumber = "";
                model.ProjectNumber = "";
                model.ProgramID = default(int);
                model.StoreID = default(int);
                model.StackNumber = default(int);
            }

            model.ReceiptDate = receive.ReceiptDate;
            model.WayBillNo = receive.WayBillNo;
            model.CommodityTypeID = receive.CommodityTypeID;
            model.ResponsibleDonorID = receive.ResponsibleDonorID;
            model.SourceDonorID = receive.SourceDonorID;
            model.CommoditySourceID = receive.CommoditySourceID;
            model.TicketNumber = receive.WeightBridgeTicketNumber;
            model.WeightBeforeUnloading = receive.WeightBeforeUnloading;
            model.WeightAfterUnloading = receive.WeightAfterUnloading;
            model.VesselName = receive.VesselName;
            model.PortName = receive.PortName;
            model.ReceiptAllocationID = receive.ReceiptAllocationID;
            model.PurchaseOrder = receive.PurchaseOrder;
            model.SupplierName = receive.SupplierName;

            model.Remark = receive.Remark;
            model.ReceivedByStoreMan = receive.ReceivedByStoreMan;

            model.ReceiveDetails =Cats.Models.Hubs.ReceiveDetailViewModel.GenerateReceiveDetailModels(receive.ReceiveDetails);
            return model;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Changes the actor's command behavior and replaces the current receive handler with the specified handler.
 /// </summary>
 /// <param name="receive">The new message handler.</param>
 protected void Become(Receive receive)
 {
     Context.Become(receive);
 }
Ejemplo n.º 9
0
 public void Become(Receive receive)
 {
     _state = _state.Become(receive);
 }
Ejemplo n.º 10
0
 public IActorState ClearBehaviorStack()
 {
     _receive = null;
     return this;
 }
Ejemplo n.º 11
0
 public void SetBehavior(Receive receive)
 {
     _behavior.Clear();
     _behavior.Push(receive);
     _receive = receive;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="receive">TBD</param>
 public void BecomeStacked(Receive receive)
 {
     _state = _state.BecomeStacked(receive);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="receive">TBD</param>
 public void Become(Receive receive)
 {
     _state = _state.Become(receive);
 }
Ejemplo n.º 14
0
 public static ReceiveBehavior <T> Receive <T>(Receive <T> onMessage) =>
 new ReceiveBehavior <T>(onMessage);
Ejemplo n.º 15
0
 public FunctionActor(Receive receive) => _receive = receive;
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        protected override bool AroundReceive(Receive receive, object message)
        {
            if (message is RedeliveryTick)
            {
                RedeliverOverdue();
                return true;
            }

            return base.AroundReceive(receive, message);
        }
Ejemplo n.º 18
0
 public void PushBehavior(Receive receive)
 {
     _behavior.Push(receive);
     _receive = receive;
 }
Ejemplo n.º 19
0
 public IActorState BecomeStacked(Receive receive)
 {
     _behaviorStack.Push(receive);
     return this;
 }
Ejemplo n.º 20
0
        public Context(Func <IActor> producer, ISupervisorStrategy supervisorStrategy, Receive receiveMiddleware, Sender senderMiddleware, PID parent)
        {
            _producer           = producer;
            _supervisorStrategy = supervisorStrategy;
            _receiveMiddleware  = receiveMiddleware;
            _senderMiddleware   = senderMiddleware;
            Parent    = parent;
            _behavior = new Stack <Receive>();
            _behavior.Push(ActorReceive);

            IncarnateActor();

            //fast path
            if (parent != null)
            {
                _watchers = new HashSet <PID>
                {
                    parent
                };
            }
        }
Ejemplo n.º 21
0
 public void Become(Receive receive, bool discardOld = true)
 {
     if(discardOld && behaviorStack.Count > 1) //We should never pop off the initial receiver
         behaviorStack.Pop();
     behaviorStack.Push(receive);
 }
Ejemplo n.º 22
0
 public BehaviorTester State(Receive receive, Func <Receive, Receive> extend = null, params Receive[] trait) =>
 State(receive, null, extend, trait);
Ejemplo n.º 23
0
 void IActorContext.Become(Receive receive, bool discardOld = true)
 {
     if(discardOld)
         Become(receive);
     else
         BecomeStacked(receive);
 }
Ejemplo n.º 24
0
 public BehaviorTester State(Receive receive, Receive super, Func <Receive, Receive> extend = null, params Receive[] trait) =>
 State(receive.Method.Name, receive, super?.Method.Name, extend, trait);
Ejemplo n.º 25
0
 public SubReceive(Receive initial)
 {
     _currentReceive = initial;
 }
Ejemplo n.º 26
0
 public BehaviorTester State(string name, Receive receive) =>
 State(name, receive, null);
Ejemplo n.º 27
0
		/// <summary>
		/// Sets the way you receive the quest.
		/// </summary>
		/// <param name="method"></param>
		protected void SetReceive(Receive method)
		{
			this.ReceiveMethod = method;
		}
Ejemplo n.º 28
0
 public BehaviorTester Initial(Receive behavior)
 {
     initial = behavior.Method.Name;
     return(this);
 }
Ejemplo n.º 29
0
 internal protected virtual bool AroundReceive(Receive receive, object message)
 {
     var wasHandled = receive(message);
     if(!wasHandled)
     {
         Unhandled(message);
     }
     return wasHandled;
 }
Ejemplo n.º 30
0
 public EmptyActor(Receive receive)
 {
     _receive = receive;
 }
Ejemplo n.º 31
0
 private void _toggleButtonVisibility()
 {
     Receive.setHidden( value : false == _canReceive(), SaveToDb : false );
     Request.setHidden( value : false == _CswNbtResources.Permit.can( CswEnumNbtActionName.Submit_Request ), SaveToDb : false );
 }
Ejemplo n.º 32
0
 public static Props FromFunc(Receive receive)
 {
     return(FromProducer(() => new EmptyActor(receive)));
 }
Ejemplo n.º 33
0
 public static PID SpawnActorFromFunc(Receive receive) => Context.Spawn(Props.FromFunc(receive));
Ejemplo n.º 34
0
        public void Update(List <ReceiveDetail> inserted, List <ReceiveDetail> updated, List <ReceiveDetail> deleted, Receive receive)
        {
            if (receive != null)
            {
                _unitOfWork.ReceiveRepository.Edit(receive);
                _unitOfWork.Save();


                foreach (ReceiveDetail insert in inserted)
                {
                    //TODO THIS should be in transaction
                    insert.ReceiveDetailID = Guid.NewGuid();
                    receive.ReceiveDetails.Add(insert);
                }

                foreach (ReceiveDetail delete in deleted)
                {
                    ReceiveDetail deletedCommodity = _unitOfWork.ReceiveDetailRepository.FindBy(p => p.ReceiveDetailID == delete.ReceiveDetailID).FirstOrDefault();
                    if (deletedCommodity != null)
                    {
                        _unitOfWork.ReceiveDetailRepository.Delete(deletedCommodity);
                    }
                }

                foreach (ReceiveDetail update in updated)
                {
                    ReceiveDetail updatedCommodity = _unitOfWork.ReceiveDetailRepository.FindBy(p => p.ReceiveDetailID == update.ReceiveDetailID).FirstOrDefault();
                    if (updatedCommodity != null)
                    {
                        updatedCommodity.CommodityID      = update.CommodityID;
                        updatedCommodity.Description      = update.Description;
                        updatedCommodity.ReceiveID        = update.ReceiveID;
                        updatedCommodity.SentQuantityInMT = update.SentQuantityInMT;
                        // updatedCommodity.QuantityInMT = updatedCommodity.QuantityInMT;
                        updatedCommodity.SentQuantityInUnit = update.SentQuantityInUnit;
                        updatedCommodity.UnitID             = update.UnitID;
                    }
                }
                _unitOfWork.Save();
            }
        }
Ejemplo n.º 35
0
 public IActorState BecomeStacked(Receive receive)
 {
     if (_receive == null)
     {
         _receive = receive;
         return this;
     }
     return GetFullState().BecomeStacked(receive);
 }
Ejemplo n.º 36
0
 public bool AddReceive(Receive entity)
 {
     _unitOfWork.ReceiveRepository.Add(entity);
     _unitOfWork.Save();
     return(true);
 }
Ejemplo n.º 37
0
 public IActorState Become(Receive receive)
 {
     if (_behaviorStack.Count > 1) //We should never pop off the initial receiver
         _behaviorStack.Pop();
     _behaviorStack.Push(receive);
     return this;
 }
Ejemplo n.º 38
0
 public bool EditReceive(Receive entity)
 {
     _unitOfWork.ReceiveRepository.Edit(entity);
     _unitOfWork.Save();
     return(true);
 }
Ejemplo n.º 39
0
 public bool AddReceive(Receive entity)
 {
     _unitOfWork.ReceiveRepository.Add(entity);
     _unitOfWork.Save();
     return true;
 }
Ejemplo n.º 40
0
 protected override bool AroundReceive(Receive receive, object message)
 {
     Log.Info($"{Self.Path.Name} received {message.GetType().Name}");
     return(base.AroundReceive(receive, message));
 }
Ejemplo n.º 41
0
 public bool EditReceive(Receive entity)
 {
     _unitOfWork.ReceiveRepository.Edit(entity);
     _unitOfWork.Save();
     return true;
 }
Ejemplo n.º 42
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="receive">TBD</param>
 /// <param name="message">TBD</param>
 /// <returns>TBD</returns>
 protected internal override bool AroundReceive(Receive receive, object message)
 {
     return(_atLeastOnceDeliverySemantic.AroundReceive(receive, message) || base.AroundReceive(receive, message));
 }
Ejemplo n.º 43
0
        protected override bool AroundReceive(Receive receive, object message)
        {
            Log.Msg(this, l => l.Debug("{0} received {1}", GetType().Name, message.GetType().Name));

            return base.AroundReceive(receive, message);
        }
Ejemplo n.º 44
0
        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",
            };

            // <Snippet0>
            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."
                    },
                },
            });
            // </Snippet0>
        }
Ejemplo n.º 45
0
 public void BecomeStacked(Receive receive)
 {
     _state = _state.BecomeStacked(receive);
 }
Ejemplo n.º 46
0
 public Receive On(Receive next) => async message =>
Ejemplo n.º 47
0
 protected void Become(Receive receive, bool discardOld = true)
 {
     if(discardOld)
         Context.Become(receive);
     else
         Context.BecomeStacked(receive);
 }
Ejemplo n.º 48
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="receive">TBD</param>
        /// <param name="message">TBD</param>
        /// <returns>TBD</returns>
        protected override bool AroundReceive(Receive receive, object message)
        {
            if (message is Request)
            {
                var req = (Request)message;
                if (req.IsProcessed)
                {
                    // it's an unstashed Request, demand is already handled
                    base.AroundReceive(receive, req);
                }
                else
                {
                    if (req.Count < 1)
                    {
                        if (_lifecycleState == LifecycleState.Active)
                        {
                            OnError(new ArgumentException("Number of requested elements must be positive. Rule 3.9"));
                        }
                    }
                    else
                    {
                        _demand += req.Count;
                        if (_demand < 0)
                        {
                            _demand = long.MaxValue; // long overflow: effectively unbounded
                        }
                        req.MarkProcessed();
                        base.AroundReceive(receive, message);
                    }
                }
            }
            else if (message is Subscribe <T> )
            {
                var sub        = (Subscribe <T>)message;
                var subscriber = sub.Subscriber;
                switch (_lifecycleState)
                {
                case LifecycleState.PreSubscriber:
                    _scheduledSubscriptionTimeout.Cancel();
                    _subscriber     = subscriber;
                    _lifecycleState = LifecycleState.Active;
                    ReactiveStreamsCompliance.TryOnSubscribe(subscriber, new ActorPublisherSubscription(Self));
                    break;

                case LifecycleState.ErrorEmitted:
                    if (_onError.Stop)
                    {
                        Context.Stop(Self);
                    }
                    ReactiveStreamsCompliance.TryOnSubscribe(subscriber, CancelledSubscription.Instance);
                    ReactiveStreamsCompliance.TryOnError(subscriber, _onError.Cause);
                    break;

                case LifecycleState.Completed:
                    ReactiveStreamsCompliance.TryOnSubscribe(subscriber, CancelledSubscription.Instance);
                    ReactiveStreamsCompliance.TryOnComplete(subscriber);
                    break;

                case LifecycleState.CompleteThenStop:
                    Context.Stop(Self);
                    ReactiveStreamsCompliance.TryOnSubscribe(subscriber, CancelledSubscription.Instance);
                    ReactiveStreamsCompliance.TryOnComplete(subscriber);
                    break;

                case LifecycleState.Active:
                case LifecycleState.Canceled:
                    if (_subscriber == subscriber)
                    {
                        ReactiveStreamsCompliance.RejectDuplicateSubscriber(subscriber);
                    }
                    else
                    {
                        ReactiveStreamsCompliance.RejectAdditionalSubscriber(subscriber, "ActorPublisher");
                    }
                    break;
                }
            }
            else if (message is Cancel)
            {
                if (_lifecycleState != LifecycleState.Canceled)
                {
                    // possible to receive again in case of stash
                    CancelSelf();
                    base.AroundReceive(receive, message);
                }
            }
            else if (message is SubscriptionTimeoutExceeded)
            {
                if (!_scheduledSubscriptionTimeout.IsCancellationRequested)
                {
                    CancelSelf();
                    base.AroundReceive(receive, message);
                }
            }
            else
            {
                return(base.AroundReceive(receive, message));
            }
            return(true);
        }
Ejemplo n.º 49
0
 /// <summary>
 /// Changes the actor's behavior and replaces the current receive handler with the specified handler.
 /// The current handler is stored on a stack, and you can revert to it by calling <see cref="IActorContext.UnbecomeStacked"/>
 /// <remarks>Please note, that in order to not leak memory, make sure every call to <see cref="BecomeStacked"/>
 /// is matched with a call to <see cref="IActorContext.UnbecomeStacked"/>.</remarks>
 /// </summary>
 /// <param name="receive">The new message handler.</param>
 protected void BecomeStacked(Receive receive)
 {
     Context.BecomeStacked(receive);
 }
Ejemplo n.º 50
0
        public Activity Create(DependencyObject target)
        {
            // Sequence container.
            var sequence = new Sequence();

            sequence.DisplayName = "Delay";

            // Correlation Handle.
            var handle          = new Variable <CorrelationHandle>("_handle");
            var trainingRequest = new Variable <TrainingRequest>("_trainingRequest");

            // Get variable collection.
            var variables = GetVariableCollection(target);

            if (variables == null)
            {
                sequence.Variables.Add(handle);
                sequence.Variables.Add(trainingRequest);
            }
            else
            {
                handle          = AddVariable <CorrelationHandle>(variables, handle);
                trainingRequest = AddVariable <TrainingRequest>(variables, trainingRequest);
            }

            // Create Receive Activity.
            var receive = new Receive();

            receive.DisplayName         = "Delay Receive";
            receive.Action              = "http://tempuri.org/ITrainingWorkflowService/Delay";
            receive.OperationName       = "Delay";
            receive.ProtectionLevel     = ProtectionLevel.None;
            receive.ServiceContractName = "ITrainingWorkflowService";

            // Add parameters to Receive
            var parameters = new ReceiveParametersContent();

            parameters.Parameters.Add("trainingRequest", new OutArgument <TrainingRequest>(trainingRequest));
            receive.Content = parameters;

            // Add CorrelationInitializer to Receive
            var initializer = new RequestReplyCorrelationInitializer();

            initializer.CorrelationHandle = new InArgument <CorrelationHandle>(handle);
            receive.CorrelationInitializers.Add(initializer);

            // Create SendReply Activity
            var send = new SendReply();

            send.DisplayName       = "Delay Reply";
            send.Action            = "http://tempuri.org/ITrainingWorkflowService/DelayResponse";
            send.Request           = receive;
            send.PersistBeforeSend = true;

            // Create Delay activity.
            Delay delay = new Delay();

            delay.DisplayName     = "Delay";
            delay.TrainingRequest = trainingRequest;

            // Add activities to sequence.
            sequence.Activities.Add(receive);
            sequence.Activities.Add(delay);
            sequence.Activities.Add(send);

            return(sequence);
        }
Ejemplo n.º 51
0
 public void Become(Receive receive) => _currentReceive = receive;
Ejemplo n.º 52
0
 public MessageEnumerator(Receive receive)
 {
     _receive = receive;
 }
Ejemplo n.º 53
0
        /// <summary>
        /// Generates the receive.
        /// </summary>
        /// <returns></returns>
        public Receive GenerateReceive()
        {
            Receive receive = new Receive()
            {
                CreatedDate = DateTime.Now,
                ReceiptDate = this.ReceiptDate,

                DriverName = this.DriverName,
                GRN = this.GRN,
                PlateNo_Prime = this.PlateNo_Prime,
                PlateNo_Trailer = this.PlateNo_Trailer,
                TransporterID = this.TransporterID,
                HubID = this.HubID,
                CommodityTypeID = this.CommodityTypeID,
                WayBillNo = this.WayBillNo,
                ResponsibleDonorID = this.ResponsibleDonorID,
                SourceDonorID = this.SourceDonorID,
                CommoditySourceID = this.CommoditySourceID,
                WeightBridgeTicketNumber = this.TicketNumber,
                WeightBeforeUnloading = this.WeightBeforeUnloading,
                WeightAfterUnloading = this.WeightAfterUnloading,
                ReceivedByStoreMan = this.ReceivedByStoreMan,
                VesselName = this.VesselName,
                PortName = this.PortName,
                PurchaseOrder = this.PurchaseOrder,
                SupplierName = this.SupplierName,
                ReceiptAllocationID = this.ReceiptAllocationID,
                Remark = this.Remark,
            };
            if (this.ReceiveID.HasValue)
            {
                receive.ReceiveID = this.ReceiveID.Value;
            }
            else
            {
                receive.ReceiveID = Guid.NewGuid();
            }
            return receive;
        }
Ejemplo n.º 54
0
        private static Activity GetCCWorkflow()
        {
            //<snippet1>
            Variable <string>            OrderId       = new Variable <string>();
            Variable <string>            Item          = new Variable <string>();
            Variable <CorrelationHandle> OrderIdHandle = new Variable <CorrelationHandle>();

            Receive StartOrder = new Receive
            {
                CanCreateInstance   = true,
                ServiceContractName = "IOrderService",
                OperationName       = "StartOrder"
            };

            //<snippet2>
            SendReply ReplyToStartOrder = new SendReply
            {
                Request = StartOrder,
                Content = SendParametersContent.Create(new Dictionary <string, InArgument>
                {
                    { "OrderId", new InArgument <string>((env) => OrderId.Get(env)) }
                }),
                CorrelationInitializers =
                {
                    new QueryCorrelationInitializer
                    {
                        CorrelationHandle = OrderIdHandle,
                        MessageQuerySet   = new MessageQuerySet
                        {
                            {
                                "OrderId",
                                new XPathMessageQuery("sm:body()/tempuri:StartOrderResponse/tempuri:OrderId")
                            }
                        }
                    }
                }
            };
            //</snippet2>

            //<snippet3>
            Receive AddItem = new Receive
            {
                ServiceContractName = "IOrderService",
                OperationName       = "AddItem",
                CorrelatesWith      = OrderIdHandle,
                CorrelatesOn        = new MessageQuerySet
                {
                    {
                        "OrderId",
                        new XPathMessageQuery("sm:body()/tempuri:AddItem/tempuri:OrderId")
                    }
                },
                Content = ReceiveParametersContent.Create(new Dictionary <string, OutArgument>
                {
                    { "OrderId", new OutArgument <string>(OrderId) },
                    { "Item", new OutArgument <string>(Item) }
                })
            };
            //</snippet3>

            SendReply ReplyToAddItem = new SendReply
            {
                Request = AddItem,
                Content = SendParametersContent.Create(new Dictionary <string, InArgument>
                {
                    { "Reply", new InArgument <string>((env) => "Item added: " + Item.Get(env)) }
                }),
            };

            // Construct a workflow using StartOrder, ReplyToStartOrder, and AddItem.
            //</snippet1>
            Activity wf = new Sequence
            {
                Variables =
                {
                    OrderId,
                    Item,
                    OrderIdHandle
                },
                Activities =
                {
                    StartOrder,
                    new Assign <string>
                    {
                        To    = new OutArgument <string>((env) => OrderId.Get(env)),
                        Value = new InArgument <string>((env) => Guid.NewGuid().ToString())
                    },
                    ReplyToStartOrder,
                    AddItem,
                    ReplyToAddItem
                }
            };

            return(wf);
        }
Ejemplo n.º 55
0
 protected override bool AroundReceive(Receive receive, object message)
 {
     _currentState.StateReceive(receive, message);
     return true;
 }
Ejemplo n.º 56
0
        private static Activity GetCCWorkflowWithInitializeCorrelationActivity()
        {
            //<snippet4>
            Variable <string>            OrderId       = new Variable <string>();
            Variable <string>            Item          = new Variable <string>();
            Variable <CorrelationHandle> OrderIdHandle = new Variable <CorrelationHandle>();

            InitializeCorrelation OrderIdCorrelation = new InitializeCorrelation
            {
                Correlation     = OrderIdHandle,
                CorrelationData = { { "OrderId", new InArgument <string>(OrderId) } }
            };

            Receive StartOrder = new Receive
            {
                CanCreateInstance   = true,
                ServiceContractName = "IOrderService",
                OperationName       = "StartOrder"
            };

            SendReply ReplyToStartOrder = new SendReply
            {
                Request = StartOrder,
                Content = SendParametersContent.Create(new Dictionary <string, InArgument> {
                    { "OrderId", new InArgument <string>((env) => OrderId.Get(env)) }
                }),
            };

            // Other messaging activities omitted...
            //</snippet4>

            Receive AddItem = new Receive
            {
                ServiceContractName = "IOrderService",
                OperationName       = "AddItem",
                CorrelatesWith      = OrderIdHandle,
                CorrelatesOn        = new MessageQuerySet
                {
                    {
                        "OrderId",
                        new XPathMessageQuery("sm:body()/tempuri:AddItem/tempuri:OrderId")
                    }
                },
                Content = ReceiveParametersContent.Create(new Dictionary <string, OutArgument>
                {
                    { "OrderId", new OutArgument <string>(OrderId) },
                    { "Item", new OutArgument <string>(Item) }
                })
            };

            SendReply ReplyToAddItem = new SendReply
            {
                Request = AddItem,
                Content = SendParametersContent.Create(new Dictionary <string, InArgument> {
                    { "Reply", new InArgument <string>((env) => "Item added: " + Item.Get(env)) }
                }),
            };

            //<snippet5>
            // Construct a workflow using OrderIdCorrelation, StartOrder, ReplyToStartOrder,
            // and other messaging activities.
            Activity wf = new Sequence
            {
                Variables =
                {
                    OrderId,
                    Item,
                    OrderIdHandle
                },
                Activities =
                {
                    // Wait for a new order.
                    StartOrder,
                    // Assign a unique identifier to the order.
                    new Assign <string>
                    {
                        To    = new OutArgument <string>((env) => OrderId.Get(env)),
                        Value = new InArgument <string>((env) => Guid.NewGuid().ToString())
                    },
                    ReplyToStartOrder,
                    // Initialize the correlation.
                    OrderIdCorrelation,
                    // Wait for an item to be added to the order.
                    AddItem,
                    ReplyToAddItem
                }
            };

            //</snippet5>

            return(wf);
        }
Ejemplo n.º 57
0
 protected override bool AroundReceive(Receive receive, object message)
 {
     return _atLeastOnceDeliverySemantic.AroundReceive(receive, message) || base.AroundReceive(receive, message);
 }
Ejemplo n.º 58
0
 public IActorState ClearBehaviorStack()
 {
     _receive = null;
     return(this);
 }
Ejemplo n.º 59
0
 /// <summary>
 /// Changes the Actor's behavior to become the new <see cref="Actor.Receive"/> handler.
 /// This method acts upon the behavior stack as follows:
 /// <para>if <paramref name="discardOld"/>==<c>true</c> it will replace the current behavior (i.e. the top element)</para>
 /// <para>if <paramref name="discardOld"/>==<c>false</c> it will keep the current behavior and push the given one atop</para>
 /// The default of replacing the current behavior on the stack has been chosen to avoid memory
 /// leaks in case client code is written without consulting this documentation first (i.e.
 /// always pushing new behaviors and never issuing an <see cref="Unbecome"/>)
 /// </summary>
 /// <param name="receive">The receive delegate.</param>
 /// <param name="discardOld">If <c>true</c> it will replace the current behavior; 
 /// otherwise it will keep the current behavior and it can be reverted using <see cref="Unbecome"/></param>
 protected void Become(Receive receive, bool discardOld = true)
 {
     Context.Become(receive, discardOld);
 }
Ejemplo n.º 60
0
 public IActorState BecomeStacked(Receive receive)
 {
     _behaviorStack.Push(receive);
     return(this);
 }