Exemplo n.º 1
0
        public object CreateManager <TRecord, TKeyCollection>(Path path = null, string ownerName = null, OpenMode?openMode = null, int recycleCount = 1000, int temporaryBufferId = 0)
            where TRecord : Record <TRecord>
            where TKeyCollection : KeyCollection <TRecord>, new()
        {
            if (path == null)
            {
                var recordInfo = Resource.GetRecordInfo(typeof(TRecord));
                if (recordInfo.PathType == PathType.Relative &&
                    this.DefaultRelativeDirectory != null)
                {
                    path = Path.Relative(relativeDirectory: this.DefaultRelativeDirectory);
                }
                else if (recordInfo.PathType == PathType.Uri &&
                         (this.DefaultUriHost != null || this.DefaultUriUser != null || this.DefaultUriDbName != null || this.DefaultUriPassword != null || this.DefaultUriPrompt != null))
                {
                    path = Path.Uri(
                        uriHost: this.DefaultUriHost,
                        uriUser: this.DefaultUriUser,
                        uriDbName: this.DefaultUriDbName,
                        uriPassword: this.DefaultUriPassword,
                        uriPrompt: this.DefaultUriPrompt);
                }
            }
            var temporaryBuffer = _temporaryBufferDictionary.ContainsKey(temporaryBufferId) ? _temporaryBufferDictionary[temporaryBufferId] : Resource.GetBuffer();
            var result          = new RecordManager <TRecord, TKeyCollection>(this.Operator, path, ownerName, openMode, recycleCount, temporaryBuffer);

            this.AddTransactionalObject(result);
            return(result);
        }
Exemplo n.º 2
0
        public RecordOperator(NativeOperator nativeOperator, Path path, string ownerName, OpenMode?openMode, int reusableCapacity, byte[] temporaryBuffer = null)
        {
            var recordType        = typeof(TRecord);
            var recordConstructor = recordType.GetConstructor(new Type[] { typeof(byte[]) });

            if (recordConstructor == null)
            {
                throw new InvalidDefinitionException();
            }
            _recordConstructor = Resource.GetRecordConstructor(typeof(TRecord));
            this.RecordInfo    = Resource.GetRecordInfo(recordType);
            if (temporaryBuffer != null && temporaryBuffer.Length < this.RecordInfo.DataBufferCapacity)
            {
                throw new ArgumentException();
            }
            this.PrimaryKeyNumber  = this.RecordInfo.PrimaryKeyNumber;
            _nativeOperator        = nativeOperator;
            this.IsClosable        = true;
            this.HasVariableFields = this.RecordInfo.VariableOption != RecordVariableOption.NotVariable && this.RecordInfo.VariableRangeFields.Count() != 0;
            this.Path            = Path.Merge(path, this.RecordInfo);
            this.OwnerName       = ownerName;
            this.OpenMode        = openMode;
            this.TemporaryBuffer = temporaryBuffer ?? new byte[ushort.MaxValue];
            _reusableCapacity    = reusableCapacity;
            _reusableRecords     = new Queue <TRecord>(_reusableCapacity);
        }
Exemplo n.º 3
0
 protected Record(byte[] dataBuffer)
 {
     if (dataBuffer == null)
     {
         throw new ArgumentNullException();
     }
     _info = Resource.GetRecordInfo(typeof(TRecord));
     if (dataBuffer.Length != _info.DataBufferCapacity)
     {
         throw new ArgumentException();
     }
     this.DataBuffer         = dataBuffer;
     this.RecordState        = RecordState.Detached;
     this.RollbackedState    = RecordState.Detached;
     this.IsManagedMember    = false;
     this.IsRollbackedMember = false;
 }
Exemplo n.º 4
0
 protected Record()
 {
     _info           = Resource.GetRecordInfo(typeof(TRecord));
     this.DataBuffer = new byte[_info.DataBufferCapacity];
     if (_info.DefaultByte != default(byte))
     {
         for (var i = 0; i < this.DataBuffer.Length; i++)
         {
             this.DataBuffer[i] = _info.DefaultByte;
         }
     }
     foreach (var fieldInfo in _info.Fields)
     {
         fieldInfo.SetDefaultValue(
             this.DataBuffer,
             fieldInfo.Position,
             fieldInfo.Length,
             fieldInfo.Parameter);
     }
     this.RecordState        = RecordState.Detached;
     this.RollbackedState    = RecordState.Detached;
     this.IsManagedMember    = false;
     this.IsRollbackedMember = false;
 }
Exemplo n.º 5
0
 public KeyCollection(Type recordType)
 {
     _keys = Resource.GetRecordInfo(recordType).Keys.ToArray();
 }
Exemplo n.º 6
0
 public RecordOperator(string applicationId, ushort threadId, Path path = null, string ownerName = null, OpenMode?openMode = null, string dllPath = null, IEnumerable <string> dependencyPaths = null, int reusableCapacity = 1000, byte[] temporaryBuffer = null)
     : this(new NativeOperator(true, dllPath ?? Resource.GetRecordInfo(typeof(TRecord)).DllPath, dependencyPaths ?? Resource.GetRecordInfo(typeof(TRecord)).DependencyPaths), path, ownerName, openMode, reusableCapacity, temporaryBuffer)
 {
     _nativeOperator.ClientId.ApplicationId = applicationId;
     _nativeOperator.ClientId.ThreadId      = threadId;
 }
Exemplo n.º 7
0
 public RecordOperator(Path path = null, string ownerName = null, OpenMode?openMode = null, string dllPath = null, IEnumerable <string> dependencyPaths = null, int reusableCapacity = 1000, byte[] temporaryBuffer = null)
     : this(new NativeOperator(false, dllPath ?? Resource.GetRecordInfo(typeof(TRecord)).DllPath, dependencyPaths ?? Resource.GetRecordInfo(typeof(TRecord)).DependencyPaths), path, ownerName, openMode, reusableCapacity, temporaryBuffer)
 {
 }
Exemplo n.º 8
0
        KeyInfo GetKey()
        {
            if (this.ApiFilter != null)
            {
                var keys = Resource.GetRecordInfo(typeof(TRecord)).Keys;
                var maxKeySegmentCount = keys.Max(k => k.Segments.Count);

                IEnumerable <KeyInfo> enabledKeys = keys, remainedKeys = new KeyInfo[0];
                var enabledKeyList = new List <KeyInfo>();
                var priorityList = new List <uint>();

                var fields = this.ApiFilter
                             .SelectMany(filter => filter.GetFields().Select(field => new {
                    State = filter.State,
                    Field = field
                }))
                             .GroupBy(f => f.Field)
                             .Select(g => new {
                    Field    = g.Key,
                    Priority = GetPriority(g.Select(f => f.State))
                });

                for (var i = 0; i < maxKeySegmentCount; i++)
                {
                    uint priority = 0;
                    foreach (var key in enabledKeys)
                    {
                        var field = fields.SingleOrDefault(f => f.Field == key.Segments[i].Field);
                        if (field != null)
                        {
                            if (field.Priority == priority)
                            {
                                enabledKeyList.Add(key);
                            }
                            else if (field.Priority > priority)
                            {
                                priority = field.Priority;
                                enabledKeyList.Clear();
                                enabledKeyList.Add(key);
                            }
                        }
                    }
                    if (enabledKeyList.Count == 0)
                    {
                        if (remainedKeys.Count() == 0)
                        {
                            remainedKeys = enabledKeys.Where(k => i == k.Segments.Count - 1).ToArray();
                        }
                        enabledKeys = enabledKeys.Where(k => i != k.Segments.Count - 1).ToArray();
                    }
                    else if (enabledKeyList.Count == 1)
                    {
                        return(enabledKeyList[0]);
                    }
                    else if (enabledKeyList.Count > 1)
                    {
                        enabledKeys  = enabledKeyList.Where(k => i != k.Segments.Count - 1).ToArray();
                        remainedKeys = enabledKeyList.Where(k => i == k.Segments.Count - 1).ToArray();
                    }
                    enabledKeyList.Clear();
                    priorityList.Add(priority);
                }
                if (priorityList.Any(p => p != 0))
                {
                    return(remainedKeys.FirstOrDefault() ?? enabledKeys.FirstOrDefault());
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }