void Client_OnSystemErrorsAdded(object sender, GXAmiSystemError[] errors) { if (this.InvokeRequired) { this.BeginInvoke(new SystemErrorsAddedEventHandler(OnSystemErrorsAdded), sender, errors); } else { OnSystemErrorsAdded(sender, errors); } }
public GXErrorsResponse(GXAmiSystemError[] errors) { this.SystemErrors = errors; }
void OnSystemErrorsAdded(object sender, GXAmiSystemError[] errors) { //If pause is checked or component has destroied. if (this.IsDisposed || EventPauseMenu.Checked) { return; } /* //If information messages are not shown... if (severity == -2 && !m_ShowInformationMessages) { return; } * */ foreach (GXAmiSystemError err in errors) { //Remove first item if maximum item count is reached. if (Gurux.DeviceSuite.Properties.Settings.Default.ErrorMaximumCount > 0 && EventsList.Items.Count == Gurux.DeviceSuite.Properties.Settings.Default.ErrorMaximumCount) { EventsList.Items[0].Remove(); } ListViewItem it = new ListViewItem(new string[] { err.TimeStamp.ToString(), "", err.Message }); EventsList.Items.Add(it); if (EventFollowLast) { EventsList.EnsureVisible(it.Index); } } }
void Client_OnSystemErrorsRemoved(object sender, GXAmiSystemError[] errors) { throw new NotImplementedException(); }
public override object HandleException(IRequest requestContext, TRequest request, Exception ex) #endif { //Do not handle connection close exceptions. if (ex is System.Net.WebException && (ex as System.Net.WebException).Status != System.Net.WebExceptionStatus.ConnectionClosed) { try { GuruxAMI.Server.AppHost.ReportError(ex); } catch (Exception ex2) { System.Diagnostics.Debug.WriteLine(ex2.Message); } try { if (!System.Diagnostics.EventLog.SourceExists("GuruxAMI")) { System.Diagnostics.EventLog.CreateEventSource("GuruxAMI", "Application"); } System.Diagnostics.EventLog appLog = new System.Diagnostics.EventLog(); appLog.Source = "GuruxAMI"; appLog.WriteEntry(ex.Message); } catch (System.Security.SecurityException) { //Security exception is thrown if GuruxAMI source is not exists and it's try to create without administrator privilege. //Just skip this, but errors are not write to eventlog. } try { #if !SS4 var httpReq = requestContext.Get <IHttpRequest>(); #else var httpReq = request.GetDto <IHttpRequest>(); #endif int id = 0; if (int.TryParse(httpReq.GetSession(false).Id, out id) && id != 0) { ActionTargets target; Actions action; GetExecutedAction(request, out target, out action); #if !SS4 IDbConnectionFactory f = this.TryResolve <IDbConnectionFactory>(); #else IDbConnectionFactory f = this.ResolveService <IDbConnectionFactory>(requestContext); #endif using (IDbConnection Db = f.OpenDbConnection()) { lock (Db) { GXAmiSystemError e = new GXAmiSystemError(id, target, action, ex); Db.Insert(e); } } } else //If DC. TODO: { } } catch (Exception ex2) { System.Diagnostics.Debug.WriteLine(ex2.Message); } } return(base.HandleException(requestContext, request, ex)); }
/// <summary> /// Start listen events. /// </summary> /// <param name="request"></param> /// <returns></returns> public GXEventsRegisterResponse Post(GXEventsRegisterRequest request) { if (request.SessionListener.Equals(Guid.Empty) || request.Instance.Equals(Guid.Empty)) { throw new Exception("Listener Guid is empty."); } if (request.Actions == Actions.None && request.Targets == ActionTargets.None) { return new GXEventsRegisterResponse(); } IAuthSession s = this.GetSession(false); long id = 0; bool superAdmin = false; Guid guid = request.DataCollectorGuid; //Guid is set if DC is retreaving new tasks. if (long.TryParse(s.Id, out id)) { superAdmin = GuruxAMI.Server.GXBasicAuthProvider.IsSuperAdmin(s); } else { if (request.DataCollectorGuid.Equals(Guid.Empty)) { throw new Exception("Data collector Guid is empty."); } } AppHost host = this.ResolveService<AppHost>(); //Check that there are no several DCs with same Guid. //Note! This might happend when DC is restarted wrong. //For this reason we are only give a warning. List<GXEventsItem> events = new List<GXEventsItem>(); if (host.IsDCRegistered(guid)) { lock (Db) { GXAmiSystemError e = new GXAmiSystemError(1, ActionTargets.SystemError, Actions.State, new Exception("Data collector already exists.")); Db.Insert<GXAmiSystemError>(e); events.Add(new GXEventsItem(ActionTargets.SystemError, Actions.Add, e)); } } ulong mask = (ulong)(((int)request.Targets << 16) | (int)request.Actions); GXEvent e1 = new GXEvent(id, superAdmin, guid, request.Instance, mask); host.AddEvent(request.SessionListener, e1); if (guid != Guid.Empty) { //Notify that DC is connected. lock (Db) { GXAmiDataCollector dc = Db.Select<GXAmiDataCollector>(q => q.Guid == guid)[0]; dc.State = Gurux.Device.DeviceStates.Connected; Db.UpdateOnly(dc, p => p.StatesAsInt, p => p.Id == dc.Id); events.Add(new GXEventsItem(ActionTargets.DataCollector, Actions.State, dc)); } host.SetEvents(Db, this.Request, 0, events); } return new GXEventsRegisterResponse(); }
/// <summary> /// Start listen events. /// </summary> /// <param name="request"></param> /// <returns></returns> public GXEventsRegisterResponse Post(GXEventsRegisterRequest request) { if (request.SessionListener.Equals(Guid.Empty) || request.Instance.Equals(Guid.Empty)) { throw new Exception("Listener Guid is empty."); } if (request.Actions == Actions.None && request.Targets == ActionTargets.None) { return(new GXEventsRegisterResponse()); } IAuthSession s = this.GetSession(false); long id = 0; bool superAdmin = false; Guid guid = request.DataCollectorGuid; //Guid is set if DC is retreaving new tasks. if (long.TryParse(s.Id, out id)) { superAdmin = GuruxAMI.Server.GXBasicAuthProvider.IsSuperAdmin(s); } else { if (request.DataCollectorGuid.Equals(Guid.Empty)) { throw new Exception("Data collector Guid is empty."); } } AppHost host = this.ResolveService <AppHost>(); //Check that there are no several DCs with same Guid. //Note! This might happend when DC is restarted wrong. //For this reason we are only give a warning. List <GXEventsItem> events = new List <GXEventsItem>(); if (host.IsDCRegistered(guid)) { lock (Db) { GXAmiSystemError e = new GXAmiSystemError(1, ActionTargets.SystemError, Actions.State, new Exception("Data collector already exists.")); Db.Insert <GXAmiSystemError>(e); events.Add(new GXEventsItem(ActionTargets.SystemError, Actions.Add, e)); } } ulong mask = (ulong)(((int)request.Targets << 16) | (int)request.Actions); GXEvent e1 = new GXEvent(id, superAdmin, guid, request.Instance, mask); host.AddEvent(request.SessionListener, e1); if (guid != Guid.Empty) { //Notify that DC is connected. lock (Db) { GXAmiDataCollector dc = Db.Select <GXAmiDataCollector>(q => q.Guid == guid)[0]; dc.State = Gurux.Device.DeviceStates.Connected; Db.UpdateOnly(dc, p => p.StatesAsInt, p => p.Id == dc.Id); events.Add(new GXEventsItem(ActionTargets.DataCollector, Actions.State, dc)); } host.SetEvents(Db, this.Request, 0, events); } return(new GXEventsRegisterResponse()); }