public UpdateController(PowerDbContext context, IMemoryCache MemoryCache, IConfiguration Configuration) { _Configuration = Configuration; Context = context; this._MemoryCache = MemoryCache; threshold = Context.ReportConstants.FirstOrDefault(r => r.Name == "threshold").Value; }
public PhaseConnectionController(PowerDbContext con) { _con = con; }
public PrimarySourceSerivce(PowerDbContext _context) { _Context = _context; }
public TestController(PowerDbContext con) { _con = con; }
public PrimarySourceController(PowerDbContext _context) { _Context = _context; }
public FactoryController(PowerDbContext con) { _con = con; }
public LoadsServices(PowerDbContext _con) { this._con = _con; }
public SecoundrySourceController(PowerDbContext _context) { _Context = _context; }
public ReportConstantServices(PowerDbContext _contect) { _Contect = _contect; }
public void InitialRecordData(RecordParams recordParams, Guid stageId) { try { Stage.Add(stageId, RecordProcessStage.OnCreatingRecord); var recordRepo = Repo <PowerRepository <Record> >(); var newRecord = new Record { RecordName = recordParams.RecordName, RecordStartDateTime = DateTime.Parse(recordParams.RecordConfigs["StartDateTime"]), RecordDuration = TimeSpan.Parse(recordParams.RecordConfigs["RecordDuration"]), RecordEndDateTime = DateTime.Parse(recordParams.RecordConfigs["EndDateTime"]) }; recordRepo.AddOrUpdateDoCommit(newRecord); newRecord.ModelState = ModelState.Changed; var configRepo = Repo <PowerRepository <SystemConfig> >(); var configs = configRepo.GetModelList(obj => obj.ConfigType == "RecordInitial") .ToDictionary(obj => obj.ConfigName, item => item.ConfigValue); var initialzation = $"{newRecord.Id}\r\n{recordParams.RecordConfigs["Period"]}\r\n{recordParams.RecordConfigs["Frequency"]}\r\n{recordParams.RecordConfigs["LineType"]}"; foreach (var file in Directory.GetFiles(configs["dataDirectory"])) { if (!recordParams.FileList.Contains(Path.GetFileNameWithoutExtension(file))) { File.Delete(file); } } if (Directory.GetFiles(configs["dataDirectory"]).Length != recordParams.FileList.Count) { Stage[stageId] = RecordProcessStage.MissingFile; return; } File.WriteAllText(configs["InitialzationFile"], initialzation); if (!Globals.IsProcessRunning(configs["MainProcessName"])) { Process.Start(configs["MainProcessPath"]); } File.WriteAllText(configs["FinishFile"], "0"); File.WriteAllText(configs["StartFile"], "1"); Stage[stageId] = RecordProcessStage.OnCaclating; while (File.ReadAllText(configs["FinishFile"]).Substring(0, 1) != "1") { Thread.Sleep(1000); } var config = new RecordConfig { LineType = (LineType)byte.Parse(recordParams.RecordConfigs["LineType"]), CalcPrecision = ushort.Parse(recordParams.RecordConfigs["Period"]), Frequency = ushort.Parse(recordParams.RecordConfigs["SampleRate"]), RecordId = newRecord.Id }; var ctx = new PowerDbContext(); ctx.RecordConfigs.Add(config); ctx.SaveChanges(); using (var connection = new MySqlConnection(configs["MySqlConnString"])) { Stage[stageId] = RecordProcessStage.OnAfterCaclating; connection.Open(); using (var transction = connection.BeginTransaction()) { try { using (var loadCmd = connection.CreateCommand()) { loadCmd.CommandType = CommandType.Text; loadCmd.CommandText = $"LOAD DATA LOCAL INFILE '{configs["ActiveFilePath"]}' INTO TABLE activevalues"; loadCmd.ExecuteNonQuery(); loadCmd.CommandText = $"LOAD DATA LOCAL INFILE '{configs["HarmonicFilePath"]}' INTO TABLE harmonics"; loadCmd.ExecuteNonQuery(); } using (var cmd = connection.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "transferPowers"; cmd.CommandTimeout = int.MaxValue; cmd.Parameters.Add(new MySqlParameter() { DbType = DbType.Int64, Direction = ParameterDirection.Input, ParameterName = "relativeRecordId", Value = newRecord.Id }); cmd.ExecuteNonQuery(); cmd.CommandText = "calcvoltageseconds"; cmd.ExecuteNonQuery(); cmd.CommandText = "calcvoltagethreeseconds"; cmd.ExecuteNonQuery(); } transction.Commit(); } catch (Exception ex) { transction.Rollback(); File.WriteAllText(configs["ActiveFilePath"], string.Empty); File.WriteAllText(configs["HarmonicFilePath"], string.Empty); LogService.Instance.Error("数据库操作执行失败。", ex); Stage[stageId] = RecordProcessStage.Failed; return; } } File.WriteAllText(configs["ActiveFilePath"], string.Empty); File.WriteAllText(configs["HarmonicFilePath"], string.Empty); File.WriteAllText(configs["StartFile"], "0"); } Stage[stageId] = RecordProcessStage.ProcessCompleted; newRecord.Finalized = true; recordRepo.AddOrUpdateDoCommit(newRecord); } catch (Exception ex) { LogService.Instance.Error("生成记录失败。", ex); } }
public DashBoardController(PowerDbContext _context) { _Context = _context; }
private static void GenerateData() { var context = new PowerDbContext(); var startDate = DateTime.Now; var duration = TimeSpan.FromMilliseconds(345600 * 250); context.Set <Record>().Add(new Record { Id = 1, RecordName = "测试记录", RecordDateTime = startDate, RecordStartDateTime = startDate, RecordDuration = duration, RecordEndDateTime = startDate + duration }); context.Set <RecordConfig>().Add(new RecordConfig { CalcPrecision = 250, Frequency = 256, LineType = LineType.StarWithMiddle, RecordId = 1 }); context.SaveChanges(); //var recordCount = 345600; //var recordIndexs = new List<int>(); //var current = 0; //while (current < recordCount) //{ // recordIndexs.Add(current); // current += 100; //} //Parallel.ForEach(recordIndexs, (index) => //{ // var done = false; // while (!done) // { // try // { // var dbContext = new PowerDbContext(); // var rd = new Random(); // var activeValues = new List<ActiveValue>(); // var harmonics = new List<Harmonic>(); // for (var i = index; i < index + 100; i++) // { // var avg = Math.Round(rd.Next(1, 100) / 100.0 + 220, 2); // var cur = Math.Round(rd.Next(1, 100) / 100.0 + 120, 2); // var activeValue = new ActiveValue // { // Voltage_AN = avg, // Voltage_BN = avg + 0.2, // Voltage_CN = avg - 0.2, // Voltage_NG = avg - 220, // Voltage_AB = avg + 0.3, // Voltage_BC = avg + 0.2, // Voltage_CA = avg + 0.1, // Current_A = cur, // Current_B = cur + 2, // Current_C = cur - 2, // Current_N = cur - 120, // RecordId = 1, // RecordIndex = i, // RecordTimeTicks = startDate.AddMilliseconds(i * 250).Ticks // }; // activeValues.Add(activeValue); // harmonics.Add(new Harmonic() // { // RecordId = 1, // RecordIndex = i // }); // } // dbContext.Configuration.AutoDetectChangesEnabled = false; // dbContext.Configuration.ValidateOnSaveEnabled = false; // dbContext.ActiveValues.AddRange(activeValues); // dbContext.Harmonics.AddRange(harmonics); // dbContext.SaveChanges(); // } // catch (Exception ex) // { // LogService.Instance.Fail("添加记录数据失败", ex); // Console.WriteLine(ex); // } // done = true; // } //}); }
public FactoryService(PowerDbContext context) { _context = context; }
public ReportsController(PowerDbContext _Context) { this._Context = _Context; ReportService = new ReportService(_Context); }
public LoadController(PowerDbContext _context) { _Context = _context; }
public DashBoardServices(PowerDbContext cont) { _Context = cont; }
public ProcessBase() { DbContext = new PowerDbContext(); }
protected ProcessBase(string connString) : this() { DbContext = new PowerDbContext(connString); }
public PhasesConnectionService(PowerDbContext _context) { this._context = _context; }
protected ProcessBase(PowerDbContext dbContext) { DbContext = dbContext; }
public HomeController(PowerDbContext context) { _con = context; }
public ConstantController(PowerDbContext _Context) { this._Context = _Context; }
public FloorController(PowerDbContext context) { _context = context; }
public ProductionService(PowerDbContext con) { _Context = con; }
public ProductionController(PowerDbContext _context) { _Context = _context; }
public SecoundrySourceService(PowerDbContext _context) { _Context = _context; }
public KwhMeterController(PowerDbContext context) { _context = context; }
public ApplianceController(PowerDbContext context) { _context = context; }