Exemple #1
0
 public RowGenerator(DbSetInfo dbSetInfo, IEnumerable <object> dataSource, IDataHelper dataHelper)
 {
     _dbSetInfo  = dbSetInfo ?? throw new ArgumentNullException(nameof(dbSetInfo));
     _dataSource = dataSource ?? throw new ArgumentNullException(nameof(dataSource));
     _dataHelper = dataHelper ?? throw new ArgumentNullException(nameof(dataHelper));
     fieldInfos  = _dbSetInfo.GetInResultFields();
     pkInfos     = _dbSetInfo.GetPKFields();
 }
Exemple #2
0
 public RowGenerator(DbSetInfo dbSetInfo, IEnumerable <object> dataSource, IDataHelper dataHelper)
 {
     _dbSetInfo  = dbSetInfo;
     _dataSource = dataSource;
     _dataHelper = dataHelper;
     fieldInfos  = _dbSetInfo.GetInResultFields();
     fieldCnt    = fieldInfos.Length;
     pkInfos     = _dbSetInfo.GetPKFields();
 }
Exemple #3
0
        private string CreateDbSetType(EntityDefinition entityDef, DbSetInfo dbSetInfo, DotNet2TS dotNet2TS)
        {
            StringBuilder      sb          = new StringBuilder(512);
            string             dbSetType   = GetDbSetTypeName(dbSetInfo.dbSetName);
            List <Association> childAssoc  = _associations.Where(assoc => assoc.childDbSetName == dbSetInfo.dbSetName).ToList();
            List <Association> parentAssoc = _associations.Where(assoc => assoc.parentDbSetName == dbSetInfo.dbSetName).ToList();
            FieldsList         fieldInfos  = dbSetInfo.fieldInfos;

            Field[] pkFields = dbSetInfo.GetPKFields();
            string  pkVals   = "";

            foreach (Field pkField in pkFields)
            {
                if (!string.IsNullOrEmpty(pkVals))
                {
                    pkVals += ", ";
                }

                pkVals += pkField.fieldName.ToCamelCase() + ": " + GetFieldDataType(pkField);
            }
            Dictionary <string, Func <TemplateParser.Context, string> > dic = new Dictionary <string, Func <TemplateParser.Context, string> >
            {
                { "DBSET_NAME", (context) => dbSetInfo.dbSetName },
                { "DBSET_TYPE", (context) => dbSetType },
                { "ENTITY_NAME", (context) => entityDef.entityName },
                { "ASPECT_NAME", (context) => entityDef.aspectName },
                { "INTERFACE_NAME", (context) => entityDef.interfaceName },
                { "VALS_NAME", (context) => entityDef.valsName },
                {
                    "DBSET_INFO",
                    (context) =>
                    {
                        //we are making copy of the object, in order that we don't change original object
                        //while it can be accessed by other threads
                        //we change our own copy, making it threadsafe
                        DbSetInfo copy = dbSetInfo.ShallowCopy();
                        copy.SetFieldInfos(new FieldsList()); //serialze with empty field infos
                        return(_serializer.Serialize(copy));
                    }
                },
                { "FIELD_INFOS", (context) => _serializer.Serialize(dbSetInfo.fieldInfos) },
                { "CHILD_ASSOC", (context) => _serializer.Serialize(childAssoc) },
                { "PARENT_ASSOC", (context) => _serializer.Serialize(parentAssoc) },
                { "QUERIES", (context) => CreateDbSetQueries(dbSetInfo, dotNet2TS) },
                { "CALC_FIELDS", (context) => CreateCalcFields(dbSetInfo) },
                { "PK_VALS", (context) => pkVals }
            };

            return(_dbSetTemplate.ToString(dic));
        }
        private string createDbSetType(string entityDef, DbSetInfo dbSetInfo)
        {
            var sb                  = new StringBuilder(512);
            var dbSetType           = GetDbSetTypeName(dbSetInfo.dbSetName);
            var entityTypeName      = GetEntityTypeName(dbSetInfo.dbSetName);
            var entityInterfaceName = GetEntityInterfaceName(dbSetInfo.dbSetName);
            var childAssoc          = _associations.Where(assoc => assoc.childDbSetName == dbSetInfo.dbSetName).ToList();
            var parentAssoc         = _associations.Where(assoc => assoc.parentDbSetName == dbSetInfo.dbSetName).ToList();
            var fieldInfos          = dbSetInfo.fieldInfos;

            var pkFields = dbSetInfo.GetPKFields();
            var pkVals   = "";

            foreach (var pkField in pkFields)
            {
                if (!string.IsNullOrEmpty(pkVals))
                {
                    pkVals += ", ";
                }
                pkVals += pkField.fieldName.toCamelCase() + ": " + GetFieldDataType(pkField);
            }
            Dictionary <string, Func <string> > dic = new Dictionary <string, Func <string> >();

            dic.Add("DBSET_NAME", () => dbSetInfo.dbSetName);
            dic.Add("DBSET_TYPE", () => dbSetType);
            dic.Add("ENTITY", () => entityDef);
            dic.Add("ENTITY_TYPE", () => entityTypeName);
            dic.Add("ENTITY_INTERFACE", () => entityInterfaceName);
            dic.Add("DBSET_INFO", () => {
                //we are making copy of the object, in order that we don't change original object
                //while it can be accessed by other threads
                //we change our own copy, making it threadsafe
                var copy         = dbSetInfo.ShallowCopy();
                copy._fieldInfos = new FieldsList(); //serialze with empty field infos
                return(_serializer.Serialize(copy));
            });
            dic.Add("FIELD_INFOS", () => _serializer.Serialize(dbSetInfo.fieldInfos));
            dic.Add("CHILD_ASSOC", () => _serializer.Serialize(childAssoc));
            dic.Add("PARENT_ASSOC", () => _serializer.Serialize(parentAssoc));
            dic.Add("QUERIES", () => createDbSetQueries(dbSetInfo));
            dic.Add("CALC_FIELDS", () => createCalcFields(dbSetInfo));
            dic.Add("PK_VALS", () => pkVals);

            return(_dbSetTemplate.ProcessTemplate(dic));
        }
        protected virtual void TrackChangesToEntity(RowInfo rowInfo)
        {
            DbSetInfo dbSetInfo = rowInfo.GetDbSetInfo();

            if (!dbSetInfo.GetIsTrackChanges())
            {
                return;
            }

            try
            {
                string[] changed = new string[0];
                switch (rowInfo.changeType)
                {
                case ChangeType.Updated:
                {
                    changed = rowInfo.GetChangeState().ChangedFieldNames;
                }
                break;

                default:
                {
                    changed = dbSetInfo.GetNames().Select(f => f.n).ToArray();
                }
                break;
                }

                string[] pknames  = dbSetInfo.GetPKFields().Select(f => f.fieldName).ToArray();
                string   diffgram = DiffGram.GetDiffGram(rowInfo.GetChangeState().OriginalEntity,
                                                         rowInfo.changeType == ChangeType.Deleted ? null : rowInfo.GetChangeState().Entity,
                                                         dbSetInfo.GetEntityType(), changed, pknames, rowInfo.changeType, dbSetInfo.dbSetName);

                OnTrackChange(dbSetInfo.dbSetName, rowInfo.changeType, diffgram);
            }
            catch (Exception ex)
            {
                _OnError(ex);
            }
        }
        public static void Initialize(this DbSetInfo dbSetInfo, IServiceContainer services)
        {
            dbSetInfo._fieldsByNames = new Dictionary <string, Field>();
            var i          = 0;
            var fieldInfos = dbSetInfo.fieldInfos.ToArray();
            var cnt        = fieldInfos.Length;

            for (i = 0; i < cnt; ++i)
            {
                services.DataHelper.ForEachFieldInfo("", fieldInfos[i], (fullName, fieldInfo) =>
                {
                    fieldInfo._FullName = fullName;
                    dbSetInfo._fieldsByNames.Add(fullName, fieldInfo);
                });
            }
            SetOrdinal(fieldInfos);
            var pkFields = dbSetInfo.GetPKFields();

            if (pkFields.Length < 1)
            {
                throw new DomainServiceException(string.Format(ErrorStrings.ERR_DBSET_HAS_NO_PK, dbSetInfo.dbSetName));
            }
            var fbn = dbSetInfo.GetFieldByNames();
        }