Example #1
0
        /// <summary>
        /// If passed-in event is a SettingsReadEvent, then this routine updates the database with the GasEndPoints.
        /// </summary>
        /// <param name="dsEvent"></param>
        private void SaveGasEndPoints(SettingsReadEvent settingsReadEvent, DataAccessTransaction trx)
        {
            // Either settingsReadEvent.DockingStation.GasEndPoints will have
            // contents or else ChangedGasEndPoints will.  Never both.
            Log.Assert((settingsReadEvent.DockingStation.GasEndPoints.Count > 0 && settingsReadEvent.DockingStation.ChangedGasEndPoints.Count > 0) == false,
                       "Both GasEndPoints and ChangedGasEndPoints cannot contain data.");

            // If GasEndPoints has contents, then the list contains all known attached
            // cylinders.
            // If ChangedGasEndPoints has contents, then the list contains known changes:
            // e.g.., if there's been no iGas card insertion/removal on, say,
            // position 2, then there will be no cylinder in the list at that position.

            GasEndPointDataAccess gepDataAccess = new GasEndPointDataAccess();

            if (settingsReadEvent.DockingStation.GasEndPoints.Count > 0)
            {
                Log.Debug(string.Format("Calling SaveInstalledCylinders (GasEndPoints.Count={0})", settingsReadEvent.DockingStation.GasEndPoints.Count));
                gepDataAccess.SaveInstalledCylinders(settingsReadEvent.DockingStation.GasEndPoints, trx);
            }
            // Note that we don't check the ChangedGasEndPoints to see if it's empty or not.
            // If GasEndPoints is empty, then we assume we're to use ChangedGasEndPoints
            // If it's empty, then it means there are no known changed cylinders. The call
            // to SaveInstalledCylinders will handle that.
            else
            {
                Log.Debug("Calling SaveChangedCylinders");
                gepDataAccess.SaveChangedCylinders(settingsReadEvent.DockingStation.ChangedGasEndPoints, trx);
            }
        }
        /// <summary>
        /// Deletes the item on the front of the queue.
        /// </summary>
        /// <returns>true or false based on success/failure of the operation.</returns>
        public bool Delete()
        {
            bool deleted = false;

            try
            {
                using (DataAccessTransaction trx = new DataAccessTransaction(_queueDataSource, false))
                {
                    QueueDataAccess dataAccess = queueDataAccess;

                    long id = dataAccess.FindOldestId(trx);

                    if (id != DomainModelConstant.NullId)
                    {
                        deleted = dataAccess.Delete(id, trx);
                    }

                    trx.Commit();
                }
            }
            catch (Exception ex)
            {
                Log.Error("Could not delete oldest item from the queue!");
                Log.Error(ex.ToString());
            }
            return(deleted);
        }
        public DockingStationEvent Execute()
        {
            string funcMsg = Name + ".Execute";

            Log.Debug(funcMsg);

            // We copy the PostUpdate and SettingsRefId from the action to the event so they can
            // be passed on to the followup SettingsRead.  See the EventProcessor.GetFollowupAction method.
            CylinderPressureResetEvent dsEvent = new CylinderPressureResetEvent(this);

            dsEvent.PostUpdate    = this.PostUpdate;
            dsEvent.SettingsRefId = this.SettingsRefId;

            List <GasEndPoint> emptyManGasEndPoints = new List <GasEndPoint>();
            List <GasEndPoint> manGasEndPoints
                = new GasEndPointDataAccess().FindAll().FindAll(m => m.InstallationType == GasEndPoint.Type.Manifold ||
                                                                m.InstallationType == GasEndPoint.Type.Manual);

            // We want to reset low/empty non-iGas cylinders to full.
            for (int position = 1; position <= Configuration.DockingStation.NumGasPorts; position++)
            {
                // We don't want to process (manual) fresh air cylinders on port 1.
                GasEndPoint man = manGasEndPoints.Find(m => m.Position == position && !(m.Position == 1 && m.Cylinder.IsFreshAir));
                if (man != null)
                {
                    Log.Debug(string.Format("{0}Position {1} {2} found (\"{3}\", \"{4}\") with {5} pressure.", LOG_LABEL, position,
                                            man.InstallationType == GasEndPoint.Type.Manifold ? "Manifold" : "Manual Cylinder",
                                            man.Cylinder.FactoryId, man.Cylinder.PartNumber, man.Cylinder.Pressure));

                    if (man.Cylinder.Pressure != PressureLevel.Full)
                    {
                        man.GasChangeType     = GasEndPoint.ChangeType.PressureChanged;
                        man.Cylinder.Pressure = PressureLevel.Full;
                        emptyManGasEndPoints.Add(man);
                    }
                }
            }

            if (emptyManGasEndPoints.Count > 0)
            {
                // Save the modified cylinders in the local database.  The followup SettingsRead with
                // ChangedSmartCards set to null will take care of updating the cylinders in memory.
                using (DataAccessTransaction trx = new DataAccessTransaction())
                {
                    new GasEndPointDataAccess().SaveChangedCylinders(emptyManGasEndPoints, trx);
                    trx.Commit();

                    Log.Debug(string.Format("{0}{1} non-iGas cylinders were reset to full.", LOG_LABEL, emptyManGasEndPoints.Count));
                }
            }
            else
            {
                Log.Debug(string.Format("{0}No manifold or manual cylinders were found that needed reset to full.", LOG_LABEL));
            }

            return(dsEvent);
        }
Example #4
0
        /// <summary>
        /// To remove the old data specific to Repair if any available, if the DSX is no longer is in a Repair account. INS-7282
        /// </summary>
        private void RemoveServiceData()
        {
            if (Configuration.IsRepairAccount())
            {
                return;
            }

            using (DataAccessTransaction trx = new DataAccessTransaction())
            {
                Log.Debug(string.Format("Deleting Sensor Calibration Limits if any, since this is no more a service account. Account type is {0}", Configuration.Schema.ServiceCode));
                new SensorCalibrationLimitsDataAccess().Delete(trx);

                //Consider Critical Errors, since this also can be configured at the Repair accounts level
                trx.Commit();
            }
        }
Example #5
0
        /// <summary>
        /// Removes data for old equipment that is no longer associated with the account.
        /// </summary>
        private void RemoveOldData()
        {
            // Contact the iNet server to get lists (serial numbers) of equipment to delete

            Schema schema = Configuration.Schema;

            DateTime version = (schema.EquipmentVersion == null) ? Configuration.DockingStation.SetupDate : (DateTime)schema.EquipmentVersion;

            // Create lists to fill in with data returned by iNet.
            List <string> instruments = new List <string>();
            List <string> sensors     = new List <string>();

            DateTime?equipmentVersion = null;

            using (InetDownloader inetDownloader = new InetDownloader())
            {
                equipmentVersion = inetDownloader.DownloadRemovedEquipment(instruments, sensors, version, _maintenanceEvent.Errors);
            }

            if (equipmentVersion == null)
            {
                Log.Debug(string.Format("{0}: Received null for equipmentVersion. ", Name));
                Log.Debug(string.Format("{0}: Couldn't connect to iNet?  Then there's nothing more we can do.", Name));
                return;
            }

            using (DataAccessTransaction trx = new DataAccessTransaction())
            {
                Log.Debug(string.Format("{0}: Deleting eventjournals for {1} instruments", Name, instruments.Count));
                RemoveEventJournals(instruments, trx);

                Log.Debug(string.Format("{0}: Deleting eventjournals for {1} sensors", Name, sensors.Count));
                RemoveEventJournals(sensors, trx);

                //Log.Debug( string.Format( "{0}: Deleting data for {1} sensors", Name, instruments.Count ) );
                //RemoveSchedules( sensors, trx );

                new SchemaDataAccess().UpdateEquipmentVersion(equipmentVersion, trx);

                trx.Commit();

                Configuration.Schema.EquipmentVersion = equipmentVersion;

                _maintenanceEvent.Errors.AddRange(trx.Errors);
            }
        }
Example #6
0
        /// <summary>
        /// Deletes all event journal records from the database for the specified serial numbers.
        /// </summary>
        /// <param name="serialNumbers"></param>
        /// <param name="trx"></param>
        private void RemoveEventJournals(IList <string> serialNumbers, DataAccessTransaction trx)
        {
            // Delete all EventJournals matching the serial numbers.
            // We do so in batches for better performance.

            const int batchSize = 25;

            EventJournalDataAccess eventJournalDataAccess = new EventJournalDataAccess();

            Queue <string> snQueue = new Queue <string>(serialNumbers);

            while (snQueue.Count > 0)
            {
                IList <string> snbatch = GetBatch(snQueue, batchSize);
                eventJournalDataAccess.DeleteBySerialNumbers(snbatch, trx);
            }
        }
