private void LOAD_APPS_LIST() { try { Classes.MySQL A = new Classes.MySQL(); A.stored_procedure("Get_AppNames"); AppNames = new List <AppName>(); while (A.rdr.Read()) { AppNames.Add(new AppName { _App = A.rdr.IsDBNull(0) ? "" : A.rdr.GetString("appname"), _PathEXE = A.rdr.IsDBNull(1) ? "" : A.rdr.GetString("path_executable"), _LatestVersion = A.rdr.IsDBNull(2) ? "" : A.rdr.GetString("latest_version"), _Path_Latest_Installer = A.rdr.IsDBNull(3) ? "" : A.rdr.GetString("path_latest_installer"), _MSI_Installer = A.rdr.IsDBNull(4) ? "" : A.rdr.GetString("msi"), _EXE_Installer = A.rdr.IsDBNull(5) ? "" : A.rdr.GetString("exe"), _PublishTo = A.rdr.IsDBNull(6) ? "" : A.rdr.GetString("company") }); } A.conn.Close(); A.conn.Dispose(); DGridAppNames.SelectionChanged -= DGridAppNames_SelectionChanged; DGridAppNames.ItemsSource = null; DGridAppNames.ItemsSource = AppNames; DGridAppNames.SelectionChanged += DGridAppNames_SelectionChanged; } catch (Exception) { throw; } }
public MainWindow() { InitializeComponent(); _CompanyName = "CSFPI"; /// CHECK CONNECTION TO SERVER Classes.MySQL A = new Classes.MySQL(); if (A.openConnection() == false) { this.DckMain.IsEnabled = false; MessageBox.Show("Error : Cannot connect to App Center Server!", "CSF APP CENTER", MessageBoxButton.OK, MessageBoxImage.Error); A.conn.Close(); A.conn.Dispose(); Application.Current.Shutdown(); } A.conn.Close(); A.conn.Dispose(); /// get file version of app StackPanel Stkpnl = new StackPanel() { Orientation = Orientation.Vertical }; TextBlock txtb1 = new TextBlock() { Text = "App Version : " + GetAssemblyFileVersion(), Foreground = Brushes.Black, FontWeight = FontWeights.Bold }; TextBlock txtb2 = new TextBlock() { Text = "Latest Version : " + AppsCenterLatestVersion(), Foreground = GetAssemblyFileVersion().Equals(AppsCenterLatestVersion()) ? Brushes.Black : Brushes.Crimson, FontWeight = FontWeights.Bold }; Stkpnl.Children.Add(txtb1); Stkpnl.Children.Add(txtb2); BtnAppInfo.ToolTip = Stkpnl; }
private string AppsCenterLatestVersion() { try { if (_AppsCenterLatestVersion == null) { using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM csf_app_center.apps where appname like '*CSF APPS CENTER';")) { Classes.MySQL A = new Classes.MySQL(); if (A.openConnection() == false) { throw new Exception("MySQL Connection is not open!"); } cmd.Connection = A.conn; MySqlDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) { _AppsCenterLatestVersion = rdr.GetString("Latest_Version"); } A.conn.Close(); A.conn.Dispose(); } } return(_AppsCenterLatestVersion); } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message, "CSF TICKETING", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } }
private void GET_NETWORK_RESOURCE_CREDS() { try { /// GET CREDENTIAL FOR SHARED FOLDER Classes.MySQL B = new Classes.MySQL(); B.stored_procedure("Get_NetShared_Creds"); if (B.rdr.Read()) { NETWORK_RESOURCE_USER_LOGIN = Classes.Pub.Decrypt(B.rdr.GetString("Domain"), Classes.Pub.passphraselesky) + "\\" + Classes.Pub.Decrypt(B.rdr.GetString("UN"), Classes.Pub.passphraselesky); NETWORK_RESOURCE_USER_PASS = Classes.Pub.Decrypt(B.rdr.GetString("PW"), Classes.Pub.passphraselesky); } B.conn.Close(); B.conn.Dispose(); } catch (Exception) { throw; } }
private bool CHECK_CREATE_DESTINATION_DIRECTORY() { try { Classes.MySQL A = new Classes.MySQL(); A.stored_procedure("GetTempPath"); if (A.rdr.Read()) { DESTINATION_FOLDER = System.IO.Path.Combine(A.rdr.GetString("my_local_path"), APP_NAME.ToUpper().Replace("*", "")); } A.conn.Close(); A.conn.Dispose(); System.IO.Directory.CreateDirectory(DESTINATION_FOLDER); return(System.IO.Directory.Exists(DESTINATION_FOLDER)); } catch (Exception) { return(false); } }
private void LoadApps() { try { //// LOAD APP NAMES TO COMBOBOX Apps = new List <App>(); CboApps.Items.Clear(); Classes.MySQL A = new Classes.MySQL(); A.stored_procedure("Get_AppNames"); while (A.rdr.Read()) { Apps.Add(new App { _AppName = A.rdr.GetString("appname"), _PathExe = A.rdr.GetString("path_executable"), _PathInstaller_EXE = !A.rdr.IsDBNull(5) ? A.rdr.GetString("exe") : null, _PathInstaller_MSI = !A.rdr.IsDBNull(4) ? A.rdr.GetString("MSI") : null, _PathInstaller_Folder = A.rdr.GetString("path_latest_installer"), _LatestVersion = A.rdr.GetString("latest_version"), _Company = A.rdr.GetString("company") }); } A.conn.Close(); A.conn.Dispose(); foreach (App X in Apps.Where(a => a._Company.Equals(_CompanyName, StringComparison.OrdinalIgnoreCase) || a._Company.Equals("", StringComparison.OrdinalIgnoreCase)).ToList()) { CboApps.Items.Add(new ComboBoxItem() { Content = X._AppName.ToUpper() }); } } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message, "CSF APP CENTER", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void BtnDelete_Click(object sender, RoutedEventArgs e) { try { if (DGridAppNames.SelectedItem == null) { throw new Exception("No APP was selected."); } if (MessageBox.Show("Delete APP?", "Apps Center", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { Classes.MySQL A = new Classes.MySQL(); A.stored_procedure_with_params("Apps_Delete"); A.cmd.Parameters.AddWithValue("@_APPNAME", (DGridAppNames.SelectedItem as AppName)._App); A.rdr = A.cmd.ExecuteReader(); if (A.rdr.RecordsAffected == 1) { MessageBox.Show("APP Deleted!", "Apps Center", MessageBoxButton.OK, MessageBoxImage.Information); REFRESH(); } else { throw new Exception("Failed deleting APP!"); } A.conn.Close(); A.conn.Dispose(); } } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message, "Apps Center", MessageBoxButton.OK, MessageBoxImage.Error); return; } finally { } }
private void BtnUpdate_Click(object sender, RoutedEventArgs e) { try { if (DGridAppNames.SelectedItem == null) { throw new Exception("No APP was selected."); } if (string.IsNullOrEmpty(TxtAppName.Text) || string.IsNullOrWhiteSpace(TxtAppName.Text)) { throw new Exception("APP Name cannot be empty."); } var _X = TxtMSI.Text; if (string.IsNullOrEmpty(_X) == false && string.IsNullOrWhiteSpace(_X) == false) { var ext = System.IO.Path.GetExtension(_X).ToLower(); if (ext.Equals(".msi") == false && ext.Equals(".exe") == false) { TxtMSI.Focus(); TxtMSI.SelectAll(); throw new Exception("Check Installer's filename extension."); } } _X = TxtEXE.Text; if (string.IsNullOrEmpty(_X) == false && string.IsNullOrWhiteSpace(_X) == false) { var ext = System.IO.Path.GetExtension(_X).ToLower(); if (ext.Equals(".msi") == false && ext.Equals(".exe") == false) { TxtEXE.Focus(); TxtEXE.SelectAll(); throw new Exception("Check Installer's filename extension."); } } if (MessageBox.Show("Update APP?", "Apps Center", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { Classes.MySQL A = new Classes.MySQL(); A.stored_procedure_with_params("Apps_Update"); A.cmd.Parameters.AddWithValue("@_APPNAME", TxtAppName.Text); A.cmd.Parameters.AddWithValue("@_PATH_EXECUTABLE", TxtPathExe.Text); A.cmd.Parameters.AddWithValue("@_LATEST_VERSION", TxtLatestVersion.Text); A.cmd.Parameters.AddWithValue("@_PATH_LATEST_INSTALLER", TxtPathInstaller.Text); A.cmd.Parameters.AddWithValue("@_MSI", TxtMSI.Text); A.cmd.Parameters.AddWithValue("@_EXE", TxtEXE.Text); A.cmd.Parameters.AddWithValue("@_COMPANY", (string.IsNullOrEmpty(CboPublishTo.Text) || CboPublishTo.Text.Equals("any", StringComparison.OrdinalIgnoreCase)) ? "" : CboPublishTo.Text); A.cmd.Parameters.AddWithValue("@_OLD_APPNAME", (DGridAppNames.SelectedItem as AppName)._App); A.rdr = A.cmd.ExecuteReader(); if (A.rdr.RecordsAffected == 1) { MessageBox.Show("APP Updated!", "Apps Center", MessageBoxButton.OK, MessageBoxImage.Information); REFRESH(); } else { throw new Exception("Failed updating APP!"); } A.conn.Close(); A.conn.Dispose(); } } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message, "Apps Center", MessageBoxButton.OK, MessageBoxImage.Error); return; } finally { } }
private void BtnAdd_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrEmpty(TxtAppName.Text) == false) { var _X = TxtMSI.Text.ToLower(); //MessageBox.Show("Extension : " + System.IO.Path.GetExtension(_X)); if (string.IsNullOrEmpty(_X) == false && string.IsNullOrWhiteSpace(_X) == false) { if (System.IO.Path.GetExtension(_X).Contains("msi") == false) { TxtMSI.SelectAll(); throw new Exception("Check Installer's filename extension."); } } _X = TxtEXE.Text.ToLower(); //MessageBox.Show("Extension : " + System.IO.Path.GetExtension(_X)); if (string.IsNullOrEmpty(_X) == false && string.IsNullOrWhiteSpace(_X) == false) { if (System.IO.Path.GetExtension(_X).Contains("exe") == false) { TxtEXE.SelectAll(); throw new Exception("Check Installer's filename extension."); } } if (MessageBox.Show("Add new App?", "Apps Center", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { Classes.MySQL A = new Classes.MySQL(); A.stored_procedure_with_params("Apps_Insert"); A.cmd.Parameters.AddWithValue("@_APPNAME", TxtAppName.Text); A.cmd.Parameters.AddWithValue("@_PATH_EXECUTABLE", TxtPathExe.Text); A.cmd.Parameters.AddWithValue("@_LATEST_VERSION", TxtLatestVersion.Text); A.cmd.Parameters.AddWithValue("@_PATH_LATEST_INSTALLER", TxtPathInstaller.Text); A.cmd.Parameters.AddWithValue("@_MSI", TxtMSI.Text); A.cmd.Parameters.AddWithValue("@_EXE", TxtEXE.Text); A.cmd.Parameters.AddWithValue("@_COMPANY", (string.IsNullOrEmpty(CboPublishTo.Text) || CboPublishTo.Text.Equals("any", StringComparison.OrdinalIgnoreCase)) ? "" : CboPublishTo.Text); A.rdr = A.cmd.ExecuteReader(); if (A.rdr.RecordsAffected == 1) { MessageBox.Show("New APP added!", "Apps Center", MessageBoxButton.OK, MessageBoxImage.Information); REFRESH(); } else { throw new Exception("Failed adding new APP!"); } A.conn.Close(); A.conn.Dispose(); } } } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message, "Apps Center", MessageBoxButton.OK, MessageBoxImage.Error); return; } finally { } }
private bool CopyInstaller_ToTEMPFolder() { try { Classes.MySQL A = new Classes.MySQL(); A.stored_procedure("GetTempPath"); if (A.rdr.Read()) { rcp_dest_folder = System.IO.Path.Combine(A.rdr.GetString("my_local_path"), CboApps.Text.Replace("*", "")); } A.conn.Close(); A.conn.Dispose(); System.IO.Directory.CreateDirectory(rcp_dest_folder); A = new Classes.MySQL(); A.stored_procedure("GetTempPath"); if (A.rdr.Read()) { if (temp.Count == 1) { /// CHECK IF LATEST INSTALLER IS A FILE OR FOLDER /// IF IT IS A FILE, THEN COPY ITS PARENT FOLDER /// IF IT IS A FOLDER, THEN COPY IT TO LOCAL PATH /// GET CREDENTIAL FOR SHARED FOLDER Classes.MySQL B = new Classes.MySQL(); B.stored_procedure("Get_NetShared_Creds"); if (B.rdr.Read()) { /// ACCESS SHARED FOLDER OF INSTALLER USING A DIFF CREDENTIAL using (System.Diagnostics.Process Proc = new System.Diagnostics.Process()) { string _SharedFolder = System.IO.Path.GetDirectoryName(_Application_LatestInstaller); Proc.StartInfo.FileName = @"C:\windows\system32\net.exe"; Proc.StartInfo.Arguments = "use \"" + _SharedFolder + "\" /user:"******"\"" + Classes.Pub.Decrypt(B.rdr.GetString("Domain"), Classes.Pub.passphraselesky) + "\\" + Classes.Pub.Decrypt(B.rdr.GetString("UN"), Classes.Pub.passphraselesky) + "\"" + " \"" + Classes.Pub.Decrypt(B.rdr.GetString("PW"), Classes.Pub.passphraselesky) + "\""; Proc.StartInfo.UseShellExecute = false; Proc.StartInfo.RedirectStandardError = true; Proc.Start(); Proc.WaitForExit(); } } B.conn.Close(); B.conn.Dispose(); if (!string.IsNullOrEmpty(rcp_source_folder) && !string.IsNullOrEmpty(rcp_dest_folder)) { /// robocopy installer using (System.Diagnostics.Process P = new System.Diagnostics.Process()) { /// robocopy source dest /mir P.StartInfo.FileName = @"C:\windows\system32\robocopy.exe"; P.StartInfo.Arguments = "\"" + rcp_source_folder + "\" " + "\"" + rcp_dest_folder + "\" /mir"; P.StartInfo.CreateNoWindow = true; P.Start(); P.WaitForExit(); } using (System.Diagnostics.Process P = new System.Diagnostics.Process()) { /// robocopy source dest /mir P.StartInfo.FileName = @"C:\windows\system32\net.exe"; P.StartInfo.Arguments = "use \"" + rcp_source_folder + "\" /d"; P.StartInfo.CreateNoWindow = true; P.Start(); P.WaitForExit(); } } } } A.conn.Close(); A.conn.Dispose(); return(true); } catch (Exception ex) { MessageBox.Show("ERROR : " + ex.Message, "CSFP Apps Center", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } }