Ejemplo n.º 1
0
        /// <summary>
        /// Vm check Id or Name
        /// </summary>
        /// <param name="vm"></param>
        /// <param name="idOrNameCheck"></param>
        /// <returns></returns>
        public static bool VmCheckIdOrName(VMInfo vm, string idOrNameCheck)
        {
            var nameLower = vm.Name.ToLower();
            var idLower   = idOrNameCheck.ToLower();

            if (StringHelper.IsNumeric(idOrNameCheck))
            {
                return(vm.Id == idOrNameCheck);
            }
            else if (idOrNameCheck.StartsWith("%") && idOrNameCheck.EndsWith("%"))
            {
                return(nameLower.Contains(idLower.Replace("%", "")));
            }
            else if (idOrNameCheck.StartsWith("%"))
            {
                return(nameLower.StartsWith(idLower.Replace("%", "")));
            }
            else if (idOrNameCheck.EndsWith("%"))
            {
                return(nameLower.EndsWith(idLower.Replace("%", "")));
            }
            else
            {
                return(nameLower == idLower);
            }
        }
Ejemplo n.º 2
0
        private static bool CheckIdOrName(VMInfo vm, string id)
        {
            var nameLower = vm.Name.ToLower();
            var idLower   = id.ToLower();

            if (StringHelper.IsNumeric(id))
            {
                //numeric
                return(vm.Id == id);
            }
            else if (id.StartsWith("%") && id.EndsWith("%"))
            {
                //contain
                return(nameLower.Contains(idLower.Replace("%", "")));
            }
            else if (id.StartsWith("%"))
            {
                //startwith
                return(nameLower.StartsWith(idLower.Replace("%", "")));
            }
            else if (id.EndsWith("%"))
            {
                //endwith
                return(nameLower.EndsWith(idLower.Replace("%", "")));
            }
            else
            {
                return(nameLower == idLower);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Info vms.
 /// </summary>
 /// <param name="vms"></param>
 /// <param name="outputType"></param>
 /// <returns></returns>
 public static string Info(this IReadOnlyList <VMInfo> vms, TableOutputType outputType)
 {
     return(vms.Count > 0 ?
            TableHelper.Create(VMInfo.GetTitlesInfo(),
                               vms.Select(a => a.GetRowInfo()),
                               outputType,
                               false) :
            "");
 }
Ejemplo n.º 4
0
        internal Snapshot(VMInfo vm, object apiData)
        {
            _apiData = apiData;
            VM       = vm;

            DynamicHelper.CheckKeyOrCreate(_apiData, "description", "no-description");
            DynamicHelper.CheckKeyOrCreate(_apiData, "parent", "no-parent");
            DynamicHelper.CheckKeyOrCreate(_apiData, "snaptime");
            DynamicHelper.CheckKeyOrCreate(_apiData, "vmstate", 0);

            Date = _apiData.snaptime == null
                        ? DateTime.Now
                        : DateTimeOffset.FromUnixTimeSeconds(_apiData.snaptime).DateTime;
        }
        /// <summary>
        /// Vm check Id or Name
        /// </summary>
        /// <param name="vm"></param>
        /// <param name="idOrNameCheck"></param>
        /// <returns></returns>
        public static bool VmCheckIdOrName(VMInfo vm, string idOrNameCheck)
        {
            var nameLower = vm.Name.ToLower();
            var idLower   = idOrNameCheck.ToLower();

            if (idOrNameCheck.Contains(":"))
            {
                //range number
                var range = idOrNameCheck.Split(':');
                if (range.Count() != 2 ||
                    !StringHelper.IsNumeric(range[0]) ||
                    !StringHelper.IsNumeric(range[1]))
                {
                    return(false);
                }

                return(long.Parse(vm.Id) >= long.Parse(range[0]) &&
                       long.Parse(vm.Id) <= long.Parse(range[1]));
            }
            else if (StringHelper.IsNumeric(idOrNameCheck))
            {
                return(vm.Id == idOrNameCheck);
            }
            else if (idOrNameCheck.StartsWith("%") && idOrNameCheck.EndsWith("%"))
            {
                return(nameLower.Contains(idLower.Replace("%", "")));
            }
            else if (idOrNameCheck.StartsWith("%"))
            {
                return(nameLower.StartsWith(idLower.Replace("%", "")));
            }
            else if (idOrNameCheck.EndsWith("%"))
            {
                return(nameLower.EndsWith(idLower.Replace("%", "")));
            }
            else
            {
                return(nameLower == idLower);
            }
        }
Ejemplo n.º 6
0
 internal Config(VMInfo vm, object apiData)
 {
     ApiData = apiData;
     VM      = vm;
     DynamicHelper.CheckKeyOrCreate(apiData, "lock", "");
 }
Ejemplo n.º 7
0
 internal Snapshots(VMInfo vm)
 {
     _vm = vm;
     RefreshList();
 }
Ejemplo n.º 8
0
 internal ConfigQemu(VMInfo vm, object apiData) : base(vm, apiData)
     => DynamicHelper.CheckKeyOrCreate(apiData, "agent", "0");