예제 #1
0
 public IndexAddTask(QueryIndexManager indexManager, object key, CacheEntry value, OperationContext operationContext)
 {
     _key = key;
     _entry = value;
     _indexManager = indexManager;
     _operationContext = operationContext;
 }
예제 #2
0
        public void Intercept(IInvocation invocation)
        {
            var cacheKey = string.Format("{0}||{1}", invocation.Method.Name, invocation.Method.DeclaringType.Name);

            if (_cache.ContainsKey(cacheKey))
            {
                var entry = _cache[cacheKey];
                if (DateTime.Now < entry.Expiry)
                {
                    invocation.ReturnValue = entry.ReturnValue;
                    return;
                }
            }

            invocation.Proceed();
         
            // Can we cache this entry?
            if (invocation.MethodInvocationTarget.GetCustomAttributes(typeof (CacheAttribute), true).Length == 0) 
                return;
            
            var newEntry = new CacheEntry()
                               {
                                   Expiry = DateTime.Now.AddSeconds(5), 
                                   ReturnValue = invocation.ReturnValue
                               };
            _cache[cacheKey] = newEntry;
        }
예제 #3
0
        public static async Task<long?> GetPrimePlatSellOrders(string primeName)
        {
            CacheEntry<long?> cacheItem;
            if (_marketCache.TryGetValue(primeName, out cacheItem))
            {
                if (!cacheItem.IsExpired(_expirationTimespan))
                {
                    return cacheItem.Value;
                }
            }

            var textInfo = new CultureInfo("en-US", false).TextInfo;

            var partName = textInfo.ToTitleCase(primeName.ToLower());

            if (_removeBPSuffixPhrases.Any(suffix => partName.EndsWith(suffix + " Blueprint")))
            {
                partName = partName.Replace(" Blueprint", "");
            }

            // Since Warframe.Market is still using the term Helmet instead of the new one, TODO: this might change
            partName = partName.Replace("Neuroptics", "Helmet");

            if (_fixedQueryStrings.ContainsKey(partName))
            {
                //Some of Warframe.Market's query strings are mangled (extra spaces, misspellings, words missing) fix them manually...
                partName = _fixedQueryStrings[partName];
            }

            string jsonData;
            using (var client = new WebClient())
            {
                var uri = new Uri(_baseUrl + Uri.EscapeDataString(partName));

                try
                {
                    jsonData = await client.DownloadStringTaskAsync(uri);

                    dynamic result = JsonConvert.DeserializeObject(jsonData);

                    // when the server responds anything that is not 200 (HTTP OK) don't bother doing something else
                    if (result.code != 200)
                    {
                        Debug.WriteLine($"Error with {partName}, Status Code: {result.code.Value}");
                        _marketCache[primeName] = new CacheEntry<long?>(null);
                        return null;
                    }

                    IEnumerable<dynamic> sellOrders = result.response.sell;
                    long? smallestPrice = sellOrders.Where(order => order.online_status).Min(order => order.price);

                    _marketCache[primeName] = new CacheEntry<long?>(smallestPrice);
                    return smallestPrice;
                }
                catch
                {
                    return null;
                }
            }            
        }
예제 #4
0
		public bool Insert(Segment seg)
		{
			Debug.Assert(Exists(seg.SegmentID) == false);

			int pos = (int)(seg.SegmentID % m_size);

			CacheEntry head = m_data[pos];

			if (head == null)
				m_data[pos] = new CacheEntry(seg);
			else
			{
				while (head.Next != null &&head.Segment.SegmentID != seg.SegmentID)
				{
					head = head.Next;
				}
				if (head.Segment.SegmentID == seg.SegmentID)
					return false;
				else
				{
					head.Next = new CacheEntry(seg,null);
				}
			}

			m_count ++;
			return true;
		}
예제 #5
0
        private CacheEntry CreateCacheEntry(Type type)
        {
            var encoderType = typeof(IFrameEncoder<>).MakeGenericType(type);

            // Func<object, Stream, object, Task> callback = (encoder, body, value) =>
            // { 
            //   return ((IStreamEncoder<T>)encoder).Encode(body, (T)value);
            // }

            var encoderParam = Expression.Parameter(typeof(object), "encoder");
            var bodyParam = Expression.Parameter(typeof(Stream), "body");
            var valueParam = Expression.Parameter(typeof(object), "value");

            var encoderCast = Expression.Convert(encoderParam, encoderType);
            var valueCast = Expression.Convert(valueParam, type);
            var encode = encoderType.GetMethod("Encode", BindingFlags.Public | BindingFlags.Instance);
            var encodeCall = Expression.Call(encoderCast, encode, bodyParam, valueCast);
            var lambda = Expression.Lambda<Func<object, Stream, object, Task>>(encodeCall, encoderParam, bodyParam, valueParam);

            var entry = new CacheEntry
            {
                Encode = lambda.Compile(),
                Encoder = _serviceProvider.GetRequiredService(encoderType)
            };

            return entry;
        }
예제 #6
0
        public CacheEntry Lookup(string fullname)
        {
            string[] names = fullname.Split('\\');

            CacheEntry current = this;
            CacheEntry child = null;
            foreach (string entry in names)
            {
                if (current.Children == null)
                    current.Children = new Dictionary<string, CacheEntry>();

                if (current.Children.TryGetValue(entry, out child))
                {
                    current = child;
                }
                else
                {
                    CacheEntry cache = new CacheEntry(entry);
                    current.Children[entry] = cache;
                    cache.Parent = current;
                    current = cache;
                }
            }

            return current;
        }
예제 #7
0
		public void Id_ShouldReturnCorrectValue(
			[Frozen]Guid id,
			CacheEntry<object> sut)
		{
			//assert
			sut.Id.Should().Be(id);
		}
예제 #8
0
        /// <summary>
        /// Returns a Matrix with the data for the TimeStep, Item
        /// TimeStep counts from 0, Item from 1.
        /// Lower left in Matrix is (0,0)
        /// </summary>
        /// <param name="TimeStep"></param>
        /// <param name="Item"></param>
        /// <param name="Layer"></param>
        /// <returns></returns>
        public Matrix GetData(int TimeStep, int Item)
        {
            CacheEntry cen;

              Dictionary<int, CacheEntry> _timeValues;

              if (!_bufferData.TryGetValue(Item, out _timeValues))
              {
            _timeValues = new Dictionary<int, CacheEntry>();
            _bufferData.Add(Item, _timeValues);
              }
              if (!_timeValues.TryGetValue(TimeStep, out cen))
              {
            ReadItemTimeStep(TimeStep, Item);
            Matrix _data = new Matrix(_numberOfRows, _numberOfColumns);
            int m = 0;
            for (int i = 0; i < _numberOfRows; i++)
              for (int j = 0; j < _numberOfColumns; j++)
              {
            _data[i, j] = dfsdata[m];
            m++;
              }
            cen = new CacheEntry(AbsoluteFileName, Item, TimeStep, _data);
            _timeValues.Add(TimeStep, cen);
            CheckBuffer();
              }
              else
            AccessList.Remove(cen);
              AccessList.AddLast(cen);
              return cen.Data;
        }
            public static void Cache(DiagnosticAnalyzer analyzer, object key, CacheEntry entry)
            {
                AssertKey(key);

                // add new cache entry
                var analyzerMap = s_map.GetOrAdd(analyzer, _ => new ConcurrentDictionary<object, CacheEntry>(concurrencyLevel: 2, capacity: 10));
                analyzerMap[key] = entry;
            }
예제 #10
0
 public async Task AddEntryAsync(CacheEntry entry, HttpResponseMessage response)
 {
     CacheEntryContainer cacheEntryContainer = GetOrCreateContainer(entry.Key);
     lock (syncRoot)
     {
         cacheEntryContainer.Entries.Add(entry);
         _responseCache[entry.VariantId] = response;
     }
 }
예제 #11
0
        public void Sanity()
        {
            var ceStr = new CacheEntry<string>(1, "3");

            Assert.AreEqual(DateTime.MinValue, ceStr.LastAccessed);
            Assert.AreEqual(1, ceStr.Key);
            Assert.AreEqual("3", ceStr.Val);
            Assert.IsTrue(ceStr.LastAccessed.AddMinutes(1) > DateTime.Now);
        }
 public async Task<CacheContent> GetContentAsync(CacheEntry cacheEntry, string secondaryKey)
 {
     var inMemoryCacheEntry = _responseCache[cacheEntry.Key];
     if (inMemoryCacheEntry.Responses.ContainsKey(secondaryKey))
     {
         return await CloneAsync(inMemoryCacheEntry.Responses[secondaryKey]);
     }
     return null;
 }
예제 #13
0
        public static object GetInstanceOf(Type providerType, object[] providerArgs)
        {
            CacheEntry entry = new CacheEntry(providerType, providerArgs);

            object instance = instances[entry];
            return instance == null
                ? instances[entry] = Reflect.Construct(providerType, providerArgs)
                : instance;
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="listener"></param>
 /// <param name="data"></param>
 public AsyncBroadcastCustomNotifyRemoval(ClusterCacheBase parent, object key, CacheEntry entry, ItemRemoveReason reason, OperationContext operationContext, EventContext eventContext)
 {
     _parent = parent;
     _key = key;
     _entry = entry;
     _reason = reason;
     _operationContext = operationContext;
     _eventContext = eventContext;
 }
예제 #15
0
 public static CacheEntry Create(object rawValue, DateTime createdAt, object options = null)
 {
     var opts = options.AsDictionary();
     var entry = new CacheEntry(null);
     entry.Value = rawValue;
     entry.CreatedAt = createdAt;
     entry.Compressed = opts["compressed"].AsBoolean();
     return entry;
 }
예제 #16
0
        private void addToCache(string fileName, CacheEntry entry)
        {
            _cache[fileName] = entry;
            calculateTotalSize();

            while (_totalBytes > _maxBytes)
            {
                deleteOldest();
            }
        }
예제 #17
0
 public static CacheQueryResult ReturnStored(CacheEntry cacheEntry, HttpResponseMessage response)
 {
     HttpCache.UpdateAgeHeader(response);
     return new CacheQueryResult()
     {
         Status = CacheStatus.ReturnStored,
         SelectedEntry = cacheEntry,
         SelectedResponse = response
     };
 }
예제 #18
0
파일: Cache.cs 프로젝트: elanwu123/dnx
 private void PropagateCacheDependencies(CacheEntry entry)
 {
     // Bubble up volatile tokens to parent context
     if (_accessor.Current != null)
     {
         foreach (var dependency in entry.Dependencies)
         {
             _accessor.Current.Monitor(dependency);
         }
     }
 }
예제 #19
0
        public void TestHashCode()
        {
            var entry1 = new CacheEntry<int, int>(1, 2);
            var entry2 = new CacheEntry<int, int>(1, 2);
            var entry3 = new CacheEntry<int, int>(1, 3);

            var set = new HashSet<object> {entry1};

            Assert.IsTrue(set.Contains(entry1));
            Assert.IsTrue(set.Contains(entry2));
            Assert.IsFalse(set.Contains(entry3));
        }
예제 #20
0
 public virtual void AddToCache(string commandText, object resultSet)
 {
     CleanCache();
     CacheEntry entry = new CacheEntry();
     entry.CacheTime = DateTime.Now;
     entry.CacheElement = resultSet;
     lock (cache)
     {
         if (cache.ContainsKey(commandText)) return;
         cache.Add(commandText, entry);
     }
 }
		public void Reload (CacheEntry entry, object data, int width, int height)
		{
			lock (items) {
				lock (entry) {
					entry.Reload = true;
					entry.Width = width;
					entry.Height = height;
					entry.Data = data;
				}
				Monitor.Pulse (items);
			}
		}
예제 #22
0
        public async Task UpdateEntryAsync(CacheEntry entry, HttpResponseMessage response)
        {

            CacheEntryContainer cacheEntryContainer = GetOrCreateContainer(entry.Key);
            
            lock (syncRoot)
            {
                var oldentry = cacheEntryContainer.Entries.First(e => e.VariantId == entry.VariantId);
                cacheEntryContainer.Entries.Remove(oldentry);
                cacheEntryContainer.Entries.Add(entry);
                _responseCache[entry.VariantId] = response;
            }
        }
예제 #23
0
		public void Value_ShouldReturnCorrectValue(
			Guid id,
			string cacheKey,
			Dictionary<string, string> attributes,
			object value,
			DateTimeOffset date)
		{
			//arrange
			var sut = new CacheEntry<object>(id, cacheKey, attributes, date, value);

			//assert
			sut.Value.Should().Be(value);
		}
            public static bool TryGetValue(DiagnosticAnalyzer analyzer, object key, out CacheEntry entry)
            {
                AssertKey(key);

                entry = default(CacheEntry);
                if (!s_map.TryGetValue(analyzer, out var analyzerMap) ||
                    !analyzerMap.TryGetValue(key, out entry))
                {
                    return false;
                }

                return true;
            }
예제 #25
0
        public static object GetInstanceOf(Type providerType, object[] providerArgs)
        {
            CacheEntry entry = new CacheEntry(providerType, providerArgs);

            object instance = instances.ContainsKey(entry)
                ?instances[entry]
                : null;

            if (instance == null)
                instances[entry] = instance = Reflect.Construct(providerType, providerArgs);

            return instance;
        }
        public Guid Add(Guid persistentUserIdentifier, DateTime expiryTimeUtc)
        {
            var key = Guid.NewGuid();

            var newEntry = new CacheEntry
            {
                ExpiryTime = expiryTimeUtc,
                PersistentUserIdentifier = persistentUserIdentifier
            };

            cache[key] = newEntry;

            return key;
        }
 public void cache_entry_should_support_this_type()
 {
     var someData = new SomeData
     {
         stringValue = "qwerty",
         intValue = 12345,
         boolValue = false,
         stringArray = new[] { "q", "w", "e" }
     };
     var cacheEntry = new CacheEntry<SomeData> {Value = someData};
     var stream = ProtoBufSerializer.Serialize(cacheEntry);
     stream.Should().NotBeNull();
     ProtoBufSerializer.Deserialize<CacheEntry<SomeData>>(stream).ShouldBeEquivalentTo(cacheEntry, options => options.Excluding(x=>x.Value));
 }
예제 #28
0
 public void AddOrUpdate(string key, Bitmap bmp, TimeSpan duration)
 {
     key = SanitizeKey (key);
     lock (entries) {
         bool existed = entries.ContainsKey (key);
         using (var stream = new BufferedStream (File.OpenWrite (Path.Combine (basePath, key))))
             bmp.Compress (Bitmap.CompressFormat.Png, 100, stream);
         AppendToJournal (existed ? JournalOp.Modified : JournalOp.Created,
                          key,
                          DateTime.UtcNow,
                          duration);
         entries[key] = new CacheEntry (DateTime.UtcNow, duration);
     }
 }
예제 #29
0
		public async Task Get_WhenValueIsUpdated_ShouldReturnCorrectValue(
			MemoryCacheEntryRepository sut,
			CacheEntry<object> cacheEntry,
			object newValue)
		{
			//arrange
			var expected = new CacheEntry<object>(cacheEntry.Id, cacheEntry.CacheKey, cacheEntry.Attributes, DateTimeOffset.Now, newValue);
			await sut.AddOrUpdate(CancellationToken.None, cacheEntry);
			await sut.AddOrUpdate(CancellationToken.None, expected);

			//act
			var actual = await sut.Get<object>(CancellationToken.None, expected.CacheKey, expected.Attributes);

			//assert
			actual.Should().Be(expected);
		}
예제 #30
0
		public async Task Get_WhenValueExists_ShouldReturnCorrectValue(
			MemoryCacheEntryRepository sut,
			[Frozen]Dictionary<string, string> attributes,
			[Frozen]string cacheKey,
			[Frozen]Guid id,
			CacheEntry<object> expected)
		{
			//arrange
			await sut.AddOrUpdate(CancellationToken.None, expected);

			//act
			var actual = await sut.Get<object>(CancellationToken.None, expected.CacheKey, expected.Attributes);

			//assert
			actual.Should().Be(expected);
		}
예제 #31
0
 public static void Set(string key, string data)
 {
     cache[key] = new CacheEntry(data, Data.TTL);
 }
예제 #32
0
        private static IEnumerable <CacheEntry> GetCacheUsage(IEnumerable <LogEntry> logEntries)
        {
            var cacheMisses         = new List <LogEntry>();
            var cacheEntries        = new List <CacheEntry>();
            var lastCacheEntryByKey = new Dictionary <string, CacheEntry>();

            foreach (var logEntry in logEntries)
            {
                if (CacheEntry.IsCacheFill(logEntry))
                {
                    var cacheEntry = new CacheEntry(logEntry);
                    cacheEntries.Add(cacheEntry);
                    lastCacheEntryByKey[cacheEntry.Key] = cacheEntry;
                }
                else if (CacheEntry.IsCacheHit(logEntry) && lastCacheEntryByKey.TryGetValue(CacheEntry.GetKeyFromCacheHit(logEntry), out var cacheEntry))
                {
                    cacheEntry.AddHit(logEntry);
                }
                //else if (CacheEntry.IsCacheMiss(logEntry))
                //{
                //    cacheMisses.Add(logEntry);
                //}
            }

            //var cacheMissesByKey = cacheMisses.ToLookup(CacheEntry.GetKeyFromCacheMiss);

            //foreach (var cacheEntry in cacheEntries)
            //{

            //}

            return(cacheEntries);
        }
예제 #33
0
        public override void Execute()
        {
            ISessionImplementor session = Session;
            object           id         = Id;
            IEntityPersister persister  = Persister;
            object           instance   = Instance;

            bool      statsEnabled = Session.Factory.Statistics.IsStatisticsEnabled;
            Stopwatch stopwatch    = null;

            if (statsEnabled)
            {
                stopwatch = Stopwatch.StartNew();
            }

            bool veto = PreUpdate();

            ISessionFactoryImplementor factory = Session.Factory;

            if (persister.IsVersionPropertyGenerated)
            {
                // we need to grab the version value from the entity, otherwise
                // we have issues with generated-version entities that may have
                // multiple actions queued during the same flush
                previousVersion = persister.GetVersion(instance);
            }

            CacheKey ck = null;

            if (persister.HasCache)
            {
                ck    = session.GenerateCacheKey(id, persister.IdentifierType, persister.RootEntityName);
                slock = persister.Cache.Lock(ck, previousVersion);
            }

            if (!veto)
            {
                persister.Update(id, state, dirtyFields, hasDirtyCollection, previousState, previousVersion, instance, null, session);
            }

            EntityEntry entry = Session.PersistenceContext.GetEntry(instance);

            if (entry == null)
            {
                throw new AssertionFailure("Possible nonthreadsafe access to session");
            }

            if (entry.Status == Status.Loaded || persister.IsVersionPropertyGenerated)
            {
                // get the updated snapshot of the entity state by cloning current state;
                // it is safe to copy in place, since by this time no-one else (should have)
                // has a reference  to the array
                TypeHelper.DeepCopy(state, persister.PropertyTypes, persister.PropertyCheckability, state, Session);
                if (persister.HasUpdateGeneratedProperties)
                {
                    // this entity defines property generation, so process those generated
                    // values...
                    persister.ProcessUpdateGeneratedProperties(id, instance, state, Session);
                    if (persister.IsVersionPropertyGenerated)
                    {
                        nextVersion = Versioning.GetVersion(state, persister);
                    }
                }
                // have the entity entry perform post-update processing, passing it the
                // update state and the new version (if one).
                entry.PostUpdate(instance, state, nextVersion);
            }

            if (persister.HasCache)
            {
                if (persister.IsCacheInvalidationRequired || entry.Status != Status.Loaded)
                {
                    persister.Cache.Evict(ck);
                }
                else
                {
                    CacheEntry ce = new CacheEntry(state, persister, persister.HasUninitializedLazyProperties(instance), nextVersion, Session, instance);
                    cacheEntry = persister.CacheEntryStructure.Structure(ce);

                    bool put = persister.Cache.Update(ck, cacheEntry, nextVersion, previousVersion);

                    if (put && factory.Statistics.IsStatisticsEnabled)
                    {
                        factory.StatisticsImplementor.SecondLevelCachePut(Persister.Cache.RegionName);
                    }
                }
            }

            PostUpdate();

            if (statsEnabled && !veto)
            {
                stopwatch.Stop();
                factory.StatisticsImplementor.UpdateEntity(Persister.EntityName, stopwatch.Elapsed);
            }
        }
예제 #34
0
        public override object RemoveSync(object[] keys, ItemRemoveReason reason, bool notify, OperationContext operationContext)
        {
            ArrayList depenedentItemList = new ArrayList();

            try
            {
                Hashtable totalRemovedItems = new Hashtable();

                CacheEntry            entry = null;
                IDictionaryEnumerator ide   = null;


                for (int i = 0; i < keys.Length; i++)
                {
                    try
                    {
                        if (keys[i] != null)
                        {
                            entry = Internal.Remove(keys[i], reason, false, null, LockAccessType.IGNORE_LOCK, operationContext);
                        }


                        if (entry != null)
                        {
                            totalRemovedItems.Add(keys[i], entry);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                ide = totalRemovedItems.GetEnumerator();
                while (ide.MoveNext())
                {
                    try
                    {
                        entry = ide.Value as CacheEntry;
                        if (entry != null)
                        {
                            if (entry.Value is CallbackEntry)
                            {
                                EventId       eventId      = null;
                                OperationID   opId         = operationContext.OperatoinID;
                                CallbackEntry cbEtnry      = (CallbackEntry)entry.Value;
                                EventContext  eventContext = null;

                                if (cbEtnry != null && cbEtnry.ItemRemoveCallbackListener != null && cbEtnry.ItemRemoveCallbackListener.Count > 0)
                                {
                                    //generate event id
                                    if (!operationContext.Contains(OperationContextFieldName.EventContext)) //for atomic operations
                                    {
                                        eventId = EventId.CreateEventId(opId);
                                    }
                                    else //for bulk
                                    {
                                        eventId = ((EventContext)operationContext.GetValueByField(OperationContextFieldName.EventContext)).EventID;
                                    }

                                    eventId.EventType = EventType.ITEM_REMOVED_CALLBACK;
                                    eventContext      = new EventContext();
                                    eventContext.Add(EventContextFieldName.EventID, eventId);
                                    EventCacheEntry eventCacheEntry = CacheHelper.CreateCacheEventEntry(cbEtnry.ItemRemoveCallbackListener, entry);
                                    eventContext.Item = eventCacheEntry;
                                    eventContext.Add(EventContextFieldName.ItemRemoveCallbackList, cbEtnry.ItemRemoveCallbackListener.Clone());

                                    //Will always reaise the whole entry for old clients
                                    NotifyCustomRemoveCallback(ide.Key, entry, reason, true, operationContext, eventContext);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(depenedentItemList);
        }
예제 #35
0
        public async Task TestHistoricMetadataPathStringRoundtrip()
        {
            LoggingContext loggingContext = CreateLoggingContextForTest();

            PipExecutionContext   context;
            HistoricMetadataCache cache = null;
            var hmcFolderName           = "hmc";

            for (int i = 0; i < 3; i++)
            {
                CreateHistoricCache(loggingContext, hmcFolderName, out context, out cache, out var memoryArtifactCache);

                var process1 = CreateDummyProcess(context, new PipId(1));
                var process2 = CreateDummyProcess(context, new PipId(2));

                var pathTable = context.PathTable;

                // Add some random paths to ensure path table indices are different after loading
                AbsolutePath.Create(pathTable, X("/H/aslj/sfas/832.stxt"));
                AbsolutePath.Create(pathTable, X("/R/f/s/Historic"));
                AbsolutePath.Create(pathTable, X("/M/hgf/sf4as/83afsd"));
                AbsolutePath.Create(pathTable, X("/Z/bd/sfas/Cache"));

                var abPath1 = AbsolutePath.Create(pathTable, X("/H/aslj/sfas/p1OUT.bin"));
                var abPath2 = AbsolutePath.Create(pathTable, X("/H/aslj/sfas/P2.txt"));

                var pathSet1 = ObservedPathSetTestUtilities.CreatePathSet(
                    pathTable,
                    X("/X/a/b/c"),
                    X("/X/d/e"),
                    X("/X/a/b/c/d"));

                PipCacheDescriptorV2Metadata metadata1 =
                    new PipCacheDescriptorV2Metadata
                {
                    StaticOutputHashes = new List <AbsolutePathFileMaterializationInfo>
                    {
                        new AbsolutePathFileMaterializationInfo
                        {
                            AbsolutePath = abPath1.GetName(pathTable).ToString(context.StringTable),
                            Info         = new BondFileMaterializationInfo {
                                FileName = "p1OUT.bin"
                            }
                        }
                    }
                };

                var storedPathSet1 = await cache.TryStorePathSetAsync(pathSet1);

                var storedMetadata1 = await cache.TryStoreMetadataAsync(metadata1);

                var weakFingerprint1   = new WeakContentFingerprint(FingerprintUtilities.CreateRandom());
                var strongFingerprint1 = new StrongContentFingerprint(FingerprintUtilities.CreateRandom());

                var cacheEntry = new CacheEntry(storedMetadata1.Result, nameof(HistoricMetadataCacheTests), ArrayView <ContentHash> .Empty);

                var publishedCacheEntry = await cache.TryPublishCacheEntryAsync(process1, weakFingerprint1, storedPathSet1.Result, strongFingerprint1, cacheEntry);

                var pathSet2 = ObservedPathSetTestUtilities.CreatePathSet(
                    pathTable,
                    X("/F/a/y/c"),
                    X("/B/d/e"),
                    X("/G/a/z/c/d"),
                    X("/B/a/b/c"));

                PipCacheDescriptorV2Metadata metadata2 =
                    new PipCacheDescriptorV2Metadata
                {
                    StaticOutputHashes = new List <AbsolutePathFileMaterializationInfo>
                    {
                        new AbsolutePathFileMaterializationInfo
                        {
                            AbsolutePath = abPath2.ToString(pathTable),
                            Info         = new BondFileMaterializationInfo {
                                FileName = abPath2.GetName(pathTable).ToString(context.StringTable)
                            }
                        }
                    },
                    DynamicOutputs = new List <List <RelativePathFileMaterializationInfo> >
                    {
                        new List <RelativePathFileMaterializationInfo>
                        {
                            new RelativePathFileMaterializationInfo
                            {
                                RelativePath = @"dir\P2Dynamic.txt",
                                Info         = new BondFileMaterializationInfo {
                                    FileName = "p2dynamic.txt"
                                }
                            },
                            new RelativePathFileMaterializationInfo
                            {
                                RelativePath = @"dir\P2dynout2.txt",
                                Info         = new BondFileMaterializationInfo {
                                    FileName = null
                                }
                            }
                        }
                    }
                };

                var storedPathSet2 = await cache.TryStorePathSetAsync(pathSet2);

                var storedMetadata2 = await cache.TryStoreMetadataAsync(metadata2);

                var cacheEntry2 = new CacheEntry(storedMetadata2.Result, nameof(HistoricMetadataCacheTests), ArrayView <ContentHash> .Empty);

                var strongFingerprint2 = new StrongContentFingerprint(FingerprintUtilities.CreateRandom());

                var publishedCacheEntry2 = await cache.TryPublishCacheEntryAsync(process1, weakFingerprint1, storedPathSet2.Result, strongFingerprint2, cacheEntry2);

                await cache.CloseAsync();

                memoryArtifactCache.Clear();

                PipExecutionContext   loadedContext;
                HistoricMetadataCache loadedCache;

                TaskSourceSlim <bool> loadCompletionSource = TaskSourceSlim.Create <bool>();
                TaskSourceSlim <bool> loadCalled           = TaskSourceSlim.Create <bool>();
                BoxRef <bool>         calledLoad           = new BoxRef <bool>();
                CreateHistoricCache(loggingContext, "hmc", out loadedContext, out loadedCache, out memoryArtifactCache, loadTask: async hmc =>
                {
                    loadCalled.SetResult(true);
                    await loadCompletionSource.Task;
                });

                var operationContext      = OperationContext.CreateUntracked(loggingContext);
                var retrievePathSet1Task  = loadedCache.TryRetrievePathSetAsync(operationContext, WeakContentFingerprint.Zero, storedPathSet1.Result);
                var retrievdMetadata1Task = loadedCache.TryRetrieveMetadataAsync(
                    process1,
                    WeakContentFingerprint.Zero,
                    StrongContentFingerprint.Zero,
                    storedMetadata1.Result,
                    storedPathSet1.Result);

                var getCacheEntry1Task = loadedCache.TryGetCacheEntryAsync(
                    process1,
                    weakFingerprint1,
                    storedPathSet1.Result,
                    strongFingerprint1);

                Assert.False(retrievePathSet1Task.IsCompleted, "Before load task completes. TryRetrievePathSetAsync operations should block");
                Assert.False(retrievdMetadata1Task.IsCompleted, "Before load task completes. TryRetrieveMetadataAsync operations should block");
                Assert.False(getCacheEntry1Task.IsCompleted, "Before load task completes. TryGetCacheEntryAsync operations should block");

                Assert.True(loadCalled.Task.Wait(TimeSpan.FromSeconds(10)) && loadCalled.Task.Result, "Load should have been called in as a result of querying");
                loadCompletionSource.SetResult(true);

                var maybeLoadedPathSet1    = await retrievePathSet1Task;
                var maybeLoadedMetadata1   = await retrievdMetadata1Task;
                var maybeLoadedCacheEntry1 = await getCacheEntry1Task;

                Assert.Equal(storedMetadata1.Result, maybeLoadedCacheEntry1.Result.Value.MetadataHash);

                var maybeLoadedPathSet2 = await loadedCache.TryRetrievePathSetAsync(operationContext, WeakContentFingerprint.Zero, storedPathSet2.Result);

                var maybeLoadedMetadata2 = await loadedCache.TryRetrieveMetadataAsync(
                    process2,
                    WeakContentFingerprint.Zero,
                    StrongContentFingerprint.Zero,
                    storedMetadata2.Result,
                    storedPathSet2.Result);

                AssertPathSetEquals(pathTable, pathSet1, loadedContext.PathTable, maybeLoadedPathSet1.Result);
                AssertPathSetEquals(pathTable, pathSet2, loadedContext.PathTable, maybeLoadedPathSet2.Result);
                AssertMetadataEquals(metadata1, maybeLoadedMetadata1.Result);
                AssertMetadataEquals(metadata2, maybeLoadedMetadata2.Result);

                await loadedCache.CloseAsync();
            }
        }
예제 #36
0
 void ICompactSerializable.Deserialize(CompactReader reader)
 {
     _entry  = (CacheEntry)reader.ReadObject();
     _result = (CacheInsResult)reader.ReadObject();
 }
예제 #37
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="entry"></param>
 /// <param name="result"></param>
 public CacheInsResultWithEntry(CacheEntry entry, CacheInsResult result)
 {
     _entry  = entry;
     _result = result;
 }
예제 #38
0
        public override void Execute()
        {
            IEntityPersister    persister = Persister;
            ISessionImplementor session   = Session;
            object instance = Instance;
            object id       = Id;

            bool      statsEnabled = Session.Factory.Statistics.IsStatisticsEnabled;
            Stopwatch stopwatch    = null;

            if (statsEnabled)
            {
                stopwatch = Stopwatch.StartNew();
            }

            bool veto = PreInsert();

            var wasDelayed = false;

            // Don't need to lock the cache here, since if someone
            // else inserted the same pk first, the insert would fail
            if (!veto)
            {
                // The identifier may be a foreign delayed identifier, which at this point should have been resolved.
                if (id is DelayedPostInsertIdentifier delayed)
                {
                    wasDelayed = true;
                    id         = delayed.ActualId ??
                                 throw new InvalidOperationException(
                                           $"The delayed foreign identifier {delayed} has not been resolved before insertion of a {instance}");
                }
                persister.Insert(id, State, instance, Session);

                EntityEntry entry = Session.PersistenceContext.GetEntry(instance);
                if (entry == null)
                {
                    throw new AssertionFailure("Possible nonthreadsafe access to session");
                }

                entry.PostInsert();
                if (wasDelayed)
                {
                    Session.PersistenceContext.ReplaceDelayedEntityIdentityInsertKeys(entry.EntityKey, id);
                }

                if (persister.HasInsertGeneratedProperties)
                {
                    persister.ProcessInsertGeneratedProperties(id, instance, State, Session);
                    if (persister.IsVersionPropertyGenerated)
                    {
                        version = Versioning.GetVersion(State, persister);
                    }
                    entry.PostUpdate(instance, State, version);
                }
            }

            ISessionFactoryImplementor factory = Session.Factory;

            if (IsCachePutEnabled(persister))
            {
                CacheEntry ce = CacheEntry.Create(State, persister, version, session, instance);
                cacheEntry = persister.CacheEntryStructure.Structure(ce);

                CacheKey ck  = Session.GenerateCacheKey(id, persister.IdentifierType, persister.RootEntityName);
                bool     put = persister.Cache.Insert(ck, cacheEntry, version);

                if (put && factory.Statistics.IsStatisticsEnabled)
                {
                    factory.StatisticsImplementor.SecondLevelCachePut(Persister.Cache.RegionName);
                }
            }

            PostInsert();

            if (statsEnabled && !veto)
            {
                stopwatch.Stop();
                factory.StatisticsImplementor.InsertEntity(Persister.EntityName, stopwatch.Elapsed);
            }
        }
예제 #39
0
        public override void Execute()
        {
            IEntityPersister    persister = Persister;
            ISessionImplementor session   = Session;
            object instance = Instance;
            object id       = Id;

            bool      statsEnabled = Session.Factory.Statistics.IsStatisticsEnabled;
            Stopwatch stopwatch    = null;

            if (statsEnabled)
            {
                stopwatch = Stopwatch.StartNew();
            }

            bool veto = PreInsert();

            // Don't need to lock the cache here, since if someone
            // else inserted the same pk first, the insert would fail
            if (!veto)
            {
                persister.Insert(id, state, instance, Session);

                EntityEntry entry = Session.PersistenceContext.GetEntry(instance);
                if (entry == null)
                {
                    throw new AssertionFailure("Possible nonthreadsafe access to session");
                }

                entry.PostInsert();

                if (persister.HasInsertGeneratedProperties)
                {
                    persister.ProcessInsertGeneratedProperties(id, instance, state, Session);
                    if (persister.IsVersionPropertyGenerated)
                    {
                        version = Versioning.GetVersion(state, persister);
                    }
                    entry.PostUpdate(instance, state, version);
                }
            }

            ISessionFactoryImplementor factory = Session.Factory;

            if (IsCachePutEnabled(persister))
            {
                CacheEntry ce = new CacheEntry(state, persister, persister.HasUninitializedLazyProperties(instance), version, session, instance);
                cacheEntry = persister.CacheEntryStructure.Structure(ce);

                CacheKey ck  = Session.GenerateCacheKey(id, persister.IdentifierType, persister.RootEntityName);
                bool     put = persister.Cache.Insert(ck, cacheEntry, version);

                if (put && factory.Statistics.IsStatisticsEnabled)
                {
                    factory.StatisticsImplementor.SecondLevelCachePut(Persister.Cache.RegionName);
                }
            }

            PostInsert();

            if (statsEnabled && !veto)
            {
                stopwatch.Stop();
                factory.StatisticsImplementor.InsertEntity(Persister.EntityName, stopwatch.Elapsed);
            }
        }
예제 #40
0
 private static bool EntryExpired(CacheEntry entry, DateTimeOffset now)
 {
     return(entry.AbsoluteExpiration < now || (now - entry.LastAccess) > entry.SlidingExpiration);
 }
예제 #41
0
 public void Update(CacheEntry entry, Gdk.Pixbuf pixbuf)
 {
     lock (items) {
         entry.SetPixbufExtended(pixbuf, true);
     }
 }
예제 #42
0
        /// <summary>
        /// Perform the second step of 2-phase load. Fully initialize the entity instance.
        /// After processing a JDBC result set, we "resolve" all the associations
        /// between the entities which were instantiated and had their state
        /// "hydrated" into an array
        /// </summary>
        public static async Task InitializeEntityAsync(object entity, bool readOnly, ISessionImplementor session, PreLoadEvent preLoadEvent, PostLoadEvent postLoadEvent, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            //TODO: Should this be an InitializeEntityEventListener??? (watch out for performance!)

            bool statsEnabled = session.Factory.Statistics.IsStatisticsEnabled;
            var  stopWath     = new Stopwatch();

            if (statsEnabled)
            {
                stopWath.Start();
            }

            IPersistenceContext persistenceContext = session.PersistenceContext;
            EntityEntry         entityEntry        = persistenceContext.GetEntry(entity);

            if (entityEntry == null)
            {
                throw new AssertionFailure("possible non-threadsafe access to the session");
            }
            IEntityPersister persister = entityEntry.Persister;
            object           id        = entityEntry.Id;

            object[] hydratedState = entityEntry.LoadedState;

            if (log.IsDebugEnabled())
            {
                log.Debug("resolving associations for {0}", MessageHelper.InfoString(persister, id, session.Factory));
            }

            IType[] types = persister.PropertyTypes;
            for (int i = 0; i < hydratedState.Length; i++)
            {
                object value = hydratedState[i];
                if (!Equals(LazyPropertyInitializer.UnfetchedProperty, value) && !(Equals(BackrefPropertyAccessor.Unknown, value)))
                {
                    hydratedState[i] = await(types[i].ResolveIdentifierAsync(value, session, entity, cancellationToken)).ConfigureAwait(false);
                }
            }

            //Must occur after resolving identifiers!
            if (session.IsEventSource)
            {
                preLoadEvent.Entity    = entity;
                preLoadEvent.State     = hydratedState;
                preLoadEvent.Id        = id;
                preLoadEvent.Persister = persister;
                IPreLoadEventListener[] listeners = session.Listeners.PreLoadEventListeners;
                for (int i = 0; i < listeners.Length; i++)
                {
                    await(listeners[i].OnPreLoadAsync(preLoadEvent, cancellationToken)).ConfigureAwait(false);
                }
            }

            persister.SetPropertyValues(entity, hydratedState);

            ISessionFactoryImplementor factory = session.Factory;

            if (persister.HasCache && session.CacheMode.HasFlag(CacheMode.Put))
            {
                if (log.IsDebugEnabled())
                {
                    log.Debug("adding entity to second-level cache: {0}", MessageHelper.InfoString(persister, id, session.Factory));
                }

                object     version = Versioning.GetVersion(hydratedState, persister);
                CacheEntry entry   =
                    new CacheEntry(hydratedState, persister, entityEntry.LoadedWithLazyPropertiesUnfetched, version, session, entity);
                CacheKey cacheKey = session.GenerateCacheKey(id, persister.IdentifierType, persister.RootEntityName);
                bool     put      =
                    await(persister.Cache.PutAsync(cacheKey, persister.CacheEntryStructure.Structure(entry), session.Timestamp, version,
                                                   persister.IsVersioned ? persister.VersionType.Comparator : null,
                                                   UseMinimalPuts(session, entityEntry), cancellationToken)).ConfigureAwait(false);

                if (put && factory.Statistics.IsStatisticsEnabled)
                {
                    factory.StatisticsImplementor.SecondLevelCachePut(persister.Cache.RegionName);
                }
            }

            bool isReallyReadOnly = readOnly;

            if (!persister.IsMutable)
            {
                isReallyReadOnly = true;
            }
            else
            {
                object proxy = persistenceContext.GetProxy(entityEntry.EntityKey);
                if (proxy != null)
                {
                    // there is already a proxy for this impl
                    // only set the status to read-only if the proxy is read-only
                    isReallyReadOnly = ((INHibernateProxy)proxy).HibernateLazyInitializer.ReadOnly;
                }
            }

            if (isReallyReadOnly)
            {
                //no need to take a snapshot - this is a
                //performance optimization, but not really
                //important, except for entities with huge
                //mutable property values
                persistenceContext.SetEntryStatus(entityEntry, Status.ReadOnly);
            }
            else
            {
                //take a snapshot
                TypeHelper.DeepCopy(hydratedState, persister.PropertyTypes, persister.PropertyUpdateability, hydratedState, session);
                persistenceContext.SetEntryStatus(entityEntry, Status.Loaded);
            }

            persister.AfterInitialize(entity, entityEntry.LoadedWithLazyPropertiesUnfetched, session);

            if (session.IsEventSource)
            {
                postLoadEvent.Entity    = entity;
                postLoadEvent.Id        = id;
                postLoadEvent.Persister = persister;
                IPostLoadEventListener[] listeners = session.Listeners.PostLoadEventListeners;
                for (int i = 0; i < listeners.Length; i++)
                {
                    listeners[i].OnPostLoad(postLoadEvent);
                }
            }

            if (log.IsDebugEnabled())
            {
                log.Debug("done materializing entity {0}", MessageHelper.InfoString(persister, id, session.Factory));
            }

            if (statsEnabled)
            {
                stopWath.Stop();
                factory.StatisticsImplementor.LoadEntity(persister.EntityName, stopWath.Elapsed);
            }
        }
예제 #43
0
 public IndexRemoveTask(QueryIndexManager indexManager, object key, CacheEntry value)
 {
     _key          = key;
     _entry        = value;
     _indexManager = indexManager;
 }
예제 #44
0
 /// <summary>
 ///  Return true if the given <paramref name="key"/> matches the given <paramref name="entry"/>.
 /// </summary>
 protected abstract bool IsMatch(TKey key, CacheEntry entry);
		private void LoadCache()
		{
			if( File.Exists( CachePath ) )
			{
				using( FileStream stream = new FileStream( CachePath, FileMode.Open, FileAccess.Read ) )
				using( BinaryReader reader = new BinaryReader( stream ) )
				{
					try
					{
						int cacheSize = reader.ReadInt32();
						assetDependencyCache = new Dictionary<string, CacheEntry>( cacheSize );

						for( int i = 0; i < cacheSize; i++ )
						{
							string assetPath = reader.ReadString();
							string hash = reader.ReadString();

							int dependenciesLength = reader.ReadInt32();
							string[] dependencies = new string[dependenciesLength];
							long[] fileSizes = new long[dependenciesLength];
							for( int j = 0; j < dependenciesLength; j++ )
							{
								dependencies[j] = reader.ReadString();
								fileSizes[j] = reader.ReadInt64();
							}

							assetDependencyCache[assetPath] = new CacheEntry( hash, dependencies, fileSizes );
						}
					}
					catch( Exception e )
					{
						assetDependencyCache = null;
						Debug.LogException( e );
					}
				}
			}

			// Generate cache for all assets for the first time
			if( assetDependencyCache == null )
			{
				assetDependencyCache = new Dictionary<string, CacheEntry>( 1024 * 8 );

				string[] allAssets = AssetDatabase.GetAllAssetPaths();
				if( allAssets.Length > 0 )
				{
					double startTime = EditorApplication.timeSinceStartup;

					try
					{
						for( int i = 0; i < allAssets.Length; i++ )
						{
							if( i % 30 == 0 && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Generating cache for the first time", (float) i / allAssets.Length ) )
							{
								EditorUtility.ClearProgressBar();
								Debug.LogWarning( "Initial cache generation cancelled, cache will be generated on the fly as more and more assets are searched." );
								break;
							}

							AssetHasAnyReference( allAssets[i] );
						}

						EditorUtility.ClearProgressBar();

						Debug.Log( "Cache generated in " + ( EditorApplication.timeSinceStartup - startTime ).ToString( "F2" ) + " seconds" );
						Debug.Log( "You can always reset the cache by deleting " + Path.GetFullPath( CachePath ) );

						SaveCache();
					}
					catch( Exception e )
					{
						EditorUtility.ClearProgressBar();
						Debug.LogException( e );
					}
				}
			}
		}
예제 #46
0
        private void AddToCache(string filename, BitmapEntry entry) {
            _fromCache = false;
            if (OptionCacheTotalEntries <= 0 || OptionCacheTotalSize <= 0 ||
                    entry.Size < OptionCacheMinSize || entry.Size > OptionCacheMaxSize) return;

            var cache = Cache;
            var lastIndex = cache.Count - 1;

            lock (cache) {
                var index = -1;
                for (var i = lastIndex; i >= 0; i--) {
                    if (string.Equals(cache[i].Key, filename, OptionCacheStringComparison)) {
                        index = i;
                        break;
                    }
                }
                
                CacheEntry item;
                if (index == -1) {
                    // item does not exist now, let’s add it
                    item = new CacheEntry {
                        Key = filename,
                        Value = entry
                    };

                    // if queue is full, remove the first entry to avoid re-creating
                    // array thing inside of the list
                    if (cache.Count == OptionCacheTotalEntries) {
                        if (OptionMarkCached) {
                            Logging.Debug($"total cached: {cache.Count} entries (capacity: {cache.Capacity})");
                        }

                        cache.RemoveAt(0);
                    }

                    cache.Add(item);
                } else {
                    // item already exists, let’s update its value
                    item = cache[index];
                    item.Value = entry;

                    if (index < lastIndex) {
                        // and move it to the end of removal queue if needed
                        cache.RemoveAt(index);
                        cache.Add(item);
                    }
                }

                // remove old entries
                var total = item.Value.Size;
                for (var i = lastIndex - 1; i >= 0; i--) {
                    total += cache[i].Value.Size;
                    if (total > OptionCacheTotalSize) {
                        if (OptionMarkCached) {
                            Logging.Debug($"total cached size: {total / 1024d / 1024:F2} MB, let’s remove first {i + 1} image{(i > 0 ? "s" : "")}");
                        }

                        cache.RemoveRange(0, i + 1);
                        return;
                    }
                }

                if (OptionMarkCached) {
                    Logging.Debug($"total cached size: {total / 1024d / 1024:F2} MB, no need to remove anything");
                }
            }
        }
예제 #47
0
파일: Settings.cs 프로젝트: DevrexLabs/Fig
        private BindResult <T> BindProperties <T>(T target, bool requireAll = true, string prefix = null, bool preload = false, List <string> errors = null)
        {
            errors = errors ?? new List <string>();

            prefix = prefix ?? _bindingPath;

            foreach (var prop in typeof(T).GetProperties())
            {
                try
                {
                    if (preload && prop.Name == nameof(Environment))
                    {
                        continue;
                    }

                    var readonlyProp = prop.GetSetMethod() is null;
                    var name         = String.IsNullOrEmpty(prefix?.Trim()) ? prop.Name : $"{prefix}.{prop.Name}";

                    // No need to continue if the property is readonly and not part of a preload operation
                    if (readonlyProp && !preload)
                    {
                        continue;
                    }

                    if (prop.PropertyType.IsAbstract || prop.PropertyType.IsInterface)
                    {
                        continue;
                    }

                    var result = GetPropertyValue(prop, name, preload, requireAll);

                    if (!(result?.Result is null))
                    {
                        // When there is a preload and the value is not in the cache yet, do that here
                        if (preload && !_cache.ContainsKey(name))
                        {
                            _cache[name] = new CacheEntry(result.Result);
                        }
                        // Otherwise set the value of the property if it is not readonly
                        else if (!readonlyProp)
                        {
                            prop.SetValue(
                                target,
                                result.Result
                                );
                        }
                    }

                    if (result?.Errors?.Any() == true)
                    {
                        errors.AddRange(result.Errors);
                    }
                }
                catch (TargetInvocationException tie)
                {
                    switch (tie.InnerException)
                    {
                    case KeyNotFoundException _:
                        errors.Add(prop.Name + " not found");
                        break;

                    case FormatException fe:
                        errors.Add("Can't parse " + prop.Name);
                        break;

                    default:
                        errors.Add(prop.Name + " failed," + tie.InnerException.Message);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    errors.Add(prop.Name + " failed, " + ex.Message);
                }
            }

            return(new BindResult <T>(errors, target));
        }
예제 #48
0
        /// <summary>
        /// Removes the object and key pair from the cache. The key is specified as parameter.
        /// Moreover it take a removal reason and a boolean specifying if a notification should
        /// be raised.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="ir"></param>
        /// <param name="notify">boolean specifying to raise the event.</param>
        /// <param name="lockId"></param>
        /// <param name="accessType"></param>
        /// <param name="operationContext"></param>
        /// <param name="removalReason">reason for the removal.</param>
        /// <returns>item value</returns>
        public override CacheEntry Remove(object key, ItemRemoveReason ir, bool notify, object lockId, LockAccessType accessType, OperationContext operationContext)
        {
            CacheEntry retVal = Internal.Remove(key, ir, notify, lockId, accessType, operationContext);

            return(retVal);
        }
예제 #49
0
        public virtual Hashtable GetQueryInfo(object key, object value)
        {
            Hashtable queryInfo     = new Hashtable();
            Hashtable queryIndex    = new Hashtable();
            Hashtable namedTagInfo  = new Hashtable();
            Hashtable namedTagsList = new Hashtable();

            Hashtable  tagInfo  = new Hashtable();
            ArrayList  tagsList = new ArrayList();
            CacheEntry entry    = (CacheEntry)value;

            if (entry.ObjectType == null)
            {
                return(queryInfo);
            }
            IQueryIndex      index            = (IQueryIndex)_indexMap[entry.ObjectType];
            IndexInformation indexInformation = entry.IndexInfo;

            lock (_indexMap.SyncRoot)
            {
                if (indexInformation != null)
                {
                    if (_typeMap != null)
                    {
                        int handleId = _typeMap.GetHandleId(entry.ObjectType);
                        if (handleId > -1)
                        {
                            ArrayList attributes = _typeMap.GetAttribList(handleId);

                            ArrayList attributeValues = new ArrayList();

                            for (int i = 0; i < attributes.Count; i++)
                            {
                                foreach (IndexStoreInformation indexStoreInfo in indexInformation.IndexStoreInformations)
                                {
                                    if (attributes[i].ToString() == indexStoreInfo.StoreName)
                                    {
                                        if (indexStoreInfo.IndexPosition == null)
                                        {
                                            attributeValues.Add(null);
                                        }
                                        else
                                        {
                                            object val = indexStoreInfo.IndexPosition.GetKey();

                                            string objValue = null;

                                            if (val is DateTime)
                                            {
                                                objValue = ((DateTime)val).Ticks.ToString();
                                            }
                                            else
                                            {
                                                objValue = val.ToString();
                                            }

                                            attributeValues.Add(objValue);
                                        }
                                        break;
                                    }
                                }
                            }
                            queryIndex.Add(handleId, attributeValues);
                            queryInfo["query-info"] = queryIndex;
                        }
                    }
                }


                if (indexInformation != null)
                {
                    foreach (IndexStoreInformation indexStoreinfo in indexInformation.IndexStoreInformations)
                    {
                        if (AttributeIndex.IsNamedTagKey(indexStoreinfo.StoreName))
                        {
                            if (indexStoreinfo.IndexPosition != null)
                            {
                                namedTagsList.Add(ConvertToNamedTag(indexStoreinfo.StoreName.ToString()), indexStoreinfo.IndexPosition.GetKey());
                            }
                        }
                        else if (indexStoreinfo.StoreName.Equals(TAG_INDEX_KEY))
                        {
                            if (indexStoreinfo.IndexPosition != null)
                            {
                                tagsList.Add(indexStoreinfo.IndexPosition.GetKey());
                            }
                        }
                    }
                }
                namedTagInfo["type"]            = entry.ObjectType;
                namedTagInfo["named-tags-list"] = namedTagsList;
                queryInfo["named-tag-info"]     = namedTagInfo;

                tagInfo["type"]       = entry.ObjectType;
                tagInfo["tags-list"]  = tagsList;
                queryInfo["tag-info"] = tagInfo;
            }
            return(queryInfo);
        }
예제 #50
0
        /// <summary>
        /// Extract a subset of the specified iterator to fit the filter's
        /// parameters (i.e. page size and page number).
        /// </summary>
        /// <remarks>
        /// The returned array is guaranteed to iterate exactly in the same
        /// order as the original iterator.
        /// </remarks>
        /// <param name="iter">
        /// An original entry iterator.
        /// </param>
        /// <returns>
        /// An array of entries extracted accordingly to the filter
        /// parameters
        /// </returns>
        public virtual object[] ExtractPage(IEnumerator iter)
        {
            int       pageSize     = PageSize;
            IComparer comparer     = Comparer;
            object    anchorTop    = TopAnchor;
            object    anchorBottom = BottomAnchor;
            var       entries      = new object[pageSize];
            int       entryIndex   = 0;

            if (comparer == null || anchorTop == null && anchorBottom == null)
            {
                int skip = Page * pageSize;

                // THIS IS A HACK: reconsider
                if (comparer == null && anchorTop is int)
                {
                    skip = ((int)anchorTop);
                }

                while (iter.MoveNext())
                {
                    object entry = iter.Current;

                    if (--skip >= 0)
                    {
                        continue;
                    }

                    entries[entryIndex] = entry;

                    if (++entryIndex == pageSize)
                    {
                        break;
                    }
                }

                if (entryIndex < pageSize)
                {
                    // last page is not full
                    int size  = entryIndex;
                    var array = new object[size];

                    if (size > 0)
                    {
                        Array.Copy(entries, 0, array, 0, size);
                    }
                    entries = array;
                }
            }
            else
            {
                bool isHeading   = anchorTop != null || anchorBottom == null;
                bool isInclusive = anchorTop != null && anchorBottom != null;
                bool skip        = isHeading;
                bool wrap        = false;
                var  entryTop    = new CacheEntry(null, anchorTop);
                var  entryBottom = new CacheEntry(null, anchorBottom);

                while (iter.MoveNext())
                {
                    var entry = (CacheEntry)iter.Current;

                    if (skip)
                    {
                        int compare = comparer.Compare(entry, entryTop);

                        skip = isInclusive ? (compare < 0) : (compare <= 0);
                        if (skip)
                        {
                            continue;
                        }
                    }

                    if (isHeading)
                    {
                        entries[entryIndex] = entry;

                        if (++entryIndex == pageSize)
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (comparer.Compare(entry, entryBottom) >= 0)
                        {
                            break;
                        }

                        entries[entryIndex] = entry;

                        if (++entryIndex == pageSize)
                        {
                            wrap       = true;
                            entryIndex = 0;
                        }
                    }
                }

                if (wrap)
                {
                    var array = new object[pageSize];

                    Array.Copy(entries, entryIndex, array, 0, pageSize - entryIndex);
                    Array.Copy(entries, 0, array, pageSize - entryIndex, entryIndex);
                    entries = array;
                }
                else if (entryIndex < pageSize)
                {
                    // last page is not full
                    int size  = entryIndex;
                    var array = new object[size];

                    if (size > 0)
                    {
                        Array.Copy(entries, 0, array, 0, size);
                    }
                    entries = array;
                }
            }
            return(entries);
        }
예제 #51
0
        /// <summary> Attempts to load the entity from the second-level cache. </summary>
        /// <param name="event">The load event </param>
        /// <param name="persister">The persister for the entity being requested for load </param>
        /// <param name="options">The load options. </param>
        /// <returns> The entity from the second-level cache, or null. </returns>
        protected virtual object LoadFromSecondLevelCache(LoadEvent @event, IEntityPersister persister, LoadType options)
        {
            ISessionImplementor source = @event.Session;
            bool useCache = persister.HasCache && source.CacheMode.HasFlag(CacheMode.Get) &&
                            @event.LockMode.LessThan(LockMode.Read);

            if (!useCache)
            {
                return(null);
            }
            ISessionFactoryImplementor factory = source.Factory;
            var batchSize = persister.GetBatchSize();

            if (batchSize > 1 && persister.Cache.PreferMultipleGet())
            {
                // The first item in the array is the item that we want to load
                var entityBatch =
                    source.PersistenceContext.BatchFetchQueue.GetEntityBatch(persister, @event.EntityId, batchSize, false);
                // Ignore null values as the retrieved batch may contains them when there are not enough
                // uninitialized entities in the queue
                var keys = new List <CacheKey>(batchSize);
                for (var i = 0; i < entityBatch.Length; i++)
                {
                    var key = entityBatch[i];
                    if (key == null)
                    {
                        break;
                    }
                    keys.Add(source.GenerateCacheKey(key, persister.IdentifierType, persister.RootEntityName));
                }
                var cachedObjects = persister.Cache.GetMany(keys.ToArray(), source.Timestamp);
                for (var i = 1; i < cachedObjects.Length; i++)
                {
                    Assemble(
                        keys[i],
                        cachedObjects[i],
                        new LoadEvent(entityBatch[i], @event.EntityClassName, @event.LockMode, @event.Session),
                        false);
                }
                return(Assemble(keys[0], cachedObjects[0], @event, true));
            }
            var cacheKey     = source.GenerateCacheKey(@event.EntityId, persister.IdentifierType, persister.RootEntityName);
            var cachedObject = persister.Cache.Get(cacheKey, source.Timestamp);

            return(Assemble(cacheKey, cachedObject, @event, true));

            object Assemble(CacheKey ck, object ce, LoadEvent evt, bool alterStatistics)
            {
                if (factory.Statistics.IsStatisticsEnabled && alterStatistics)
                {
                    if (ce == null)
                    {
                        factory.StatisticsImplementor.SecondLevelCacheMiss(persister.Cache.RegionName);
                        log.Debug("Entity cache miss: {0}", ck);
                    }
                    else
                    {
                        factory.StatisticsImplementor.SecondLevelCacheHit(persister.Cache.RegionName);
                        log.Debug("Entity cache hit: {0}", ck);
                    }
                }

                if (ce != null)
                {
                    CacheEntry entry = (CacheEntry)persister.CacheEntryStructure.Destructure(ce, factory);

                    // Entity was found in second-level cache...
                    // NH: Different behavior (take a look to options.ExactPersister (NH-295))
                    if (!options.ExactPersister || persister.EntityMetamodel.SubclassEntityNames.Contains(entry.Subclass))
                    {
                        return(AssembleCacheEntry(entry, evt.EntityId, persister, evt));
                    }
                }

                return(null);
            }
        }
예제 #52
0
        public QualityMessage GetValue(SolutionMessage message, Evaluator evaluate, ExtensionRegistry extensions)
        {
            var  entry     = new CacheEntry(message.ToString());
            bool lockTaken = false;
            bool waited    = false;

            try {
                Monitor.Enter(cacheLock, ref lockTaken);
                while (true)
                {
                    LinkedListNode <CacheEntry> node;
                    if (index.TryGetValue(entry, out node))
                    {
                        list.Remove(node);
                        list.AddLast(node);
                        Hits++;
                        lockTaken = false;
                        Monitor.Exit(cacheLock);
                        OnChanged();
                        return(node.Value.GetMessage(extensions));
                    }
                    else
                    {
                        if (!waited && activeEvaluations.Contains(entry.Key))
                        {
                            while (activeEvaluations.Contains(entry.Key))
                            {
                                Monitor.Wait(cacheLock);
                            }
                            waited = true;
                        }
                        else
                        {
                            activeEvaluations.Add(entry.Key);
                            lockTaken = false;
                            Monitor.Exit(cacheLock);
                            OnChanged();
                            try {
                                entry.SetMessage(evaluate(message));
                                Monitor.Enter(cacheLock, ref lockTaken);
                                index[entry] = list.AddLast(entry);
                                Trim();
                            } finally {
                                if (!lockTaken)
                                {
                                    Monitor.Enter(cacheLock, ref lockTaken);
                                }
                                activeEvaluations.Remove(entry.Key);
                                Monitor.PulseAll(cacheLock);
                                lockTaken = false;
                                Monitor.Exit(cacheLock);
                            }
                            OnChanged();
                            return(entry.GetMessage(extensions));
                        }
                    }
                }
            } finally {
                if (lockTaken)
                {
                    Monitor.Exit(cacheLock);
                }
            }
        }
예제 #53
0
        public virtual void AddToIndex(object key, object value, OperationContext operationContext)
        {
            CacheEntry entry     = (CacheEntry)value;
            Hashtable  queryInfo = entry.QueryInfo["query-info"] as Hashtable;

            if (queryInfo == null)
            {
                return;
            }


            lock (_indexMap.SyncRoot)
            {
                IDictionaryEnumerator queryInfoEnumerator = queryInfo.GetEnumerator();

                while (queryInfoEnumerator.MoveNext())
                {
                    int    handleId = (int)queryInfoEnumerator.Key;
                    string type     = _typeMap.GetTypeName(handleId);
                    if (_indexMap.Contains(type))
                    {
                        Hashtable indexAttribs    = new Hashtable();
                        Hashtable metaInfoAttribs = new Hashtable();

                        ArrayList values = (ArrayList)queryInfoEnumerator.Value;

                        ArrayList attribList = _typeMap.GetAttribList(handleId);
                        for (int i = 0; i < attribList.Count; i++)
                        {
                            string attribute = attribList[i].ToString();
                            string val       = _typeMap.GetAttributes(handleId)[attribList[i]] as string;
                            if (Common.Util.JavaClrTypeMapping.JavaToClr(val) != null)
                            {
                                val = Common.Util.JavaClrTypeMapping.JavaToClr(val);
                            }
                            Type t1 = Type.GetType(val, true, true);

                            object obj = null;

                            if (values[i] != null)
                            {
                                try
                                {
                                    if (t1 == typeof(System.DateTime))
                                    {
                                        obj = new DateTime(Convert.ToInt64(values[i]));
                                    }
                                    else
                                    {
                                        obj = Convert.ChangeType(values[i], t1);
                                    }
                                }
                                catch (Exception)
                                {
                                    throw new System.FormatException("Cannot convert '" + values[i] + "' to " + t1.ToString());
                                }

                                indexAttribs.Add(attribute, obj);
                            }
                            else
                            {
                                indexAttribs.Add(attribute, null);
                            }


                            metaInfoAttribs.Add(attribute, obj);
                        }

                        MetaInformation metaInformation = new MetaInformation(metaInfoAttribs);
                        metaInformation.CacheKey = key as string;
                        metaInformation.Type     = _typeMap.GetTypeName(handleId);

                        operationContext.Add(OperationContextFieldName.IndexMetaInfo, metaInformation);

                        entry.ObjectType = _typeMap.GetTypeName(handleId);

                        IQueryIndex index    = (IQueryIndex)_indexMap[type];
                        long        prevSize = index.IndexInMemorySize;
                        index.AddToIndex(key, new QueryItemContainer(entry, indexAttribs));

                        this._queryIndexMemorySize += index.IndexInMemorySize - prevSize;
                    }
                }
            }
        }
예제 #54
0
파일: Dfs.cs 프로젝트: mematrix/WinRTCifs
 /// <exception cref="WinrtCifs.Smb.SmbAuthException"></exception>
 public virtual DfsReferral Resolve(string domain, string root, string path, NtlmPasswordAuthentication
                                    auth)
 {
     lock (this)
     {
         DfsReferral dr  = null;
         long        now = Runtime.CurrentTimeMillis();
         if (Disabled || root.Equals("IPC$"))
         {
             return(null);
         }
         Hashtable domains = GetTrustedDomains(auth);
         if (domains != null)
         {
             domain = domain.ToLower();
             Hashtable roots = (Hashtable)domains.Get(domain);
             if (roots != null)
             {
                 SmbTransport trans = null;
                 root = root.ToLower();
                 CacheEntry links = (CacheEntry)roots.Get(root);
                 if (links != null && now > links.Expiration)
                 {
                     //Sharpen.Collections.Remove(roots, root);
                     roots.Remove(root);
                     links = null;
                 }
                 if (links == null)
                 {
                     if ((trans = GetDc(domain, auth)) == null)
                     {
                         return(null);
                     }
                     dr = GetReferral(trans, domain, root, path, auth);
                     if (dr != null)
                     {
                         int len = 1 + domain.Length + 1 + root.Length;
                         links = new CacheEntry(0L);
                         DfsReferral tmp = dr;
                         do
                         {
                             if (path == null)
                             {
                                 // TODO: fix this
                                 //tmp.map = links.map;
                                 tmp.Key = "\\";
                             }
                             tmp.PathConsumed -= len;
                             tmp = tmp.Next;
                         }while (tmp != dr);
                         if (dr.Key != null)
                         {
                             links.Map.Put(dr.Key, dr);
                         }
                         roots.Put(root, links);
                     }
                     else
                     {
                         if (path == null)
                         {
                             roots.Put(root, FalseEntry);
                         }
                     }
                 }
                 else
                 {
                     if (links == FalseEntry)
                     {
                         links = null;
                     }
                 }
                 if (links != null)
                 {
                     string link = "\\";
                     dr = (DfsReferral)links.Map.Get(link);
                     if (dr != null && now > dr.Expiration)
                     {
                         //Sharpen.Collections.Remove(links.map, link);
                         links.Map.Remove(link);
                         dr = null;
                     }
                     if (dr == null)
                     {
                         if (trans == null)
                         {
                             if ((trans = GetDc(domain, auth)) == null)
                             {
                                 return(null);
                             }
                         }
                         dr = GetReferral(trans, domain, root, path, auth);
                         if (dr != null)
                         {
                             dr.PathConsumed -= 1 + domain.Length + 1 + root.Length;
                             dr.Link          = link;
                             links.Map.Put(link, dr);
                         }
                     }
                 }
             }
         }
         if (dr == null && path != null)
         {
             if (Referrals != null && now > Referrals.Expiration)
             {
                 Referrals = null;
             }
             if (Referrals == null)
             {
                 Referrals = new CacheEntry(0);
             }
             string key = "\\" + domain + "\\" + root;
             if (path.Equals("\\") == false)
             {
                 key += path;
             }
             key = key.ToLower();
             //ListIterator<object> iter = new ListIterator<object>(referrals.map.Keys.GetEnumerator(), 0);
             foreach (var current in Referrals.Map.Keys)
             {
                 string _key  = (string)current;
                 int    klen  = _key.Length;
                 bool   match = false;
                 if (klen == key.Length)
                 {
                     match = _key.Equals(key);
                 }
                 else
                 {
                     if (klen < key.Length)
                     {
                         match = _key.RegionMatches(false, 0, key, 0, klen) && key[klen] == '\\';
                     }
                 }
                 if (match)
                 {
                     dr = (DfsReferral)Referrals.Map.Get(_key);
                 }
             }
         }
         return(dr);
     }
 }
예제 #55
0
        private object AssembleCacheEntry(CacheEntry entry, object id, IEntityPersister persister, LoadEvent @event)
        {
            object       optionalObject        = @event.InstanceToLoad;
            IEventSource session               = @event.Session;
            ISessionFactoryImplementor factory = session.Factory;

            if (log.IsDebugEnabled())
            {
                log.Debug("assembling entity from second-level cache: {0}", MessageHelper.InfoString(persister, id, factory));
            }

            IEntityPersister subclassPersister = factory.GetEntityPersister(entry.Subclass);
            object           result            = optionalObject ?? session.Instantiate(subclassPersister, id);

            // make it circular-reference safe
            EntityKey entityKey = session.GenerateEntityKey(id, subclassPersister);

            TwoPhaseLoad.AddUninitializedCachedEntity(entityKey, result, subclassPersister, LockMode.None, entry.AreLazyPropertiesUnfetched, entry.Version, session);

            IType[]  types  = subclassPersister.PropertyTypes;
            object[] values = entry.Assemble(result, id, subclassPersister, session.Interceptor, session);             // intializes result by side-effect
            TypeHelper.DeepCopy(values, types, subclassPersister.PropertyUpdateability, values, session);

            object version = Versioning.GetVersion(values, subclassPersister);

            if (log.IsDebugEnabled())
            {
                log.Debug("Cached Version: {0}", version);
            }

            IPersistenceContext persistenceContext = session.PersistenceContext;
            bool isReadOnly = session.DefaultReadOnly;

            if (persister.IsMutable)
            {
                object proxy = persistenceContext.GetProxy(entityKey);
                if (proxy != null)
                {
                    // this is already a proxy for this impl
                    // only set the status to read-only if the proxy is read-only
                    isReadOnly = ((INHibernateProxy)proxy).HibernateLazyInitializer.ReadOnly;
                }
            }
            else
            {
                isReadOnly = true;
            }

            persistenceContext.AddEntry(
                result,
                isReadOnly ? Status.ReadOnly : Status.Loaded,
                values,
                null,
                id,
                version,
                LockMode.None,
                true,
                subclassPersister,
                false,
                entry.AreLazyPropertiesUnfetched);

            subclassPersister.AfterInitialize(result, entry.AreLazyPropertiesUnfetched, session);
            persistenceContext.InitializeNonLazyCollections();
            // upgrade the lock if necessary:
            //lock(result, lockMode);

            //PostLoad is needed for EJB3
            //TODO: reuse the PostLoadEvent...
            PostLoadEvent postLoadEvent = new PostLoadEvent(session);

            postLoadEvent.Entity    = result;
            postLoadEvent.Id        = id;
            postLoadEvent.Persister = persister;

            IPostLoadEventListener[] listeners = session.Listeners.PostLoadEventListeners;
            for (int i = 0; i < listeners.Length; i++)
            {
                listeners[i].OnPostLoad(postLoadEvent);
            }
            return(result);
        }
    public Windows8x(byte[] rawBytes, AppCompatCache.OperatingSystemVersion os, int controlSet)
    {
        Entries = new List <CacheEntry>();

        var index = 128;

        var signature = "00ts";

        ControlSet = controlSet;

        EntryCount = -1;

        if (os == AppCompatCache.OperatingSystemVersion.Windows81_Windows2012R2)
        {
            signature = "10ts";
        }

        var position = 0;

        while (index < rawBytes.Length)
        {
            try
            {
                var ce = new CacheEntry
                {
                    Signature = Encoding.ASCII.GetString(rawBytes, index, 4)
                };

                if (ce.Signature != signature)
                {
                    break;
                }

                index += 4;

                // skip 4 unknown
                index += 4;

                var ceDataSize = BitConverter.ToUInt32(rawBytes, index);
                index += 4;

                ce.PathSize = BitConverter.ToUInt16(rawBytes, index);
                index      += 2;

                ce.Path = Encoding.Unicode.GetString(rawBytes, index, ce.PathSize).Replace(@"\??\", "");
                index  += ce.PathSize;

                var packageLen = BitConverter.ToUInt16(rawBytes, index);
                index += 2;
                //skip package data
                index += packageLen;

                // skip 4 unknown (insertion flags?)
                ce.InsertFlags = (AppCompatCache.InsertFlag)BitConverter.ToInt32(rawBytes, index);
                index         += 4;

                // skip 4 unknown (shim flags?)
                index += 4;

                ce.LastModifiedTimeUTC =
                    DateTimeOffset.FromFileTime(BitConverter.ToInt64(rawBytes, index)).ToUniversalTime();

                if (ce.LastModifiedTimeUTC.Value.Year == 1601)
                {
                    ce.LastModifiedTimeUTC = null;
                }

                index += 8;

                ce.DataSize = BitConverter.ToInt32(rawBytes, index);
                index      += 4;

                ce.Data = rawBytes.Skip(index).Take(ce.DataSize).ToArray();
                index  += ce.DataSize;

                if ((ce.InsertFlags & AppCompatCache.InsertFlag.Executed) == AppCompatCache.InsertFlag.Executed)
                {
                    ce.Executed = AppCompatCache.Execute.Yes;
                }
                else
                {
                    ce.Executed = AppCompatCache.Execute.No;
                }

                ce.ControlSet = controlSet;

                ce.CacheEntryPosition = position;

                Entries.Add(ce);
                position += 1;
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error parsing cache entry. Position: {Position} Index: {Index}, Error: {Message} ", position, index, ex.Message);

                //TODO report this
                //take what we can get
                break;
            }
        }
    }
예제 #57
0
        /// <summary>
        /// Serialize the example.
        /// </summary>
        /// <param name="example">The example to serialize.</param>
        /// <param name="label">The label to be serialized.</param>
        /// <param name="index">The optional index of the example, the <paramref name="label"/> should be attributed to.</param>
        /// <returns>The serialized example.</returns>
        /// <remarks>If <typeparamref name="TExample"/> is annotated using the Cachable attribute, examples are returned from cache.</remarks>
        public VowpalWabbitExample Serialize(TExample example, ILabel label = null, int?index = null)
        {
            Contract.Requires(example != null);
            Contract.Requires(index == null);

            if (this.exampleCache == null || label != null)
            {
                using (var context = new VowpalWabbitMarshalContext(vw))
                {
                    this.serializerFunc(context, example, label);

                    var vwExample = context.ExampleBuilder.CreateExample();

                    if (this.EnableStringExampleGeneration)
                    {
                        vwExample.VowpalWabbitString = context.ToString();
                    }

                    return(vwExample);
                }
            }

            CacheEntry result;

            if (this.exampleCache.TryGetValue(example, out result))
            {
                result.LastRecentUse = DateTime.UtcNow;

#if DEBUG
                if (result.InUse)
                {
                    throw new ArgumentException("Cached example already in use.");
                }
#endif
            }
            else
            {
                VowpalWabbitExample nativeExample = null;

                try
                {
                    using (var context = new VowpalWabbitMarshalContext(this))
                    {
                        this.serializerFunc(context, example, label);
                        nativeExample = context.ExampleBuilder.CreateExample();
                    }

                    result = new CacheEntry
                    {
                        Example       = nativeExample,
                        LastRecentUse = DateTime.UtcNow
                    };

                    this.exampleCache.Add(example, result);

#if DEBUG
                    this.reverseLookup.Add(result.Example, result);
#endif
                }
                catch (Exception e)
                {
                    if (nativeExample != null)
                    {
                        nativeExample.Dispose();
                    }

                    throw e;
                }
            }

#if DEBUG
            result.InUse = true;
#endif

            // TODO: support Label != null here and update cached example using new label
            return(result.Example);
        }
예제 #58
0
        public ReaderResultSet GetRecordSet(string readerId, int nextIndex, bool inproc, OperationContext context)
        {
            ReaderResultSet      readerChunk      = null;
            IRecordSet           partialRecordSet = null;
            ReaderResultSet      reader           = null;
            RecordRow            row      = null;
            CacheEntry           entry    = null;
            CompressedValueEntry cmpEntry = null;
            int size = 0;

            try
            {
                if (!string.IsNullOrEmpty(readerId))
                {
                    if (_readers.ContainsKey(readerId))
                    {
                        reader = _readers[readerId];
                    }
                }
                if (reader != null)
                {
                    if (nextIndex != 0 && reader.RecordSet.SubsetInfo.LastAccessedRowID == nextIndex)
                    {
                        reader.RecordSet.RemoveRows(reader.RecordSet.SubsetInfo.StartIndex, nextIndex - reader.RecordSet.SubsetInfo.StartIndex);
                    }

                    if (reader.RecordSet.RowCount > 0)
                    {
                        readerChunk           = new ReaderResultSet();
                        reader.LastAccessTime = DateTime.Now;
                        partialRecordSet      = new RecordSet(reader.RecordSet.GetColumnMetaData());
                        int chunkSize = reader.ChunkSize;
                        reader.RecordSet.SubsetInfo.StartIndex = nextIndex;

                        int nextRowID = nextIndex;
                        while (size <= chunkSize)
                        {
                            row = reader.RecordSet.GetRow(nextRowID++);
                            if (row == null)
                            {
                                break;
                            }
                            row = row.Clone() as RecordRow;
                            if (reader.GetData && !reader.IsGrouped)
                            {
                                entry           = _context.CacheImpl.Get(row.GetColumnValue(QueryKeyWords.KeyColumn), context);
                                row.IsSurrogate = entry != null && entry.IsSurrogate;

                                if (entry != null && !entry.IsSurrogate)
                                {
                                    if (inproc)
                                    {
                                        row.SetColumnValue(QueryKeyWords.ValueColumn, entry.Value);
                                    }
                                    else
                                    {
                                        cmpEntry       = new CompressedValueEntry();
                                        cmpEntry.Value = entry.Value;
                                        if (cmpEntry.Value is CallbackEntry)
                                        {
                                            cmpEntry.Value = ((CallbackEntry)cmpEntry.Value).Value;
                                        }

                                        cmpEntry.Flag = ((CacheEntry)entry).Flag;
                                        row.SetColumnValue(QueryKeyWords.ValueColumn, cmpEntry);
                                    }

                                    size += entry.Size;
                                }



                                if (entry != null)
                                {
                                    if (entry.IsSurrogate)
                                    {
                                        size += 1024;
                                    }

                                    partialRecordSet.AddRow(row);
                                    size += row.GetSize();
                                }
                            }
                            else
                            {
                                partialRecordSet.AddRow(row);
                                size += row.GetSize();
                            }
                        }

                        //Value column has been filled if getData is true
                        if (reader.GetData && !reader.IsGrouped)
                        {
                            reader.RecordSet.GetColumnMetaData()[QueryKeyWords.ValueColumn].IsFilled = true;
                        }

                        reader.RecordSet.SubsetInfo.LastAccessedRowID += partialRecordSet.RowCount;
                        readerChunk.RecordSet = partialRecordSet;
                        readerChunk.NextIndex = reader.RecordSet.SubsetInfo.LastAccessedRowID;

                        if (!inproc)
                        {
                            readerChunk.NodeAddress = GetReciepent();
                        }

                        readerChunk.OrderByArguments = reader.OrderByArguments;
                        readerChunk.IsGrouped        = reader.IsGrouped;
                        readerChunk.ReaderID         = reader.ReaderID;
                    }
                    else
                    {
                        DisposeReader(reader.ReaderID);
                    }
                }

                return(readerChunk);
            }
            catch (Exception ex)
            {
                if (ex is InvalidReaderException)
                {
                    DisposeReader(reader.ReaderID);
                }
                throw;
            }
        }
예제 #59
0
        private void AddChildrenRecursive(string directory, int depth, string[] entries)
        {
            for (int i = 0; i < entries.Length; i++)
            {
                string entry = entries[i];
                if (string.IsNullOrEmpty(entry))
                {
                    continue;
                }

                int          instanceID  = GetInstanceIDFromPath(entry);
                string       displayName = Path.GetFileNameWithoutExtension(entry);
                TreeViewItem item        = null;
                if (!isSearching || textComparer.IndexOf(displayName, searchString, textCompareOptions) >= 0)
                {
                    item = new TreeViewItem(instanceID, !isSearching ? depth : 0, displayName)
                    {
                        icon = AssetDatabase.GetCachedIcon(entry) as Texture2D
                    };
                    rows.Add(item);
                }

                if (Directory.Exists(entry))
                {
                    if (isSearching || IsExpanded(instanceID))
                    {
                        string[] entries2;
                        if (FolderHasEntries(entry, out entries2))
                        {
                            AddChildrenRecursive(entry, depth + 1, entries2);
                        }
                    }
                    else if (FolderHasEntries(entry))
                    {
                        item.children = CreateChildListForCollapsedParent();
                    }
                }
                else
                {
                    CacheEntry cacheEntry  = GetCacheEntry(instanceID, entry);
                    int[]      childAssets = cacheEntry.ChildIDs;
                    if (childAssets.Length > 0)
                    {
                        if (isSearching || IsExpanded(instanceID))
                        {
                            string[]    childNames      = cacheEntry.ChildNames;
                            Texture2D[] childThumbnails = cacheEntry.ChildThumbnails;

                            if (!isSearching)
                            {
                                for (int j = 0; j < childAssets.Length; j++)
                                {
                                    rows.Add(new TreeViewItem(childAssets[j], depth + 1, childNames[j])
                                    {
                                        icon = childThumbnails[j]
                                    });
                                }
                            }
                            else
                            {
                                for (int j = 0; j < childAssets.Length; j++)
                                {
                                    if (textComparer.IndexOf(childNames[j], searchString, textCompareOptions) >= 0)
                                    {
                                        rows.Add(new TreeViewItem(childAssets[j], 0, childNames[j])
                                        {
                                            icon = childThumbnails[j]
                                        });
                                    }
                                }
                            }
                        }
                        else
                        {
                            item.children = CreateChildListForCollapsedParent();
                        }
                    }
                }
            }
        }
예제 #60
0
 public override void ResetLeasable()
 {
     _result = CacheInsResult.Success;
     _entry  = null;
 }