All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alachisoft.ncache.ncactivate.appdata.MachineInfo Maven / Gradle / Ivy

There is a newer version: 5.3.3
Show newest version
/*
 * MachineInfo.java
 *
 * Created on October 7, 2006, 3:40 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package com.alachisoft.ncache.ncactivate.appdata;

import com.alachisoft.ncache.ncactivate.license.NCCpuInfo;
import com.alachisoft.ncache.ncactivate.utils.EnvironmentUtil;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Locale;

/**
 * @author Administrator
 */
public class MachineInfo {

    public String ComputerName;
    public int NumCpus = 0;
    public int PhysicalCpus = 0;
    public String Mac1 = new String("");
    public String Mac2 = new String("");
    public String Mac3 = new String("");
    public String Mac4 = new String("");

    /**
     * Creates a new instance of MachineInfo
     */

    public MachineInfo() {
        Load();
    }

    public int Load() {
        try {
            ComputerName = EnvironmentUtil.getComputerName();
            ComputerName = ComputerName.toUpperCase();
            NumCpus = NCCpuInfo.GetNumProcessors();//EnvironmentUtil.GetProcessorsCount();
            PhysicalCpus = NCCpuInfo.getPhysicalCoreCount();//1;//EnvironmentUtil.GetProcessorsCount();
            ArrayList adapters = EnvironmentUtil.GetAdaptersInfo();
            int num = adapters.size();
            if(num>0)
            {
                Mac1=(String)adapters.get(0);
            }
            if(num>1)
            {
                Mac2=(String)adapters.get(1);
            }
            if(num>3)
            {
                Mac3=(String)adapters.get(2);
            }
            if(num>4)
            {
                Mac4=(String)adapters.get(3);
            }
        } catch (IOException ioe) {
        } catch (Exception e) {
        }
        return 0;
    }

    public void Save() {
        return;
    }

    public String ToXml() {
        String xml = new String("");

        xml += "";
        xml += ComputerName;
        xml += "";

        String numCpu = new String();
        numCpu.format(Locale.US, "%d", NumCpus);
        xml += "";
        xml += numCpu;
        xml += "";

        String physicalCpus = new String();
        ;
        physicalCpus.format(Locale.US, "%d", PhysicalCpus);
        xml += "";
        xml += physicalCpus;
        xml += "";

        xml += "";
        xml += Mac1;
        xml += "";

        xml += "";
        xml += Mac2;
        xml += "";

        xml += "";
        xml += Mac3;
        xml += "";

        xml += "";
        xml += Mac4;
        xml += "";

        xml += "";
        return xml;
    }

    public ArrayList getMacs(){
        ArrayList macs = new ArrayList<>();
        if(Mac1!="")
            macs.add(Mac1);
        if(Mac2!="")
            macs.add(Mac2);
        if(Mac3!="")
            macs.add(Mac3);
        if(Mac4!="")
            macs.add(Mac4);
        return  macs;
    }

    public String ToLinearText() {

        String text = String.format(Locale.US, "%s\t%d\t%d\t%s\t%s\t%s\t%s", ComputerName, NumCpus, PhysicalCpus, Mac1, Mac2, Mac3, Mac4);
        return text;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy