Example #1
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;
            }
        }
Example #2
0
        private static VMwareHostSystemInformation Parse(DataRow row)
        {
            var sysinfo = new VMwareHostSystemInformation();

            foreach (PropertyInfo propInfo in sysinfo.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                var val = row[propInfo.Name];

                if (val is DBNull)
                {
                    if (propInfo.PropertyType == typeof(string))
                    {
                        propInfo.SetValue(sysinfo, "");
                    }
                }
                else
                {
                    propInfo.SetValue(sysinfo, Convert.ChangeType(val, propInfo.PropertyType));
                }
            }

            return(sysinfo);
        }