Exemplo n.º 1
0
        /// <summary>
        /// ReadIPAMFiles()
        /// </summary>
        /// <param name="searchFile"></param>
        protected void ReadIPAMFiles(string searchFile)
        {
            try
            {
                string[] lines = System.IO.File.ReadAllLines(searchFile);

                //Fill myIPAMList - LIST<myIPAMClass>
                for (int i = 1; i <= (lines.Count() - 1); i++)
                {
                    string[] cols;
                    string   fLine = "";

                    try
                    {
                        fLine = lines[i].ToString();
                        cols  = fLine.Split(',');

                        myIPAMClass ln = new myIPAMClass
                        {
                            ID             = i,
                            IPAddress      = cols[0],
                            Status         = "Active",
                            Description    = cols[2],
                            Hostname       = cols[3],
                            Mac            = cols[4],
                            TheSwitch      = "",
                            Unknown        = "",
                            Port           = cols[7],
                            Note           = cols[8],
                            SerialNumber   = cols[9],
                            DeviceLocation = cols[10]
                        };
                        myIPAMList.Add(ln);
                    }
                    catch (Exception E1)
                    {
                        MessageBox.Show("An error occurred while processing the File. Error: " + E1.Message + ", fLine = " + fLine + ", Length = " + fLine.Length);
                        //throw;
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("An error occurred while reading the File. Error: " + e.Message);
                //throw;
            }
        }
Exemplo n.º 2
0
        private void ReadFileColumns(string fn)
        {
            string[] lines = System.IO.File.ReadAllLines(fn);
            for (int i = 1; i <= (lines.Count() - 1); i++)
            {
                string[] cols;
                string   fLine = "";

                try
                {
                    fLine = lines[i].ToString();
                    cols  = fLine.Split(',');

                    if (Int32.TryParse(cols[0], out int x))
                    {
                        // you know that the parsing attempt was successful
                        myIPAMClass ln = new myIPAMClass
                        {
                            ID             = x, //i is current line number
                            IPAddress      = cols[6],
                            Status         = "Active",
                            Description    = cols[1],
                            Hostname       = "CCTV",
                            Mac            = cols[8],
                            TheSwitch      = "",
                            Unknown        = "",
                            Port           = (cols[3] + " & " + cols[2]).ToUpper(), //Switch & Data
                            Note           = "",
                            SerialNumber   = cols[9],
                            DeviceLocation = cols[1]
                        };
                        myIPAMList.Add(ln);
                    }
                }
                catch (Exception E1)
                {
                    MessageBox.Show("An error occurred while processing the File. Error: " + E1.Message + ", fLine = " + fLine + ", line # = " + i);
                    //throw;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// ReadXCELFile()
        /// </summary>
        /// <param name="searchFile"></param>
        /// <param name="type"></param>
        protected void ReadXCELFile(string searchFile, string type)
        {
            try
            {
                string[] lines = System.IO.File.ReadAllLines(searchFile);

                //Converts CBS CCTV spreadsheet format to IPAM Import Format
                if (type == "CCTV")
                {
                    for (int i = 1; i <= (lines.Count() - 1); i++)
                    {
                        string[] cols;
                        string   fLine = "";

                        try
                        {
                            fLine = lines[i].ToString();
                            cols  = fLine.Split(',');

                            if (Int32.TryParse(cols[0], out int x))
                            {
                                // you know that the parsing attempt was successful
                                myIPAMClass ln = new myIPAMClass
                                {
                                    ID             = x, //i is current line number
                                    IPAddress      = cols[6],
                                    Status         = "Active",
                                    Description    = cols[1],
                                    Hostname       = "CCTV",
                                    Mac            = cols[8],
                                    TheSwitch      = "",
                                    Unknown        = "",
                                    Port           = (cols[3] + " & " + cols[2]).ToUpper(), //Switch & Data
                                    Note           = "",
                                    SerialNumber   = cols[9],
                                    DeviceLocation = cols[1]
                                };
                                myIPAMList.Add(ln);
                            }
                        }
                        catch (Exception E1)
                        {
                            MessageBox.Show("An error occurred while processing the File. Error: " + E1.Message + ", fLine = " + fLine + ", line # = " + i);
                            //throw;
                        }
                    }
                }

                //Converts CBS Access Control spreadsheet format to IPAM Import Format
                if (type == "Access Control")
                {
                    for (int i = 1; i <= (lines.Count() - 1); i++)
                    {
                        string[] cols;
                        string   fLine = "";

                        try
                        {
                            fLine = lines[i].ToString();
                            cols  = fLine.Split(',');

                            if (Int32.TryParse(cols[0], out int x))
                            {
                                // you know that the parsing attempt was successful
                                myIPAMClass ln = new myIPAMClass
                                {
                                    ID             = x,
                                    IPAddress      = cols[6],
                                    Status         = "Active",
                                    Description    = cols[1],
                                    Hostname       = "Access Control",
                                    Mac            = cols[7],
                                    TheSwitch      = "",
                                    Unknown        = "",
                                    Port           = (cols[2] + " & " + cols[3]).ToUpper(), //Switch & Data
                                    Note           = "",
                                    SerialNumber   = cols[8],
                                    DeviceLocation = cols[1]
                                };
                                myIPAMList.Add(ln);
                            }
                        }
                        catch (Exception E1)
                        {
                            MessageBox.Show("An error occurred while processing the File. Error: " + E1.Message + ", fLine = " + fLine + ", line # = " + i);
                            //throw;
                        }
                    }
                }

                //Converts CBS Workstations spreadsheet format to IPAM Import Format
                if (type == "Workstations")
                {
                    for (int i = 1; i <= (lines.Count() - 1); i++)
                    {
                        string[] cols;
                        string   fLine = "";

                        try
                        {
                            fLine = lines[i].ToString();
                            cols  = fLine.Split(',');

                            myIPAMClass ln = new myIPAMClass
                            {
                                ID             = i,
                                IPAddress      = cols[0],
                                Status         = "Active",
                                Description    = cols[2],
                                Hostname       = cols[3],
                                Mac            = cols[4],
                                TheSwitch      = "",
                                Unknown        = "",
                                Port           = cols[7], //Switch & Data
                                Note           = cols[8],
                                SerialNumber   = cols[9],
                                DeviceLocation = cols[10]
                            };
                            myIPAMList.Add(ln);
                        }
                        catch (Exception E1)
                        {
                            MessageBox.Show("An error occurred while processing the File. Error: " + E1.Message + ", fLine = " + fLine + ", Length = " + fLine.Length);
                            //throw;
                        }
                    }
                }

                // No conversion
                if (type == "IPAM Import")
                {
                    for (int i = 1; i <= (lines.Count() - 1); i++)
                    {
                        string[] cols;
                        string   fLine = "";

                        try
                        {
                            fLine = lines[i].ToString();
                            cols  = fLine.Split(',');

                            myIPAMClass ln = new myIPAMClass
                            {
                                ID             = i,
                                IPAddress      = cols[0],
                                Status         = cols[1],
                                Description    = cols[2],
                                Hostname       = cols[3],
                                Mac            = cols[4],
                                TheSwitch      = cols[5],
                                Unknown        = cols[6],
                                Port           = cols[7], //Switch & Data
                                Note           = cols[8],
                                SerialNumber   = cols[9],
                                DeviceLocation = cols[10]
                            };
                            myIPAMList.Add(ln);
                        }
                        catch (Exception E1)
                        {
                            MessageBox.Show("An error occurred while processing the File. Error: " + E1.Message + ", fLine = " + fLine + ", Length = " + fLine.Length);
                            //throw;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("An error occurred while reading the File. Error: " + e.Message);
                //throw;
            }
        }