Ejemplo n.º 1
0
        public async Task <Report1Response> Report1()
        {
            System.Collections.Generic.IEnumerable <Domain.Models.DbEntities.Report1Entity> dbEntity = await _repository.Report1();

            return(new Report1Response
            {
                Data = dbEntity.GroupBy(g => new { g.ClientId, g.PersonalNumber }).Select(s => new Report1
                {
                    ClientId = s.Key.ClientId,
                    PersonalNumber = s.Key.PersonalNumber,
                    Data = s.Select(d => new Report1Data {
                        Type = (RelatedClientType)d.TypeId, RelativeCount = d.RelativeCount
                    })
                })
            });
        }
        /// <summary>
        ///  Post the State
        /// </summary>
        /// <param name="batchOfMessages"></param>
        /// <param name="cancellationToken"></param>
        // ReSharper disable once UnusedParameter.Global
        protected internal new async System.Threading.Tasks.Task WriteMessagesAsync(System.Collections.Generic.IEnumerable <Generic.LogMessage <System.Object> > batchOfMessages, System.Threading.CancellationToken cancellationToken)
        {
#if DEBUG
            System.Console.WriteLine($"{{ {System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName}.{System.Reflection.MethodBase.GetCurrentMethod().Name} }}");
#endif

            var groupOfMessagesHavingALogType = batchOfMessages.GroupBy(message => message.LogType);

            foreach (IGrouping <System.String, Generic.LogMessage <System.Object> > messages in groupOfMessagesHavingALogType)
            {
                var key  = messages.Key;
                var json = messages.ToJson();
                // ReSharper disable once UnusedVariable
                var resp = await this.PostData(key, json, this.CustomerId, this.SharedKey);

#if DEBUG
                System.Console.WriteLine($"{{ \"LogType\" : \"{key}\", \r\n  \"messages\" : {json} }}");
#endif
            }
        }
        protected internal override async System.Threading.Tasks.Task WriteMessagesAsync(
            System.Collections.Generic.IEnumerable <Generic.LogMessage <System.Object> > batchOfMessages,
            System.Threading.CancellationToken token)
        {
            System.IO.Directory.CreateDirectory(this.Path);

            foreach (IGrouping <(System.Int32 Year, System.Int32 Month, System.Int32 Day), Generic.LogMessage <System.Object> > group in batchOfMessages.GroupBy(FileLoggerProvider.GetGrouping))
            {
                var fullName = this.GetFullName(group.Key);
                var fileInfo = new System.IO.FileInfo(fullName);
                if (this.MaxFileSize > 0 && fileInfo.Exists && fileInfo.Length > this.MaxFileSize)
                {
                    return;
                }

                using (var streamWriter = System.IO.File.AppendText(fullName))
                {
                    foreach (var item in group)
                    {
                        await streamWriter.WriteAsync(item.Message);
                    }
                }
            }

            this.RollFiles();
        }
Ejemplo n.º 4
0
 public static System.Collections.Generic.IEnumerable <TSource> DistinctBy <TSource, TKey>(this System.Collections.Generic.IEnumerable <TSource> list, System.Func <TSource, TKey> expr)
 {
     return(list.GroupBy(expr).Select(x => x.First()));
 }
        public override void Enable()
        {
            foreach (string scope in Scopes)
            {
                try
                {
                    HardwareMonitorScope = new ManagementScope(scope, null);
                    HardwareMonitorScope.Connect();
                }
                catch
                {
                    _logger.Warning($"Could not connect to WMI scope: {scope}");
                    //if the connection to one of the scopes fails,
                    //ignore the exception and try the other one.
                    //this way both Open and Libre HardwareMonitors
                    //can be supported since only the name of
                    //scope differs
                    continue;
                }

                SensorSearcher   = new ManagementObjectSearcher(HardwareMonitorScope, SensorQuery);
                HardwareSearcher = new ManagementObjectSearcher(HardwareMonitorScope, HardwareQuery);

                System.Collections.Generic.List <Sensor>   sensors   = Sensor.FromCollection(SensorSearcher.Get());
                System.Collections.Generic.List <Hardware> hardwares = Hardware.FromCollection(HardwareSearcher.Get());

                if (sensors.Count == 0 || hardwares.Count == 0)
                {
                    _logger.Warning($"Connected to WMI scope \"{scope}\" but it did not contain any data.");
                    continue;
                }

                int hardwareIdCounter = 0;
                foreach (Hardware hw in hardwares.OrderBy(hw => hw.HardwareType))
                {
                    //loop through the hardware,
                    //and find all the sensors that hardware has
                    System.Collections.Generic.IEnumerable <Sensor> children = sensors.Where(s => s.Parent == hw.Identifier);

                    //if we don't find any sensors, skip and do the next hardware
                    if (!children.Any())
                    {
                        continue;
                    }

                    HardwareDynamicDataModel hwDataModel = DataModel.AddDynamicChild(
                        new HardwareDynamicDataModel(),
                        $"{hw.HardwareType}{hardwareIdCounter++}",
                        hw.Name,
                        hw.HardwareType.ToString()
                        );

                    //group sensors by type for easier UI navigation.
                    //this is also the way the UI of the HardwareMonitor
                    //programs displays the sensors, so let's keep that consistent
                    foreach (IGrouping <SensorType, Sensor> sensorsOfType in children.GroupBy(s => s.SensorType))
                    {
                        SensorTypeDynamicDataModel sensorTypeDataModel = hwDataModel.AddDynamicChild(
                            new SensorTypeDynamicDataModel(),
                            sensorsOfType.Key.ToString()
                            );

                        int sensorIdCounter = 0;
                        //for each type of sensor, we add all the sensors we found
                        foreach (Sensor sensorOfType in sensorsOfType.OrderBy(s => s.Name))
                        {
                            //this switch is only useful for the unit of each sensor
                            SensorDynamicDataModel dataModel = sensorsOfType.Key switch
                            {
                                SensorType.Temperature => new TemperatureDynamicDataModel(sensorOfType.Identifier),
                                SensorType.Load => new PercentageDynamicDataModel(sensorOfType.Identifier),
                                SensorType.Level => new PercentageDynamicDataModel(sensorOfType.Identifier),
                                SensorType.Voltage => new VoltageDynamicDataModel(sensorOfType.Identifier),
                                SensorType.SmallData => new SmallDataDynamicDataModel(sensorOfType.Identifier),
                                SensorType.Data => new BigDataDynamicDataModel(sensorOfType.Identifier),
                                SensorType.Power => new PowerDynamicDataModel(sensorOfType.Identifier),
                                SensorType.Fan => new FanDynamicDataModel(sensorOfType.Identifier),
                                SensorType.Throughput => new ThroughputDynamicDataModel(sensorOfType.Identifier),
                                SensorType.Clock => new ClockDynamicDataModel(sensorOfType.Identifier),
                                _ => new SensorDynamicDataModel(sensorOfType.Identifier),
                            };

                            sensorTypeDataModel.AddDynamicChild(
                                dataModel,
                                (sensorIdCounter++).ToString(),
                                sensorOfType.Name
                                );
                        }
                    }
                }
                AddTimedUpdate(TimeSpan.FromMilliseconds(500), UpdateData);
                _logger.Information($"Successfully connected to WMI scope: {scope}");
                return;
                //success!
            }
            throw new ArtemisPluginException(Plugin, "Could not find hardware monitor WMI scope with data");
        }