public void Create()
        {
            var commandHub        = new Mock <ISendCommandsToRemoteEndpoints>();
            var id                = new DatasetId();
            var endpoint          = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var networkId         = NetworkIdentifier.ForLocalMachine();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var notifications   = new Mock <IDatasetApplicationNotifications>();
            var notificationHub = new Mock <INotifyOfRemoteEndpointEvents>();
            {
                notificationHub.Setup(n => n.HasNotificationsFor(It.IsAny <EndpointId>()))
                .Returns(true);
                notificationHub.Setup(n => n.NotificationsFor <IDatasetApplicationNotifications>(It.IsAny <EndpointId>()))
                .Callback <EndpointId>(e => Assert.AreSame(endpoint, e))
                .Returns(notifications.Object);
            }

            var info = new DatasetOnlineInformation(
                id,
                endpoint,
                networkId,
                commandHub.Object,
                notificationHub.Object,
                systemDiagnostics);

            Assert.AreSame(id, info.Id);
            Assert.AreSame(endpoint, info.Endpoint);
            Assert.AreSame(networkId, info.RunsOn);
        }
Ejemplo n.º 2
0
        public Relay Read(NetworkIdentifier networkId, RelayIdentifier relayId)
        {
            var network = _networks[networkId];

            return(Convert(network.Relays
                           .Single(x => x.Id == relayId)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns NetworkIdentifier.GetHashCode() ^ RemoteEndPoint.GetHashCode();
        /// </summary>
        /// <returns>The hashcode for this connection info</returns>
        public override int GetHashCode()
        {
            lock (internalLocker)
            {
                if (!hashCodeCacheSet)
                {
                    if (RemoteEndPoint != null & LocalEndPoint != null)
                    {
                        hashCodeCache = NetworkIdentifier.GetHashCode() ^ LocalEndPoint.GetHashCode() ^ RemoteEndPoint.GetHashCode() ^ (ApplicationLayerProtocol == ApplicationLayerProtocolStatus.Enabled ? 1 << 31 : 0);
                    }
                    if (RemoteEndPoint != null)
                    {
                        hashCodeCache = NetworkIdentifier.GetHashCode() ^ RemoteEndPoint.GetHashCode() ^ (ApplicationLayerProtocol == ApplicationLayerProtocolStatus.Enabled ? 1 << 31 : 0);
                    }
                    else if (LocalEndPoint != null)
                    {
                        hashCodeCache = NetworkIdentifier.GetHashCode() ^ LocalEndPoint.GetHashCode() ^ (ApplicationLayerProtocol == ApplicationLayerProtocolStatus.Enabled ? 1 << 31 : 0);
                    }
                    else
                    {
                        hashCodeCache = NetworkIdentifier.GetHashCode() ^ (ApplicationLayerProtocol == ApplicationLayerProtocolStatus.Enabled ? 1 << 31 : 0);
                    }

                    hashCodeCacheSet = true;
                }

                return(hashCodeCache);
            }
        }
Ejemplo n.º 4
0
    public void CreateLocalPlayer()
    {
        Vector3           spawnPoint  = new Vector3(Random.Range(-2f, 2f), Random.Range(-2f, 2f), 0f);
        GameObject        localPlayer = Instantiate(playerPrefab, spawnPoint, Quaternion.identity);
        NetworkIdentifier identifier  = localPlayer.GetComponent <NetworkIdentifier>();

        identifier.id     = Client.connectionID;
        identifier.isMine = true;

        DataSender.SendInstantiate(spawnPoint, "others");
    }
        public void AvailableCommands()
        {
            var id                = new DatasetId();
            var endpoint          = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var networkId         = NetworkIdentifier.ForLocalMachine();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var commandList = new Dictionary <Type, ICommandSet>
            {
                {
                    typeof(IMockCommandSetWithTaskReturn),
                    new Mock <IMockCommandSetWithTaskReturn>().Object
                },
                {
                    typeof(IMockCommandSetWithTypedTaskReturn),
                    new Mock <IMockCommandSetWithTaskReturn>().Object
                },
                {
                    typeof(IMockCommandSetForInternalUse),
                    new Mock <IMockCommandSetWithTaskReturn>().Object
                },
            };

            var commandHub = new Mock <ISendCommandsToRemoteEndpoints>();
            {
                commandHub.Setup(h => h.AvailableCommandsFor(It.IsAny <EndpointId>()))
                .Returns(commandList.Keys);
                commandHub.Setup(h => h.CommandsFor(It.IsAny <EndpointId>(), It.IsAny <Type>()))
                .Returns <EndpointId, Type>((e, t) => commandList[t]);
            }

            var notifications   = new Mock <IDatasetApplicationNotifications>();
            var notificationHub = new Mock <INotifyOfRemoteEndpointEvents>();
            {
                notificationHub.Setup(n => n.HasNotificationsFor(It.IsAny <EndpointId>()))
                .Returns(true);
                notificationHub.Setup(n => n.NotificationsFor <IDatasetApplicationNotifications>(It.IsAny <EndpointId>()))
                .Callback <EndpointId>(e => Assert.AreSame(endpoint, e))
                .Returns(notifications.Object);
            }

            var info = new DatasetOnlineInformation(
                id,
                endpoint,
                networkId,
                commandHub.Object,
                notificationHub.Object,
                systemDiagnostics);
            var commands = info.AvailableCommands();

            Assert.AreEqual(2, commands.Count());
        }
 public string ConnectedSsid()
 {
     try
     {
         NetworkIdentifier ss     = NativeWifi.EnumerateConnectedNetworkSsids().FirstOrDefault();
         string            result = ss?.ToString();
         return(result);
     }
     catch (Exception)
     {
         return(null);
     }
 }
        public bool IsConnectedToWirelessNetwork()
        {
            NetworkIdentifier ss = NativeWifi.EnumerateConnectedNetworkSsids().FirstOrDefault();

            if (ss == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DatasetOnlineInformation"/> class.
        /// </summary>
        /// <param name="id">The ID number of the dataset.</param>
        /// <param name="endpoint">The ID number of the endpoint that has the actual dataset loaded.</param>
        /// <param name="networkId">The network identifier of the machine on which the dataset runs.</param>
        /// <param name="commandHub">The object that handles sending commands to the remote endpoint.</param>
        /// <param name="notificationHub">The object that handles the event notifications for remote endpoints.</param>
        /// <param name="systemDiagnostics">The object that provides the diagnostics methods for the system.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="id"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="endpoint"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="networkId"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="commandHub"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="notificationHub"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="systemDiagnostics"/> is <see langword="null" />.
        /// </exception>
        public DatasetOnlineInformation(
            DatasetId id,
            EndpointId endpoint,
            NetworkIdentifier networkId,
            ISendCommandsToRemoteEndpoints commandHub,
            INotifyOfRemoteEndpointEvents notificationHub,
            SystemDiagnostics systemDiagnostics)
        {
            {
                Enforce.Argument(() => id);
                Enforce.Argument(() => endpoint);
                Enforce.Argument(() => networkId);
                Enforce.Argument(() => commandHub);
                Enforce.Argument(() => notificationHub);
                Enforce.Argument(() => systemDiagnostics);
            }

            Id            = id;
            Endpoint      = endpoint;
            RunsOn        = networkId;
            m_CommandHub  = commandHub;
            m_Diagnostics = systemDiagnostics;

            m_NotificationHub = notificationHub;
            {
                Debug.Assert(
                    m_NotificationHub.HasNotificationFor(Endpoint, typeof(IDatasetApplicationNotifications)),
                    "Missing essential notification set.");

                var notifications = m_NotificationHub.NotificationsFor <IDatasetApplicationNotifications>(Endpoint);
                notifications.OnSwitchToEditingMode +=
                    (s, e) =>
                {
                    m_IsEditMode = true;
                    RaiseOnSwitchToEditMode();
                };
                notifications.OnSwitchToExecutingMode +=
                    (s, e) =>
                {
                    m_IsEditMode = false;
                    RaiseOnSwitchToExecutingMode();
                };
                notifications.OnTimelineUpdate +=
                    (s, e) =>
                {
                    RaiseOnTimelineUpdate();
                };
            }
        }
        public void Close()
        {
            var id                = new DatasetId();
            var endpoint          = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var networkId         = NetworkIdentifier.ForLocalMachine();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var datasetCommands = new Mock <IDatasetApplicationCommands>();
            {
                datasetCommands.Setup(d => d.Close())
                .Returns(
                    Task.Factory.StartNew(
                        () => { },
                        new CancellationToken(),
                        TaskCreationOptions.None,
                        new CurrentThreadTaskScheduler()))
                .Verifiable();
            }

            var commandHub = new Mock <ISendCommandsToRemoteEndpoints>();
            {
                commandHub.Setup(h => h.HasCommandFor(It.IsAny <EndpointId>(), It.IsAny <Type>()))
                .Returns(true);
                commandHub.Setup(h => h.CommandsFor <IDatasetApplicationCommands>(It.IsAny <EndpointId>()))
                .Returns(datasetCommands.Object);
            }

            var notifications   = new Mock <IDatasetApplicationNotifications>();
            var notificationHub = new Mock <INotifyOfRemoteEndpointEvents>();
            {
                notificationHub.Setup(n => n.HasNotificationsFor(It.IsAny <EndpointId>()))
                .Returns(true);
                notificationHub.Setup(n => n.NotificationsFor <IDatasetApplicationNotifications>(It.IsAny <EndpointId>()))
                .Callback <EndpointId>(e => Assert.AreSame(endpoint, e))
                .Returns(notifications.Object);
            }

            var info = new DatasetOnlineInformation(
                id,
                endpoint,
                networkId,
                commandHub.Object,
                notificationHub.Object,
                systemDiagnostics);

            info.Close();

            datasetCommands.Verify(d => d.Close(), Times.Once());
        }
Ejemplo n.º 10
0
        public DistributionPlan(
            Func<DistributionPlan, CancellationToken, Action<int, string, bool>, Task<DatasetOnlineInformation>> activator,
            IDatasetOfflineInformation dataset,
            NetworkIdentifier machine,
            DatasetActivationProposal proposal)
        {
            {
                Enforce.Argument(() => activator);
                Enforce.Argument(() => dataset);
                Enforce.Argument(() => machine);
                Enforce.Argument(() => proposal);
            }

            m_Activator = activator;
            DistributionFor = dataset;
            MachineToDistributeTo = machine;
            Proposal = proposal;
        }
        private bool IsConnectedToPmcNetwork()
        {
            bool result = false;

            try
            {
                NetworkIdentifier ss = NativeWifi.EnumerateConnectedNetworkSsids().FirstOrDefault();
                if (ss != null)
                {
                    result = ss.ToString().Contains("PMC");
                }
            }
            catch (Exception ex)
            {
                EsEventManager.PublishEsEvent(EsEventSenderEnum.ComManager, "ERROR", EsMessagePriority.DebugInfo, "error in IsConnectedToPmcNetwork ", null, ex, null);
            }

            return(result);
        }
        public void Command()
        {
            var id                = new DatasetId();
            var endpoint          = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var networkId         = NetworkIdentifier.ForLocalMachine();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var commandList = new SortedList <Type, ICommandSet>
            {
                {
                    typeof(IMockCommandSetWithTaskReturn),
                    new Mock <IMockCommandSetWithTaskReturn>().Object
                },
            };
            var commandHub = new Mock <ISendCommandsToRemoteEndpoints>();
            {
                commandHub.Setup(h => h.CommandsFor <IMockCommandSetWithTaskReturn>(It.IsAny <EndpointId>()))
                .Returns((IMockCommandSetWithTaskReturn)commandList.Values[0]);
            }

            var notifications   = new Mock <IDatasetApplicationNotifications>();
            var notificationHub = new Mock <INotifyOfRemoteEndpointEvents>();
            {
                notificationHub.Setup(n => n.HasNotificationsFor(It.IsAny <EndpointId>()))
                .Returns(true);
                notificationHub.Setup(n => n.NotificationsFor <IDatasetApplicationNotifications>(It.IsAny <EndpointId>()))
                .Callback <EndpointId>(e => Assert.AreSame(endpoint, e))
                .Returns(notifications.Object);
            }

            var info = new DatasetOnlineInformation(
                id,
                endpoint,
                networkId,
                commandHub.Object,
                notificationHub.Object,
                systemDiagnostics);
            var commands = info.Command <IMockCommandSetWithTaskReturn>();

            Assert.AreSame(commandList.Values[0], commands);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Returns NetworkIdentifier.GetHashCode() ^ RemoteEndPoint.GetHashCode();
        /// </summary>
        /// <returns>The hashcode for this connection info</returns>
        public override int GetHashCode()
        {
            lock (internalLocker)
            {
                if (!hashCodeCacheSet)
                {
                    if (RemoteEndPoint != null)
                    {
                        hashCodeCache = NetworkIdentifier.GetHashCode() ^ RemoteEndPoint.GetHashCode();
                    }
                    else
                    {
                        hashCodeCache = NetworkIdentifier.GetHashCode();
                    }

                    hashCodeCacheSet = true;
                }

                return(hashCodeCache);
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Constructor
 /// </summary>
 public BssNetworkPack(
     InterfaceInfo interfaceInfo,
     NetworkIdentifier ssid,
     BssType bssType,
     NetworkIdentifier bssid,
     int signalStrength,
     int linkQuality,
     int frequency,
     float band,
     int channel)
 {
     this.Interface      = interfaceInfo;
     this.Ssid           = ssid;
     this.BssType        = bssType;
     this.Bssid          = bssid;
     this.SignalStrength = signalStrength;
     this.LinkQuality    = linkQuality;
     this.Frequency      = frequency;
     this.Band           = band;
     this.Channel        = channel;
 }
Ejemplo n.º 15
0
        private static DistributionPlan CreateNewDistributionPlan(
            DatasetActivationProposal proposal,
            IDatasetOfflineInformation offlineInfo,
            SystemDiagnostics systemDiagnostics)
        {
            var plan = new DistributionPlan(
                (p, t, r) => Task <DatasetOnlineInformation> .Factory.StartNew(
                    () => new DatasetOnlineInformation(
                        new DatasetId(),
                        new EndpointId("id"),
                        new NetworkIdentifier("machine"),
                        new Mock <ISendCommandsToRemoteEndpoints>().Object,
                        new Mock <INotifyOfRemoteEndpointEvents>().Object,
                        systemDiagnostics),
                    t),
                offlineInfo,
                NetworkIdentifier.ForLocalMachine(),
                proposal);

            return(plan);
        }
Ejemplo n.º 16
0
 public Domain.NetworkAggregate.Network Read(NetworkIdentifier id)
 {
     return(Convert(_networks[id]));
 }
Ejemplo n.º 17
0
        public IEnumerable <Relay> ReadAll(NetworkIdentifier networkId)
        {
            var network = _networks[networkId];

            return(network.Relays.Select(Convert));
        }
Ejemplo n.º 18
0
 void Start()
 {
     identifier = GetComponent <NetworkIdentifier>();
 }
Ejemplo n.º 19
0
 public void Delete(NetworkIdentifier id)
 {
     _networks.Remove(id);
 }