Example #7
0
        /// <summary>
        /// </summary>
        /// <param name="serialNumber"></param>
        /// <returns></returns>
        private DockingStation LoadSettings(string serialNumber)
        {
            Log.Debug(string.Format("{0}: UseDockingStation={1}", Name, UseDockingStation));

            // Assume settings were already given to us (via the UpdateAction) if
            // UseDockingStation has been set.  This would be the case for an update of some
            // setting from VDS.Config.
            if (this.UseDockingStation == true)
            {
                Log.Debug(string.Format("{0}: UseDockingStation=true, Using refId={1}", Name, (this.DockingStation.RefId == DomainModelConstant.NullId ? "NullId" : this.DockingStation.RefId.ToString())));
                return(this.DockingStation);
            }
            // Otherwise, load settings from the database.

            //Suresh 12-SEPTEMBER-2011 INS-2248
            using (DataAccessTransaction trx = new DataAccessTransaction(true))
            {
                // For the SettingsUpdate, find the settings we've previously received from
                // the iNet server that are kept persisted in the database.
                DockingStation ds = new DockingStationDataAccess().Find(trx);

                if (ds == null)
                {
                    string errMsg = string.Format("{0}: NO DOCKINGSTATION SETTINGS FOUND.", Name);
                    Log.Error(errMsg);
#if DEBUG
                    Log.Debug("DO YOU NEED TO SET UseDockingStation TO TRUE?");
#endif
                    _settingsUpdateEvent.Errors.Add(new DockingStationError(errMsg, DockingStationErrorLevel.Warning));
                    return(null);
                }

                //Suresh 12-SEPTEMBER-2011 INS-2248
                ds.ReplacedDSNetworkSettings = new ReplacedNetworkSettingsDataAccess().Find(trx);

                ds.SerialNumber = serialNumber;

                Log.Debug(string.Format("{0}: Loaded DockingStation Settings, refId={1}", Name, ds.RefId));

                return(ds);
            }
        }
        /// <summary>
        /// Loads the ReplacedEquipment serial numbers from the locally stored database.
        /// </summary>
        private void LoadReplacedEquipment()
        {
            List <string> replacedSerialNumberList;

            using (DataAccessTransaction trx = new DataAccessTransaction(true))
            {
                replacedSerialNumberList = new ReplacedEquipmentDataAccess().FindAll(trx);
            }

            Dictionary <string, string> replacedEquipment = new Dictionary <string, string>();

            foreach (string key in replacedSerialNumberList)
            {
                // if the key does not exist (which is expected),
                // a new key/value pair is added to the dictionary
                replacedEquipment[key] = key;
            }

            Master.Instance.ExecuterService.ReplacedEquipment = replacedEquipment;
        }
Example #9
0
        /// <summary>
        /// Removes old manufacturing data that is no longer needed in the iNet DS database.
        /// </summary>
        private void RemoveOldMfgData()
        {
            // Only purge old data if this is a manufacturing account.  If this is a docking station that belongs
            // to a non-manufacturing account, then simply leave this method before taking any action.
            if (!Configuration.Schema.IsManufacturing)
            {
                return;
            }

            // Calculate the time span to apply as an age limit on the journal entries.
            TimeSpan journalAge = new TimeSpan(MAX_MFG_DAYS, 0, 0, 0);

            using (DataAccessTransaction trx = new DataAccessTransaction())
            {
                Log.Debug(string.Format("{0}: Deleting eventjournals from the manufacturing account older than {1} days, {2} hours, {3} minutes, and {4} seconds",
                                        Name, journalAge.Days, journalAge.Hours, journalAge.Minutes, journalAge.Seconds));
                RemoveEventJournals(journalAge, trx);
                trx.Commit();
            }
        }
Example #10
0
        private bool SaveEventJournals(DockingStationEvent dsEvent, DateTime lastDockedTime, DataAccessTransaction trx)
        {
            if (dsEvent.EventCode == null)
            {
                return(true);
            }

            EventJournalDataAccess ejDataAccess = new EventJournalDataAccess();

            EventJournal eventJournal = null;

            // If the event implements IPassed, then use the result of its
            // Passed property.  Otherwise, just default to true.
            bool passed = ((dsEvent is IPassed)) ? ((IPassed)dsEvent).Passed : true;

            if (dsEvent is InstrumentEvent)
            {
                // special case for // bump & cals... need to save a separate
                // event journal for every sensor involved in gas operation.
                // Note that in this situation, we also do NOT save an entry for the instrument itself.
                if (dsEvent is InstrumentGasResponseEvent && !(dsEvent is InstrumentManualOperationsDownloadEvent))
                {
                    InstrumentGasResponseEvent gasResponseTestEvent = (InstrumentGasResponseEvent)dsEvent;
                    if (gasResponseTestEvent.GasResponses.Count <= 0)
                    {
                        return(true);
                    }

                    bool allSaved = true;
                    foreach (SensorGasResponse sgr in gasResponseTestEvent.GasResponses)
                    {
                        eventJournal = new EventJournal(gasResponseTestEvent.EventCode.Code, sgr.Uid,
                                                        gasResponseTestEvent.DockedInstrument.SerialNumber,
                                                        sgr.Time, dsEvent.Time, sgr.Passed,
                                                        sgr.Position, gasResponseTestEvent.DockedInstrument.SoftwareVersion);
                        allSaved &= ejDataAccess.Save(eventJournal, trx);
                    }
                    // If gasResponseEvent is a InstrumentBumpTestEvent, it might have calibration gas responses due to O2 high bump test failure.
                    // If there are any gas responses in HighBumpFailCalGasResponses, store them to the event journals.
                    foreach (SensorGasResponse sgr in gasResponseTestEvent.HighBumpFailCalGasResponses)
                    {
                        eventJournal = new EventJournal(EventCode.Calibration, sgr.Uid,
                                                        gasResponseTestEvent.DockedInstrument.SerialNumber,
                                                        sgr.Time, dsEvent.Time, sgr.Passed,
                                                        sgr.Position, gasResponseTestEvent.DockedInstrument.SoftwareVersion);
                        allSaved &= ejDataAccess.Save(eventJournal, trx);
                    }
                    return(allSaved);
                }
                else
                {
                    eventJournal = new EventJournal(dsEvent.EventCode, ((InstrumentEvent)dsEvent).DockedInstrument.SerialNumber, dsEvent.Time, dsEvent.Time, passed, ((InstrumentEvent)dsEvent).DockedInstrument.SoftwareVersion);
                }
            }
            else // DockingStationEvent
            {
                eventJournal = new EventJournal(dsEvent.EventCode, dsEvent.DockingStation.SerialNumber, dsEvent.Time, dsEvent.Time, passed, dsEvent.DockingStation.SoftwareVersion);
            }

            return(ejDataAccess.Save(eventJournal, trx));  // Update/insert EventJournal record for the event.
        }
