Esempio n. 1
0
 private void SetPowerPlan(POWERBROADCAST_SETTING ps, IntPtr pData)
 {
     string eventText;
     if (ps.DataLength == Marshal.SizeOf(typeof(Guid)))
     {
         Guid newPersonality = (Guid)Marshal.PtrToStructure(pData, typeof(Guid));
         if (newPersonality == GUID_MAX_POWER_SAVINGS)
         {
             powerPlan = PowerPlan.PowerSaver;
             eventText = "Switched to Max Power savings";
         }
         else if (newPersonality == GUID_MIN_POWER_SAVINGS)
         {
             powerPlan = PowerPlan.HighPerformance;
             eventText = "Switched to Min Power savings";
         }
         else if (newPersonality == GUID_TYPICAL_POWER_SAVINGS)
         {
             powerPlan = PowerPlan.Automatic;
             eventText = "Switched to Automatic Power savings";
         }
         else
         {
             eventText = "switched to unknown Power savings";
         }
     }
 }
Esempio n. 2
0
        private void LoadOptions()
        {
            AvailablePowerPlans = PowerPlan.GetAvailablePowerPlans();

            if (AvailablePowerPlans.Count > 0)
            {
                IsChangePPWhenListeningModeChanged = _optionsProvider.PowerPlanOptions.ChangePowerPlanOnListeningModeChange;

                DesiredPowerPlanWhenNotListening = _optionsProvider.PowerPlanOptions.DesiredPowerPlanWhenNotListening == Guid.Empty ? DesiredPowerPlanWhenNotListening = PowerPlan.GetActive() : _optionsProvider.PowerPlanOptions.DesiredPowerPlanWhenNotListening;

                DesiredPowerPlanWhenListening = _optionsProvider.PowerPlanOptions.DesiredPowerPlanWhenListening == Guid.Empty ? DesiredPowerPlanWhenListening = PowerPlan.GetActive() : _optionsProvider.PowerPlanOptions.DesiredPowerPlanWhenListening;
            }
        }
Esempio n. 3
0
        public void ManualIntegrationTest()
        {
            PowerPlans plans = PowerPlans.Instance;

            Assert.AreEqual(3, plans.Plans.Count);
            Assert.AreSame(plans.Plans[1], plans.ActivePlan);
            var expectedPlans = new PowerPlan[]
            {
                new PowerPlan("381b4222-f694-41f0-9685-ff5bb260df2e", "Balanced"),
                //new PowerPlan("6d1902df-e109-4499-a36e-39f6393ca9ae", "My Custom Plan 1"),
                new PowerPlan("8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c", "High performance"),
                new PowerPlan("a1841308-3541-4fab-bc81-f71556f20b4a", "Power saver")
            };
        }
Esempio n. 4
0
        private void OnNoiseDetectorChangeEvent(NoiseDetectorEvent evnt)
        {
            switch (evnt)
            {
            case NoiseDetectorEvent.StartListening:
                if (IsChangePPWhenListeningModeChanged)
                {
                    PowerPlan.SetActive(DesiredPowerPlanWhenListening);
                }
                break;

            case NoiseDetectorEvent.StopListening:
                if (IsChangePPWhenListeningModeChanged)
                {
                    PowerPlan.SetActive(DesiredPowerPlanWhenNotListening);
                }
                break;
            }
        }
        public PowerPlan GetPowerPlan()
        {
            PowerPlan PP    = new PowerPlan();
            DataSet   ds    = new DataSet();
            string    query = Resources.PowerPlan;

            try
            {
                ds           = (DataSet)ExecuteQuery(query);
                PP.powerPlan = (String)ds.Tables["Table"].Rows[0]["powerplan"];
                PP.Success   = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception catched: " + ex.Message);
                PP.Success = false;
            }

            return(PP);
        }
