Esempio n. 1
0
        //
        // WORKING FUNCTIONS
        //

        private InjectorInfo BuildInjectorInfo()
        {
            var iInfo  = new InjectorInfo();
            var nInfos = new List <NetworkInfo>();

            foreach (var nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (nic.GetIPProperties() != null)
                {
                    var n_info = new NetworkInfo();

                    n_info.Ip = nic.GetIPProperties().UnicastAddresses.Count > 0
                                                                        ? nic.GetIPProperties().UnicastAddresses[0].Address
                                                                        : IPAddress.None;
                    n_info.Mac  = nic.GetPhysicalAddress().ToString();
                    n_info.Name = nic.Name;

                    nInfos.Add(n_info);
                }
            }
            iInfo.Interfaces = nInfos.ToArray();

            iInfo.HostName   = IPGlobalProperties.GetIPGlobalProperties().HostName;
            iInfo.DomainName = IPGlobalProperties.GetIPGlobalProperties().DomainName;

            return(iInfo);
        }
Esempio n. 2
0
        //
        //	CONSTRUCTORS
        //

        public KeepAliveClient(IPAddress address, int port)
        {
            ObjectFactory.ResolveDependencies(this);

            _rem = new IPEndPoint(address, port);

            _injector = BuildInjectorInfo();

            _communication            = new CommunicationChannelTcp();
            _communication.Received  += HandleReceivedObject;
            _communication.Connected += HandleConnectedClient;
            _communication.Error     += HandleErrorOccurred;

            _poller = new Timer(HandleConnectionPolling, null, TimeSpan.Zero, TimeSpan.FromMilliseconds(TimeOut > 0 ? TimeOut : DEFAULTTIMEOUT));
        }
Esempio n. 3
0
        public void RemoveInjector(InjectorInfo injector)
        {
            if (String.IsNullOrEmpty(injector.HostName))
            {
                return;
            }

            if (this.GetInjectorByHostname(injector.HostName) != null)
            {
                lock (((ICollection)_injectors).SyncRoot)
                {
                    //remove event handler and remove from watch list..
                    injector.Changed -= HandleInjectorStatusChanged;
                    _injectors.Remove(injector);
                }
            }
        }
Esempio n. 4
0
        public void AddInjector(InjectorInfo injector)
        {
            if (String.IsNullOrEmpty(injector.HostName))
            {
                return;
            }

            if (this.GetInjectorByHostname(injector.HostName) == null)
            {
                lock (((ICollection)_injectors).SyncRoot)
                {
                    injector.Status = InjectorStates.Unreachable;

                    //set event handler and add to watch list..
                    injector.Changed += HandleInjectorStatusChanged;
                    _injectors.Add(injector);
                }
            }
        }
Esempio n. 5
0
        private void HandleInjectorStatusChanged(InjectorInfo iInfo)
        {
            //EventLog.WriteEntry("KeepAliveServer", "StatusChanged: " + iInfo.LastStatus.ToString() + " - " + iInfo.Status.ToString());
            Log.Debug("{3}: Remote status changed ({2}) {0} -> {1}", iInfo.LastStatus.ToString(), iInfo.Status.ToString(), iInfo.ToString(), this.GetType().ToString());

            if (iInfo != null)
            {
                if (iInfo.Status == InjectorStates.Ready)
                {
                    if (iInfo.LastStatus == InjectorStates.Unreachable)
                    {
                        //APPENA COLLEGATO..
                        Log.Info("{1}: Remote connected ({0})", iInfo.ToString(), this.GetType().ToString());
                        if (InjectorConnected != null)
                        {
                            InjectorConnected(this, new InjectorConnectedEventArgs(iInfo));
                        }
                    }
                    //else
                    //if(i_info.LastStatus == InjectorStates.Injecting){}
                    //else
                    //if(i_info.LastStatus == InjectorStates.Armed){}
                    //else
                    //if(i_info.LastStatus == InjectorStates.Inactive){}
                }
                else if (iInfo.Status == InjectorStates.Unreachable)
                {
                    Log.Info("{1}: Remote disconnected ({0})", iInfo.ToString(), this.GetType().ToString());
                    if (InjectorDisconnected != null)
                    {
                        InjectorDisconnected(this, new InjectorConnectedEventArgs(iInfo));
                    }

                    if (iInfo.LastStatus == InjectorStates.Ready)
                    {
                    }
                    //todo..
                }
            }
        }
Esempio n. 6
0
 public InjectorConnectedEventArgs(InjectorInfo i)
 {
     info = i;
 }