示例#1
0
        public void Add(VariableShutdownDetail entity)
        {
            _logger.Log(new LogEntry(LoggingEventType.Information, $"MachineSnapshotRepository.Add {entity.ToJson()}"));

            var connectionStringName = ConfigurationProvider.ConnectionStringName;
            var connectionString     = ConfigurationProvider.GetConnectionString(connectionStringName);

            try
            {
                using (var conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    using (var command = new SqlCommand(InsertQuery(), conn))
                    {
                        command.Parameters.AddWithValue("MachineIp", entity.MachineIp);
                        command.Parameters.AddWithValue("MachineName", entity.MachineName);
                        command.Parameters.AddWithValue("PouchesPerMinute", entity.PouchesPerMinute);
                        command.Parameters.AddWithValue("CyclingTime", entity.CyclingTime);
                        command.Parameters.AddWithValue("CycleCount", entity.CycleCount);
                        command.Parameters.AddWithValue("HourMeter", entity.HourMeter);
                        command.Parameters.AddWithValue("Comment", entity.Comment);

                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Log(new LogEntry(LoggingEventType.Error, $"MachineSnapshotRepository.Add {ex.Message}", ex));
                _logger.Log(new LogEntry(LoggingEventType.Error, $"connectionStringName={connectionStringName}; connectionString={connectionString}"));
                _logger.Log(new LogEntry(LoggingEventType.Error, $"commandQuery={InsertQuery()}"));
            }
        }
示例#2
0
        public async Task <DataResponse> Snapshot(string cpuName)
        {
            _logger.Log(new LogEntry(LoggingEventType.Information,
                                     $"VariableProcessor Operation=WriteToDb. cpuName={cpuName}"));

            var response = await _pviApplication.GetCpuData(cpuName);

            var cpuDetails = await _pviApplication.GetCpuByName(cpuName);

            if (response.Error == null)
            {
                var detail = new VariableShutdownDetail();


                var variableDict = (IDictionary <string, object>)response.Data;


                dynamic data = response.Data as ExpandoObject;


                detail.MachineIp   = cpuDetails.IpAddress;
                detail.MachineName = cpuDetails.Name;

                if (variableDict.ContainsKey("PouchPerMinute"))
                {
                    int pouch;
                    Int32.TryParse(variableDict["PouchPerMinute"].ToString(), out pouch);
                    detail.PouchesPerMinute = pouch;
                }

                if (variableDict.ContainsKey("TimeDisplay.CyclingTime"))
                {
                    detail.CyclingTime = variableDict["TimeDisplay.CyclingTime"].ToString();
                }

                if (variableDict.ContainsKey("CycleCount"))
                {
                    int cycle;
                    Int32.TryParse(variableDict["CycleCount"].ToString(), out cycle);
                    detail.CycleCount = cycle;
                }

                if (variableDict.ContainsKey("HourMeter"))
                {
                    int meter;
                    Int32.TryParse(variableDict["HourMeter"].ToString(), out meter);
                    detail.HourMeter = meter;
                }

                detail.Comment = "API Request";

                await _sqlApi.AddSnapshot(detail);
            }

            return(response);
        }
示例#3
0
        private void OnShutdown(Cpu cpu)
        {
            EventHandler <ShutdownEventArgs> temp = Shutdown;

            if (temp != null)
            {
                var details = new VariableShutdownDetail();

                details.MachineIp   = cpu.Connection.TcpIp.DestinationIpAddress;
                details.MachineName = cpu.Name;
                details.Comment     = "Operator Shutdown";

                if (cpu.Variables.ContainsKey("PouchPerMinute"))
                {
                    details.PouchesPerMinute = cpu.Variables["PouchPerMinute"].Value.ToInt32(CultureInfo.CurrentCulture);
                }

                if (cpu.Variables.ContainsKey("TimeDisplay.CyclingTime"))
                {
                    details.CyclingTime = cpu.Variables["TimeDisplay.CyclingTime"].Value.ToString();
                }

                if (cpu.Variables.ContainsKey("CycleCount"))
                {
                    details.CycleCount = cpu.Variables["CycleCount"].Value.ToInt32(CultureInfo.CurrentCulture);
                }

                if (cpu.Variables.ContainsKey("HourMeter"))
                {
                    details.HourMeter = cpu.Variables["HourMeter"].Value.ToInt32(CultureInfo.CurrentCulture);
                }

                var eventArgs = new ShutdownEventArgs
                {
                    Details = details
                };

                temp(cpu, eventArgs);
            }
        }
        public async Task AddSnapshot(VariableShutdownDetail detail)
        {
            var repository = new MachineSnapshotRepository();

            await Task.Run(() => repository.Add(detail));
        }