示例#1
0
        public SignalCharting(ISignalChart chartControl, TickerType tickerType, BarItemType barType, object dataStreamSource)
        {
            this.dataStreamSource    = dataStreamSource;
            this.tickerType          = tickerType;
            this.barType             = barType;
            this.chartControl        = chartControl;
            this.registeredAnalytics = new List <AnalyticsItem>();

            SharedCacheFactory.Instance.CacheWriter = new FileCacheWriter("cache");
            SharedCacheFactory.Instance.CacheReader = new FileCacheReader("cache");

            if (dataStreamSource is string)
            {
                FileInfo    file        = new FileInfo(dataStreamSource.ToString());
                long        fileHash    = file.Attributes.GetHashCode() ^ file.CreationTime.Ticks ^ file.LastWriteTime.Ticks ^ file.Length;
                CacheConfig cacheConfig = new CacheConfig("cache");
                cacheConfig.Initialize();
                cacheConfig.Open(CachingModeOption.Reading);
                CacheRow row = cacheConfig.Read(fileHash);
                cacheConfig.Close();

                if (row == null)
                {
                    cacheConfig.Open(CachingModeOption.Writing);
                    cacheId = Guid.NewGuid();
                    cacheConfig.Append(fileHash, cacheId, SessionModeOption.Backtesting);
                    cacheConfig.Close();
                }
                else
                {
                    cacheId = new Guid((byte[])row["SessionId"]);
                }
            }
        }
示例#2
0
        public BarItem[] SelectBars(DateTime targetDate, int frameSize)
        {
            BarItem[] bars = null;

            if (this.Indexed)
            {
                long closestRowNumber = ClosestLowerTargetRowNumber(targetDate);

                int  halfFrame = frameSize / 2;
                long targetRow = closestRowNumber - halfFrame > 0 ? closestRowNumber - halfFrame : 0;
                long rowCount  = targetRow + Math.Max(this.rowsPerIndex, frameSize) + halfFrame;

                CacheRow[] cacheRows = this.Select(targetRow, rowCount);

                int startIndex = 0;
                int endIndex   = 0;
                FindStartEndIndexes(cacheRows, targetDate, frameSize, ref startIndex, ref endIndex);

                bars = new BarItem[endIndex - startIndex + 1];
                int barIndex = 0;
                for (int filterIndex = startIndex; filterIndex <= endIndex; filterIndex++)
                {
                    CacheRow cacheRow = cacheRows[filterIndex];
                    bars[barIndex] = new BarItem(new DateTime((long)cacheRow[0]), (double)cacheRow[1], (double)cacheRow[2], (double)cacheRow[3], (double)cacheRow[4]);
                    barIndex++;
                }
            }

            return(bars);
        }
示例#3
0
        public CacheRow Find(string identityCode, string searchKey)
        {
            CacheRow cacheRow      = null;
            long     lastRowNumber = 0;

            if (binaryFiles.ContainsKey(identityCode))
            {
                BinaryNavigator navigator = binaryFiles[identityCode].Navigator;
                navigator.MoveToFirst();
                object[] row   = null;
                bool     found = false;
                while (!navigator.EOF())
                {
                    lastRowNumber = navigator.RowNumber;
                    row           = navigator.Read();
                    if (((long)row[0]).ToString() == searchKey)
                    {
                        found = true;
                        break;
                    }
                }

                if (found)
                {
                    cacheRow = new CacheRow(binaryFiles[identityCode].Header.Columns, lastRowNumber, row);
                }
            }

            return(cacheRow);
        }
        private void addAddressToCache(int address)
        {
            int rowNumber = (address / (BytesPerBlock)) % NumberOfRows;
            int tag       = address / (BytesPerBlock * NumberOfRows);

            CacheRow row = Cache[rowNumber];

            //Removes The Tag From The Queue If It Is There So It Can Be At The End Of The Queue;
            for (int i = 0; i < row.CacheSet.Count; i++)
            {
                int cacheTag = row.CacheSet.Dequeue();
                if (cacheTag == tag)
                {
                    continue;
                }
                row.CacheSet.Enqueue(cacheTag);
            }

            // Forgets About The Least Used Tag From The Cache Set
            if (row.CacheSet.Count == SetsPerRow)
            {
                row.CacheSet.Dequeue();
            }

            // Adds Tag To The Cache Set As The Last Used Item
            row.CacheSet.Enqueue(tag);

            Cache[rowNumber] = row;
        }
示例#5
0
        public Dictionary <long, long> CreateIndex()
        {
            cache.OpenForReading();

            lastRowCount = cache.GetRowCount();

            rowsPerIndex = lastRowCount / 1000;

            Dictionary <long, long> cacheIndex = new Dictionary <long, long>();

            if (rowsPerIndex < 10)
            {
                CacheRow cacheRow = cache.Select(0)[0];
                cacheIndex.Add((long)cacheRow[0], cacheRow.RowNumber);
                cacheRow = cache.NextItem();
                while (cacheRow != null)
                {
                    cacheIndex.Add((long)cacheRow[0], cacheRow.RowNumber);
                    cacheRow = cache.NextItem();
                }
            }
            else
            {
                for (int indexCount = 0; indexCount < rowsPerIndex; indexCount++)
                {
                    CacheRow[] cacheRow = cache.Select(indexCount * rowsPerIndex);
                    if (cacheRow != null)
                    {
                        cacheIndex.Add((long)cacheRow[0][0], cacheRow[0].RowNumber);
                    }
                }
            }

            return(cacheIndex.Count > 0 ? cacheIndex : null);
        }
        private bool tagIsInCacheRow(int tag, CacheRow row)
        {
            foreach (int cacheTag in row.CacheSet)
            {
                if (tag == cacheTag)
                {
                    return(true);
                }
            }

            return(false);
        }
        public override bool getMem(int address)
        {
            int rowNumber = (address / (BytesPerBlock)) % NumberOfRows;
            int tag       = address / (BytesPerBlock * NumberOfRows);

            CacheRow possibleCacheRow = Cache[rowNumber];

            bool isCacheHit = tagIsInCacheRow(tag, possibleCacheRow);

            addAddressToCache(address);

            string stringAddress   = toBin(address, 16);
            string stringRowNumber = toBin(rowNumber, ceilLog2(NumberOfRows));
            string stringTag       = toBin(tag, 16 - ceilLog2(NumberOfRows) - ceilLog2(BytesPerBlock));

            return(isCacheHit);
        }
示例#8
0
        Convert(
            PackageId packageId,
            CacheRow cacheRow)
        {
            RestoredCommandIdentifier restoredCommandIdentifier =
                new RestoredCommandIdentifier(
                    packageId,
                    NuGetVersion.Parse(cacheRow.Version),
                    NuGetFramework.Parse(cacheRow.TargetFramework),
                    cacheRow.RuntimeIdentifier,
                    new ToolCommandName(cacheRow.Name));

            RestoredCommand restoredCommand =
                new RestoredCommand(
                    new ToolCommandName(cacheRow.Name),
                    cacheRow.Runner,
                    new FilePath(cacheRow.PathToExecutable));

            return(restoredCommandIdentifier, restoredCommand);
        }
示例#9
0
        Convert(
            PackageId packageId,
            CacheRow cacheRow,
            DirectoryPath nuGetGlobalPackagesFolder)
        {
            RestoredCommandIdentifier restoredCommandIdentifier =
                new RestoredCommandIdentifier(
                    packageId,
                    NuGetVersion.Parse(cacheRow.Version),
                    NuGetFramework.Parse(cacheRow.TargetFramework),
                    cacheRow.RuntimeIdentifier,
                    new ToolCommandName(cacheRow.Name));

            RestoredCommand restoredCommand =
                new RestoredCommand(
                    new ToolCommandName(cacheRow.Name),
                    cacheRow.Runner,
                    nuGetGlobalPackagesFolder
                    .WithFile(cacheRow.RelativeToNuGetGlobalPackagesFolderPathToDll));

            return(restoredCommandIdentifier, restoredCommand);
        }
示例#10
0
        public CacheRow Read(long datafeedHashKey)
        {
            CacheRow cacheRow = cacheReader.Find(CACHE_CONFIG_FILE, datafeedHashKey.ToString());

            return(cacheRow);
        }