Пример #1
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");
        }
Пример #2
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>();
 }