Example #11
0
		public DataAccessScope(DataAccessIsolationLevel isolationLevel, DataAccessScopeOptions options, TimeSpan timeout)
		{
			this.IsolationLevel = isolationLevel;
			var currentTransaction = DataAccessTransaction.Current;

			this.options = options;

			switch (options)
			{
			case DataAccessScopeOptions.Required:
				if (currentTransaction == null)
				{
					this.isRoot = true;
					this.transaction = new DataAccessTransaction(isolationLevel, timeout);
					DataAccessTransaction.Current = this.transaction;
				}
				else
				{
					this.transaction = currentTransaction;
					this.outerTransaction = currentTransaction;
				}
				break;
			case DataAccessScopeOptions.RequiresNew:
				this.isRoot = true;
				this.outerTransaction = currentTransaction;
				if (Transaction.Current != null)
				{
					this.nativeScope = new TransactionScope(TransactionScopeOption.RequiresNew);
				}
				this.transaction = new DataAccessTransaction(isolationLevel, timeout);
				DataAccessTransaction.Current = this.transaction;
				break;
			case DataAccessScopeOptions.Suppress:
				if (Transaction.Current != null)
				{
					this.nativeScope = new TransactionScope(TransactionScopeOption.Suppress);
				}
				if (currentTransaction != null)
				{
					this.outerTransaction = currentTransaction;
					DataAccessTransaction.Current = null;
				}
				break;
			}
		}
 public DefaultSqlTransactionalCommandsContext(SqlDatabaseContext sqlDatabaseContext, DataAccessTransaction transaction)
     : base(sqlDatabaseContext, sqlDatabaseContext.OpenConnection(), transaction)
 {
     this.sqlDataTypeProvider      = sqlDatabaseContext.SqlDataTypeProvider;
     this.tableNamePrefix          = sqlDatabaseContext.TableNamePrefix;
     this.parameterIndicatorPrefix = sqlDatabaseContext.SqlDialect.GetSyntaxSymbolString(SqlSyntaxSymbol.ParameterPrefix);
 }
