Пример #1
0
 public PropertyRepository(DmsDbContext dmsDbContext,
                           IEntityPropertyUpdater <Property, int> entityPropertyUpdater)
 {
     this.dmsDbContext          = dmsDbContext ?? throw new ArgumentNullException(nameof(dmsDbContext));
     this.entityPropertyUpdater = entityPropertyUpdater ?? throw new ArgumentNullException(nameof(entityPropertyUpdater));
     this.entityPropertyUpdater.EntityFactoryFunc = id => new Property {
         PropertyId = id
     };
 }
Пример #2
0
 public PhysicalDocumentContainerRepository(DmsDbContext dbContext,
                                            IEntityPropertyUpdater <PhysicalDocumentContainer, int> entityPropertyUpdater)
 {
     this.dbContext             = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     this.entityPropertyUpdater = entityPropertyUpdater ?? throw new ArgumentNullException(nameof(entityPropertyUpdater));
     this.entityPropertyUpdater.EntityFactoryFunc = id => new PhysicalDocumentContainer {
         PhysicalDocumentContainerId = id
     };
 }
Пример #3
0
 public EntityPropertyUpdater(DmsDbContext dmsDbContext)
 {
     this.dmsDbContext = dmsDbContext ?? throw new ArgumentNullException(nameof(dmsDbContext));
 }
        /// <summary>
        /// Gets sensor's datatype Json-schema from db. <br/>
        /// Puts distinct sensors with their parsed datatype in <i>SensorWithParsedDatatypes</i> list.
        /// </summary>
        /// <param name="sensors">List of sensors to retrieve from database and parse their datatypes.</param>
        /// <returns></returns>
        public static async Task ParseSensorsDatatypeAsync(List <Sensor> sensors)
        {
            foreach (var sensor in sensors)
            {
                if (SensorWithParsedDatatypes
                    .Any(x => x.IpAddress == sensor.IpAddress && x.Port == sensor.Port))
                {
                    continue;
                }

                await using var context = new DmsDbContext(AppSettings.SensorOutputParser.PostgresConnectionString);

                SensorConnector.Persistence.Entities.Sensor sensorWithDatatype = null;

                try
                {
                    sensorWithDatatype = await context.Sensors
                                         .Include(x => x.DataType)
                                         .Include(x => x.CommunicationProtocol)
                                         .FirstOrDefaultAsync(x => x.IpAddress == sensor.IpAddress &&
                                                              x.Port == sensor.Port);
                }
                catch (Npgsql.PostgresException e)
                {
                    var composedErrorMessage = $"Failed to connect to the Postgres database.\r\n";

                    if (e.SqlState != null && e.SqlState.Equals("42P01"))
                    {
                        composedErrorMessage = composedErrorMessage +
                                               $"There is no schema with the specified \'{AppSettings.SensorOutputParser.PostgresSchemaName}\' name in database.";

                        throw new Npgsql.PostgresException(composedErrorMessage, e.Severity, e.InvariantSeverity, e.SqlState);
                    }

                    composedErrorMessage = composedErrorMessage +
                                           $"{e.Message}";

                    throw new Npgsql.PostgresException(composedErrorMessage, e.Severity, e.InvariantSeverity, e.SqlState);
                }

                if (sensorWithDatatype == null)
                {
                    throw new NullReferenceException(($"Sensor {sensor.IpAddress}:{sensor.Port} was not found in database."));
                }

                var parsedJson = JObject.Parse(sensorWithDatatype.DataType.Schema);

                var sensorFieldDescriptions = new List <SensorFieldDescription>();

                foreach (var property in parsedJson.Properties())
                {
                    var fieldName     = property.Name;
                    var fieldTypeName = property.Value.ToString();

                    sensorFieldDescriptions.Add(
                        new SensorFieldDescription(fieldName, fieldTypeName));
                }

                SensorWithParsedDatatypes.Add(
                    new SensorWithParsedDatatype()
                {
                    SensorId          = sensorWithDatatype.SensorId,
                    IpAddress         = sensorWithDatatype.IpAddress,
                    Port              = sensorWithDatatype.Port,
                    FieldDescriptions = sensorFieldDescriptions
                });
            }
        }
 public Repository(DmsDbContext context)
 {
     _context = context;
     _dbSet   = context.Set <TEntity>();
 }
 public CategoryDocumentRepository(DmsDbContext dmsDbContext)
 {
     this.dmsDbContext = dmsDbContext ?? throw new ArgumentNullException(nameof(dmsDbContext));
 }
Пример #7
0
 public ObjectRepository(DmsDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
 public UnitOfWork(DmsDbContext dmsDbContext)
 {
     _context = dmsDbContext;
 }