Enum in C#

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Diagnostics;

using System.IO;

 

namespace SNMP

{

    class Program

    {

        enum Connectivity { Updatesever = 1, Gateway, Dnsserver, Deviceip, Devicemacaddress, Ewsaddress };

        enum Environ { Powersupply = 1, Usbpairstatus, Hookstate };

        enum Interfaces { Michealth = 1, Echometric };

        enum System { Cpuusage = 1, Memory, Diskfreespace };

        enum Version { Swversion = 1, Manufacturer, Model };

        enum Trapinfo { Domoerror = 1, Dwcode, Useruri, Logindelay, Ucclientsigninstate };

 

        public static string deviceIP = @"10.171.42.138";

        public static string deskPhoneMIB = @".1.3.6.1.4.1.311.70.1.";

 

        static void Main(string[] args)

        {

            try

            {

                DisplayParameterValue(typeof(Connectivity), false);

                DisplayParameterValue(typeof(Environ), true);

                DisplayParameterValue(typeof(Interfaces), true);

                DisplayParameterValue(typeof(System), true);

                DisplayParameterValue(typeof(Version), true);

                DisplayParameterValue(typeof(Trapinfo), true);

            }

            catch (Exception e)

            {

                Console.WriteLine(e.Message);

            }

        }

        static void DisplayParameterValue(Type enumType, bool append)

        {

            int index = 0;

            int maxValue = Enum.GetValues(enumType).Cast<int>().Max();

            StreamWriter sw = new StreamWriter(@"D:\output.txt", append);

            Console.WriteLine(enumType.Name + " Parameters");

            sw.WriteLine(enumType.Name + " Parameters");

            Console.WriteLine("=======================");

            sw.WriteLine("=======================");

            switch (enumType.Name)

            {

                case "Connectivity":

                    index = 1;

                    break;

                case "Environ":

                    index = 2;

                    break;

                case "Interfaces":

                    index = 3;

                    break;

                case "System":

                    index = 4;

                    break;

                case "Version":

                    index = 5;

                    break;

                case "Trapinfo":

                    index = 6;

                    break;

                default:

                    break;

 

            }

            for (int i = 0; i < (int)maxValue; i++)

            {

                Environment.SetEnvironmentVariable("Path", @"C:\");

                Process myProcess1 = new Process();

                myProcess1.StartInfo.FileName = "SNMPUTIL.EXE";

                Console.WriteLine(Enum.GetNames(enumType).GetValue(i));

                sw.WriteLine(Enum.GetNames(enumType).GetValue(i));

                Console.WriteLine("================");

                sw.WriteLine("================");

                myProcess1.StartInfo.Arguments = @"get " + deviceIP + " MSDESKPHONE " + deskPhoneMIB + index.ToString() + "." + Enum.GetValues(enumType).Cast<int>().ElementAt<int>(i).ToString();

                myProcess1.StartInfo.UseShellExecute = false;

                myProcess1.StartInfo.RedirectStandardOutput = true;

                myProcess1.StartInfo.CreateNoWindow = true;

                myProcess1.Start();

                string output1 = myProcess1.StandardOutput.ReadToEnd();

                myProcess1.WaitForExit();

                myProcess1.Close();

                Console.WriteLine(output1);

                sw.WriteLine(output1);

            }

            sw.Close();

        }

    }

}

Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s