Example #13
0
        /// <summary>
        /// Saves/updates in the database whatever needs to be saved/updated based
        /// on the results of the passed-in event.
        /// Includes saving the event, updating installed cylinders, deleting ScheduledOnces.
        /// </summary>
        /// <param name="dsEvent"></param>
        /// <param name="lastDockedTime"></param>
        internal void Save(DockingStationEvent dsEvent, DateTime lastDockedTime)
        {
            // We don't want to start a transaction unless we know we're going to update
            // the database, since merely just beginning a writable transaction causes a write.
            // Not every event type will have a code.  For those that don't, we don't
            // need the last run time saved (such as Nothing events or interactive diagnostics)
            if (dsEvent.EventCode == null)
            {
                return;
            }

            // Save event journals and installed cylinder updates all in a single transaction.
            // If this event was invoked by a run-once schedule, then that schedule is also
            // deleted in the same transaction.
            using (DataAccessTransaction trx = new DataAccessTransaction())
            {
                // Save/update EventJournals for the event.
                bool saved = SaveEventJournals(dsEvent, lastDockedTime, trx);

                Log.Debug(string.Format("SaveEventJournals({0})={1}", dsEvent, saved));

                // If this event was invoked by a run-once schedule, then delete the schedule
                // since, by definition, "run once" schedules are run once, then deleted.
                if ((dsEvent.Schedule != null) && (dsEvent.Schedule is ScheduledOnce))
                {
                    bool deleted = new ScheduledOnceDataAccess().DeleteById(dsEvent.Schedule.Id, trx);
                    Log.Debug(string.Format("ScheduledOnceDataAccess.Delete({0})={1}", dsEvent.Schedule.Id, deleted));
                }

                // If event is a SettingsRead, then SaveGasEndPoints will update the GasEndPoints
                // in the database based on what what cylinders the SettingsRead found attached to
                // the docking station.
                if (dsEvent is SettingsReadEvent)
                {
                    SaveGasEndPoints((SettingsReadEvent)dsEvent, trx);

                    // If this is a SettingsReadEvent, reload the GasEndPoints from the database
                    // now that  they've been saved and cache them in our global dockingstation.
                    // This also has the side effect of setting ech of their 'Supported' properties
                    // to null which will force a revalidation of their part numbers against the
                    // known FactoryCylinder part numbers.
                    Configuration.DockingStation.GasEndPoints = new GasEndPointDataAccess().FindAll(trx);
                }
                else if (dsEvent is InstrumentSettingsReadEvent)
                {
                    // If this is a InstrumentSettingsReadEvent, then refresh the switch'service's
                    // docked instrument information with the information from the event.
                    // If we don't do this, then the switch service's information can become out of
                    // date after Instrument Settings Updates are performed, or instrument firmware
                    // is updated, etc.
                    //
                    // TODO: the following is probably not necessary anymore do to changes made for INS-3825.
                    // InstrumentSettingsRead operation is now just returning a clone of SwitchService.Instrument.
                    // So setting the SwitchService.Instrument to be a clone of what InstrumentSettingsRead
                    // returned is pretty much just setting it to a clone of an exact copy of itself.
                    // -- JMP, 2/13/2013.
                    Master.Instance.SwitchService.Instrument = (DomainModel.Instrument)((InstrumentSettingsReadEvent)dsEvent).DockedInstrument.Clone();

                    //Suresh 05-JAN-2012 INS-2564
                    //During instrument setting read if we find any sensor in error state then we want to report it to iNet
                    Master.Instance.ExecuterService.ReportDiscoveredInstrumentErrors((InstrumentEvent)dsEvent);
                }
                else if ((dsEvent is InstrumentCalibrationEvent) &&
                         (Master.Instance.SwitchService.Instrument.SerialNumber != string.Empty)) // can this happen here?
                {
                    // Keep the Sensors in the cached instrument object updated with the status
                    // of what happened during the calibration, for use by the scheduler.

                    bool            cylinderHoseProblem   = false;
                    UsedGasEndPoint gasEndPointUsedForCal = null;       // INS-8446 RHP v7.6

                    foreach (SensorGasResponse sgr in (dsEvent as InstrumentCalibrationEvent).GasResponses)
                    {
                        // If any sensor failed calibration with a zero span reserve, then set the SwitchService's CylinderHoseProblem to true.
                        // We don't do this for O2 sensors, though, as a O2 calibration failure with a zero span reserve would not indicate a
                        // a problem with the hoses. - INS-1279, 6/20/2011, JMP // INETQA-4131 RHP v7.6 - Added Status.Failed condition check below.
                        if (sgr.SensorCode != SensorCode.O2 && (sgr.Status == Status.SpanFailed || sgr.Status == Status.SpanFailedZeroFailed || sgr.Status == Status.Failed) &&
                            sgr.FullSpanReserve == 0.0)
                        {
                            cylinderHoseProblem = true;
                            // INS-8446 RHP v7.6 - Save the Cylinder details which is expected to have hose problems.
                            // Do a NULL to ensure that we identify the first gas response that failed a calibration with Zero Span reserve and fetch its gas end point being used.
                            if (gasEndPointUsedForCal == null)
                            {
                                gasEndPointUsedForCal = sgr.UsedGasEndPoints.Find(uge => uge.Usage == CylinderUsage.Calibration && !uge.Cylinder.IsFreshAir && !uge.Cylinder.IsZeroAir);
                            }
                        }

                        Sensor sensor = (Sensor)Master.Instance.SwitchService.Instrument.InstalledComponents.Find(ic => ic.Component.Uid == sgr.Uid).Component;
                        if (sensor != null)
                        {
                            sensor.CalibrationStatus = sgr.Status;
                        }
                    }

                    //Suresh 22-Feb-2012 INS-2705
                    //After calibration is completed , we need to update sensor bump test status because in scheduler we have logic
                    //to force calibration based on sensor BumpTestStatus
                    foreach (InstalledComponent installedComponent in (dsEvent as InstrumentCalibrationEvent).DockedInstrument.InstalledComponents)
                    {
                        if (!(installedComponent.Component is Sensor))  // Skip non-sensors.
                        {
                            continue;
                        }

                        if (!installedComponent.Component.Enabled) // Skip disabled sensors.
                        {
                            continue;
                        }

                        Sensor bumpTestedSensor = (Sensor)installedComponent.Component;

                        Sensor sensor = (Sensor)Master.Instance.SwitchService.Instrument.InstalledComponents.Find(ic => ic.Component.Uid == bumpTestedSensor.Uid).Component;
                        if (sensor != null)
                        {
                            sensor.BumpTestStatus = bumpTestedSensor.BumpTestStatus;
                        }
                    }

                    // If at least one sensor had a status of InstrumentAborted, then we know the instrument reset.
                    // The check cylinders message should not be shown on the LCD.
                    foreach (SensorGasResponse sgr in (dsEvent as InstrumentCalibrationEvent).GasResponses)
                    {
                        if (sgr.Status == Status.InstrumentAborted)
                        {
                            cylinderHoseProblem   = false;
                            gasEndPointUsedForCal = null;
                            break;
                        }
                    }

                    Master.Instance.SwitchService.BadGasHookup = cylinderHoseProblem;
                    // INS-8446 RHP v7.6 - Set the SwitchService's BadGasHookUpCylinderPartNumber which is expected to have hose problems to display the same on LCD
                    Master.Instance.SwitchService.BadGasHookUpCylinderPartNumber = gasEndPointUsedForCal == null ? string.Empty : gasEndPointUsedForCal.Cylinder.PartNumber;
                    Log.Debug(string.Format("EventProcessor : BadGasHookUpCylinderPartNumber identified cylinder with Part Number {0}", Master.Instance.SwitchService.BadGasHookUpCylinderPartNumber));
                }
                //Suresh 22-Feb-2012 INS-2705
                else if ((dsEvent is InstrumentBumpTestEvent) &&
                         (Master.Instance.SwitchService.Instrument.SerialNumber != string.Empty)) // can this happen here?
                {
                    // Keep the Sensors in the cached instrument object updated with the status
                    // of what happened during the bumptest, for use by the scheduler.

                    foreach (InstalledComponent installedComponent in (dsEvent as InstrumentBumpTestEvent).DockedInstrument.InstalledComponents)
                    {
                        if (!(installedComponent.Component is Sensor))  // Skip non-sensors.
                        {
                            continue;
                        }

                        if (!installedComponent.Component.Enabled) // Skip disabled sensors.
                        {
                            continue;
                        }

                        Sensor bumpTestedSensor = (Sensor)installedComponent.Component;

                        Sensor sensor = (Sensor)Master.Instance.SwitchService.Instrument.InstalledComponents.Find(ic => ic.Component.Uid == bumpTestedSensor.Uid).Component;
                        if (sensor != null)
                        {
                            sensor.BumpTestStatus = bumpTestedSensor.BumpTestStatus;
                        }
                    }
                }

                trx.Commit();
            }
        }
