Ejemplo n.º 1
0
        public Supplement.JsonOutput GetOutput(string arg)
        {
            Supplement.ServiceStartType filter;
            switch (arg) {
                case ARG_SERVICE:
                case ARG_SERVICE_ANY:
                    filter = Supplement.ServiceStartType.Auto |
                        Supplement.ServiceStartType.Demand |
                        Supplement.ServiceStartType.Disabled;
                    break;
                case ARG_SERVICE_AUTO:
                    filter = Supplement.ServiceStartType.Auto;
                    break;
                case ARG_SERVICE_DEMAND:
                    filter = Supplement.ServiceStartType.Demand;
                    break;
                case ARG_SERVICE_DISABLED:
                    filter = Supplement.ServiceStartType.Disabled;
                    break;
                default:
                    return null;
            }

            Supplement.JsonOutput jout = new Supplement.JsonOutput();

            foreach (ServiceController sc in ServiceController.GetServices()) {
                Supplement.SCManager scm = new Supplement.SCManager(sc.ServiceName);
                if ((scm.StartType & filter) != scm.StartType)
                    continue;

                Dictionary<string, string> item =
                    new Dictionary<string, string>(4);

                item.Add("SVCNAME", sc.ServiceName);
                item.Add("SVCDESC", sc.DisplayName);
                item.Add("SVCSTATUS", sc.Status.ToString());
                item.Add("SVCSTARTTYPE", scm.StartType.ToString());
                jout.Add(item);
            }

            return jout;
        }
Ejemplo n.º 2
0
        public Supplement.JsonOutput GetOutput(string arg)
        {
            if (arg != ARG_NETWORK)
                return null;

            Supplement.JsonOutput jout = new Supplement.JsonOutput ();

            NetworkInterface[] netifs = NetworkInterface.GetAllNetworkInterfaces ();
            foreach (NetworkInterface n in netifs) {
                if (n.NetworkInterfaceType != NetworkInterfaceType.Loopback &&
                    n.NetworkInterfaceType != NetworkInterfaceType.Tunnel) {
                    Dictionary<string, string> item =
                        new Dictionary<string, string> (3);

                    item.Add ("IFDESC", n.Description);
                    item.Add ("IFNAME", n.Name);
                    item.Add ("IFADDR", n.GetPhysicalAddress ().ToString ());
                    jout.Add (item);
                }
            }

            return jout;
        }
Ejemplo n.º 3
0
        public Supplement.JsonOutput GetOutput(string key)
        {
            bool mounted = false;
            bool mfolder = false;
            bool mletter = false;
            bool nomount = false;
            bool swap = false;
            bool noswap = false;
            bool onlyNative = false;

            DriveType dtype;
            switch (key) {
                case ARG_DRIVE_FIXED:
                    dtype = DriveType.Fixed;
                    break;
                case ARG_DRIVE_REMOVABLE:
                    dtype = DriveType.Removable;
                    break;
                case ARG_DRIVE_MOUNTED:
                    dtype = DriveType.Fixed;
                    mounted = true;
                    break;
                case ARG_DRIVE_MFOLDER:
                    dtype = DriveType.Fixed;
                    mfolder = true;
                    break;
                case ARG_DRIVE_MLETTER:
                    dtype = DriveType.Fixed;
                    mletter = true;
                    break;
                case ARG_DRIVE_NOMOUNT:
                    dtype = DriveType.Fixed;
                    nomount = true;
                    break;
                case ARG_DRIVE_SWAP:
                    dtype = DriveType.Fixed;
                    swap = true;
                    break;
                case ARG_DRIVE_NOSWAP:
                    dtype = DriveType.Fixed;
                    noswap = true;
                    break;
                case ARG_DRIVE_NETWORK:
                    dtype = DriveType.Network;
                    onlyNative = true;
                    break;
                default:
                    return null;
            }

            Supplement.JsonOutput jout = new Supplement.JsonOutput ();

            Supplement.IVolumeInfo[] vols = null;

            if (onlyNative)
            {
                vols = Supplement.NativeVolume.GetVolumes();
            }
            else
            {
                if (!TryGetVolumesViaWmi(out vols))
                {
                    if (MainClass.DEBUG)
                        MainClass.WriteLogEntry(string.Format("{0}.GetOutput: Fallback to native method.", CLASS_FULL_PATH));

                    // Fallback to native method
                    vols = Supplement.NativeVolume.GetVolumes();
                }
            }

            if (MainClass.DEBUG)
            {
                MainClass.WriteLogEntry(string.Format("{0}.GetOutput: got volumes. " +
                    "vols.Length: {1}", CLASS_FULL_PATH, vols.Length));
                for (int i = 0; i < vols.Length; i++)
                {
                    MainClass.WriteLogEntry(string.Format("{0}.GetOutput: vol[{1}] {{ " +
                        "Automount={2}, Caption={3}, DriveLetter={4}, DriveType={5}, " +
                        "IsMounted={6}, Label={7}, Name={8}, PageFilePresent={9}, " +
                        "VolumeFormat={10}, VolumeGuid={11} }}.", CLASS_FULL_PATH, i,
                        vols[i].Automount.ToString(), vols[i].Caption, vols[i].DriveLetter,
                        vols[i].DriveType.ToString(), vols[i].IsMounted.ToString(),
                        vols[i].Label, vols[i].Name, vols[i].PageFilePresent.ToString(),
                        vols[i].VolumeFormat, vols[i].VolumeGuid.ToString()));
                }
            }

            bool ismounted, ismletter;
            foreach (Supplement.IVolumeInfo v in vols) {
                ismounted = v.IsMounted;
                ismletter = (v.DriveLetter != null);

                if (v.Automount &&                              // Match to drives mounted automatically
                    v.DriveType == dtype &&                     // Match drive type
                    (!mounted || ismounted) &&                  // If defined to mounted drives, then match mounted drives
                    (!mfolder || (ismounted && !ismletter)) &&  // If defined to folder mounted drives, then match mounted and not has letter
                    (!mletter || (ismounted && ismletter)) &&   // If defined to letter mounted drives, then match mounted and has letter
                    (!nomount || !ismounted) &&                 // If defined to not mounted drives, then match not mounted drives
                    (!swap || v.PageFilePresent) &&             // If defined to drives that has page files, then match to drives that has page file
                    (!noswap || !v.PageFilePresent)) {          // If defined to drives that no page files, then match to drives that has no page file
                    Dictionary<string, string> item =
                        new Dictionary<string, string> (2);

                    string pmInstName = string.Empty;
                    if (ismounted) {
                        pmInstName = v.Name.TrimEnd('\\');
                    } else {
                        pmInstName = Supplement.PerfMon.LogicalDisk.GetInstanceName(v.VolumeGuid);
                    }

                    item.Add ("FSNAME", v.Name);
                    item.Add ("FSPERFMON", pmInstName);
                    item.Add ("FSLABEL", v.Label ?? "");
                    item.Add ("FSFORMAT", v.VolumeFormat);
                    item.Add ("FSCAPTION", v.Caption);
                    jout.Add (item);
                }
            }

            return jout;
        }