/// <summary>
        /// This is simply a stub; it should be replaced with a method that reads the appropriate user
        /// from the database
        /// </summary>
        /// <returns></returns>
        public static User GetUser(string userName)
        {
            IIdentity identity = new SystemIdentity(userName);

            string[] roleNames = new string[] { };

            switch (userName)
            {
            case "rrobert":
                roleNames = new string[] { "Role1" };
                break;

            default:
                roleNames = new string[] { "Role2" };
                break;
            }

            List <Role> roles = new List <Role>();

            foreach (var roleName in roleNames)
            {
                roles.Add(new Role(roleName));
            }

            User toReturn = new User(identity, roles);

            return(toReturn);
        }
Exemple #2
0
        /// <summary>
        /// Constructs for the given lower layer.
        /// </summary>
        /// <param name="address">The address of this device.</param>
        /// <param name="connectionType">The type of the connection in use (required in case we have to re-open).</param>
        /// <param name="tikConnection">The lower layer connection for talking to this device.</param>
        /// <param name="options">The options to use.</param>
        /// <param name="sysIdent">The system ident (to create SystemData from).</param>
        /// /// <param name="sysResource">The system resource info (to create SystemData from).</param>
        /// <param name="sysRouterboard">The system routerboard info (to create SystemData from).</param>
        public MikrotikApiDeviceHandler(IpAddress address, TikConnectionType connectionType, ITikConnection tikConnection, IQuerierOptions options, SystemIdentity sysIdent, SystemResource sysResource, SystemRouterboard sysRouterboard)
        {
            if ((options.AllowedApis & this.SupportedApi) == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(options), $"This device handler doesn't support any of the APIs allowed by the IQuerierOptions (allowed: {options.AllowedApis}, supported {this.SupportedApi}).");
            }

            this.sysRouterboard = sysRouterboard ?? throw new ArgumentNullException(nameof(sysRouterboard), "sysRouterboard is null when creating a MikrotikApiDeviceHandler");
            this.sysResource    = sysResource ?? throw new ArgumentNullException(nameof(sysResource), "sysResource is null when creating a MikrotikApiDeviceHandler");
            this.sysIdent       = sysIdent ?? throw new ArgumentNullException(nameof(sysIdent), "sysIdent is null when creating a MikrotikApiDeviceHandler");

            this.Address                = address ?? throw new ArgumentNullException(nameof(address), "address is null when creating a MikrotikApiDeviceHandler");
            this.TikConnection          = tikConnection ?? throw new ArgumentNullException(nameof(tikConnection), "tikConnection is null when creating a MikrotikApiDeviceHandler");
            this.DetectedConnectionType = connectionType;
            this.Options                = options ?? throw new ArgumentNullException(nameof(options), "options are null when creating a MikrotikApiDeviceHandler");
        }
        public override Task <SystemIdentity> Identify(Empty request, ServerCallContext context)
        {
            var identity = new SystemIdentity()
            {
                MachineName = Environment.MachineName,
                OSVersion   = Environment.OSVersion.ToString()
            };

            using (ModularInstrumentsSystem sys = new ModularInstrumentsSystem())
            {
                foreach (DeviceInfo device in sys.DeviceCollection)
                {
                    identity.InstrumentIdentities.Add(new InstrumentIdentity()
                    {
                        Model        = device.Model,
                        Name         = device.Name,
                        SerialNumber = device.SerialNumber,
                        SlotNumber   = device.SlotNumber
                    });
                }
            }
            return(Task.FromResult(identity));
        }
Exemple #4
0
 /// <summary>
 /// Queries the system data via API.<br/>
 /// This implicitly checks whether the connection is open and authentication was successful.
 /// </summary>
 private void QuerySystemData()
 {
     this.sysResource    = this.tikConnection.LoadSingle <SystemResource>();
     this.sysRouterboard = this.tikConnection.LoadSingle <SystemRouterboard>();
     this.sysIdent       = this.tikConnection.LoadSingle <SystemIdentity>();
 }
        public static void Initialize(DataContext context)
        {
            context.Database.EnsureCreated();

            if (context.TemperatureSensor.Any())
            {
                return; // DB has already been seeded
            }

            var temperature = new TemperatureSensor[] {
                new TemperatureSensor {
                    Id = 1, Value = 19.21, ReadDate = DateTime.Parse("01/09/2005 12:10")
                },
                new TemperatureSensor {
                    Id = 2, Value = 20.27, ReadDate = DateTime.Parse("01/09/2005 12:20")
                },
                new TemperatureSensor {
                    Id = 3, Value = 21.12, ReadDate = DateTime.Parse("01/09/2005 12:30")
                },
                new TemperatureSensor {
                    Id = 4, Value = 21.05, ReadDate = DateTime.Parse("01/09/2005 12:40")
                },
                new TemperatureSensor {
                    Id = 5, Value = 21.02, ReadDate = DateTime.Parse("01/09/2005 12:50")
                }
            };

            foreach (TemperatureSensor t in temperature)
            {
                context.TemperatureSensor.Add(t);
            }
            context.SaveChanges();

            Guid[] GuidsArray;
            GuidsArray = GenerateGuidArray();

            var systemID = new SystemIdentity[] {
                new SystemIdentity {
                    Id = 1, ProductId = GuidsArray[0]
                },
                new SystemIdentity {
                    Id = 2, ProductId = GuidsArray[1]
                },
                new SystemIdentity {
                    Id = 3, ProductId = GuidsArray[2]
                }
            };

            foreach (SystemIdentity sID in systemID)
            {
                context.SystemID.Add(sID);
            }
            context.SaveChanges();

            RecordEvent[] recordEvent;
            int           numberOfRecords = 3360;
            int           timeInterval    = 15; // in minutes
            bool          dateTimeNow     = false;
            DateTime      testingTime;

            // can go to live times or a set time, set time is useful for testing on the mobile app, production will have live
            if (dateTimeNow)
            {
                testingTime = DateTime.Now;
            }
            else
            {
                testingTime = DateTime.Parse("11/07/2021 12:00");
            }

            recordEvent = RecordEventArrayGenerator(numberOfRecords, timeInterval, testingTime);
            foreach (RecordEvent re in recordEvent)
            {
                context.RecordEvent.Add(re);
            }
            context.SaveChanges();

            // pump true/false auto/manual on/off
            var systemStatus = new SystemStatus[] {
                new SystemStatus {
                    Id = 1, SystemIdentityID = 1, PumpMode = true, SetTemperature = 27, ManualPumpOn = true, PumpStatus = true
                },
                new SystemStatus {
                    Id = 2, SystemIdentityID = 2, PumpMode = true, SetTemperature = 22, ManualPumpOn = true, PumpStatus = false
                },
                new SystemStatus {
                    Id = 3, SystemIdentityID = 3, PumpMode = true, SetTemperature = 20, ManualPumpOn = false, PumpStatus = false
                }
            };

            foreach (SystemStatus ss in systemStatus)
            {
                context.SystemStatus.Add(ss);
            }
            context.SaveChanges();
        }