Esempio n. 1
0
 internal WndExternals(WndSettings prefs, PNExternal ext)
     : this()
 {
     m_Prefs = prefs;
     m_Mode = AddEditMode.Edit;
     m_Ext = ext;
 }
 private bool importExternals(string iniPath)
 {
     try
     {
         var result = false;
         var size = 1024;
         var buffer = new string(' ', size);
         while (PNInterop.GetPrivateProfileString("external_programs", null, null, buffer, size, iniPath) ==
                size - 2)
         {
             // loop until sufficient buffer size
             size *= 2;
             buffer = new string(' ', size);
         }
         var names = buffer.Split('\0');
         var keys = names.Where(n => n.Trim().Length > 0);
         var listSql = new List<string>();
         var externals = new List<PNExternal>();
         foreach (string key in keys)
         {
             var prog = new StringBuilder(1024);
             while (
                 PNInterop.GetPrivateProfileStringByBuilder("external_programs", key, "", prog, prog.Capacity,
                                                            iniPath) == prog.Capacity - 1)
             {
                 prog.Capacity *= 2;
             }
             var data = prog.ToString().Split((char)1);
             var ext = new PNExternal { Name = key, Program = data[0] };
             var sb = new StringBuilder();
             sb.Append("INSERT OR REPLACE INTO EXTERNALS (EXT_NAME, PROGRAM, COMMAND_LINE) VALUES(");
             sb.Append("'");
             sb.Append(key);
             sb.Append("', ");
             sb.Append("'");
             sb.Append(data[0]);
             sb.Append("', ");
             sb.Append("'");
             if (data.Length == 2)
             {
                 sb.Append(data[1]);
                 ext.CommandLine = data[1];
             }
             sb.Append("'");
             sb.Append(")");
             listSql.Add(sb.ToString());
             externals.Add(ext);
         }
         if (listSql.Count > 0 && PNData.ExecuteTransactionForList(listSql, PNData.ConnectionString))
         {
             result = true;
             foreach (PNExternal ext in externals)
             {
                 PNStatic.Externals.RemoveAll(ex => ex.Name == ext.Name);
                 PNStatic.Externals.Add(ext);
             }
         }
         return result;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return false;
     }
 }
Esempio n. 3
0
 internal void ExternalReplace(PNExternal ext)
 {
     try
     {
         var e = _Externals.FirstOrDefault(ex => ex.Name == ext.Name);
         if (e == null) return;
         e.Program = ext.Program;
         e.CommandLine = ext.CommandLine;
         fillExternals(false);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
Esempio n. 4
0
 internal void ExternalAdd(PNExternal ext)
 {
     try
     {
         _Externals.Add(ext);
         fillExternals(false);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
Esempio n. 5
0
 private void editExternal(PNExternal ext)
 {
     try
     {
         if (ext == null) return;
         var dex = new WndExternals(this, ext) { Owner = this };
         var showDialog = dex.ShowDialog();
         if (showDialog != null && showDialog.Value)
         {
             fillExternals(false);
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
Esempio n. 6
0
 private void cmdOK_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var name = txtExtName.Text.Trim();
         if (m_Mode == AddEditMode.Add && m_Prefs.ExternalExists(name))
         {
             var message = PNLang.Instance.GetMessageText("ext_exists", "External program with this name already exists");
             PNMessageBox.Show(message, PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Information);
         }
         else
         {
             if (m_Mode == AddEditMode.Add)
             {
                 m_Ext = new PNExternal { Name = name, Program = txtExtProg.Text.Trim(), CommandLine = txtCommandLine.Text.Trim() };
                 m_Prefs.ExternalAdd(m_Ext);
             }
             else
             {
                 m_Ext.Program = txtExtProg.Text.Trim();
                 m_Ext.CommandLine = txtCommandLine.Text.Trim();
                 m_Prefs.ExternalReplace(m_Ext);
             }
             DialogResult = true;
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }