コード例 #1
0
 /// <summary>
 /// Move para o próximo nome de tipo que será processado.
 /// </summary>
 /// <returns></returns>
 private bool MoveNextTypeMetadata()
 {
     while (_typeMetadatasEnumerator != null && _typeMetadatasEnumerator.MoveNext())
     {
         var typeMetadata = _typeMetadatasEnumerator.Current;
         _loader.Observer.OnStageChanged(new CacheLoaderStage("LoadingType", ResourceMessageFormatter.Create(() => Properties.Resources.CacheLoader_LoadingTypeName, typeMetadata.FullName)));
         _loader.Observer.OnCurrentProgressChanged(new System.ComponentModel.ProgressChangedEventArgs((_position++ *100 / _typeMetadatasCount), null));
         if (_loader.Observer is IDataCacheLoaderObserver)
         {
             ((IDataCacheLoaderObserver)_loader.Observer).OnBeginLoadTypeMetadata(typeMetadata);
         }
         var typeName = new Colosoft.Reflection.TypeName(!string.IsNullOrEmpty(typeMetadata.Assembly) ? string.Format("{0}, {1}", typeMetadata.FullName, typeMetadata.Assembly) : typeMetadata.FullName);
         Query.IQueryResult result = null;
         try
         {
             var columns = new List <Query.ProjectionEntry>(typeMetadata.Select(f => new Query.ProjectionEntry(f.Name, null)));
             if (typeMetadata.IsVersioned && !columns.Exists(f => {
                 var column = f.GetColumnInfo();
                 return(column != null && StringComparer.InvariantCultureIgnoreCase.Equals(column.Name, "RowVersion"));
             }))
             {
                 columns.Add(new ProjectionEntry("RowVersion", null));
             }
             result            = _loader.SourceContext.CreateQuery().From(new Query.EntityInfo(typeMetadata.FullName)).Select(new Query.Projection(columns)).NoUseCache().Execute();
             _recordEnumerator = result.GetEnumerator();
         }
         catch (Exception ex)
         {
             var args = new CacheLoaderErrorEventArgs(ResourceMessageFormatter.Create(() => Properties.Resources.DataCacheLoader_CreateQueryError, typeMetadata.FullName), ex);
             _loader.OnLoadError(typeName, args);
             if (_loader.Observer is IDataCacheLoaderObserver)
             {
                 ((IDataCacheLoaderObserver)_loader.Observer).OnEndLoadTypeMetadata(typeMetadata, ex);
             }
             continue;
         }
         _currentTypeName  = typeName;
         _currentGenerator = _loader.RecordKeyFactory.CreateGenerator(_currentTypeName);
         return(true);
     }
     _currentTypeName  = null;
     _currentGenerator = null;
     if (_recordEnumerator != null)
     {
         try
         {
             _recordEnumerator.Dispose();
         }
         catch
         {
         }
     }
     _recordEnumerator = null;
     return(false);
 }
コード例 #2
0
ファイル: DataEntry.cs プロジェクト: fabrimaciel/colosoft
        /// <summary>
        /// Serializa os dados da instancia.
        /// </summary>
        /// <param name="writer"></param>
        void Colosoft.Serialization.ICompactSerializable.Serialize(Serialization.IO.CompactWriter writer)
        {
            if (_typeName == null)
            {
                writer.Write((byte)0);
            }
            else
            {
                writer.Write((byte)1);
                _typeName.Serialize(writer);
            }
            writer.Write(_version);
            var serializable = _result as Colosoft.Serialization.ICompactSerializable;

            if (serializable == null && _result != null)
            {
                var recordEnumerator = _result.GetEnumerator();
                if (recordEnumerator.MoveNext())
                {
                    var record = recordEnumerator.Current;
                    if (serializable == null)
                    {
                        serializable = new Colosoft.Query.QueryResult(record.Descriptor, new Colosoft.Query.Record[] {
                            record
                        }.Concat(GetRecords(recordEnumerator)));
                    }
                }
            }
            if (serializable != null)
            {
                writer.Write((byte)1);
                serializable.Serialize(writer);
            }
            else
            {
                writer.Write((byte)0);
            }
        }