Beispiel #1
0
        internal int InsertEmptyObject(SqoTypeInfo tinf)
        {
            int oid = GetNextOID(tinf);

            byte[] oidBuff  = ByteConverter.IntToByteArray(oid);
            long   position = MetaHelper.GetSeekPosition(tinf, oid);

            file.Write(position, oidBuff);
            SaveNrRecords(tinf, tinf.Header.numberOfRecords + 1);
            return(oid);
        }
Beispiel #2
0
        public void SerializeObject(byte[] objectData, int oid, SqoTypeInfo ti, bool insert)
        {
            long position = MetaHelper.GetSeekPosition(ti, oid);

            file.Write(position, objectData);

            if (insert)
            {
                SaveNrRecords(ti, ti.Header.numberOfRecords + 1);
            }
        }
Beispiel #3
0
        public async Task SerializeObjectAsync(byte[] objectData, int oid, SqoTypeInfo ti, bool insert)
        {
            long position = MetaHelper.GetSeekPosition(ti, oid);

            await file.WriteAsync(position, objectData).ConfigureAwait(false);

            if (insert)
            {
                await SaveNrRecordsAsync(ti, ti.Header.numberOfRecords + 1).ConfigureAwait(false);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Updates this instance.
 /// </summary>
 public void Update()
 {
     if (String.IsNullOrEmpty(MetaValueCtrl.Text) && MetaField.AllowNulls)
     {
         MetaHelper.SetMetaFieldValue(base.MDContext, MetaObject, MetaField.Name, new object[] { null });
     }
     else
     {
         MetaHelper.SetMetaFieldValue(base.MDContext, MetaObject, MetaField.Name, new object[] { Boolean.Parse(MetaValueCtrl.Text) });
     }
 }
Beispiel #5
0
 public void Update()
 {
     if (String.IsNullOrEmpty(DicSingleValueCtrl.SelectedValue) && MetaField.AllowNulls)
     {
         MetaHelper.SetMetaFieldValue(MetaField.Context, MetaObject, MetaField.Name, new object[] { null });
     }
     else
     {
         MetaHelper.SetMetaFieldValue(MetaField.Context, MetaObject, MetaField.Name, new object[] { DicSingleValueCtrl.SelectedValue });
     }
 }
Beispiel #6
0
        private Dictionary <FieldSqoInfo, FieldSqoInfo> JoinFieldsSqoInfo(SqoTypeInfo actualTypeinfo, SqoTypeInfo oldTypeinfo)
        {
            Dictionary <FieldSqoInfo, FieldSqoInfo> fields = new Dictionary <FieldSqoInfo, FieldSqoInfo>();

            foreach (FieldSqoInfo fi in actualTypeinfo.Fields)
            {
                FieldSqoInfo oldFi = MetaHelper.FindField(oldTypeinfo.Fields, fi.Name);
                fields[fi] = oldFi;
            }
            return(fields);
        }
Beispiel #7
0
 public IBTree GetIndex(SqoTypeInfo type, string fieldName)
 {
     if (cache.ContainsKey(type))
     {
         FieldSqoInfo fi = MetaHelper.FindField(type.Fields, fieldName);
         if (fi != null)
         {
             return(this.GetIndex(type, fi));
         }
     }
     return(null);
 }
Beispiel #8
0
        public void SaveComplexFieldContent(KeyValuePair <int, int> oid_Tid, FieldSqoInfo fi, SqoTypeInfo ti, int oid)
        {
            byte[] by         = new byte[MetaExtractor.GetAbsoluteSizeOfField(MetaExtractor.complexID)];
            byte[] complexOID = ByteConverter.IntToByteArray(oid_Tid.Key);
            byte[] complexTID = ByteConverter.IntToByteArray(oid_Tid.Value);
            Array.Copy(complexOID, 0, by, 0, complexOID.Length);
            Array.Copy(complexTID, 0, by, 4, complexTID.Length);

            long position = MetaHelper.GetSeekPosition(ti, oid);

            file.Write((long)(position + (long)fi.Header.PositionInRecord), by);
        }
        internal int ReadFirstTID(int oid, FieldSqoInfo fi, SqoTypeInfo ti, RawdataSerializer rawdataSerializer)
        {
            long position     = MetaHelper.GetSeekPosition(ti, oid);
            int  recordLength = ti.Header.lengthOfRecord;

            if (fi == null)
            {
                throw new SiaqodbException("Field not exists in the Type Definition, if you use a Property you have to use UseVariable Attribute");
            }
            byte[] b = new byte[fi.Header.Length];

            file.Read((long)(position + (long)fi.Header.PositionInRecord), b);
            return(rawdataSerializer.ReadComplexArrayFirstTID(b, ti.Header.version, this));
        }
Beispiel #10
0
        public int SerializeObjectWithNewOID(byte[] objectData, SqoTypeInfo ti)
        {
            int oid = GetNextOID(ti);

            byte[] oidBuff = ByteConverter.IntToByteArray(oid);
            Array.Copy(oidBuff, 0, objectData, 0, oidBuff.Length);

            long position = MetaHelper.GetSeekPosition(ti, oid);

            file.Write(position, objectData);

            SaveNrRecords(ti, ti.Header.numberOfRecords + 1);
            return(oid);
        }
        internal async Task <List <KeyValuePair <int, int> > > ReadComplexArrayOidsAsync(int oid, FieldSqoInfo fi, SqoTypeInfo ti, RawdataSerializer rawdataSerializer)
        {
            long position     = MetaHelper.GetSeekPosition(ti, oid);
            int  recordLength = ti.Header.lengthOfRecord;

            if (fi == null)
            {
                throw new SiaqodbException("Field not exists in the Type Definition, if you use a Property you have to use UseVariable Attribute");
            }
            byte[] b = new byte[fi.Header.Length];

            await file.ReadAsync((long)(position + (long)fi.Header.PositionInRecord), b).ConfigureAwait(false);

            return(rawdataSerializer.ReadComplexArrayOids(b, ti.Header.version, this));
        }
Beispiel #12
0
        public async Task <int> SerializeObjectWithNewOIDAsync(byte[] objectData, SqoTypeInfo ti)
        {
            int oid = GetNextOID(ti);

            byte[] oidBuff = ByteConverter.IntToByteArray(oid);
            Array.Copy(oidBuff, 0, objectData, 0, oidBuff.Length);

            long position = MetaHelper.GetSeekPosition(ti, oid);

            await file.WriteAsync(position, objectData).ConfigureAwait(false);

            await SaveNrRecordsAsync(ti, ti.Header.numberOfRecords + 1).ConfigureAwait(false);

            return(oid);
        }
        public async Task <KeyValuePair <int, int> > ReadOIDAndTIDAsync(SqoTypeInfo ti, int oid, FieldSqoInfo fi)
        {
            long position     = MetaHelper.GetSeekPosition(ti, oid);
            int  recordLength = ti.Header.lengthOfRecord;

            if (fi == null)
            {
                throw new SiaqodbException("Field not exists in the Type Definition, if you use a Property you have to use UseVariable Attribute");
            }
            byte[] b = new byte[fi.Header.Length];

            await file.ReadAsync((long)(position + (long)fi.Header.PositionInRecord), b).ConfigureAwait(false);

            return(ReadOIDAndTID(b));
        }
        public async Task PreLoadBytesAsync(int oidStart, int oidEnd, SqoTypeInfo ti)
        {
            this.oidStart = oidStart;
            this.oidEnd   = oidEnd;

            long positionStart = MetaHelper.GetSeekPosition(ti, oidStart);
            long positionEnd   = MetaHelper.GetSeekPosition(ti, oidEnd);

            int recordLength = ti.Header.lengthOfRecord;

            if (preloadedBytes == null || preloadedBytes.Length != (recordLength + (positionEnd - positionStart)))
            {
                preloadedBytes = new byte[recordLength + (positionEnd - positionStart)];
            }
            await file.ReadAsync(positionStart, preloadedBytes).ConfigureAwait(false);
        }
        public void PreLoadBytes(int oidStart, int oidEnd, SqoTypeInfo ti)
        {
            this.oidStart = oidStart;
            this.oidEnd   = oidEnd;

            long positionStart = MetaHelper.GetSeekPosition(ti, oidStart);
            long positionEnd   = MetaHelper.GetSeekPosition(ti, oidEnd);

            int recordLength = ti.Header.lengthOfRecord;

            if (preloadedBytes == null || preloadedBytes.Length != (recordLength + (positionEnd - positionStart)))
            {
                preloadedBytes = new byte[recordLength + (positionEnd - positionStart)];
            }
            file.Read(positionStart, preloadedBytes);
        }
Beispiel #16
0
        /// <summary>
        /// Adds a "grade" field to the search index
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="metaField"></param>
        /// <param name="metaObject"></param>
        private void AddGradeFields(Document doc, MetaField metaField, System.Collections.Hashtable metaObject)
        {
            object val = MetaHelper.GetMetaFieldValue(metaField, metaObject[metaField.Name]);

            string[] grades = parseGradeRange(val.ToString());
            if (grades.Length > 0)
            {
                //Add the smallest grade to the index and make it a number for sorting
                int gradeNumber = parseGradeName(grades[0]) + 1;                  //no negative numbers in the index
                doc.Add(new Field("GradeNumber", ConvertStringToSortable(gradeNumber.ToString()), Field.Store.YES, Field.Index.UN_TOKENIZED));
            }
            foreach (string grade in grades)
            {
                doc.Add(new Field("Grade", grade, Field.Store.YES, Field.Index.UN_TOKENIZED));
            }
        }
Beispiel #17
0
        public static ATuple <int, object> GetPartialObjectInfo(object o, SqoTypeInfo ti, string fieldName, Cache.MetaCache metaCache)
        {
            int oid = metaCache.GetOIDOfObject(o, ti);

            foreach (FieldSqoInfo attKey in ti.Fields)
            {
                if (attKey.Name != fieldName)
                {
                    continue;
                }
#if SILVERLIGHT
                object objVal = null;
                try
                {
                    objVal = MetaHelper.CallGetValue(attKey.FInfo, o, ti.Type);
                }
                catch (Exception ex)
                {
                    throw new SiaqodbException("Override GetValue and SetValue methods of SqoDataObject-Silverlight limitation to private fields");
                }
#else
                object objVal = attKey.FInfo.GetValue(o);
#endif
                if (attKey.FInfo.FieldType == typeof(string))
                {
                    if (objVal == null)
                    {
                        objVal = string.Empty;
                    }
                }
                if (attKey.AttributeTypeId == MetaExtractor.documentID && objVal != null)
                {
                    Sqo.MetaObjects.DocumentInfo dinfo = new Sqo.MetaObjects.DocumentInfo();
                    dinfo.OID      = metaCache.GetDocumentInfoOID(ti, o, attKey.Name);
                    dinfo.TypeName = MetaHelper.GetDiscoveringTypeName(attKey.AttributeType);

                    if (SiaqodbConfigurator.DocumentSerializer == null)
                    {
                        throw new SiaqodbException("Document serializer is not set, use SiaqodbConfigurator.SetDocumentSerializer method to set it");
                    }
                    dinfo.Document = SiaqodbConfigurator.DocumentSerializer.Serialize(objVal);
                    objVal         = dinfo;
                }
                return(new ATuple <int, object>(oid, objVal));
            }
            return(null);
        }
Beispiel #18
0
        internal List <int> DeleteObjectBy(SqoTypeInfo ti, Dictionary <string, object> criteria)
        {
            int       i     = 0;
            ICriteria wPrev = null;

            foreach (string fieldName in criteria.Keys)
            {
                FieldSqoInfo fi = MetaHelper.FindField(ti.Fields, fieldName);
                if (fi == null)
                {
                    throw new SiaqodbException("Field:" + fieldName + " was not found as member of Type:" + ti.TypeName);
                }

                Where w = new Where(fieldName, OperationType.Equal, criteria[fieldName]);
                w.StorageEngine     = this;
                w.ParentSqoTypeInfo = ti;
                w.ParentType.Add(w.ParentSqoTypeInfo.Type);
                if (i > 0)
                {
                    And and = new And();
                    and.Add(w, wPrev);

                    wPrev = and;
                }
                else
                {
                    wPrev = w;
                }
                i++;
            }

            List <int> oids = wPrev.GetOIDs();

            ObjectSerializer serializer = SerializerFactory.GetSerializer(this.path, GetFileByType(ti), useElevatedTrust);

            lock (_syncRoot)
            {
                foreach (int oid in oids)
                {
                    this.MarkObjectAsDelete(serializer, oid, ti);

                    this.indexManager.UpdateIndexesAfterDelete(oid, ti);
                }
            }
            return(oids);
        }
Beispiel #19
0
        /// <summary>
        /// Updates this instance.
        /// </summary>
        public void Update()
        {
            if (DictionaryItemsTable != null)
            {
                MetaStringDictionary dict = new MetaStringDictionary();
                foreach (DataRow row in DictionaryItemsTable.Rows)
                {
                    dict.Add((string)row["Key"], (string)row["Value"]);
                }

                MetaHelper.SetMetaFieldValue(MetaField.Context, MetaObject, MetaField.Name, new object[] { dict });
            }
            else
            {
                MetaHelper.SetMetaFieldValue(MetaField.Context, MetaObject, MetaField.Name, new object[] { null });
            }
        }
        public async Task <int> ReadOidOfComplexAsync(SqoTypeInfo ti, int oid, FieldSqoInfo fi, RawdataSerializer rawSerializer)
        {
            long position     = MetaHelper.GetSeekPosition(ti, oid);
            int  recordLength = ti.Header.lengthOfRecord;

            if (fi == null)
            {
                throw new SiaqodbException("Field not exists in the Type Definition, if you use a Property you have to use UseVariable Attribute");
            }
            byte[] b = new byte[fi.Header.Length];

            await file.ReadAsync((long)(position + (long)fi.Header.PositionInRecord), b).ConfigureAwait(false);

            byte[] oidOfComplexObjBuff = GetFieldBytes(b, 0, 4);
            int    oidOfComplexObj     = ByteConverter.ByteArrayToInt(oidOfComplexObjBuff);

            return(oidOfComplexObj);
        }
Beispiel #21
0
        private void LoadModules()
        {
            string file = this.cbxFiles.SelectedValue;

            file = Path.Combine(Server.MapPath("~/bin/"), file);

            var assembly = Assembly.LoadFile(file);
            var types    = assembly.GetTypes().Where(p => p.IsPublic && this.GetBizCount(p) > 0).ToList();

            var vList = new List <EAS.Explorer.Entities.Module>();

            foreach (var item in types)
            {
                var xList = item.GetMethods().Where(x => Attribute.GetCustomAttribute(x, typeof(ServiceMethodAttribute)) != null)
                            .Select(p => new { Type = item, Method = p, M = Attribute.GetCustomAttribute(p, typeof(ServiceMethodAttribute)) as ServiceMethodAttribute })
                            .Select(p => new EAS.Explorer.Entities.Module
                {
                    Guid        = p.M.Guid.ToUpper(),
                    Name        = p.M.Name,
                    Description = p.M.Description,
                    Type        = MetaHelper.GetTypeString(p.Type),
                    Assembly    = MetaHelper.GetAssemblyString(p.Type),
                    Method      = p.Method.Name,
                    Developer   = MetaHelper.GetDeveloperString(p.Type),
                    Version     = MetaHelper.GetVersionString(p.Type),
                    SortCode    = 0,
                    LMTime      = DateTime.Now
                })
                            .ToList();

                vList.AddRange(xList);
            }

            string sortField     = this.Grid2.SortField;
            string sortDirection = this.Grid2.SortDirection;

            if (!string.IsNullOrEmpty(sortField))
            {
                vList = vList.AsQueryable().DynamicSorting(sortField, sortDirection).ToList();
            }

            this.Grid2.DataSource = vList;
            this.Grid2.DataBind();
        }
Beispiel #22
0
        public void Update()
        {
            // Add new values if any
            if (DictionaryItemsTable != null)
            {
                foreach (DataRow row in DictionaryItemsTable.Rows)
                {
                    if ((int)row["Id"] == -1)
                    {
                        int id = MetaField.Dictionary.Add((string)row["Value"]);
                        row["Id"] = id;
                        foreach (ListItem item in MetaMultiValueCtrl.Items)
                        {
                            if (Int32.Parse(item.Value) == -1 && String.Compare((string)row["Value"], item.Text) == 0)
                            {
                                item.Value = id.ToString();
                            }
                        }
                    }
                }
            }

            //// Add new values if any
            //foreach(ListItem item in MetaMultiValueCtrl.Items)
            //{
            //    if(item.Value.Length == 0)
            //        MetaField.DictionaryAdd(item.Text);
            //}

            // Save selected values
            ArrayList selected = new ArrayList();

            foreach (ListItem item in MetaMultiValueCtrl.Items)
            {
                if (item.Selected)
                {
                    selected.Add(item.Value);
                }
            }

            MetaHelper.SetMetaFieldValue(MetaField.Context, MetaObject, MetaField.Name, (string[])selected.ToArray(typeof(string)));

            //MetaField.Value = (string[])selected.ToArray(typeof(string));
        }
        internal void ReadObjectRow(Sqo.Utilities.ObjectRow row, SqoTypeInfo ti, int oid, RawdataSerializer rawSerializer)
        {
            lock (file)
            {
                // long position = (long)ti.Header.headerSize + (long)((long)(oid - 1) * (long)ti.Header.lengthOfRecord);
                long   position     = MetaHelper.GetSeekPosition(ti, oid);
                int    recordLength = ti.Header.lengthOfRecord;
                byte[] b            = new byte[recordLength];
                if (oidStart == 0 && oidEnd == 0)
                {
                    file.Read(position, b);
                }
                else
                {
                    int recordPosition = (oid - oidStart) * recordLength;
                    Array.Copy(preloadedBytes, recordPosition, b, 0, b.Length);
                }
                int    fieldPosition = 0;
                byte[] oidBuff       = GetFieldBytes(b, fieldPosition, 4);
                int    oidFromFile   = ByteConverter.ByteArrayToInt(oidBuff);

                foreach (FieldSqoInfo ai in ti.Fields)
                {
                    byte[] field = GetFieldBytes(b, ai.Header.PositionInRecord, ai.Header.Length);
                    if (typeof(IList).IsAssignableFrom(ai.AttributeType) || ai.IsText || ai.AttributeTypeId == MetaExtractor.complexID || ai.AttributeTypeId == MetaExtractor.dictionaryID || ai.AttributeTypeId == MetaExtractor.documentID)
                    {
                        row[ai.Name] = field;
                    }
                    else
                    {
                        try
                        {
                            row[ai.Name] = ByteConverter.DeserializeValueType(ai.AttributeType, field, true, ti.Header.version);
                        }
                        catch (Exception ex)
                        {
                            //SiaqodbConfigurator.LogMessage("Field's" + ai.Name + " value of Type " + ti.TypeName + "cannot be loaded,will be set to default.", VerboseLevel.Info);
                            //row[ai.Name] = MetaHelper.GetDefault(ai.AttributeType);
                            throw ex;
                        }
                    }
                }
            }
        }
Beispiel #24
0
        public static void FindAddIndexes(SqoTypeInfo ti, FieldSqoInfo fi)
        {
            bool found = false;

            if (fi.FInfo != null)
            {
                if (typeof(IList).IsAssignableFrom(fi.FInfo.FieldType))//ignore
                {
                    return;
                }
                object[] customAttStr = fi.FInfo.GetCustomAttributes(typeof(IndexAttribute), false);
                if (customAttStr.Length > 0)
                {
                    ti.IndexedFields.Add(fi);
                    found = true;
                }
                else
                {
                    PropertyInfo pi = MetaHelper.GetAutomaticProperty(fi.FInfo);
                    if (pi != null)
                    {
                        customAttStr = pi.GetCustomAttributes(typeof(IndexAttribute), false);
                        if (customAttStr.Length > 0)
                        {
                            ti.IndexedFields.Add(fi);
                            found = true;
                        }
                    }
                }
                if (!found)//look in configuration
                {
                    if (SiaqodbConfigurator.Indexes != null)
                    {
                        if (SiaqodbConfigurator.Indexes.ContainsKey(ti.Type))
                        {
                            if (SiaqodbConfigurator.Indexes[ti.Type].Contains(fi.Name))
                            {
                                ti.IndexedFields.Add(fi);
                            }
                        }
                    }
                }
            }
        }
Beispiel #25
0
        public IDbConnection BuildConnection(string driver, string connectionString)
        {
            IDbConnection conn = null;

            switch (driver.ToUpper())
            {
            case MyMetaDrivers.MySql2:
                conn = new MySqlConnection(connectionString);
                break;

            case MyMetaDrivers.PostgreSQL:
            case MyMetaDrivers.PostgreSQL8:
                conn = new NpgsqlConnection(connectionString);
                break;

            case MyMetaDrivers.Firebird:
            case MyMetaDrivers.Interbase:
                conn = new FbConnection(connectionString);
                break;

            case MyMetaDrivers.SQLite:
                conn = new SQLiteConnection(connectionString);
                break;

#if !IGNORE_VISTA
            case MyMetaDrivers.VistaDB:
                try
                {
                    var mh = new MetaHelper();
                    conn = mh.GetConnection(connectionString);
                }
                catch
                {
                    throw new Exception("Invalid VistaDB connection or VistaDB not installed");
                }
                break;
#endif
            default:
                break;
            }
            return(conn);
        }
Beispiel #26
0
        public static void FindFields(ICollection <FieldInfo> fields, Dictionary <FieldInfo, PropertyInfo> automaticProperties, Type t)
        {
            var flags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static;

            foreach (var field in t.GetFields(flags))
            {
                // Ignore inherited fields + OID
                if (field.DeclaringType == t && field.Name != "oid" && field.Name != "<OID>k__BackingField")
                {
                    //get automatic properties
                    PropertyInfo pi = MetaHelper.GetAutomaticProperty(field);
                    if (pi != null)
                    {
                        bool found = false;
                        foreach (FieldInfo fiAuto in automaticProperties.Keys)
                        {
                            if (fiAuto.Name == field.Name)
                            {
                                found = true;
                                break;
                            }
                        }
                        if (found)
                        {
                            continue;
                        }
                        automaticProperties[field] = pi;
                    }
                    fields.Add(field);
                }
            }

#if WinRT
            var baseType = t.GetBaseType();
#else
            var baseType = t.BaseType;
#endif
            if (baseType != null)
            {
                FindFields(fields, automaticProperties, baseType);
            }
        }
Beispiel #27
0
        private async Task <IBTree> RenewIndexAsync(SqoTypeInfo ti, string fieldName)
        {
            FieldSqoInfo finfo     = MetaHelper.FindField(ti.Fields, fieldName);
            IndexInfo2   indexInfo = null;

            if (finfo != null)
            {
                string             indexName = finfo.Name + ti.TypeName;
                IList <IndexInfo2> stIndexes = await this.GetStoredIndexesAsync().ConfigureAwait(false);

                foreach (IndexInfo2 ii in stIndexes)
                {
                    if (indexName.StartsWith(ii.IndexName) || ii.IndexName.StartsWith(indexName))
                    {
                        indexInfo = ii;
                        break;
                    }
                }

                if (indexInfo != null)
                {
                    if (storedIndexes != null && storedIndexes.Contains(indexInfo))
                    {
                        storedIndexes.Remove(indexInfo);
                    }
                    await siaqodb.DeleteAsync(indexInfo);
                }
                Type            t     = typeof(BTree <>).MakeGenericType(finfo.AttributeType);
                ConstructorInfo ctor  = t.GetConstructor(new Type[] { typeof(Siaqodb) });
                IBTree          index = (IBTree)ctor.Invoke(new object[] { this.siaqodb });
                indexInfo = await this.BuildIndexAsync(finfo, ti, index);

                index.SetIndexInfo(indexInfo);
                await index.PersistAsync();

                cacheIndexes.Set(ti, finfo, index);

                return(index);
            }
            return(null);
        }
Beispiel #28
0
        public static void FindAddConstraints(SqoTypeInfo ti, FieldSqoInfo fi)
        {
            bool found = false;

            if (fi.FInfo != null)//if is null can be from OLD schema version and now field is missing
            {
                object[] customAttStr = fi.FInfo.GetCustomAttributes(typeof(UniqueConstraint), false);
                if (customAttStr.Length > 0)
                {
                    ti.UniqueFields.Add(fi);
                    found = true;
                }
                else
                {
                    PropertyInfo pi = MetaHelper.GetAutomaticProperty(fi.FInfo);
                    if (pi != null)
                    {
                        customAttStr = pi.GetCustomAttributes(typeof(UniqueConstraint), false);
                        if (customAttStr.Length > 0)
                        {
                            ti.UniqueFields.Add(fi);
                            found = true;
                        }
                    }
                }
                if (!found)//look in configuration
                {
                    if (SiaqodbConfigurator.Constraints != null)
                    {
                        if (SiaqodbConfigurator.Constraints.ContainsKey(ti.Type))
                        {
                            if (SiaqodbConfigurator.Constraints[ti.Type].Contains(fi.Name))
                            {
                                ti.UniqueFields.Add(fi);
                            }
                        }
                    }
                }
            }
        }
Beispiel #29
0
        private async Task CheckForConcurencyAsync(object oi, ObjectInfo objInfo, SqoTypeInfo ti, ObjectSerializer serializer, bool updateTickCountInDB)
        {
            if (SiaqodbConfigurator.OptimisticConcurrencyEnabled)
            {
                FieldSqoInfo fi = MetaHelper.FindField(ti.Fields, "tickCount");
                if (fi != null)
                {
                    if (fi.AttributeType == typeof(ulong))
                    {
                        ulong tickCount = 0;

                        if (objInfo.Oid > 0 && objInfo.Oid <= ti.Header.numberOfRecords) //update or delete
                        {
                            tickCount = (ulong)(await serializer.ReadFieldValueAsync(ti, objInfo.Oid, fi).ConfigureAwait(false));
                            if (objInfo.TickCount != 0)
                            {
                                if (tickCount != objInfo.TickCount)
                                {
                                    throw new OptimisticConcurrencyException("Another version of object with OID=" + objInfo.Oid.ToString() + " of Type:" + ti.TypeName + " is saved in database, refresh your object before save!");
                                }
                            }
                        }
                        tickCount          = tickCount + 1L;
                        objInfo.AtInfo[fi] = tickCount;
#if SILVERLIGHT
                        MetaHelper.CallSetValue(fi.FInfo, tickCount, oi, ti.Type);
#else
                        fi.FInfo.SetValue(oi, tickCount);
#endif

                        if (updateTickCountInDB)
                        {
                            await serializer.SaveFieldValueAsync(objInfo.Oid, "tickCount", ti, tickCount, this.rawSerializer).ConfigureAwait(false);
                        }
                    }
                }
            }
        }
        internal async Task <ATuple <int, int> > GetArrayMetaOfFieldAsync(SqoTypeInfo ti, int oid, FieldSqoInfo fi)
        {
            long position     = MetaHelper.GetSeekPosition(ti, oid);
            int  recordLength = ti.Header.lengthOfRecord;

            if (fi == null)
            {
                throw new SiaqodbException("Field not exists in the Type Definition, if you use a Property you have to use UseVariable Attribute");
            }
            byte[] bytes = new byte[fi.Header.Length];

            await file.ReadAsync((long)(position + (long)fi.Header.PositionInRecord), bytes).ConfigureAwait(false);

            byte[] oidBytes = new byte[4];
            Array.Copy(bytes, 1, oidBytes, 0, 4);
            int rawInfoOID = (int)ByteConverter.DeserializeValueType(typeof(int), oidBytes, ti.Header.version);

            byte[] nrElemeBytes = new byte[4];
            Array.Copy(bytes, MetaExtractor.ExtraSizeForArray - 4, nrElemeBytes, 0, 4);
            int nrElem = (int)ByteConverter.DeserializeValueType(typeof(int), nrElemeBytes, ti.Header.version);

            return(new ATuple <int, int>(rawInfoOID, nrElem));
        }