public static void CreateZip()
        {
            using (var zip = new Ionic.Zip.ZipFile())
            {
                using (FileStream fs = File.Create(SavingPath))
                {
                    zip.AddDirectory(OutputPath);
                    zip.Save(fs);
                }
            }
            try
            {
                var dir = new DirectoryInfo(OutputPath);
                dir.Attributes = dir.Attributes & ~FileAttributes.ReadOnly;
                dir.Delete(true);
            }
            catch (IOException ex)
            {
                FileParser.LogException(ex);
            }

            /*using (var zip = new Ionic.Zip.ZipFile())
             * {
             *  zip.AddDirectory(Environment.GetFolderPath(
             * System.Environment.SpecialFolder.DesktopDirectory) + "\\code");
             *  FileStream x = File.Create("D:\\Visual Studio\\CommandGenerator\\MyFile.zip");
             *  zip.Save(x);
             *  x.Close();
             *  zip.Dispose();
             * }
             */
        }
Beispiel #2
0
        private void ListingNetworks()
        {
            SQLiteConnection myconn = new SQLiteConnection(path);

            try
            {
                myconn.Open();
            }
            catch (Exception ex)
            {
                FileParser.LogException(ex);
                MessageBox.Show("Check Network");
            }
            Queries           q    = new Queries();
            DataTable         show = new DataTable();
            SQLiteDataAdapter adap = new SQLiteDataAdapter(q.ShowNetworks(), myconn);

            adap.Fill(show);
            try
            {
                NetworkGrid.DataSource = show;
            }
            catch (Exception ex)
            {
                NetworkGrid.Rows[row].Cells[2].Value = oldip;
                NetworkGrid.Rows[row].Cells[3].Value = olduser;
                NetworkGrid.Rows[row].Cells[4].Value = Encrypt(oldpass);
                NetworkGrid.Rows[row].Cells[5].Value = oldname;
                // FileParser.LogException(ex);
            }
            myconn.Close();
        }
Beispiel #3
0
 public void BrowzeButtonClicked(ComboBox sheetsCB)
 {
     try
     {
         using (OpenFileDialog ofd = new OpenFileDialog()
         {
             Filter = "Excel Workbook 97-2003|*.xls|Excel Workbook|*.xlsx", ValidateNames = true
         })
         {
             if (ofd.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(ofd.FileName))
             {
                 workbookProcessor.ReadWorkbook(ofd.FileName, ofd.FilterIndex);
                 sheetsCB.Items.Clear();
                 foreach (DataTable dt in workbookProcessor.GetSheets())
                 {
                     sheetsCB.Items.Add(dt.TableName);
                 }
                 workbookProcessor.InitializeStatus();
             }
         }
     }
     catch (Exception ex)
     {
         FileParser.LogException(ex);
     }
 }
 public static void SaveResult(string name, string IP, string commandText, string result)
 {
     try
     {
         string path = Path.GetFullPath(OutputPath);
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         path += ("\\" + name);
         path  = Path.GetFullPath(path);
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         string Filep = "command_" + Ncounter + ".txt";
         string file  = Path.Combine(path, Filep);
         string text  = name + Environment.NewLine + IP + Environment.NewLine + commandText + Environment.NewLine + result + Environment.NewLine + Environment.NewLine;
         File.WriteAllText(file, text);
         string alltxt = OutputPath + "\\AllCommands.txt";
         using (StreamWriter w = File.AppendText(alltxt))
         {
             w.WriteLine(text);
         }
         Ncounter++;
     }
     catch (Exception ex)
     {
         FileParser.LogException(ex);
     }
 }
        public bool Excute(string name, string command)
        {
            string[] data     = dbr.AccessNetworkElement(name);
            string   IP       = data[0];
            string   username = data[1];
            string   password = data[2];

            try
            {
                using (var client = new SshClient(IP, username, password))
                {
                    client.Connect();
                    var cmd = client.RunCommand(command);
                    if (FileParser.SetSavingPath())
                    {
                        FileParser.CreateDirectory();
                        FileParser.SaveResult(name, IP, cmd.CommandText, cmd.Result);
                        FileParser.CreateZip();
                    }
                    client.Disconnect();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                FileParser.LogException(ex);
                return(false);
            }
        }
        private bool AddingNetworks(String Username, String Enc_Password, String IP, String Name)
        {
            SQLiteConnection myconn = new SQLiteConnection(pathh);

            try
            {
                myconn.Open();
            }
            catch (Exception ex)
            {
                FileParser.LogException(ex);
                MessageBox.Show("Check Network");
            }
            Queries       q      = new Queries();
            DataTable     show   = new DataTable();
            SQLiteCommand cmd    = new SQLiteCommand(q.AddNetwork(Username, Enc_Password, IP, Name), myconn);
            int           Result = cmd.ExecuteNonQuery();

            myconn.Close();
            if (Result > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public void RefreshConnection(string name)
 {
     try
     {
         int position = networkElements.IndexOf(name);
         if (position >= 0)
         {
             int status = dataBaseReference.CheckConn1(name);
             networkElementsStatus[position] = status;
             RefreshStatus(name, status);
         }
         //networkElementsStatus[position] = dataBaseReference.CheckConn1(name);
     }
     catch (Exception ex)
     {
         FileParser.LogException(ex);
     }
 }
 public bool TestConnection(string SSHIp, string Username, string Password)
 {
     try
     {
         bool res = false;
         using (var client = new SshClient(SSHIp, Username, Password))
         {
             client.Connect();
             res = client.IsConnected;
             client.Disconnect();
         }
         return(res);
     }
     catch (Exception ex)
     {
         FileParser.LogException(ex);
         return(false);
     }
 }
Beispiel #9
0
        private bool Login()
        {
            String logname  = txt_Username.Text;
            String Password = User.Encrypt(txt_Password.Text);

            string[] s        = { "\\bin" };
            string   database =
                Application.StartupPath.Split(s, StringSplitOptions.None)[0] + "\\Data\\Nokia.db";
            string connectionString =
                "Data Source=" + Path.GetFullPath(database);
            SQLiteConnection myconn = new SQLiteConnection(connectionString);

            try
            {
                myconn.Open();

                Queries       q    = new Queries();
                DataTable     show = new DataTable();
                SQLiteCommand cmd  = new SQLiteCommand(q.Login(logname, Password), myconn);

                int Result = Convert.ToInt32(cmd.ExecuteScalar());
                Console.WriteLine(Result);
                myconn.Close();
                if (Result > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PROBLEM RETRIEVING DATA PLEASE TRY AGAIN");
                FileParser.LogException(ex);
            }


            return(false);
        }
Beispiel #10
0
        private void RefreshUsers()
        {
            SQLiteConnection myconn = new SQLiteConnection(pathh);

            myconn.Open();
            DataTable         show = new DataTable();
            SQLiteDataAdapter adap = new SQLiteDataAdapter("Select * from usersTable", myconn);

            adap.Fill(show);
            try
            {
                usersGrid.DataSource = show;
            }
            catch (Exception ex)
            {
                usersGrid.Rows[User.row].Cells[2].Value = User.oldUsername;
                usersGrid.Rows[User.row].Cells[3].Value = User.Encrypt(User.oldPassword);
                FileParser.LogException(ex);
            }
            myconn.Close();
        }
        private void ListingNetworks()
        {
            SQLiteConnection myconn = new SQLiteConnection(pathh);

            try
            {
                myconn.Open();
            }
            catch (Exception ex)
            {
                FileParser.LogException(ex);
                MessageBox.Show("Check Network");
            }
            Queries           q    = new Queries();
            DataTable         show = new DataTable();
            SQLiteDataAdapter adap = new SQLiteDataAdapter(q.ShowNetworks(), myconn);

            adap.Fill(show);
            NetworkGrid.DataSource = show;
            myconn.Close();
        }
Beispiel #12
0
        //////////--------------------Networks Tab--------------------\\\\\\\\\\

        private void NetworkGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                try
                {
                    string str = NetworkGrid.Rows[e.RowIndex].Cells[5].Value.ToString();
                    if (MessageBox.Show("Are you sure you want to delete network element '" + str + "' ?", "Confirm Deletion", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        SQLiteConnection myconnection = new SQLiteConnection(path);
                        myconnection.Open();
                        SQLiteCommand cmd = new SQLiteCommand(q.DeleteNetwork(str), myconnection);
                        cmd.ExecuteNonQuery();
                        myconnection.Close();
                        ListingNetworks();
                    }
                }
                catch (Exception ex)
                {
                    FileParser.LogException(ex);
                }
            }
        }
Beispiel #13
0
 private void UsersGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 0)
     {
         try
         {
             string str = usersGrid.Rows[e.RowIndex].Cells[2].Value.ToString();
             if (MessageBox.Show("Are you sure you want to delete user '" + str + "' ?", "Confirm Deletion", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 SQLiteConnection myconnection = new SQLiteConnection(path);
                 myconnection.Open();
                 SQLiteCommand cmd = new SQLiteCommand("delete from usersTable where username = @username;", myconnection);
                 cmd.Parameters.Add(new SQLiteParameter("@username", str));
                 cmd.ExecuteNonQuery();
                 myconnection.Close();
                 RefreshUsers();
             }
         }
         catch (Exception ex)
         {
             FileParser.LogException(ex);
         }
     }
 }
 private static void MyCommonExceptionHandlingMethod(object sender, ThreadExceptionEventArgs e)
 {
     //#comment use your logger
     FileParser.LogException(e.Exception);
     throw new NotImplementedException();
 }