Example #1
0
 private int __total() //MB単位
 {
     if (NWEnviroment.isWindows())
     {
         float                      total = 0;
         ManagementClass            mc    = new ManagementClass("Win32_OperatingSystem");
         ManagementObjectCollection moc   = mc.GetInstances();
         foreach (ManagementObject mo in moc)
         {
             total = (int.Parse(mo["TotalVisibleMemorySize"].ToString()) + int.Parse(mo["TotalVirtualMemorySize"].ToString())) / 1000;
         }
         moc.Dispose();
         mc.Dispose();
         return((int)total);
     }
     else
     {
         string free = LinuxCommand.execute("free -m");
         using (StringReader sr = new StringReader(free)){
             string line = "";
             while ((line = sr.ReadLine()) != null)
             {
                 if (line.Contains("-/+"))
                 {
                     string[] parts = Regex.Split(line, @"\s+");
                     int      total = int.Parse(parts[parts.Length - 1]) + int.Parse(parts[parts.Length - 2]);
                     sr.Close();
                     sr.Dispose();
                     return(total);
                 }
             }
         }
     }
     return(0);//TODO: Exception?
 }
Example #2
0
        private int __available() //MB単位
        {
            if (NWEnviroment.isWindows())
            {
                string mem      = "Memory";
                string countMem = "Available Mbytes";
                System.Diagnostics.PerformanceCounter pcMem = new System.Diagnostics.PerformanceCounter(mem, countMem);
                float available = pcMem.NextValue();
                pcMem.Close();
                pcMem.Dispose();
                return((int)available);
            }
            else
            {
                string free = LinuxCommand.execute("free -m");
                using (StringReader sr = new StringReader(free)){
                    string line = "";
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.Contains("-/+"))
                        {
                            string[] parts     = Regex.Split(line, @"\s+");
                            int      available = int.Parse(parts[parts.Length - 1]);
                            sr.Close();
                            sr.Dispose();
                            return(available);
//                            Console.WriteLine("rate:{0}",(int)(100*int.Parse(parts[2])/(int.Parse(parts[3])+int.Parse(parts[2]))));
                        }
                    }
                }
            }
            return(0);//TODO: Exception?
        }
Example #3
0
        private object _toKana(INakoFuncCallInfo info)
        {
            string s = info.StackPopAsString();

            if (NWEnviroment.isWindows())
            {
                return(Strings.StrConv(s, VbStrConv.Hiragana, 0));
            }
            else
            {
                return(LinuxCommand.execute("echo '" + s + "' | nkf --hiragana").Replace("\n", ""));
            }
        }
Example #4
0
        public EnvInfo GetEnvInfo()
        {
            var osName = LinuxCommand.Execute("cat", "/etc/issue");

            var time = DateTime.Now;

            TimeZoneInfo localZone = TimeZoneInfo.Local;
            string       zone      = localZone.StandardName;
            string       utcOffset = localZone.GetUtcOffset(time).TotalHours.ToString();
            var          timeInfo  = new EnvTimeInfo(String.Format(timeFmt, time), zone, utcOffset);

            return(new EnvInfo(osName.Split('\\')[0], timeInfo));
        }
Example #5
0
        private object _alnumToEn(INakoFuncCallInfo info)
        {
            string s = info.StackPopAsString();

            return(Regex.Replace(s, @"[0-9A-Za-z:- ]+", delegate(Match m){
                if (NWEnviroment.isWindows())
                {
                    return Strings.StrConv(m.Value, VbStrConv.Narrow, 0);
                }
                else
                {
                    return LinuxCommand.execute("echo '" + m.Value + "' | nkf -Z3").Replace("\n", "");
                }
            }));
        }
Example #6
0
        public Object _execCommandAndGetResult(INakoFuncCallInfo info)
        {
            string s   = info.StackPopAsString();
            string ret = "";

            if (NWEnviroment.isWindows())
            {
                ret = WindowsCommand.execute(s);
            }
            else
            {
                ret = LinuxCommand.execute(s);
            }
            return(ret);
        }