/// <summary> /// This is the handler for the "Model Saved" event, this is the bulk of the "helping" logic /// </summary> /// <param name="args"></param> private void _context_ModelSaved(IModelSavedArgs args) { try { string myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); DataTable dtUsageLog = null; dtUsageLog = SimioAPIHelpers.LogHelpers.ConvertLogToDataTable(_context.Model.Plan.MaterialUsageLog); dtUsageLog.WriteXml(Path.Combine(myDocs, dtUsageLog.TableName + ".xml")); //dtUsageLog = SimioAPIHelpers.LogHelpers.ConvertLogToDataTable(_context.Model.Plan.ResourceUsageLog); //dtUsageLog.WriteXml(Path.Combine(myDocs, dtUsageLog.TableName + ".xml")); //dtUsageLog = SimioAPIHelpers.LogHelpers.ConvertLogToDataTable(_context.Model.Plan.ResourceCapacityLog); //dtUsageLog.WriteXml(Path.Combine(myDocs, dtUsageLog.TableName + ".xml")); //dtUsageLog = SimioAPIHelpers.LogHelpers.ConvertLogToDataTable(_context.Model.Plan.ResourceInfoLog); //dtUsageLog.WriteXml(Path.Combine(myDocs, dtUsageLog.TableName + ".xml")); //dtUsageLog = SimioAPIHelpers.LogHelpers.ConvertLogToDataTable(_context.Model.Plan.ResourceStateLog); //dtUsageLog.WriteXml(Path.Combine(myDocs, dtUsageLog.TableName + ".xml")); //dtUsageLog = SimioAPIHelpers.LogHelpers.ConvertLogToDataTable(_context.Model.Plan.ConstraintLog); //dtUsageLog.WriteXml(Path.Combine(myDocs, dtUsageLog.TableName + ".xml")); //dtUsageLog = SimioAPIHelpers.LogHelpers.ConvertLogToDataTable(_context.Model.Plan.StateObservationLog); //dtUsageLog.WriteXml(Path.Combine(myDocs, dtUsageLog.TableName + ".xml")); //dtUsageLog = SimioAPIHelpers.LogHelpers.ConvertLogToDataTable(_context.Model.Plan.TallyObservationLog); //dtUsageLog.WriteXml(Path.Combine(myDocs, dtUsageLog.TableName + ".xml")); //dtUsageLog = SimioAPIHelpers.LogHelpers.ConvertLogToDataTable(_context.Model.Plan.TaskLog); //dtUsageLog.WriteXml(Path.Combine(myDocs, dtUsageLog.TableName + ".xml")); //dtUsageLog = SimioAPIHelpers.LogHelpers.ConvertLogToDataTable(_context.Model.Plan.TaskStateLog); //dtUsageLog.WriteXml(Path.Combine(myDocs, dtUsageLog.TableName + ".xml")); //dtUsageLog = SimioAPIHelpers.LogHelpers.ConvertLogToDataTable(_context.Model.Plan.TransporterUsageLog); //dtUsageLog.WriteXml(Path.Combine(myDocs, dtUsageLog.TableName + ".xml")); int tableCount = 0; foreach (ITable simioTable in _context.Model.Tables) { tableCount++; DataTable dtTable = SimioAPIHelpers.TableHelpers.ConvertSimioTableToDataTable(simioTable); if (dtTable != null) { string tablename = simioTable.Name + ".xml"; string outputFilename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), tablename); dtTable.WriteXml(outputFilename); } } } catch (Exception ex) { Alert(ex.Message); } }
/// <summary> /// Optionally prompt for saving tables and SimioLogs to the database. /// and then save them. /// </summary> /// <param name="args"></param> private void _context_ModelSaved(IModelSavedArgs args) { // // This is the handler for the "Model Saved" event, this is the bulk of the "helping" logic // bool isInteractive = _context.AddInEnvironment == ModelAddInEnvironment.InteractiveDesktop; string marker = "Begin."; try { // Saves tables and then logs Boolean saveTables = true; Boolean saveLogs = true; if (isInteractive) { SaveDataToSql("Export Simio Tables/Logs Back To SQL Server?", "Export Tables/Logs To SQL Server", out saveTables, out saveLogs); } StringBuilder sbSaveMessage = new StringBuilder(); if (saveTables) { int tablesSaved = 0; DirectConnectUtils.SaveSimioTablesToDB(_context.Model, String.Empty, ref tablesSaved); marker = $"Saved Tables. Number Of Tables Exported: {tablesSaved}"; sbSaveMessage.AppendLine(marker); Logit(marker); } // non-interactive, or user says ok to save if (saveLogs) { int logsSaved = 0; DirectConnectUtils.SaveSimioLogsToDB(_context.Model, ref logsSaved); marker = $"Saved Logs. Number Of Logs Exported: {logsSaved}"; sbSaveMessage.AppendLine(marker); Logit(marker); } // non-interactive, or user says ok to save ShowStatus(isInteractive, "Exported", sbSaveMessage.ToString()); if (!string.IsNullOrEmpty(DirectConnectUtils.DirectConnectLogPath)) { Loggerton.Instance.WriteLogs(DirectConnectUtils.DirectConnectLogPath); } } catch (Exception ex) { ShowStatus(isInteractive, "Export Error", $"Error Saving: {ex.Message}"); } }