/// <summary> /// Detaches all event sources. /// </summary> protected void DetachEventSources() { foreach (var item in EventSources.Values.Select(item => item.GetTargetOrDefault()).Where(item => item != null)) { item.PropertyChanged -= RelaySource_PropertyChanged; } EventSources.Clear(); }
/// <summary> /// Detaches all event sources. /// </summary> protected void DetachEventSources() { foreach (var item in EventSources.Values.ToArray()) { item.Detach(); } EventSources.Clear(); }
/// <summary> /// Detaches the event source. /// </summary> /// <param name="item">The item to detach.</param> protected void DetachEventSource([NotNull] INotifyPropertyChanged item) { var sourceType = item.GetType(); if (EventSources.TryGetValue(sourceType, out var oldListener) && oldListener.TryGetTarget(out var target)) { target.PropertyChanged -= RelaySource_PropertyChanged; EventSources.Remove(sourceType); } }
/// <summary> /// Detaches the event source. /// </summary> /// <param name="item">The item to detach.</param> protected void DetachEventSource([NotNull] INotifyPropertyChanged item) { var sourceType = item.GetType(); if (EventSources.TryGetValue(sourceType, out var oldListern)) { oldListern?.Detach(); EventSources.Remove(sourceType); } }
bool IPacketHandler.OnPacket(byte eventId, Context context, Network.ByteInStream stream) { EventDescriptor <T> descriptor = descriptors[eventId]; T target = ReadEventHeader(stream); // Verify event target object if (target == null) { log.Error("Failed to resolve target for event #{0}", eventId); return(false); } // Unpack event Event <T> ev = descriptor.Create(target); ev.Source = stream.Player; ev.SourceGameTime = stream.RemoteGameTime; ev.Unpack(stream); // Increase stats counter Context.Stats.AddInEvent(); // Special logic depending on // if we're a server or client if (context.IsServer) { EventSources s = ev.AllowedSources; bool raisedByOwner = IsSourceTargetOwner(ev); bool isOwnerValid = raisedByOwner && (s & EventSources.Owner) == EventSources.Owner; bool isRemoteValid = !raisedByOwner && (s & EventSources.Remotes) == EventSources.Remotes; if (isOwnerValid || isRemoteValid) { raiseEventOnServer(ev); } else { log.Warn("Event {0} was remotely raised by {1}, but that player is not allowed to raise events of that type on target {2}", ev, ev.Source, ev.Target); } } else { QueueOnClient(ev); } // Everythings fine, return true return(true); }
// Constructor sets service properties and adds event sources public EventingService(ProtocolVersion version) : base(version) { // Add ServiceNamespace. Set ServiceID and ServiceTypeName ServiceNamespace = new WsXmlNamespace("evnt", "http://schemas.example.org/EventingService"); ServiceID = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b91"; ServiceTypeName = "EventingService"; // Add event sources EventSources.Add(new DpwsWseEventSource("evnt", "http://schemas.example.org/EventingService", "SimpleEvent")); EventSources.Add(new DpwsWseEventSource("evnt", "http://schemas.example.org/EventingService", "IntegerEvent")); this.AddEventServices(); // Start the event simulator StartEventSimulator(); }
public EventingService(ProtocolVersion version) : base(version) { // Set base service properties ServiceNamespace = new WsXmlNamespace("eve", "http://schemas.example.org/EventingService"); ServiceID = "urn:uuid:cd35d6ba-3e2f-440b-bc2f-b7c375dc6536"; ServiceTypeName = "EventingService"; // Add service types here // Add event sources here EventSources.Add(new DpwsWseEventSource("eve", "http://schemas.example.org/EventingService", "SimpleEvent")); EventSources.Add(new DpwsWseEventSource("eve", "http://schemas.example.org/EventingService", "IntegerEvent")); this.AddEventServices(); }
/// <summary> /// Relays the property changed events of the source object. /// The properties to relay must be declared with the <see cref="RelayedEventAttribute"/>. /// </summary> /// <param name="source">The source.</param> protected void RelayEventsOf([NotNull] INotifyPropertyChanged source) { Contract.Requires(source != null); var sourceType = source.GetType(); if (RelayMapping.Keys.All(key => key?.IsAssignableFrom(sourceType) != true)) throw new InvalidOperationException(@"This class has no property with a RelayedEventAttribute for the type " + sourceType); INotifyPropertyChanged oldSource; if (EventSources.TryGetValue(sourceType, out oldSource) && (oldSource != null)) oldSource.PropertyChanged -= RelaySource_PropertyChanged; source.PropertyChanged += RelaySource_PropertyChanged; EventSources[sourceType] = source; }
// Constructor sets service properties and defines operations and adds event sources public SimpleService(ProtocolVersion version) : base(version) { // Add ServiceNamespace. Set ServiceID and ServiceTypeName ServiceNamespace = new WsXmlNamespace("sim", "http://schemas.example.org/SimpleService"); ServiceID = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b90"; ServiceTypeName = "SimpleService"; // Add service operations ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "OneWay")); ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "TwoWayRequest")); // Add event sources DpwsWseEventSource SimpleEvent = new DpwsWseEventSource("sim", "http://schemas.example.org/EventingService", "SimpleEvent"); EventSources.Add(SimpleEvent); this.AddEventServices(); }
/// <summary> /// Relays the property changed events of the source object. /// The properties to relay must be declared with the <see cref="RelayedEventAttribute"/>. /// </summary> /// <param name="source">The source.</param> protected void RelayEventsOf([NotNull] INotifyPropertyChanged source) { var sourceType = source.GetType(); if (RelayMapping.Keys.All(key => key?.IsAssignableFrom(sourceType) != true)) { throw new InvalidOperationException(@"This class has no property with a RelayedEventAttribute for the type " + sourceType); } if (EventSources.TryGetValue(sourceType, out var oldListern)) { oldListern?.Detach(); } var newListener = new WeakEventListener(this, source, OnWeakEvent, OnAttach, OnDetach); EventSources[sourceType] = newListener; }
/// <summary> /// Relays the property changed events of the source object. /// The properties to relay must be declared with the <see cref="RelayedEventAttribute"/>. /// </summary> /// <param name="source">The source.</param> protected void RelayEventsOf([NotNull] INotifyPropertyChanged source) { var sourceType = source.GetType(); if (RelayMapping.Keys.All(key => key?.IsAssignableFrom(sourceType) != true)) { throw new InvalidOperationException(@"This class has no property with a RelayedEventAttribute for the type " + sourceType); } if (EventSources.TryGetValue(sourceType, out var oldListener) && oldListener.TryGetTarget(out var oldTarget)) { oldTarget.PropertyChanged -= RelaySource_PropertyChanged; } source.PropertyChanged += RelaySource_PropertyChanged; EventSources[sourceType] = new WeakReference <INotifyPropertyChanged>(source); }
public static void Unload(AppDomain domain) { var assembly = domain.GetAssemblies()[1]; var filePath = assembly.CodeBase; Commands.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => Commands.Remove(c)); EventConsumers.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => EventConsumers.Remove(c)); EventSources.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => EventSources.Remove(c)); Services.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => { c.Stop(); Services.Remove(c); }); Bindings.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => Bindings.Remove(c)); Domains.Remove(domain); AppDomain.Unload(domain); GC.Collect(); // collects all unused memory GC.WaitForPendingFinalizers(); // wait until GC has finished its work GC.Collect(); //File.Delete(filePath); }
public TestService(string guid, ProtocolVersion version) : base(version) { // Add ServiceNamespace. Set ServiceID and ServiceTypeName ServiceNamespace = new WsXmlNamespace("sim", "http://schemas.example.org/SimpleService"); ServiceID = "urn:uuid:" + guid; ServiceTypeName = "TestService"; // Add additional namesapces if needed // example: Namespaces.Add("someprefix", "http://some/Namespace"); // Add service operations ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "OneWay")); ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "TwoWayRequest")); // Add event sources DpwsWseEventSource SimpleEvent = new DpwsWseEventSource("sim", "http://schemas.example.org/EventingService", "SimpleEvent"); EventSources.Add(SimpleEvent); this.AddEventServices(); }
void raiseEventOnClient(Event <T> ev) { EventTargets t = ev.DistributionTargets; EventSources s = ev.AllowedSources; bool toOwner = (t & EventTargets.Owner) == EventTargets.Owner; bool toRemotes = (t & EventTargets.Remotes) == EventTargets.Remotes; bool toServer = (t & EventTargets.Server) == EventTargets.Server; bool allowedOwner = (s & EventSources.Owner) == EventSources.Owner; bool allowedRemotes = (s & EventSources.Remotes) == EventSources.Remotes; if (IsLocalTargetOwner(ev)) { if (toOwner) { QueueOnClient(ev); } if ((toServer || toRemotes) && allowedOwner) { SendToServer(ev); } } else { if (toRemotes) { QueueOnClient(ev); } if ((toServer || toOwner) && allowedRemotes) { SendToServer(ev); } } }
public EventSimple(EventTargets targets, EventSources sources) : base(targets, sources) { }
/// <summary> /// Constructor /// </summary> /// <param name="targets">The targets this event should be distributed to</param> /// <param name="sources">The sources this event is allowed to be raised from</param> protected Event(EventTargets targets, EventSources sources) { DistributionTargets = targets; AllowedSources = sources; }
protected void Page_Load(object sender, EventArgs e) { if (this.DoType == "Del") { FrmEvent delFE = new FrmEvent(); delFE.MyPK = this.FK_MapData + "_" + this.Request.QueryString["RefXml"]; delFE.Delete(); } FrmEvents ndevs = new FrmEvents(); if (this.FK_MapData != null) { ndevs.Retrieve(FrmEventAttr.FK_MapData, this.FK_MapData); } EventLists xmls = new EventLists(); xmls.RetrieveAll(); BP.WF.XML.EventSources ess = new EventSources(); ess.RetrieveAll(); string myEvent = this.Event; BP.WF.XML.EventList myEnentXml = null; #region //生成事件列表 foreach (EventSource item in ess) { if (item.No == "Frm" && this.FK_MapData == null) { continue; } if (item.No == "Node" && string.IsNullOrEmpty(this.NodeID)) { continue; } if (item.No == "Flow" && string.IsNullOrEmpty(this.FK_Flow)) { continue; } Pub1.Add(string.Format("<div title='{0}' style='padding:10px; overflow:auto' data-options=''>", item.Name)); Pub1.AddUL("class='navlist'"); foreach (BP.WF.XML.EventList xml in xmls) { if (xml.EventType != item.No) { continue; } FrmEvent nde = ndevs.GetEntityByKey(FrmEventAttr.FK_Event, xml.No) as FrmEvent; if (nde == null) { if (myEvent == xml.No) { CurrentEventGroup = item.Name; myEnentXml = xml; Pub1.AddLi( string.Format("<div style='font-weight:bold'><a href='javascript:void(0)'><span class='nav'>{0}</span></a></div>{1}", xml.Name, Environment.NewLine)); } else { Pub1.AddLi( string.Format("<div><a href='Action.aspx?NodeID={0}&Event={1}&FK_Flow={2}&tk={5}&FK_MapData={6}'><span class='nav'>{3}</span></a></div>{4}", NodeID, xml.No, FK_Flow, xml.Name, Environment.NewLine, new Random().NextDouble(), this.FK_MapData)); } } else { if (myEvent == xml.No) { CurrentEventGroup = item.Name; myEnentXml = xml; Pub1.AddLi( string.Format("<div style='font-weight:bold'><a href='javascript:void(0)'><span class='nav'>{0}</span></a></div>{1}", xml.Name, Environment.NewLine)); } else { Pub1.AddLi( string.Format("<div><a href='Action.aspx?NodeID={0}&Event={1}&FK_Flow={2}&MyPK={3}&tk={6}&FK_MapData={6}'><span class='nav'>{4}</span></a></div>{5}", NodeID, xml.No, FK_Flow, nde.MyPK, xml.Name, Environment.NewLine, new Random().NextDouble(), this.FK_MapData)); } } } Pub1.AddULEnd(); Pub1.AddDivEnd(); } #endregion if (myEnentXml == null) { CurrentEvent = "帮助"; Pub2.Add("<div style='width:100%; text-align:center' data-options='noheader:true'>"); Pub2.AddH2("事件是ccflow与您的应用程序接口"); this.Pub2.AddUL(); this.Pub2.AddLi("流程在运动的过程中会产生很多的事件,比如:节点发送前、发送成功时、发送失败时、退回前、退后后。"); this.Pub2.AddLi("在这些事件里ccflow允许调用您编写的业务逻辑,完成与界面交互、与其他系统交互、与其他流程参与人员交互。"); this.Pub2.AddLi("按照事件发生的类型,ccflow把事件分为:节点、表单、流程三类的事件。"); this.Pub2.AddULEnd(); Pub2.AddDivEnd(); return; } FrmEvent mynde = ndevs.GetEntityByKey(FrmEventAttr.FK_Event, myEvent) as FrmEvent; if (mynde == null) { mynde = new FrmEvent(); mynde.FK_Event = myEvent; } this.Title = "设置:事件接口=》" + myEnentXml.Name; this.CurrentEvent = myEnentXml.Name; int col = 50; Pub2.Add("<div id='tabMain' class='easyui-tabs' data-options='fit:true'>"); Pub2.Add("<div title='事件接口' style='padding:5px'>" + Environment.NewLine); Pub2.Add("<iframe id='src1' frameborder='0' src='' style='width:100%;height:100%' scrolling='auto'></iframe>"); Pub2.Add("</div>" + Environment.NewLine); if (myEnentXml.IsHaveMsg == true) { HaveMsg = true; Pub2.Add("<div title='向当事人推送消息' style='padding:5px'>" + Environment.NewLine); Pub2.Add("<iframe id='src2' frameborder='0' src='' style='width:100%;height:100%' scrolling='auto'></iframe>"); Pub2.Add("</div>" + Environment.NewLine); Pub2.Add("<div title='向其他指定的人推送消息' style='padding:5px'>" + Environment.NewLine); Pub2.Add("<iframe id='src3' frameborder='0' src='' style='width:100%;height:100%' scrolling='auto'></iframe>"); Pub2.Add("</div>" + Environment.NewLine); } //BP.WF.Dev2Interface.Port_Login("zhoupeng"); // BP.WF.Dev2Interface.Port_SigOut(); Pub2.Add("</div>"); }
protected void Page_Load(object sender, EventArgs e) { if (this.DoType == "Del") { FrmEvent delFE = new FrmEvent(); delFE.MyPK = this.FK_MapData + "_" + this.Request.QueryString["RefXml"]; delFE.Delete(); } FrmEvents ndevs = new FrmEvents(); if (this.FK_MapData != null) { ndevs.Retrieve(FrmEventAttr.FK_MapData, this.FK_MapData); } EventLists xmls = new EventLists(); xmls.RetrieveAll(); BP.WF.XML.EventSources ess = new EventSources(); ess.RetrieveAll(); string myEvent = this.Event; BP.WF.XML.EventList myEnentXml = null; #region //生成事件列表 foreach (EventSource item in ess) { if (item.No != this.ShowType) { continue; } Pub1.Add(string.Format("<div title='{0}' style='padding:10px; overflow:auto' data-options=''>", item.Name)); Pub1.AddUL("class='navlist'"); string msg = ""; foreach (BP.WF.XML.EventList xml in xmls) { if (xml.EventType != item.No) { continue; } msg = ""; if (xml.IsHaveMsg == true) { msg = "<img src='/WF/Img/Msg.png' />"; } FrmEvent nde = ndevs.GetEntityByKey(FrmEventAttr.FK_Event, xml.No) as FrmEvent; if (nde == null) { if (myEvent == xml.No) { CurrentEventGroup = item.Name; myEnentXml = xml; Pub1.AddLi(string.Format("<div style='font-weight:bold'><a href='javascript:void(0)'><span class='nav'><img src='/WF/Img/Event.png' border=0/>" + msg + "{0}</span></a></div>{1}", xml.Name, Environment.NewLine)); } else { Pub1.AddLi(string.Format("<div><a href='Action.aspx?NodeID={0}&Event={1}&FK_Flow={2}&tk={5}&FK_MapData={6}'><span class='nav'><img src='/WF/Img/Event.png' border=0/>" + msg + "{3}</span></a></div>{4}", NodeID, xml.No, FK_Flow, xml.Name, Environment.NewLine, new Random().NextDouble(), this.FK_MapData)); } } else { if (myEvent == xml.No) { CurrentEventGroup = item.Name; myEnentXml = xml; Pub1.AddLi(string.Format("<div style='font-weight:bold'><a href='javascript:void(0)'><span class='nav'><img src='/WF/Img/Event.png' border=0/>" + msg + "{0}</span></a></div>{1}", xml.Name, Environment.NewLine)); } else { Pub1.AddLi(string.Format("<div><a href='Action.aspx?NodeID={0}&Event={1}&FK_Flow={2}&MyPK={3}&tk={6}&FK_MapData={7}'><span class='nav'><img src='/WF/Img/Event.png' border=0/>" + msg + "{4}</span></a></div>{5}", NodeID, xml.No, FK_Flow, nde.MyPK, xml.Name, Environment.NewLine, new Random().NextDouble(), this.FK_MapData)); } } } Pub1.AddULEnd(); Pub1.AddDivEnd(); } #endregion if (myEnentXml == null) { CurrentEvent = "帮助"; this.Pub2.Add("<div style='width:100%; text-align:left' data-options='noheader:true'>"); this.Pub2.AddH2("事件是ccbpm与您的应用程序接口"); if (this.NodeID != "0") { this.Pub2.AddFieldSet("节点事件"); this.Pub2.AddUL(); this.Pub2.AddLi("流程在运动过程中,有许多的事件,比如节点发送前、发送成功后、发送失败后、退回前、退回后、撤销发送前、这小发送后、流程结束前、结束后、删除前删除后。"); this.Pub2.AddLi("ccbpm把事件分为流程事件与节点事件,流程属性里定义流程事件,节点属性里定义节点事件。"); this.Pub2.AddLi("在这些事件里ccbpm允许调用您编写的业务逻辑,完成与界面交互、与其他系统交互、与其他流程参与人员交互。"); this.Pub2.AddLi("按照事件发生的类型,ccbpm把事件分为:节点、表单、流程三类的事件。"); this.Pub2.AddLi("在BPMN2.0规范里没有定义节点事件表单事件,这是ccbpm特有的概念与元素。"); this.Pub2.AddULEnd(); this.Pub2.AddFieldSetEnd(); } if (this.FK_Flow != null && this.NodeID == "0") { this.Pub2.AddFieldSet("流程事件"); this.Pub2.AddUL(); this.Pub2.AddLi("流程在运动过程中,有许多的事件,比如节点发送前、发送成功后、发送失败后、退回前、退回后、撤销发送前、这小发送后、流程结束前、结束后、删除前删除后。"); this.Pub2.AddLi("ccbpm把事件分为流程事件与节点事件,流程属性里定义流程事件,节点属性里定义节点事件。"); this.Pub2.AddLi("在这些事件里ccbpm允许调用您编写的业务逻辑,完成与界面交互、与其他系统交互、与其他流程参与人员交互。"); this.Pub2.AddLi("按照事件发生的类型,ccbpm把事件分为:节点、表单、流程三类的事件。"); this.Pub2.AddLi("在BPMN2.0规范里定义了,流程发起事件,流程发起错误事件。在ccbpm里取消了这些概念,取而代之的是开始节点的发送前、发送失败时、发送成功时的事件与之对应。"); this.Pub2.AddULEnd(); this.Pub2.AddFieldSetEnd(); } if (this.FK_MapData != null && this.FK_MapData != "") { this.Pub2.AddFieldSet("表单事件"); this.Pub2.AddUL(); this.Pub2.AddLi("流程在运动过程中,有许多的事件,比如节点发送前、发送成功后、发送失败后、退回前、退回后、撤销发送前、这小发送后、流程结束前、结束后、删除前删除后。"); this.Pub2.AddLi("ccbpm把事件分为流程事件与节点事件,流程属性里定义流程事件,节点属性里定义节点事件。"); this.Pub2.AddLi("在这些事件里ccbpm允许调用您编写的业务逻辑,完成与界面交互、与其他系统交互、与其他流程参与人员交互。"); this.Pub2.AddLi("按照事件发生的类型,ccbpm把事件分为:节点、表单、流程三类的事件。"); this.Pub2.AddLi("在BPMN2.0规范里定义了,流程发起事件,流程发起错误事件。在ccbpm里取消了这些概念,取而代之的是开始节点的发送前、发送失败时、发送成功时的事件与之对应。"); this.Pub2.AddULEnd(); this.Pub2.AddFieldSetEnd(); } this.Pub2.AddDivEnd(); return; } FrmEvent mynde = ndevs.GetEntityByKey(FrmEventAttr.FK_Event, myEvent) as FrmEvent; if (mynde == null) { mynde = new FrmEvent(); mynde.FK_Event = myEvent; } this.Title = "设置:事件接口=》" + myEnentXml.Name; this.CurrentEvent = myEnentXml.Name; Pub2.Add("<div id='tabMain' class='easyui-tabs' data-options='fit:true'>"); Pub2.Add("<div title='事件接口' style='padding:5px'>" + Environment.NewLine); Pub2.Add("<iframe id='src1' frameborder='0' src='' style='width:100%;height:100%' scrolling='auto'></iframe>"); Pub2.Add("</div>" + Environment.NewLine); /* 该模块jflow暂时不翻译,注释掉 by fanleiwei 20160531 * if (myEnentXml.IsHaveMsg == true) * { * HaveMsg = true; * Pub2.Add("<div title='向当事人推送消息' style='padding:5px'>" + Environment.NewLine); * Pub2.Add("<iframe id='src2' frameborder='0' src='' style='width:100%;height:100%' scrolling='auto'></iframe>"); * Pub2.Add("</div>" + Environment.NewLine); * * Pub2.Add("<div title='向其他指定的人推送消息' style='padding:5px'>" + Environment.NewLine); * Pub2.Add("<iframe id='src3' frameborder='0' src='' style='width:100%;height:100%' scrolling='auto'></iframe>"); * Pub2.Add("</div>" + Environment.NewLine); * } */ Pub2.Add("</div>"); }
/// <summary> /// Detaches the event source. /// </summary> /// <param name="item">The item to detach.</param> protected void DetachEventSource([NotNull] INotifyPropertyChanged item) { Contract.Requires(item != null); item.PropertyChanged -= RelaySource_PropertyChanged; EventSources.Remove(item.GetType()); }
private static void LoadSources() { EventSources.AddRange(GetClassesOfType <IEventSource>()); }
protected void Page_Load(object sender, EventArgs e) { if (this.DoType == "Del") { FrmEvent delFE = new FrmEvent(); delFE.MyPK = this.FK_MapData + "_" + this.Request.QueryString["RefXml"]; delFE.Delete(); } this.Pub3.AddCaptionLeft("节点表单/节点/流程:事件"); FrmEvents ndevs = new FrmEvents(); ndevs.Retrieve(FrmEventAttr.FK_MapData, this.FK_MapData); EventLists xmls = new EventLists(); xmls.RetrieveAll(); BP.WF.XML.EventSources ess = new EventSources(); ess.RetrieveAll(); string myEvent = this.Event; BP.WF.XML.EventList myEnentXml = null; foreach (EventSource item in ess) { this.Pub1.AddFieldSet(item.Name); this.Pub1.AddUL(); foreach (BP.WF.XML.EventList xml in xmls) { if (xml.EventType != item.No) { continue; } FrmEvent nde = ndevs.GetEntityByKey(FrmEventAttr.FK_Event, xml.No) as FrmEvent; if (nde == null) { if (myEvent == xml.No) { myEnentXml = xml; this.Pub1.AddLi("<font color=green><b>" + xml.Name + "</b></font>"); } else { this.Pub1.AddLi("Action.aspx?NodeID=" + this.NodeID + "&Event=" + xml.No + "&FK_Flow=" + this.FK_Flow, xml.Name); } } else { if (myEvent == xml.No) { myEnentXml = xml; this.Pub1.AddLi("<font color=green><b>" + xml.Name + "</b></font>"); } else { this.Pub1.AddLi("Action.aspx?NodeID=" + this.NodeID + "&Event=" + xml.No + "&MyPK=" + nde.MyPK + "&FK_Flow=" + this.FK_Flow, "<b>" + xml.Name + "</b>"); } } } this.Pub1.AddULEnd(); this.Pub1.AddFieldSetEnd(); } if (myEnentXml == null) { this.Pub2.AddFieldSet("帮助"); this.Pub2.AddH2("事件是ccflow与您的应用程序接口,"); this.Pub2.AddFieldSetEnd(); return; } FrmEvent mynde = ndevs.GetEntityByKey(FrmEventAttr.FK_Event, myEvent) as FrmEvent; if (mynde == null) { mynde = new FrmEvent(); } this.Title = "设置:事件接口=》" + myEnentXml.Name; this.Pub2.AddFieldSet(myEnentXml.Name); int col = 80; this.Pub2.Add("内容类型:"); DDL ddl = new DDL(); ddl.BindSysEnum("EventDoType"); ddl.ID = "DDL_EventDoType"; ddl.SetSelectItem((int)mynde.HisDoType); this.Pub2.Add(ddl); this.Pub2.Add(" 要执行的内容<br>"); TextBox tb = new TextBox(); tb.ID = "TB_Doc"; tb.Columns = col; tb.TextMode = TextBoxMode.MultiLine; tb.Rows = 10; tb.Text = mynde.DoDoc; this.Pub2.Add(tb); this.Pub2.AddBR(); tb = new TextBox(); tb.ID = "TB_MsgOK"; tb.Columns = col; tb.Text = mynde.MsgOKString; tb.TextMode = TextBoxMode.MultiLine; tb.Rows = 4; this.Pub2.Add("执行成功信息提示(可为空)<br>"); this.Pub2.Add(tb); this.Pub2.AddBR(); this.Pub2.Add("执行失败信息提示(可为空)<br>"); tb = new TextBox(); tb.ID = "TB_MsgErr"; tb.Columns = col; tb.Text = mynde.MsgErrorString; tb.TextMode = TextBoxMode.MultiLine; tb.Rows = 4; this.Pub2.Add(tb); this.Pub2.AddBR(); Button btn = new Button(); btn.ID = "Btn_Save"; btn.Text = "Save"; btn.CssClass = "Btn"; btn.Click += new EventHandler(btn_Click); this.Pub2.Add(" "); this.Pub2.Add(btn); if (this.MyPK != null) { this.Pub2.Add(" <a href=\"javascript:DoDel('" + this.NodeID + "','" + this.Event + "')\"><img src='/WF/Img/Btn/Delete.gif' />删除</a>"); } this.Pub2.AddFieldSetEnd(); }
public async Task GenerateAsync() { var selectedEventSourceIds = EventSources.Where(p => p.IsSelected) .SelectMany(p => p.ServiceIds) .ToList(); var selectedReportingSinkTypes = ReportingSinks.Where(p => p.IsSelected) .SelectMany(p => p.ServiceIds) .ToList(); var selectedStartLocalTime = m_startLocalTime; var selectedEndLocalTime = m_endLocalTime; var selectedIsGeneratePerSourceEnabled = m_isGeneratePerSourceEnabled; var selectedIsGeneratePerSummaryEnabled = m_isGenerateSummaryEnabled; if (selectedEventSourceIds.Any() && selectedReportingSinkTypes.Any() && (selectedIsGeneratePerSourceEnabled || selectedIsGeneratePerSummaryEnabled)) { ProgressPercentage = 0; IsBusy = true; ProgressPercentage = 1; ProgressStatus = String.Empty; string currentActivity = string.Empty; var uiDispatcher = Dispatcher.CurrentDispatcher; await Task.Run(() => { try { var eventQueryServiceRegistrations = m_eventQueryServices .Where(p => selectedEventSourceIds.Contains(p.Key.Id)); var renderServiceRegistrations = m_renderServices .Where(p => selectedReportingSinkTypes.Contains(p.Key.Id)); var eventQueryServiceRegistrationsCount = eventQueryServiceRegistrations.Count(); var totalProgressSteps = eventQueryServiceRegistrationsCount; if (selectedIsGeneratePerSourceEnabled) { totalProgressSteps += eventQueryServiceRegistrationsCount; } if (selectedIsGeneratePerSummaryEnabled) { totalProgressSteps += eventQueryServiceRegistrationsCount; // uhh nice padding for summary generation } var progressIncrement = 100 / Math.Max(totalProgressSteps, 1); var processingResults = new List <ProcessingResult>(); var cancelSource = new CancellationTokenSource(); var tf = new TaskFactory(); var taskList = new List <Task>(); foreach (var eventQueryServiceRegistration in eventQueryServiceRegistrations) { if (m_isParallelProcessingEnabled) { var task = tf.StartNew(() => { if (cancelSource.IsCancellationRequested) { return; } var result = ProcessResult(eventQueryServiceRegistration, uiDispatcher, selectedStartLocalTime, selectedEndLocalTime, progressIncrement); if (result.Exception != null) { m_messenger.Send(result.Exception); cancelSource.Cancel(); return; } processingResults.Add(result); }, cancelSource.Token); taskList.Add(task); } else { var result = ProcessResult(eventQueryServiceRegistration, uiDispatcher, selectedStartLocalTime, selectedEndLocalTime, progressIncrement); if (result.Exception != null) { m_messenger.Send(result.Exception); cancelSource.Cancel(); return; } processingResults.Add(result); } } Task.WaitAll(taskList.ToArray()); if (cancelSource.IsCancellationRequested) { return; } if (selectedIsGeneratePerSourceEnabled) { foreach (var result in processingResults) { foreach (var render in renderServiceRegistrations) { KeyValuePair <ServiceRegistration, IRenderEvents> render1 = render; currentActivity = String.Format("Rendering data for {0} - {1} with {2} - {3}...", result.EventSourceService.Family, result.EventSourceService.Name, render1.Key.Family, render1.Key.Name); uiDispatcher.Invoke( () => { ProgressStatus = String.Format("{0}...", currentActivity); }); Action renderEventsDelegate = () => render1.Value.Render(result.EventSourceService.Id, selectedStartLocalTime, (selectedEndLocalTime.AddDays(1).AddTicks(-1)), result.Events, result.WeightedTags, result.WeightedPeople, result.ImportantSentences); if (render.Key.InvokeOnShellDispatcher) { uiDispatcher.Invoke(renderEventsDelegate); } else { renderEventsDelegate(); } } } } if (selectedIsGeneratePerSummaryEnabled) { var summaryEvents = new List <Event>(); var summaryWeightedTags = new ConcurrentDictionary <string, int>(); var summaryWeightedPeople = new ConcurrentDictionary <string, int>(); var summaryImportantSentences = new List <string>(); foreach (var result in processingResults) { summaryEvents.AddRange(result.Events); foreach (var weightedTagEntry in result.WeightedTags) { summaryWeightedTags.AddOrUpdate(weightedTagEntry.Key, weightedTagEntry.Value, (s, i) => i + weightedTagEntry.Value); } foreach (var weightedPersonEntry in result.WeightedPeople) { summaryWeightedPeople.AddOrUpdate(weightedPersonEntry.Key, weightedPersonEntry.Value, (s, i) => i + weightedPersonEntry.Value); } summaryImportantSentences.AddRange(result.ImportantSentences); } foreach (var render in renderServiceRegistrations) { KeyValuePair <ServiceRegistration, IRenderEvents> render1 = render; Action renderEventsDelegate = () => render1.Value.Render("Summary", selectedStartLocalTime, (selectedEndLocalTime.AddDays(1).AddTicks(-1)), summaryEvents, summaryWeightedTags, summaryWeightedPeople, summaryImportantSentences); currentActivity = String.Format("Rendering summary data with {0} - {1}", render1.Key.Family, render1.Key.Name); uiDispatcher.Invoke(() => { ProgressStatus = String.Format("{0}...", currentActivity); }); if (render.Key.InvokeOnShellDispatcher) { uiDispatcher.Invoke(renderEventsDelegate); } else { renderEventsDelegate(); } } } uiDispatcher.Invoke(() => { ProgressPercentage = 100; }); } catch (AggregateException ex) { Trace.WriteLine("Aggregate inner exception: " + ex.InnerException); m_messenger.Send(new ExceptionMessage(ex.InnerException, currentActivity)); } catch (Exception ex) { Trace.WriteLine(ex); m_messenger.Send(new ExceptionMessage(ex, currentActivity)); } }); IsBusy = false; ProgressStatus = "...done."; ProgressPercentage = 100; } }