Ejemplo n.º 1
0
        /// <summary>
        /// OnStart(): Put startup code here
        ///  - Start threads, get inital data, etc.
        /// </summary>
        /// <param name="args"></param>
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);
            string userName = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\WakeYourPC\\",
                                                        "UserName", "saimanoj");

            this.EventLog.WriteEntry(string.Format("User name is {0}", userName), EventLogEntryType.Information, 100, 1);
            // Checking whether the username is valid
            UserEntity agentUser = ExternalConnector.GetUser(userName);

            if (agentUser == null)
            {
                this.EventLog.WriteEntry("Invalid User name Or the user is not registered yet" +
                                         string.Format("Please register the {0} first and then try passing as a command line argument.", userName) +
                                         "Exiting Now :-(");
                return;
            }
            UserEntitySingletonFactory.CreateUserEntity(userName);

            _wolPollTimer = new Timer(WolTimerCallback, null, 0, WakeOnLanConstants.WolPollInterval);

            //WOLTimerCallback(null);

            /*string macAddress = MacAddress.GetMac("10.171.41.67");
             *
             * this.EventLog.WriteEntry("MacAddress=" + macAddress);
             * byte[] macBytes = MacAddress.GetMacBytes(macAddress, '-');
             *
             * MagicPacket mp = new MagicPacket(macBytes, "10.171.41.67");
             * mp.WakeUp();
             * bool result = mp.Verify();
             * this.EventLog.WriteEntry(result);*/
        }
Ejemplo n.º 2
0
        public void WolTimerCallback(Object state)
        {
            this.EventLog.WriteEntry("Entered WOL Timer Callback");
            if (_wolStarted)
            {
                this.EventLog.WriteEntry("Previous work is in progress");
                return;
            }

            try
            {
                _wolStarted = true;
                List <MachineEntity> model = ExternalConnector.GetMachinesToAwake();

                foreach (var MachineObj in model)
                {
                    if (MachineObj.ShouldWakeup && MachineObj.MacAddress != null)
                    {
                        byte[] macBytes = MacAddress.GetMacBytes(MachineObj.MacAddress, '-');

                        // MagicPacket mp = new MagicPacket(macBytes, "10.171.41.67");
                        MagicPacket mp = new MagicPacket(macBytes, MachineObj.HostName); // TODO verify
                        mp.WakeUp();

                        bool result = mp.Verify();
                        MachineObj.ShouldWakeup = false;
                        MachineObj.State        = (result) ? MachineState.Available.ToString() : MachineState.Unreachable.ToString();

                        // PUT this machine object to azure service
                        ExternalConnector.UpdateMachineInfo(MachineObj);
                    }
                }
            }
            catch (Exception e)
            {
                this.EventLog.WriteEntry("Exception in WOLTImer call back " + e);
            }

            _wolStarted = false;
        }