private void _GuessNamespace() { if (OutputPath.EndsWith(".Entities")) { // Likely in an RA component, try to grab namespace from CSPROJ var projectFiles = Directory.GetFiles(OutputPath, "*.Entities.csproj"); if (projectFiles.Length == 1) { XDocument docment = XDocument.Load(projectFiles[0]); var projectDefaultNamespace = docment.Descendants().SingleOrDefault(element => element.Name.LocalName.EndsWith("RootNamespace")); if (projectDefaultNamespace != null) { Namespace = projectDefaultNamespace.Value; } } } else if (OutputPath.Contains("XXX.Dal")) { // Derive namespace from folders var pathParts = OutputPath.Split('\\'); var namespacePart = pathParts.Last(); if (namespacePart == "Entities") { namespacePart = pathParts.Reverse().Skip(1).First(); } Namespace = "XXX." + namespacePart; } else if (OutputPath.Contains("XXX.Models")) { MessageBox.Show("Entities should NEVER be placed in XXX.Models.", "ENTITIES NEVER GO IN MODELS", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private string GetPath() { if (_customGetPathFunc != null) { return(_customGetPathFunc()); } if (OutputPath.Contains('{')) { var now = DateTime.Now; return(OutputPath .Replace("{Day}", now.Day.ToString()) .Replace("{Month}", now.Month.ToString()) .Replace("{Year}", now.Year.ToString()) .Replace("{Hour}", now.Hour.ToString()) .Replace("{Minute}", now.Minute.ToString()) ); } return(OutputPath); }
/// <summary> /// /// </summary> /// <param name="numberOfThreads"></param> public void RunSimulations(int numberOfThreads = -1) { int noCoresToUse = numberOfThreads; int noCores = Environment.ProcessorCount; if (noCoresToUse <= 0) { noCoresToUse += noCores; } //Set up outputs (on main thread) if (OutputType == OutputType.CSVOutput) { FileInfo hlkFile = new FileInfo(FileName); if (OutputPath == null) { OutputPath = hlkFile.Directory.FullName; } if (!OutputPath.Contains(":")) { DirectoryInfo outDir = new DirectoryInfo(Path.Combine(hlkFile.Directory.FullName, OutputPath)); if (!outDir.Exists) { outDir.Create(); } OutputPath = outDir.FullName; } } else if (OutputType == OutputType.SQLiteOutput) { if (OutputPath == null) { OutputPath = FileName.Replace(".hlk", ".sqlite"); } //if (DBContext == null) //{ // DBContext = new HLDBContext(new SQLiteConnection("data source=" + OutputPath + ";foreign keys=false"), true); // DBContext.Configuration.AutoDetectChangesEnabled = false; // DBContext.Configuration.ValidateOnSaveEnabled = false; // //DBContext.SaveChanges(); //} //List<string> OutputIndicies = new List<string>(); //for(int i = 0; i < OutputDataElements.Count; i++) //{ // OutputIndicies.Add("x" + (i + 1).ToString()); //} SQLiteConnection.CreateFile(OutputPath); SQLConn = new SQLiteConnection("Data Source=" + OutputPath + ";Version=3;"); SQLConn.Open(); //Will need to create tables //Data string sql = "create table data (SimId int, Day int," + String.Join(" double,", OutputDataElements.Select(x => x.Name)) + " double)"; // sql = "create table data (SimId int, Day int," + String.Join(" double,", OutputIndicies) + " double)"; SQLiteCommand command = new SQLiteCommand(sql, SQLConn); command.ExecuteNonQuery(); //Annual sum data sql = "create table annualdata (SimId int, Year int," + String.Join(" double,", OutputDataElements.Select(x => x.Name)) + " double)"; // sql = "create table annualdata (SimId int, Year int," + String.Join(" double,", OutputIndicies) + " double)"; command = new SQLiteCommand(sql, SQLConn); command.ExecuteNonQuery(); //Annual sum average data sql = "create table annualaveragedata (SimId int," + String.Join(" double,", OutputDataElements.Select(x => x.Name)) + " double)"; // sql = "create table annualaveragedata (SimId int," + String.Join(" double,", OutputIndicies) + " double)"; command = new SQLiteCommand(sql, SQLConn); command.ExecuteNonQuery(); //Outputs sql = "create table outputs (Name string, Description string, Units string, Controller string)"; command = new SQLiteCommand(sql, SQLConn); command.ExecuteNonQuery(); StringBuilder sb = new StringBuilder(); sb.Append("INSERT INTO OUTPUTS (Name, Description , Units, Controller) VALUES "); foreach (OutputDataElement ode in OutputDataElements) { string comma = ","; if (ode == OutputDataElements.First()) { comma = ""; } sb.Append(comma + "(\"" + ode.Name + "\",\"" + ode.Output.Description + "\",\"" + ode.Output.Unit + "\",\"" + ode.HLController.GetType().Name + "\")"); } sql = sb.ToString(); command = new SQLiteCommand(sql, SQLConn); command.ExecuteNonQuery(); //Simulations sql = "create table simulations (Id int, Name string, StartDate DATETIME, EndDate DATETIME)"; command = new SQLiteCommand(sql, SQLConn); command.ExecuteNonQuery(); //Models sql = "create table models (SimId int, Name string, InputType string)"; command = new SQLiteCommand(sql, SQLConn); command.ExecuteNonQuery(); } else if (OutputType == OutputType.NetCDF) { //if (HLNC == null) //{ // // HLNC = new HLNCFile(this, this.Simulations[0].StartDate, this.Simulations[0].EndDate, FileName.Replace(".hlk", ".nc")); //} } //SQLite //Reset the counters CurrentSimIndex = 0; NoSimsComplete = 0; StartRunTime = DateTime.Now; //Create a list of background workers BackgroundWorkers = new List <HLBackGroundWorker>(noCoresToUse); //Populate the Background workers and run for (int i = 0; i < noCoresToUse; i++) { BackgroundWorkers.Add(new HLBackGroundWorker()); BackgroundWorkers[i].DoWork += HLBackgroundWorker_DoWork; BackgroundWorkers[i].RunWorkerCompleted += HLBackgroundWorker_RunWorkerCompleted; Simulation sim = GetSimulationElement(); if (sim != null) { // BackgroundWorkers[i].RunWorkerAsync(new List<object>(new object[] { xe, handler })); BackgroundWorkers[i].RunWorkerAsync(new List <object>(new object[] { sim })); } } }