Exemplo n.º 1
0
        public static VMwareHostSystemInformation Get(string ipOrHostname)
        {
            try {
                var dt = SQLiteDataAccess.GetDataTable("Select * from VMwareHostSystemInformations where ipOrHostname=@param1", CommandType.Text, null, new SQLiteParameter("@param1", ipOrHostname));
                if (dt.Rows.Count == 0)
                {
                    return(null);
                }

                return(Parse(dt.Rows[0]));
            }
            catch (Exception ex) {
                //Let IIS handle the errors, but using own logging.
                Loggers.Log(Level.Error, "Failed retrieving vhost system info", ex, new object[] { ipOrHostname });
                throw;
            }
        }
Exemplo n.º 2
0
        public static void AddOrUpdate(VMwareHostSystemInformation row)
        {
            try {
                var propNames  = new List <string>();
                var paramNames = new List <string>();
                var parameters = new List <SQLiteParameter>();

                int paramI = 0;
                foreach (PropertyInfo propInfo in row.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
                {
                    propNames.Add(propInfo.Name);

                    string paramName = "@param" + (++paramI);
                    paramNames.Add(paramName);
                    parameters.Add(new SQLiteParameter(paramName, propInfo.GetValue(row)));
                }

                if (Get(row.ipOrHostname) == null)
                {
                    SQLiteDataAccess.ExecuteSQL("Insert into VMwareHostSystemInformations(" + string.Join(",", propNames) + ") values(" + string.Join(",", paramNames) + ")", CommandType.Text, null, parameters.ToArray());
                }
                else
                {
                    var set = new List <string>();
                    for (int i = 0; i != propNames.Count; i++)
                    {
                        set.Add(propNames[i] + "=" + paramNames[i]);
                    }


                    string paramName = "@param" + (++paramI);
                    parameters.Add(new SQLiteParameter(paramName, row.ipOrHostname));

                    SQLiteDataAccess.ExecuteSQL("Update VMwareHostSystemInformations set " + string.Join(",", set) + " where ipOrHostname=" + paramName, CommandType.Text, null, parameters.ToArray());
                }
            }
            catch (Exception ex) {
                //Let IIS handle the errors, but using own logging.
                Loggers.Log(Level.Error, "Failed adding or updating vhost system info to the database", ex, new object[] { row });
                throw;
            }
        }
Exemplo n.º 3
0
        public static void Remove(params string[] ipOrHostnames)
        {
            try {
                var paramNames = new List <string>();
                var parameters = new List <SQLiteParameter>();

                int paramI = 0;
                foreach (string hostname in ipOrHostnames)
                {
                    string paramName = "@param" + (++paramI);
                    paramNames.Add(paramName);
                    parameters.Add(new SQLiteParameter(paramName, hostname));
                }

                SQLiteDataAccess.ExecuteSQL("Delete from VMwareHostSystemInformations where ipOrHostname in(" + string.Join(",", paramNames) + ")", CommandType.Text, null, parameters.ToArray());
            }
            catch (Exception ex) {
                //Let IIS handle the errors, but using own logging.
                Loggers.Log(Level.Error, "Failed removing vhost system info", ex, new object[] { ipOrHostnames });
                throw;
            }
        }
Exemplo n.º 4
0
        public static VMwareHostSystemInformation[] GetAll()
        {
            try {
                var dt = SQLiteDataAccess.GetDataTable("Select * from VMwareHostSystemInformations");
                if (dt == null)
                {
                    return(new VMwareHostSystemInformation[0]);
                }

                var all = new VMwareHostSystemInformation[dt.Rows.Count];
                for (int i = 0; i != all.Length; i++)
                {
                    all[i] = Parse(dt.Rows[i]);
                }

                return(all);
            }
            catch (Exception ex) {
                //Let IIS handle the errors, but using own logging.
                Loggers.Log(Level.Error, "Failed retrieving all vhost system info", ex);
                throw;
            }
        }