public void Dispose() { DirectConnectUtils.ClearConnectionAndConnectionString(); // Unsubscribing from the events here, as we no longer need to listen to them, _context.ModelSaved -= _context_ModelSaved; }
public IEnumerator <IGridDataRecord> GetEnumerator() { var ds = DirectConnectUtils.GetDataSet(_settings.TableOrViewName, _settings.IsStoredProcedure); foreach (DataRow dr in ds.Tables[0].Rows) { yield return(new DirectConnectGridDataRecord(dr, ds.Tables[0].Columns.Count)); } ds.Clear(); }
/// <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}"); } }
private void previewButton_Click(object sender, EventArgs e) { try { var ds = DirectConnectUtils.GetDataSet(tableViewOrSPNameTextBox.Text, isStoredProcedureCheckbox.Checked); dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ex) { string errString = String.Format("Error Connecting To {0}...{1}", tableViewOrSPNameTextBox.Text, ex.Message); Alert(errString); } }
/// <summary> /// Called at the time the model is loaded. /// </summary> /// <param name="context"></param> /// <returns></returns> public IDisposable CreateInstance(IModelHelperContext context) { DirectConnectUtils.DirectConnectLogPath = string.Empty; if ((bool)context.PropertyValues.FirstOrDefault(p => p.Name == "LogToDisk").Value) { DirectConnectUtils.DirectConnectLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SimioAPI-DirectConnect.log"); File.Delete(DirectConnectUtils.DirectConnectLogPath); } Logit($"Info: Creating ModelHelper Instance. Model={context.Model.Name} #Tables={context.Model.Tables.Count}"); Logit($"Info: Creating ModelHelper Instance. API Name={Name} Description={Description} Guid={UniqueID}"); // Setup lists to be used by this plugin DirectConnectUtils.NewModelSetup(context.Model); // get connect string var connectionString = context.PropertyValues.FirstOrDefault(p => p.Name == "ConnectionString"); if (connectionString?.Value != null) { Logit($"Info: CreateInstance. ConnectionString={connectionString.Value}"); try { if (string.IsNullOrEmpty(connectionString.Value.ToString())) { throw new Exception("ConnectionString Is Blank. Define connection string and re-enable model helper."); } DirectConnectUtils.SetConnectionAndConnectionString(connectionString.Value.ToString()); } catch (Exception ex) { Logit(ex.Message); } } // get connection TimeOut var connectionTimeOut = context.PropertyValues.FirstOrDefault(p => p.Name == "ConnectionTimeOut"); if (connectionTimeOut?.Value != null) { Logit($"Info: CreateInstance. ConnectionTimeOut={connectionTimeOut.Value}"); try { if (string.IsNullOrEmpty(connectionTimeOut.Value.ToString())) { throw new Exception("Connection TimeOut Is Blank. Define connection timeout and re-enable model helper."); } Int32 connectionTimeOutInt = 0; if (Int32.TryParse(connectionTimeOut.Value.ToString(), out connectionTimeOutInt)) { DirectConnectUtils.SetConnectionTimeOut(connectionTimeOutInt); } else { throw new Exception($"Connection TimeOut ({connectionTimeOut.Value}) Is Not An Integer. Redefine connection timeout and re-enable model helper."); } } catch (Exception ex) { Logit(ex.Message); } } // get date time format var dateTimeFormatProp = context.PropertyValues.FirstOrDefault(p => p.Name == "DateTimeFormat"); if (dateTimeFormatProp?.Value != null) { Logit($"CreateInstance. DateTimeFormat={dateTimeFormatProp.Value}"); try { if (string.IsNullOrEmpty(dateTimeFormatProp.Value.ToString())) { throw new Exception("DateTimeFormat string Is Blank. Define the DateTime Format String and re-enable model helper."); } DirectConnectUtils.SetDateTimeFormatString(dateTimeFormatProp.Value.ToString()); } catch (Exception ex) { Logit(ex.Message); } } return(new DirectConnectOnSaveInstance(context)); }