Esempio n. 6
0
 /// <summary>
 /// Power plan for benchmarks.
 /// The default value is HighPerformance.
 /// <remarks>Only available for Windows.</remarks>
 /// </summary>
 public static Job WithPowerPlan(this Job job, PowerPlan powerPlan) => job.WithCore(j => j.Environment.PowerPlanMode = PowerManagementApplier.Map(powerPlan));
 /// <summary>
 /// Power plan for benchmarks.
 /// The default value is HighPerformance.
 /// <remarks>Only available for Windows.</remarks>
 /// </summary>
 public static Job WithPowerPlan(this Job job, PowerPlan powerPlan) => job.WithCore(j => j.Environment.PowerPlanMode.PowerPlan = powerPlan);
Esempio n. 8
0
        private void UpdateNotificationIcon()
        {
            // ReSharper disable PossibleInvalidOperationException
            Battery batteryInfo = Battery.GetInformation();
            PowerPlan powerPlanInfo = PowerPlan.GetActivePowerPlan();
            if (batteryInfo == _prevBatteryStatus && powerPlanInfo == _prevPowerPlan)
            {
                //TimeLog("Power status did not change");
                return;
            }
            _prevBatteryStatus = batteryInfo;
            _prevPowerPlan = powerPlanInfo;

            BatteryStatus status = batteryInfo.PowerStatus;
            //TimeLog("Battery status: " + status);
            //TimeLog("Current power plan: " + powerPlanInfo.Name);
            TimeLog("Notification icon refreshed");

            Icon icon;
            switch (status)
            {
                case BatteryStatus.Unknown:
                    icon = UnknownIcon;
                    break;
                case BatteryStatus.NoBattery:
                    icon = NoBatteryIcon;
                    break;
                default:
                    Icon[] icons = batteryInfo.IsPluggedIn.Value ? ChargingIcons : DischargingIcons;
                    icon = icons[(batteryInfo.RemainingCharge.Value - 1) / 10];
                    break;
            }

            string chargeText;
            switch (status)
            {
                case BatteryStatus.Charging:
                case BatteryStatus.Discharging:
                case BatteryStatus.NotCharging:
                    chargeText = " (" + batteryInfo.RemainingCharge.Value + "%)";
                    break;
                default:
                    chargeText = string.Empty;
                    break;
            }

            string statusText;
            switch (status)
            {
                case BatteryStatus.FullyCharged:
                    statusText = "Fully charged";
                    break;
                case BatteryStatus.Charging:
                    statusText = "Charging";
                    break;
                case BatteryStatus.NotCharging:
                    statusText = "Plugged in, not charging";
                    break;
                case BatteryStatus.Discharging:
                    statusText = "Discharging";
                    break;
                case BatteryStatus.NoBattery:
                    statusText = "No battery";
                    break;
                default: //BatteryStatus.Unknown
                    statusText = "Unknown";
                    break;
            }

            string activePlan = powerPlanInfo.Name;
            string newCaption = "Battery status: " + statusText + chargeText + "\n" +
                                "Active power plan: " + activePlan;
            _notifyIconWrapper.Text = newCaption;
            _notifyIconWrapper.Icon = icon;
        }
