Beispiel #1
0
        /// <summary>
        /// Initializes the core generator description from a component instance.
        /// </summary>
        /// <param name="desc">description to initialize</param>
        /// <param name="component">component instance</param>
        public static void FromComponent(this CoreGenDescription desc, Component component)
        {
            Type type           = component.GetType();
            var  componentProps = type.GetProperties(BindingFlags.Instance |
                                                     BindingFlags.Public |
                                                     BindingFlags.NonPublic);
            var cgProps = componentProps.Where(p => Attribute.IsDefined(p, typeof(CoreGenProp)));
            List <CoreGenCommand> cmds = new List <CoreGenCommand>();

            foreach (PropertyInfo pi in cgProps)
            {
                var  cgProp    = (CoreGenProp)Attribute.GetCustomAttribute(pi, typeof(CoreGenProp));
                var  attrs     = pi.GetCustomAttributes(typeof(PresentOn), true);
                var  conds     = attrs.Select(o => ((PresentOn)o).PresenceCondition);
                bool fulfilled = !conds.Any() ||
                                 conds.Any(c => cgProps.Any(p => object.Equals(c, p.GetValue(component, new object[0]))));
                if (!fulfilled)
                {
                    continue;
                }
                object propValue    = pi.GetValue(component, new object[0]);
                string propValueStr = PropEnum.ToString(propValue, EPropAssoc.CoreGen);
                switch (cgProp.Usage)
                {
                case ECoreGenUsage.Select:
                    desc.Select(propValueStr, propValue.GetType());
                    break;

                case ECoreGenUsage.CSet:
                {
                    string propIDStr = PropEnum.ToString(pi, EPropAssoc.CoreGen);
                    desc.CSet(propIDStr, propValueStr, propValue.GetType());
                }
                break;

                default:
                    throw new NotImplementedException();
                }
            }
            desc.Generate();
        }
Beispiel #2
0
        internal static void FromProject(this CoreGenDescription desc, XilinxProject proj, EPropAssoc assoc)
        {
            PropertyBag pbag = proj.PBag.Copy(assoc);

            if (assoc == EPropAssoc.CoreGenProj)
            {
                string fname = Path.GetFileNameWithoutExtension(desc.Path);
                string wdir  = "./tmp/" + fname + "/";
                pbag.PutProperty(EXilinxProjectProperties.CoreGen_WorkingDirectory, wdir);
            }
            IList <PropDesc> allProps = PropEnum.EnumProps(typeof(EXilinxProjectProperties));

            foreach (PropDesc pd in allProps)
            {
                if (!pd.IDs.ContainsKey(assoc))
                {
                    continue;
                }

                object value = pbag.GetProperty((EXilinxProjectProperties)pd.EnumValue);
                desc.Set(pd.IDs[assoc], PropEnum.ToString(value, assoc), value.GetType());
            }
        }
Beispiel #3
0
 private void EnsureCreateTable(SQLiteConnection conn, CoreGenDescription desc)
 {
     var cmd = conn.CreateCommand();
     cmd.CommandText = desc.GetSql_CreateTable();
     if (cmd.ExecuteNonQuery() < 0)
         throw new IPDatabaseException("Unable to create table");
 }
Beispiel #4
0
 public void UpdatePerformanceRecord(CoreGenDescription desc, PerformanceRecord prec)
 {
     using (var conn = Connect())
     {
         EnsureCreateTable(conn, desc);
         if (QueryPerformanceRecord(conn, desc) == null)
         {
             InsertPerformanceRecord(conn, desc, prec);
         }
         else
         {
             UpdatePerformanceRecord(conn, desc, prec);
         }
     }
 }
Beispiel #5
0
 public PerformanceRecord QueryPerformanceRecord(CoreGenDescription desc)
 {
     using (var conn = Connect())
     {
         EnsureCreateTable(conn, desc);
         return QueryPerformanceRecord(conn, desc);
     }
 }
Beispiel #6
0
 private void UpdatePerformanceRecord(SQLiteConnection conn, CoreGenDescription desc, PerformanceRecord prec)
 {
     var cmd = conn.CreateCommand();
     cmd.CommandText = desc.GetSql_UpdateRecord(prec);
     if (cmd.ExecuteNonQuery() < 0)
         throw new IPDatabaseException("unable to update performance record");
 }
Beispiel #7
0
 private PerformanceRecord QueryPerformanceRecord(SQLiteConnection conn, CoreGenDescription desc)
 {
     var cmd = conn.CreateCommand();
     cmd.CommandText = desc.GetSql_QueryRecord();
     var reader = cmd.ExecuteReader();
     if (reader.Read())
     {
         var result = new PerformanceRecord();
         var props = typeof(PerformanceRecord).GetProperties();
         foreach (var pi in props)
         {
             object value = SqlCommands.UnwrapSqlValue(reader[pi.Name], pi.PropertyType);
             pi.SetValue(result, value, new object[0]);
         }
         return result;
     }
     else
     {
         return null;
     }
 }