Example #14
0
		internal TransactionContext(DataAccessTransaction dataAccessTransaction, DataAccessModel dataAccessModel)
		{
			this.dataAccessModel = dataAccessModel;
			this.DataAccessTransaction = dataAccessTransaction;
			this.DatabaseContextCategoriesKey = "*";
			this.attributes = new Dictionary<string, object>();
			this.executionVersion = dataAccessModel.AsyncLocalExecutionVersion;
		}
Example #15
0
		public virtual SqlTransactionalCommandsContext CreateSqlTransactionalCommandsContext(DataAccessTransaction transaction)
		{
			return new DefaultSqlTransactionalCommandsContext(this, transaction);
		}
Example #16
0
		internal TransactionContext(DataAccessTransaction dataAccessTransaction, DataAccessModel dataAccessModel)
		{
			this.dataAccessModel = dataAccessModel;
			this.DataAccessTransaction = dataAccessTransaction;
			this.DatabaseContextCategoriesKey = "*";
			this.executionVersion = dataAccessModel.AsyncLocalExecutionVersion;

			this.commandsContextsBySqlDatabaseContexts = new ConcurrentDictionary<SqlDatabaseContext, SqlTransactionalCommandsContext>();
		}
Example #17
0
        /// <summary>
        /// Deletes all event journal records from the database older than the specified amount of time.
        /// </summary>
        /// <param name="journalAge"></param>
        /// <param name="trx"></param>
        private void RemoveEventJournals(TimeSpan journalAge, DataAccessTransaction trx)
        {
            EventJournalDataAccess eventJournalDataAccess = new EventJournalDataAccess();

            eventJournalDataAccess.DeleteByTime(journalAge, trx);
        }
        private DockingStationAction ExamineGasEndPoints()
        {
            // First, for each attached cylinder, make sure it's a valid part number.
            // We try to not hit the database over and over to do this check
            // The GasEndPoints.Supported property helps us do that. If it's null,
            // then we've not checked the cylinder, so we query the database to do so.
            // We then set it to true or false appropiately.  Once all GasEndPoints' Supported
            // properties are non-null, we don't have to hit the database anymore.
            // Note that there's no need to check the 'part number' for fresh air.

            List <GasEndPoint> unverifiedGasEndPoints
                = Configuration.DockingStation.GasEndPoints.FindAll(g => g.Supported == null && g.Cylinder.PartNumber != FactoryCylinder.FRESH_AIR_PART_NUMBER);

            if (unverifiedGasEndPoints.Count > 0)
            {
                // Next, for every currently installed cylinder, verify that we recognize
                // the part number.  We check because the user may attach a cylinder
                // that has a new part number not yet known to iNet.
                FactoryCylinderDataAccess fcDataAccess = new FactoryCylinderDataAccess();

                using (DataAccessTransaction trx = new DataAccessTransaction(true))
                {
                    foreach (GasEndPoint g in unverifiedGasEndPoints)
                    {
                        g.Supported = fcDataAccess.FindByPartNumber(g.Cylinder.PartNumber, trx) != null;

                        Log.Debug(string.Format("Verified GasEndPoint {0} on port {1}. Supported={2}", g.Cylinder.PartNumber, g.Position, g.Supported));

                        if (g.Supported == false)   // no match found? Must be an unknown part number.
                        {
                            return(CreateUnsupportedCylinderAction(g));
                        }
                    }
                }
            }

            // At this point, we expect that cylinders have been verified.
            // We now check to see that each cylinder is supported by checking the
            // InstalledCylinder.Supported property.
            List <GasEndPoint> unsupportedGasEndPoints = Configuration.DockingStation.GasEndPoints.FindAll(g => g.Supported != null && g.Supported == false);

            if (unsupportedGasEndPoints.Count > 0)
            {
                GasEndPoint gep = unsupportedGasEndPoints[0];
                Log.Debug(string.Format("GasEndPoint {0} on port {1}. Supported={2}", gep.Cylinder.PartNumber, gep.Position, gep.Supported));
                return(CreateUnsupportedCylinderAction(gep));
            }

            // Next, verify that the cylinder on port 1 is legal for whatever the
            // current Fresh/Zero air restriction for that port.

            GasEndPoint gasEndPoint = Configuration.DockingStation.GasEndPoints.Find(g => g.Position == 1);

            // Either zero air OR fresh air is allowed?
            if (Configuration.DockingStation.Port1Restrictions == (PortRestrictions.FreshAir | PortRestrictions.ZeroAir))
            {
                if (gasEndPoint != null && !gasEndPoint.Cylinder.IsFreshAir && !gasEndPoint.Cylinder.IsZeroAir)
                {
                    Log.Debug(string.Format("Port1Restriction={0}, but cylinder is {1}", Configuration.DockingStation.Port1Restrictions.ToString(), gasEndPoint.Cylinder.PartNumber));
                    return(CreateUnsupportedCylinderAction(gasEndPoint));
                }
            }

            // Only fresh air is allowed?  It's illegal to have a non-freshAir cylinder is installed.
            if (Configuration.DockingStation.Port1Restrictions == PortRestrictions.FreshAir)
            {
                if (gasEndPoint != null && !gasEndPoint.Cylinder.IsFreshAir)
                {
                    Log.Debug(string.Format("Port1Restriction is FreshAir, but cylinder is {0}", gasEndPoint.Cylinder.PartNumber));
                    return(CreateUnsupportedCylinderAction(gasEndPoint));
                }
            }

            // Only zero air is allowed? It's illegal to have either fresh air or a non-zeroAir
            // cylinder installed.
            else if (Configuration.DockingStation.Port1Restrictions == PortRestrictions.ZeroAir)
            {
                // It's required that we have a zero-air cylinder on port1.  So return
                // Unsupported gas if there is no cylinder, or if the cylinder is not zero-air.
                if (gasEndPoint == null)
                {
                    Log.Debug("Port1Restriction is ZeroAir, but no cylinder is installed");
                    return(CreateUnsupportedCylinderAction(GasEndPoint.CreateFreshAir(Controller.FRESH_AIR_GAS_PORT)));
                }

                if (!gasEndPoint.Cylinder.IsZeroAir)
                {
                    Log.Debug(string.Format("Port1Restriction is ZeroAir, but cylinder is {0}", gasEndPoint.Cylinder.PartNumber));
                    return(CreateUnsupportedCylinderAction(gasEndPoint));
                }
            }

            return(null);
        }
        /// <summary>
        /// </summary>
        /// <remarks>
        /// 1) Updates the cylinder's pressure in the database (change it from Full to Low, or Low to Empty).
        /// 2) Update cached cylinder (in Configuration.DockingStation.InstalledCylinders) with the pressure
        /// change.
        /// 3) Also forces an upload of a SettingsReadEvent in order to notify iNet of the pressure change.
        /// </remarks>
        /// <param name="emptyCylinderError"></param>
        /// <param name="inetUploader"></param>
        /// <returns></returns>
        private DockingStationAction ProcessEmptyGasEndPoint(GasEndPoint emptyEndPoint, InetUploader inetUploader)
        {
            Log.Debug(string.Format("Empty Cylinder was reported on position {0}", emptyEndPoint.Position));

            GasEndPoint gasEndPoint = null;

            using (DataAccessTransaction trx = new DataAccessTransaction())
            {
                GasEndPointDataAccess gepDataAccess = new GasEndPointDataAccess();

                gasEndPoint = gepDataAccess.FindByPosition(emptyEndPoint.Position, trx);

                if (gasEndPoint == null)
                {
                    return(null); // should we display an error?
                }
                if (gasEndPoint.Cylinder.Pressure == PressureLevel.Full)
                {
                    gasEndPoint.Cylinder.Pressure = PressureLevel.Low;
                    Log.Warning("Low pressure warning, position " + emptyEndPoint.Position);
                }
                else
                {
                    gasEndPoint.Cylinder.Pressure = PressureLevel.Empty;
                    Log.Warning("Empty pressure warning, position " + emptyEndPoint.Position);
                }

                Log.Debug(string.Format("Changing pressure to \"{0}\" for cylinder on position {1}", gasEndPoint.Cylinder.Pressure.ToString(), gasEndPoint.Position));
                Log.Debug(string.Format("...PartNumber={0}, FactoryId={1}", gasEndPoint.Cylinder.PartNumber, gasEndPoint.Cylinder.FactoryId));

                gepDataAccess.UpdatePressureLevel(gasEndPoint, trx);

                trx.Commit();
            }

            // After updating the database, we need to update the cached copy of the
            // installed cylinder, too, which is kept in the global DockingStation.
            GasEndPoint cachedGasEndPoint = Configuration.DockingStation.GasEndPoints.Find(g => g.Position == gasEndPoint.Position);

            if (cachedGasEndPoint != null)
            {
                cachedGasEndPoint.Cylinder.Pressure = gasEndPoint.Cylinder.Pressure;
            }

            // We need to inform iNet whenever a cylinder's pressure changes. We can only do this
            // by uploading a full docking station with the cylinder information.  Which means we
            // need to immediately do a SettingsRead to get the full docking station info, and then
            // upload that info along with the currently installed cylinder info.

            SettingsReadOperation settingsReadOperation = new SettingsReadOperation();

            // Explicitly set the ChangedSmartCards to all falses so that no smart cards are read.
            settingsReadOperation.ChangedSmartCards = new bool[Configuration.DockingStation.NumGasPorts];

            SettingsReadEvent settingsReadEvent = (SettingsReadEvent)settingsReadOperation.Execute();

            // Copy currently installed cylinder info to the docking station object we're going to upload.
            settingsReadEvent.DockingStation.GasEndPoints.Clear();
            settingsReadEvent.DockingStation.ChangedGasEndPoints.Clear();

            foreach (GasEndPoint gep in Configuration.DockingStation.GasEndPoints)
            {
                settingsReadEvent.DockingStation.GasEndPoints.Add((GasEndPoint)gep.Clone());
            }

            inetUploader.UploadEvent(settingsReadEvent, Configuration.DockingStation.TimeZoneInfo);

            // BEGIN INS-8630 RHP v7.5
            List <string> consoleMessages = new List <string>();

            consoleMessages.Add(gasEndPoint.Cylinder.Pressure.ToString());

            if (!string.IsNullOrEmpty(gasEndPoint.Cylinder.PartNumber)) // For ISC Pass the Cylinder Part Number
            {
                consoleMessages.Add(gasEndPoint.Cylinder.PartNumber);
            }
            // For Non ISC Pass the gas code. But I believe that both ISC and Non-ISC cylinders have their own PArt numbers.
            // So below condition may not be required ?
            else if (gasEndPoint.Cylinder.GasConcentrations.Count > 0)
            {
                consoleMessages.Add(gasEndPoint.Cylinder.GasConcentrations[0].Type.Symbol);
            }

            Log.Info("Sending IDS ReplaceCylinderAction");
            DockingStationAction dsAction = new ResourceUnavailableAction(new List <string>()
            {
                gasEndPoint.Cylinder.Pressure.ToString()
            }, consoleMessages);

            // END INS-8630

            return(dsAction);
        }
