private void button1_Click(object sender, EventArgs e) { dataGridView1.Rows.Clear(); MarkovChain chain = new MarkovChain(); Generator generator = new Generator(Convert.ToDouble(txtBoxP.Text), true, chain.Listener); HandlerNode handlerNode1 = new HandlerNode(Convert.ToDouble(txtBoxPI1.Text), true, chain.Listener); QueueNode queue = new QueueNode(false, 2, chain.Listener); HandlerNode handlerNode2 = new HandlerNode(Convert.ToDouble(txtBoxPI2.Text), false, chain.Listener); chain.IntializeChain(generator, handlerNode1, queue, handlerNode2); chain.TiksCount = Convert.ToInt32(txtBoxTiksCount.Text); chain.Work(); txtBoxDenyvalue.Text = chain.Statistics.DenyChanceValue.ToString(); txtBoxAvgQueueLen.Text = chain.Statistics.AverageQueueLength.ToString(); txtBoxAverageReqCountInQueue.Text = chain.Statistics.AvgRequestsCountInSystem.ToString(); txtBoxQ.Text = chain.Statistics.RelativePassAbility.ToString(); txtBoxA.Text = chain.Statistics.AbsolutePassAbility.ToString(); txtBoxAvgReqTimeInQueue.Text = chain.Statistics.AvgTimeRequestInQueue.ToString(); txtBoxAvgReqTimeInSystem.Text = chain.Statistics.AvgTimeRequestInSystem.ToString(); txtBoxLoadCoef1.Text = chain.Statistics.CanalLoadCoef[1].ToString(); txtBoxLoadCoef2.Text = chain.Statistics.CanalLoadCoef[0].ToString(); int i = 0; foreach (var item in chain.Statistics.StatesFrequency) { dataGridView1.Rows.Add("P" + item.Key, chain.Statistics.StatesChances[i]); i++; } }
public override void WriteFilterMethod(HandlerNode handlerNode, TemplateContext ctx, CodeMemberMethod handlerFilterMethod, CodeMethodInvokeExpression invoker) { var component = handlerNode.InputFrom <IMappingsConnectable>(); invoker.Parameters.Add(new CodeSnippetExpression(string.Format("data.Component as {0}", component.Name))); handlerFilterMethod.Statements.Add(invoker); }
/// <summary> /// Initializes an instance of an actor. /// </summary> public override async Task InitializeInstance() { this.xmppCredentials = await this.GetInstanceCredentials(); this.sniffer = this.Model.GetSniffer(this.userName); if (this.sniffer is null) { this.client = new XmppClient(this.xmppCredentials, "en", typeof(XmppActor).GetTypeInfo().Assembly); } else { this.client = new XmppClient(this.xmppCredentials, "en", typeof(XmppActor).GetTypeInfo().Assembly, this.sniffer); } this.client.OnStateChanged += this.Client_OnStateChanged; this.client.OnChatMessage += Client_OnChatMessage; this.client.OnConnectionError += Client_OnConnectionError; this.client.OnError += Client_OnError; this.client.OnErrorMessage += Client_OnErrorMessage; this.client.OnGroupChatMessage += Client_OnGroupChatMessage; this.client.OnHeadlineMessage += Client_OnHeadlineMessage; this.client.OnNormalMessage += Client_OnNormalMessage; this.client.OnPresence += Client_OnPresence; this.client.OnPresenceSubscribe += Client_OnPresenceSubscribe; this.client.OnRosterItemAdded += Client_OnRosterItemAdded; this.client.OnRosterItemRemoved += Client_OnRosterItemRemoved; this.client.OnRosterItemUpdated += Client_OnRosterItemUpdated; this.client.CustomPresenceXml += Client_CustomPresenceXml; if (this.Parent is IActor ParentActor) { foreach (ISimulationNode Node in ParentActor.Children) { if (Node is HandlerNode HandlerNode) { HandlerNode.RegisterHandlers(this, this.client); } if (Node is Extensions.IXmppExtension Extension) { await Extension.Add(this, Client); } } } this.connected = new TaskCompletionSource <bool>(); if (this.alwaysConnected) { this.client.Connect(this.domain); if (this.xmppCredentials.AllowRegistration && !(await this.connected.Task)) { throw new Exception("Unable to create account for " + this.userName + "@" + this.domain); } } }
public override void WriteSetupMethod(HandlerNode handlerNode, TemplateContext ctx, CodeMemberMethod handlerMethod) { var component = handlerNode.InputFrom <IMappingsConnectable>(); ctx._("this.OnEvent<ComponentDestroyedEvent>().Where(x=>x.Component is {0}).Subscribe(_=>{{ {1}(_); }}).DisposeWith(this)", component.Name, handlerNode.HandlerFilterMethodName ); }
/// <summary> /// Build a Handler based on the node configuration /// </summary> /// <typeparam name="T"></typeparam> /// <param name="nodeCtx"></param> /// <param name="node"></param> /// <returns></returns> public T BuildHandler <T>(IActivationContext nodeCtx, HandlerNode node) { nodeCtx.Register <IEventDataConverter>(node.BuildDataFilter); nodeCtx.Register <ConfiguredArguments>(node.BuildArguments); var plugin = _pluginManager.GetPlugin(typeof(T), node); var handler = nodeCtx.Resolve <T>(plugin.Type); return(handler); }
private static HandlerNode ToLinkedList(IEnumerable <CloudTableProjectionHandler> handlers) { using (var enumerator = handlers.GetEnumerator()) { HandlerNode handlerNode = null; while (enumerator.MoveNext()) { handlerNode = new HandlerNode(enumerator.Current, handlerNode); } return(handlerNode); } }
public HandlerPlugin GetPlugin(Type type, HandlerNode node) { var plugin = GetPlugins(type).FirstOrDefault(p => p.Name == node.Name || (string.IsNullOrEmpty(node.Name) && p.Type == node.Type)); if (plugin == null) { if (node.Type != null) { if (type.IsAssignableFrom(node.Type)) { return(new HandlerPlugin { Type = node.Type }); } } System.Diagnostics.Trace.WriteLine($"HandlerPlugin {node.Name}, {node.Type} does not exist"); } return(plugin); }
public HandlerNode(CloudTableProjectionHandler handler, HandlerNode next) { Handler = handler; Next = next; }
private static HandlerNode ToLinkedList(IEnumerable<CloudTableProjectionHandler> handlers) { using (var enumerator = handlers.GetEnumerator()) { HandlerNode handlerNode = null; while (enumerator.MoveNext()) { handlerNode = new HandlerNode(enumerator.Current, handlerNode); } return handlerNode; } }
/// <summary> /// Initializes an instance of an actor. /// </summary> public override async Task InitializeInstance() { this.xmppCredentials = await this.GetInstanceCredentials(); this.sniffer = this.Model.GetSniffer(this.userName); if (this.sniffer is null) { this.client = new XmppClient(this.xmppCredentials, "en", typeof(XmppActor).GetTypeInfo().Assembly); } else { this.client = new XmppClient(this.xmppCredentials, "en", typeof(XmppActor).GetTypeInfo().Assembly, this.sniffer); } this.client.OnStateChanged += this.Client_OnStateChanged; this.client.OnChatMessage += Client_OnChatMessage; this.client.OnConnectionError += Client_OnConnectionError; this.client.OnError += Client_OnError; this.client.OnErrorMessage += Client_OnErrorMessage; this.client.OnGroupChatMessage += Client_OnGroupChatMessage; this.client.OnHeadlineMessage += Client_OnHeadlineMessage; this.client.OnNormalMessage += Client_OnNormalMessage; this.client.OnPresence += Client_OnPresence; this.client.OnPresenceSubscribe += Client_OnPresenceSubscribe; this.client.OnRosterItemAdded += Client_OnRosterItemAdded; this.client.OnRosterItemRemoved += Client_OnRosterItemRemoved; this.client.OnRosterItemUpdated += Client_OnRosterItemUpdated; this.client.CustomPresenceXml += Client_CustomPresenceXml; string InstanceIndexSuffix = this.InstanceIndex.ToString(); int c = this.N.ToString().Length; int Nr0 = c - InstanceIndexSuffix.Length; if (Nr0 > 0) { InstanceIndexSuffix = new string('0', Nr0) + InstanceIndexSuffix; } if (this.Parent is IActor ParentActor) { foreach (ISimulationNode Node in ParentActor.Children) { if (Node is HandlerNode HandlerNode) { HandlerNode.RegisterHandlers(this, this.client); } if (Node is Extensions.IXmppExtension Extension) { object ExtensionObj = await Extension.Add(this, Client); if (!string.IsNullOrEmpty(Extension.Id)) { this.Model.Variables[Extension.Id + InstanceIndexSuffix] = ExtensionObj; } } } } if (this.alwaysConnected) { this.client.Connect(this.domain); if (this.xmppCredentials.AllowRegistration) { switch (await this.client.WaitStateAsync(30000, XmppState.Connected, XmppState.Error, XmppState.Offline)) { case 0: // Connected break; case 1: // Error case 2: // Offline default: throw new Exception("Unable to create account for " + this.userName + "@" + this.domain); } } } }