Esempio n. 9
0
        internal void ApplyPerformancePlan(PowerPlan powerPlan)
        {
            var guid = powerPlansDict[powerPlan];

            ApplyPerformancePlan(guid);
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            var RunDate = DateTime.Now;

            RunDate = RunDate.AddTicks(-(RunDate.Ticks % 10000000));;

            var Instances = InstanceServices.GetAllActive();
            var Jobs      = JobServices.GetById(1);

            Jobs.RunDate  = RunDate;
            Jobs.RunCount = Jobs.RunCount + 1;
            JobServices.Update(Jobs);
            //JobLogServices.logging = true;

            var LogBook = new JobLog {
                JobId = Jobs.Id, RunDate = RunDate, RunCount = (Int32)Jobs.RunCount
            };

            LogBook.Type = "INF"; LogBook.Message = "***** START OF LOG FILE *****";
            JobLogServices.Insert(LogBook);
            //Console.WriteLine("***** START OF LOG FILE *****");

            if (Jobs.Enabled == true)
            {
                LogBook.Type = "INF"; LogBook.Message = ("JOB: " + Jobs.Name + " IS ENABLED"); LogBook.RunDate = DateTime.Now;
                JobLogServices.Insert(LogBook);
                #region SchedulerSettings
                // construct a scheduler factory
                //ISchedulerFactory schedulerFactory = new StdSchedulerFactory();

                //get a scheduler
                // _scheduler = schedulerFactory.GetScheduler();


                //// add scheduler listener
                ////_scheduler.ListenerManager.AddSchedulerListener(new SchedulerListener());

                //// add global job listener
                ////_scheduler.ListenerManager.AddJobListener(new JobListener(), GroupMatcher<JobKey>.AnyGroup());

                //// add global trigger listener
                ////_scheduler.ListenerManager.AddTriggerListener(new TriggerListener(), GroupMatcher<TriggerKey>.AnyGroup());

                //_scheduler.Start();
                // Console.WriteLine("Starting Scheduler");
                #endregion

                #region CallQuartzJob

                /*foreach (string value in servers)
                 * {
                 * //  if (_utility.VerifyRemoteMachineStatus(value) == true)
                 *  //{
                 *
                 *      // foreach (string value in servers)
                 *      //{
                 *
                 *      Jobs.getServerName srvName = new Jobs.getServerName(); //This Constructor needs to be parameterless
                 *      AddSimpleJob(srvName, value);
                 *
                 *      Jobs.getCpuData cpuData = new Jobs.getCpuData();
                 *      AddSimpleJob(cpuData, value);
                 *
                 *  //}
                 *  //else
                 *  //{
                 *    //  Console.WriteLine("Server: " + value + " is offline");
                 *  //}
                 *
                 * }*/
                #endregion
                LogBook.Type = "INF"; LogBook.Message = ("INITIATING SQL CONNECTIVITY TEST"); LogBook.RunDate = DateTime.Now;
                JobLogServices.Insert(LogBook);
                //Console.WriteLine("INFORMATIVE: INITIATING SQL CONNECTIVITY TEST");
                foreach (var i in Instances)
                {
                    var objLogic = new BusinessLayer.BusinessLayer();
                    objLogic.SetConnString(i.Name);

                    if (objLogic.IsServerConnected(objLogic.objDataLayer.ConnString) == true)
                    {
                        //Console.WriteLine("INFORMATIVE: SQL INSTANCE :" + i.Name + " IS UP");
                        LogBook.Type = "INF"; LogBook.Message = ("SQL INSTANCE :" + i.Name + " IS UP"); LogBook.RunDate = DateTime.Now;
                        JobLogServices.Insert(LogBook);
                        var helper_ServerProperty = new ServerProperty();
                        var helper_SysConfig      = new SysConfig();
                        var helper_SysOsInfo      = new SysOsInfo();
                        var helper_PowerPlan      = new PowerPlan();

                        var InstanceDetail_obj = new InstanceDetail();

                        Console.WriteLine("INFORMATIVE: Getting Information from Instance: " + i.Name);

                        helper_ServerProperty = objLogic.GetServerProperties();
                        if (helper_ServerProperty.Success == true)
                        {
                            LogBook.Type = "INF"; LogBook.Message = ("<SUCCESS> GET SERVER PROPERTIES"); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                            helper_SysConfig = objLogic.GetSysConfiguration();
                            if (helper_SysConfig.Success == true)
                            {
                                LogBook.Type = "INF"; LogBook.Message = ("<SUCCESS> GET SYSTEM CONFIG"); LogBook.RunDate = DateTime.Now;
                                JobLogServices.Insert(LogBook);
                                helper_SysOsInfo = objLogic.GetSysOsInformation();
                                if (helper_SysOsInfo.Success == true)
                                {
                                    LogBook.Type = "INF"; LogBook.Message = ("<SUCCESS> GET SYSTEM OS INFORMATION"); LogBook.RunDate = DateTime.Now;
                                    JobLogServices.Insert(LogBook);
                                    helper_PowerPlan = objLogic.GetPowerPlan();
                                    if (helper_PowerPlan.Success == true)
                                    {
                                        LogBook.Type = "INF"; LogBook.Message = ("<SUCCESS> GET POWER PLAN"); LogBook.RunDate = DateTime.Now;
                                        JobLogServices.Insert(LogBook);
                                        InstanceDetail_obj.Edition     = helper_ServerProperty.Edition;
                                        InstanceDetail_obj.Version     = helper_ServerProperty.ProductVersion;
                                        InstanceDetail_obj.ServicePack = helper_ServerProperty.ProductLevel;
                                        InstanceDetail_obj.AuthMode    = helper_ServerProperty.AuthMode;
                                        InstanceDetail_obj.InstallDate = helper_ServerProperty.SQLInstallDate;
                                        InstanceDetail_obj.TcpPort     = helper_ServerProperty.LocalTcpPort;

                                        InstanceDetail_obj.MaxServerMemory_MB = helper_SysConfig.MaxServerMemory;
                                        InstanceDetail_obj.MinServerMemory_MB = helper_SysConfig.MinServerMemory;
                                        InstanceDetail_obj.BackupCompression  = helper_SysConfig.BackupCompression;
                                        InstanceDetail_obj.MaxDOP             = helper_SysConfig.MaxDop;
                                        InstanceDetail_obj.Xp_Cmdshell        = helper_SysConfig.Xp_Cmdshell;

                                        InstanceDetail_obj.CPU_Count       = helper_SysOsInfo.CpuCount;
                                        InstanceDetail_obj.ServerMemory_MB = helper_SysOsInfo.ServerMemory;
                                        InstanceDetail_obj.LastStartDate   = helper_SysOsInfo.SQLStartTime;
                                        InstanceDetail_obj.MachineType     = helper_SysOsInfo.MachineType;
                                        InstanceDetail_obj.PowerPlan       = helper_PowerPlan.powerPlan;

                                        InstanceDetail_obj.InstanceId = i.Id;
                                        InstanceDetail_obj.RunCount   = (Int32)Jobs.RunCount;
                                        InstanceDetail_obj.RunDate    = (DateTime)Jobs.RunDate;

                                        try
                                        {
                                            InstanceDetailServices.Insert(InstanceDetail_obj);
                                        }
                                        catch (Exception ex)
                                        {
                                            //Console.WriteLine("ERROR: FAILED TO INSERT OBJECT INTO InstanceDetailed TABLE");
                                            LogBook.Type = "ERR"; LogBook.Message = ("<FAILED> COULD NOT INSERT OBJECT INTO InstanceDetailed TABLE - INSTANCE: " + i.Name + " TABLE - EXCEPTION: " + ex.Message); LogBook.RunDate = DateTime.Now;
                                            JobLogServices.Insert(LogBook);
                                        }
                                    }
                                    else
                                    {
                                        LogBook.Type = "ERR"; LogBook.Message = ("<FAIL> GET POWER PLAN - INSTANCE: " + i.Name); LogBook.RunDate = DateTime.Now;
                                        JobLogServices.Insert(LogBook);
                                    }
                                }
                                else
                                {
                                    LogBook.Type = "ERR"; LogBook.Message = ("<FAIL> GET SYSTEM OS INFORMATION - INSTANCE: " + i.Name); LogBook.RunDate = DateTime.Now;
                                    JobLogServices.Insert(LogBook);
                                }
                            }
                            else
                            {
                                LogBook.Type = "ERR"; LogBook.Message = ("<FAIL> GET SYSTEM CONFIG - INSTANCE: " + i.Name); LogBook.RunDate = DateTime.Now;
                                JobLogServices.Insert(LogBook);
                            }
                        }
                        else
                        {
                            LogBook.Type = "ERR"; LogBook.Message = ("<FAIL> GET SERVER PROPERTIES - INSTANCE: " + i.Name); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        //var databaselist = new List<DataLayer.HelperClasses.DatabaseOption>();
                        //databaselist =
                        try
                        {
                            foreach (DatabaseOption DO in objLogic.GetDatabaseOptions())
                            {
                                DO.InstanceId = i.Id;
                                DO.RunDate    = (DateTime)Jobs.RunDate;
                                DO.RunCount   = (Int32)Jobs.RunCount;

                                DatabaseOptionServices.Insert(DO);
                            }
                            LogBook.Type = "INF"; LogBook.Message = ("<SUCCESS> GET DATABASE OPTIONS"); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        catch (Exception ex)
                        {
                            //Console.WriteLine("Exception: " + ex.Message);
                            LogBook.Type = "ERR"; LogBook.Message = ("<FAIL> COULD NOT RETRIEVE OR INSERT DATA INTO DatabaseOptions TABLE - INSTANCE: " + i.Name + " - EXCEPTION: " + ex.Message); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        try
                        {
                            foreach (Backup B in objLogic.GetBackups())
                            {
                                B.RunDate    = (DateTime)Jobs.RunDate;
                                B.RunCount   = (Int32)Jobs.RunCount;
                                B.InstanceId = i.Id;
                                BackupServices.Insert(B);
                            }
                            LogBook.Type = "INF"; LogBook.Message = ("<SUCCESS> GET BACKUPS"); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        catch (Exception ex)
                        {
                            //Console.WriteLine("Exception: " + ex.Message);
                            LogBook.Type = "ERR"; LogBook.Message = ("<FAIL> COULD NOT RETRIEVE OR INSERT DATA INTO Backups TABLE - INSTANCE: " + i.Name + " - EXCEPTION: " + ex.Message); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        try
                        {
                            foreach (Drive D in objLogic.GetDrives())
                            {
                                D.RunDate    = (DateTime)Jobs.RunDate;
                                D.RunCount   = (Int32)Jobs.RunCount;
                                D.InstanceId = i.Id;
                                DriveServices.Insert(D);
                            }
                            LogBook.Type = "INF"; LogBook.Message = ("<SUCCESS> GET DRIVE INFORMATION"); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        catch (Exception ex)
                        {
                            //Console.WriteLine("Exception: " + ex.Message);
                            LogBook.Type = "ERR"; LogBook.Message = ("<FAIL> COULD NOT RETRIEVE OR INSERT DATA INTO Drives TABLE - INSTANCE: " + i.Name + " - EXCEPTION: " + ex.Message); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        try
                        {
                            foreach (DatabaseFile DBF in objLogic.GetDatabaseFiles())
                            {
                                DBF.RunDate    = (DateTime)Jobs.RunDate;
                                DBF.RunCount   = (Int32)Jobs.RunCount;
                                DBF.InstanceId = i.Id;
                                DatabaseFileServices.Insert(DBF);
                            }
                            LogBook.Type = "INF"; LogBook.Message = ("<SUCCESS> GET DATABASE FILE INFORMATION"); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        catch (Exception ex)
                        {
                            //Console.WriteLine("Exception: " + ex.Message);
                            LogBook.Type = "ERR"; LogBook.Message = ("<FAIL> COULD NOT RETRIEVE OR INSERT DATA INTO DatabaseFiles TABLE - INSTANCE: " + i.Name + " - EXCEPTION: " + ex.Message); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        try
                        {
                            foreach (DatabaseSize DBS in objLogic.GetDatabaseSize())
                            {
                                DBS.RunDate    = (DateTime)Jobs.RunDate;
                                DBS.RunCount   = (Int32)Jobs.RunCount;
                                DBS.InstanceId = i.Id;
                                DatabaseSizeServices.Insert(DBS);
                            }
                            LogBook.Type = "INF"; LogBook.Message = ("<SUCCESS> GET DATABASE SIZE INFORMATION"); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        catch (Exception ex)
                        {
                            //Console.WriteLine("Exception: " + ex.Message);
                            LogBook.Type = "ERR"; LogBook.Message = ("<FAIL> COULD NOT RETRIEVE OR INSERT DATA INTO DatabaseSize TABLE - INSTANCE: " + i.Name + " - EXCEPTION: " + ex.Message); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        try
                        {
                            foreach (UserMembership UM in objLogic.GetUserMembership())
                            {
                                UM.RunDate    = (DateTime)Jobs.RunDate;
                                UM.RunCount   = (Int32)Jobs.RunCount;
                                UM.InstanceId = i.Id;
                                UserMembershipServices.Insert(UM);
                            }
                            LogBook.Type = "INF"; LogBook.Message = ("<SUCCESS> GET USER MEMBERSHIP INFORMATION"); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        catch (Exception ex)
                        {
                            //Console.WriteLine("Exception: " + ex.Message);
                            LogBook.Type = "ERR"; LogBook.Message = ("<FAIL> COULD NOT RETRIEVE OR INSERT DATA INTO UserMembership TABLE - INSTANCE: " + i.Name + " - EXCEPTION: " + ex.Message); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        try
                        {
                            foreach (LoginMembership LM in objLogic.GetLoginMembership())
                            {
                                LM.RunDate    = (DateTime)Jobs.RunDate;
                                LM.RunCount   = (Int32)Jobs.RunCount;
                                LM.InstanceId = i.Id;
                                LoginMembershipServices.Insert(LM);
                            }
                            LogBook.Type = "INF"; LogBook.Message = ("<SUCCESS> GET LOGIN MEMBERSHIP INFORMATION"); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        catch (Exception ex)
                        {
                            //Console.WriteLine("Exception: " + ex.Message);
                            LogBook.Type = "ERR"; LogBook.Message = ("<FAIL> COULD NOT RETRIEVE OR INSERT DATA INTO LoginMembership TABLE - INSTANCE: " + i.Name + " - EXCEPTION: " + ex.Message); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        try
                        {
                            foreach (LogSize LS in objLogic.GetLogSize())
                            {
                                LS.RunDate    = (DateTime)Jobs.RunDate;
                                LS.RunCount   = (Int32)Jobs.RunCount;
                                LS.InstanceId = i.Id;
                                LogSizeServices.Insert(LS);
                            }
                            LogBook.Type = "INF"; LogBook.Message = ("<SUCCESS> GET LOG SIZE INFORMATION"); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                        catch (Exception ex)
                        {
                            //Console.WriteLine("Exception: " + ex.Message);
                            LogBook.Type = "ERR"; LogBook.Message = ("<FAIL> COULD NOT RETRIEVE OR INSERT DATA INTO LogSize TABLE - INSTANCE: " + i.Name + " - EXCEPTION: " + ex.Message); LogBook.RunDate = DateTime.Now;
                            JobLogServices.Insert(LogBook);
                        }
                    }
                    else
                    {
                        //Console.WriteLine("WARNING: COULD NOT CONNECT TO SQL INSTANCE: " + i.Name);
                        LogBook.Type = "WRN"; LogBook.Message = ("COULD NOT CONNECT TO SQL INSTANCE: " + i.Name); LogBook.RunDate = DateTime.Now;
                        JobLogServices.Insert(LogBook);
                    }
                }

                //JobServices.Update(Jobs);
            }
            else
            {
                LogBook.Type = "INF"; LogBook.Message = ("JOB: " + Jobs.Name + " IS DISABLED");
                JobLogServices.Insert(LogBook);
            }
            //_scheduler.Shutdown();

            Console.WriteLine("***** END OF LOG FILE *****");
            LogBook.Type = "INF"; LogBook.Message = "***** END OF LOG FILE *****";
            JobLogServices.Insert(LogBook);
            //Console.ReadLine();
        }