Ejemplo n.º 1
0
        public bool?Update(DateTime utcNow, long counter, ConnectionState?simulateConnection)
        {
            bool?result = null;

            PeerGroup peerGroup = this.Location.PeerGroup;

            if (peerGroup.CanPoll(utcNow, this.lastPolled))
            {
                ConnectionState priorConnection = this.Connection;

                using (Pinger pinger = new Pinger(peerGroup.Wait))
                {
                    TimeSpan roundtripTime = TimeSpan.Zero;
                    if (simulateConnection != null)
                    {
                        this.Connection = simulateConnection.Value;
                    }
                    else
                    {
                        bool?ping = pinger.TryPing(this.Location.Address, out roundtripTime);
                        switch (ping)
                        {
                        case true:
                            this.Connection = ConnectionState.Connected;
                            break;

                        case false:
                            this.Connection = ConnectionState.Disconnected;
                            break;

                        default:
                            this.Connection = ConnectionState.Unavailable;
                            break;
                        }
                    }

                    this.RoundtripTime = roundtripTime;
                    this.UpdateCounter = counter;
                }

                result          = this.Connection != priorConnection;
                this.lastPolled = utcNow;
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public void Give(IDbConnection connection)
        {
            if (connection is null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (connection != Connection)
            {
                throw new ArgumentException("Does not belong to this provider.", nameof(connection));
            }
            Contract.EndContractBlock();

            if (TakenConnectionState == ConnectionState.Closed)
            {
                connection.Close();
            }

            TakenConnectionState = null;
        }
Ejemplo n.º 3
0
        internal override ValueTask ConnectAsync(CancellationToken cancellationToken = default)
        {
            CheckDisposed();

            if (Connected)
            {
                throw new InvalidOperationException("Already connected");
            }

            Debug.Assert(_isClient, "not connected but also not _isClient??");

            MockListener?listener = MockListener.TryGetListener(_remoteEndPoint);

            if (listener is null)
            {
                throw new InvalidOperationException("Could not find listener");
            }

            // TODO: deal with protocol negotiation
            _state = new ConnectionState(_sslClientAuthenticationOptions !.ApplicationProtocols ![0])
Ejemplo n.º 4
0
 /// <summary>
 /// Get an existing Connection resource's state with the given name, ID, and optional extra
 /// properties used to qualify the lookup.
 /// </summary>
 ///
 /// <param name="name">The unique name of the resulting resource.</param>
 /// <param name="id">The unique provider ID of the resource to lookup.</param>
 /// <param name="state">Any extra arguments used during the lookup.</param>
 /// <param name="options">A bag of options that control this resource's behavior</param>
 public static Connection Get(string name, Input <string> id, ConnectionState?state = null, CustomResourceOptions?options = null)
 {
     return(new Connection(name, id, state, options));
 }
Ejemplo n.º 5
0
 private Connection(string name, Input <string> id, ConnectionState?state = null, CustomResourceOptions?options = null)
     : base("alicloud:rds/connection:Connection", name, state, MakeResourceOptions(options, id))
 {
 }
Ejemplo n.º 6
0
        /// <summary>Closes the connection to the database.</summary>
        /// <exception cref="T:System.InvalidOperationException">An error occurred when closing the connection.</exception>
        public override void Close()
        {
            _fakeConnectionState = null;

            // It's a no-op if there isn't an underlying connection
            if (_storeConnection == null)
            {
                return;
            }

            StoreCloseHelper(); // note: we will update our own state since we are subscribed to event on underlying store connection
        }
Ejemplo n.º 7
0
        /// <summary>Establishes a connection to the data source by calling the underlying data provider's Open method.</summary>
        /// <exception cref="T:System.InvalidOperationException">An error occurs when you open the connection, or the name of the underlying data provider is not known.</exception>
        /// <exception cref="T:System.Data.Entity.Core.MetadataException">The inline connection string contains an invalid Metadata keyword value.</exception>
        public override void Open()
        {
            _fakeConnectionState = null;

            if (!DbInterception.Dispatch.CancelableEntityConnection.Opening(this, InterceptionContext))
            {
                _fakeConnectionState = ConnectionState.Open;

                return;
            }

            if (_storeConnection == null)
            {
                throw Error.EntityClient_ConnectionStringNeededBeforeOperation();
            }

            if (State == ConnectionState.Broken)
            {
                throw Error.EntityClient_CannotOpenBrokenConnection();
            }

            if (DbInterception.Dispatch.Connection.GetState(_storeConnection, InterceptionContext) != ConnectionState.Open)
            {
                var metadataWorkspace = GetMetadataWorkspace();
                try
                {
                    DbProviderServices.GetExecutionStrategy(_storeConnection, metadataWorkspace).Execute(
                        () => DbInterception.Dispatch.Connection.Open(_storeConnection, InterceptionContext));
                }
                catch (Exception e)
                {
                    if (e.IsCatchableExceptionType())
                    {
                        var exceptionMessage = Strings.EntityClient_ProviderSpecificError("Open");
                        throw new EntityException(exceptionMessage, e);
                    }

                    throw;
                }

                // With every successful open of the store connection, always null out the current db transaction and enlistedTransaction
                ClearTransactions();
            }

            // the following guards against the case when the user closes the underlying store connection
            // in the state change event handler, as a consequence of which we are in the 'Broken' state
            if (_storeConnection == null
                || DbInterception.Dispatch.Connection.GetState(_storeConnection, InterceptionContext) != ConnectionState.Open)
            {
                throw Error.EntityClient_ConnectionNotOpen();
            }
        }
Ejemplo n.º 8
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Object"></see> class.</summary>
 public StateItem(DateTime time, ConnectionState?state)
 {
     Time  = time;
     State = state;
 }
Ejemplo n.º 9
0
 private Connection(string name, Input <string> id, ConnectionState?state = null, CustomResourceOptions?options = null)
     : base("sumologic:index/connection:Connection", name, state, MakeResourceOptions(options, id))
 {
 }
Ejemplo n.º 10
0
 private Connection(string name, Input <string> id, ConnectionState?state = null, CustomResourceOptions?options = null)
     : base("gcp:servicenetworking/connection:Connection", name, state, MakeResourceOptions(options, id))
 {
 }
Ejemplo n.º 11
0
 public Camera(
     bool isDeleting,
     string?mac,
     string?host,
     string?connectionHost,
     string?type,
     string?name,
     DateTimeOffset upSince,
     DateTimeOffset lastSeen,
     DateTimeOffset connectedSince,
     string?state,
     string?hardwareRevision,
     string?firmwareVersion,
     string?firmwareBuild,
     bool isUpdating,
     bool isAdopting,
     bool isManaged,
     bool isProvisioned,
     bool isRebooting,
     bool isSshEnabled,
     bool canManage,
     bool isHidden,
     DateTimeOffset lastMotion,
     double micVolume,
     bool isMicEnabled,
     bool isRecording,
     bool isMotionDetected,
     bool isAttemptingToConnect,
     double phyRate,
     bool hdrMode,
     object?isProbingForWifi,
     object?apMac,
     object?apRssi,
     object?elementInfo,
     double chimeDuration,
     bool isDark,
     int motionStartCalls,
     object?lastRing,
     ConnectionState?wiredConnectionState,
     IReadOnlyList <Channel>?channels,
     IspSettings?ispSettings,
     TalkbackSettings?talkbackSettings,
     OsdSettings?osdSettings,
     LedSettings?ledSettings,
     SpeakerSettings?speakerSettings,
     RecordingSettings?recordingSettings,
     object?recordingSchedule,
     IReadOnlyList <MotionZone>?motionZones,
     IReadOnlyList <object>?privacyZones,
     CameraStats?stats,
     CameraFeatures?featureFlags,
     PirSettings?pirSettings,
     WifiStats?wifiConnectionState,
     string?id,
     bool isConnected,
     string?platform,
     bool hasSpeaker,
     bool hasWifi,
     int audioBitrate,
     string?modelKey)
 {
     IsDeleting            = isDeleting;
     Mac                   = mac;
     Host                  = host;
     ConnectionHost        = connectionHost;
     Type                  = type;
     Name                  = name;
     UpSince               = upSince;
     LastSeen              = lastSeen;
     ConnectedSince        = connectedSince;
     State                 = state;
     HardwareRevision      = hardwareRevision;
     FirmwareVersion       = firmwareVersion;
     FirmwareBuild         = firmwareBuild;
     IsUpdating            = isUpdating;
     IsAdopting            = isAdopting;
     IsManaged             = isManaged;
     IsProvisioned         = isProvisioned;
     IsRebooting           = isRebooting;
     IsSshEnabled          = isSshEnabled;
     CanManage             = canManage;
     IsHidden              = isHidden;
     LastMotion            = lastMotion;
     MicVolume             = micVolume;
     IsMicEnabled          = isMicEnabled;
     IsRecording           = isRecording;
     IsMotionDetected      = isMotionDetected;
     IsAttemptingToConnect = isAttemptingToConnect;
     PhyRate               = phyRate;
     HdrMode               = hdrMode;
     IsProbingForWifi      = isProbingForWifi;
     ApMac                 = apMac;
     ApRssi                = apRssi;
     ElementInfo           = elementInfo;
     ChimeDuration         = chimeDuration;
     IsDark                = isDark;
     MotionStartCalls      = motionStartCalls;
     LastRing              = lastRing;
     WiredConnectionState  = wiredConnectionState;
     Channels              = channels ?? Array.Empty <Channel>();
     IspSettings           = ispSettings;
     this.talkbackSettings = talkbackSettings;
     OsdSettings           = osdSettings;
     LedSettings           = ledSettings;
     SpeakerSettings       = speakerSettings;
     RecordingSettings     = recordingSettings;
     RecordingSchedule     = recordingSchedule;
     MotionZones           = motionZones ?? Array.Empty <MotionZone>();
     PrivacyZones          = privacyZones ?? Array.Empty <object>();
     Stats                 = stats;
     FeatureFlags          = featureFlags;
     PirSettings           = pirSettings;
     WifiConnectionState   = wifiConnectionState;
     Id           = id;
     IsConnected  = isConnected;
     Platform     = platform;
     HasSpeaker   = hasSpeaker;
     HasWifi      = hasWifi;
     AudioBitrate = audioBitrate;
     ModelKey     = modelKey;
 }
Ejemplo n.º 12
0
        public void Update(DateTime utcNow, IReadOnlyList <LocationState> locations, ConnectionState?simulateConnection)
        {
            this.LastUpdateRequest = utcNow;
            if (this.PeerGroup.CanPoll(utcNow, this.LastUpdated))
            {
                this.LastUpdated = utcNow;

                // Increment this each time so we can uniquely identify which Update call last
                // updated an item and so we'll round-robin through each location in the list.
                this.UpdateCounter++;

                ConnectionState priorConnection = this.Connection;

                ConnectionState?peerGroupConnection = null;
                int             numLocations        = locations.Count;
                for (int i = 0; i < numLocations; i++)
                {
                    int           locationIndex      = (int)unchecked ((this.UpdateCounter + i) % numLocations);
                    LocationState locationState      = locations[locationIndex];
                    bool?         wasLocationUpdated = locationState.Update(utcNow, this.UpdateCounter, simulateConnection);

                    // A null result means we've polled it too recently.
                    if (wasLocationUpdated != null)
                    {
                        // If we get a Connected result, then we can quit early.
                        // If we only get Disconnected or Unavailable, then we have to check them all.
                        peerGroupConnection = locationState.Connection;
                        if (peerGroupConnection == ConnectionState.Connected)
                        {
                            break;
                        }
                    }
                }

                // This should only be null when we've polled all the locations too recently, so Connection shouldn't change.
                if (peerGroupConnection != null)
                {
                    this.Connection = peerGroupConnection.Value;
                }

                if (this.Connection != priorConnection)
                {
                    this.ConnectionChanged = utcNow;
                }

                bool wasFailed = this.IsFailed;
                if (this.Connection == ConnectionState.Connected || this.Connection == ConnectionState.Unavailable)
                {
                    this.IsFailed = false;
                }
                else if (!this.IsFailed && (this.ConnectionChanged == null || utcNow >= (this.ConnectionChanged.Value + this.PeerGroup.Fail)))
                {
                    this.IsFailed = true;
                }

                if (this.IsFailed != wasFailed)
                {
                    this.IsFailedChanged = utcNow;
                }
            }
        }
Ejemplo n.º 13
0
        private void OnPacketHandled(int id, IPacketWithSize packet, ConnectionState? state)
        {
            if (!Connected)
                return;

            switch ((PacketsServer) id)
            {
                case PacketsServer.ServerIdentification:
                    State = ConnectionState.Joined;
                    break;

                case PacketsServer.Ping:
                    break;

                case PacketsServer.LevelInitialize:
                    break;

                case PacketsServer.LevelDataChunk:
                    var levelDataChunkPacket = (LevelDataChunkPacket) packet;
                    //Level.ReadFromSteam(levelDataChunkPacket.ChunkData);
                    break;

                case PacketsServer.LevelFinalize:
                    var levelFinalizePacket = (LevelFinalizePacket) packet;

                    var chunkList = Level.ReadFromArray(levelFinalizePacket.Coordinates);
                    OnChunkList(chunkList);
                    break;

                case PacketsServer.SetBlock:
                    var setBlockPacket = (SetBlockPacket) packet;

                    OnBlockChange(setBlockPacket.Coordinates, setBlockPacket.BlockType);
                    break;

                case PacketsServer.SpawnPlayer:
                    var spawnPlayerPacket = (SpawnPlayerPacket) packet;

                    OnSpawnPoint(spawnPlayerPacket.Coordinates);
                    break;

                case PacketsServer.PositionAndOrientationTeleport:
                    break;

                case PacketsServer.PositionAndOrientationUpdate:
                    var positionAndOrientationUpdatePacket = (PositionAndOrientationUpdatePacket) packet;

                    OnPlayerLook(new Vector3(positionAndOrientationUpdatePacket.Yaw, positionAndOrientationUpdatePacket.Pitch));
                    OnPlayerPosition(positionAndOrientationUpdatePacket.ChangeLocation);

                    break;

                case PacketsServer.PositionUpdate:
                    var positionUpdatePacket = (PositionUpdatePacket)packet;

                    OnPlayerPosition(positionUpdatePacket.ChangeLocation);
                    break;

                case PacketsServer.OrientationUpdate:
                    var orientationUpdatePacket = (OrientationUpdatePacket)packet;

                    OnPlayerLook(new Vector3(orientationUpdatePacket.Yaw, orientationUpdatePacket.Pitch));
                    break;

                case PacketsServer.DespawnPlayer:
                    break;

                case PacketsServer.Message:
                    var messagePacket = (MessagePacket) packet;

                    OnChatMessage(messagePacket.Message);
                    break;

                case PacketsServer.DisconnectPlayer:
                    break;

                case PacketsServer.UpdateUserType:
                    break;


                case PacketsServer.ExtInfo:
                    break;

                case PacketsServer.ExtEntry:
                    break;

                case PacketsServer.SetClickDistance:
                    break;

                case PacketsServer.CustomBlockSupportLevel:
                    break;

                case PacketsServer.HoldThis:
                    break;

                case PacketsServer.SetTextHotKey:
                    break;

                case PacketsServer.ExtAddPlayerName:
                    break;

                case PacketsServer.ExtRemovePlayerName:
                    break;

                case PacketsServer.EnvSetColor:
                    break;

                case PacketsServer.MakeSelection:
                    break;

                case PacketsServer.RemoveSelection:
                    break;

                case PacketsServer.SetBlockPermission:
                    break;

                case PacketsServer.ChangeModel:
                    break;

                case PacketsServer.EnvSetMapAppearance:
                    break;

                case PacketsServer.EnvSetWeatherType:
                    break;

                case PacketsServer.HackControl:
                    break;

                case PacketsServer.ExtAddEntity2:
                    break;

                default:
                    throw new ProtocolException("Connection error: Incorrect data.");
            }
        }