Example #20
0
 public override SqlTransactionalCommandsContext CreateSqlTransactionalCommandsContext(DataAccessTransaction transaction)
 {
     return(new PostgresDotConnectSqlTransactionalCommandsContext(this, transaction));
 }
Example #21
0
 public override SqlTransactionalCommandsContext CreateSqlTransactionalCommandsContext(DataAccessTransaction transaction)
 {
     return(new SqlServerSqlTransactionsCommandContext(this, transaction));
 }
 public PostgresSqlTransactionalCommandsContext(SqlDatabaseContext sqlDatabaseContext, DataAccessTransaction transaction)
     : base(sqlDatabaseContext, transaction)
 {
 }
 public SqlServerSqlTransactionsCommandContext(SqlDatabaseContext sqlDatabaseContext, DataAccessTransaction transaction)
     : base(sqlDatabaseContext, transaction)
 {
 }
Example #24
0
 private void RemoveSchedules(IList <string> serialNumbers, DataAccessTransaction trx)
 {
		public override SqlTransactionalCommandsContext CreateSqlTransactionalCommandsContext(DataAccessTransaction transaction)
		{
			return new PostgresSqlTransactionalCommandsContext(this, transaction);
		}
Example #26
0
 public virtual SqlTransactionalCommandsContext CreateSqlTransactionalCommandsContext(DataAccessTransaction transaction)
 {
     return(new DefaultSqlTransactionalCommandsContext(this, transaction));
 }
Example #27
0
        protected SqlTransactionalCommandsContext(SqlDatabaseContext sqlDatabaseContext, IDbConnection dbConnection, DataAccessTransaction transaction)
        {
            this.DbConnection       = dbConnection;
            this.SqlDatabaseContext = sqlDatabaseContext;
            this.DataAccessModel    = sqlDatabaseContext.DataAccessModel;

            this.emulateMultipleActiveResultSets = !sqlDatabaseContext.SqlDialect.SupportsCapability(SqlCapability.MultipleActiveResultSets);

            if (transaction != null)
            {
                this.dbTransaction = dbConnection.BeginTransaction(ConvertIsolationLevel(transaction.IsolationLevel));
            }
        }