Пример #1
0
 internal PolarStereographicProjectionGridDefinition(BufferedBinaryReader reader) : base(reader)
 {
     Lad = reader.ReadInt32() * 1e-6;
     Lov = reader.ReadUInt32() * 1e-6;
     Dx  = reader.ReadUInt32() * 1e-3;
     Dy  = reader.ReadUInt32() * 1e-3;
     ProjectionCenter = reader.ReadUInt8();
     ScanMode         = reader.ReadUInt8();
 }
Пример #2
0
        private static object ReadValue(BufferedBinaryReader reader, SystemTypeCode type)
        {
            switch (type)
            {
            case SystemTypeCode.Boolean:
                return(reader.ReadBoolean());

            case SystemTypeCode.Int8:
                return(reader.ReadInt8());

            case SystemTypeCode.UInt8:
                return(reader.ReadUInt8());

            case SystemTypeCode.Int16:
                return(reader.ReadInt16());

            case SystemTypeCode.UInt16:
                return(reader.ReadUInt16());

            case SystemTypeCode.Int32:
                return(reader.ReadInt32());

            case SystemTypeCode.UInt32:
                return(reader.ReadUInt32());

            case SystemTypeCode.Int64:
                return(reader.ReadInt64());

            case SystemTypeCode.UInt64:
                return(reader.ReadUInt64());

            case SystemTypeCode.Single:
                return(reader.ReadSingle());

            case SystemTypeCode.Double:
                return(reader.ReadDouble());

            case SystemTypeCode.Decimal:
                throw new NotImplementedException();

            case SystemTypeCode.DateTime:
                throw new NotImplementedException();

            case SystemTypeCode.Char:
                return(reader.ReadChar());

            case SystemTypeCode.String:
                return(reader.ReadCountedUtf8());

            case SystemTypeCode.Enum:
                throw new NotImplementedException();

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #3
0
        private void ReadData()
        {
            var path = PathResolver.UserMatrixOutputProcessed;

            _list = new List <Tuple <int, List <int> > >();
            using (var reader = new BufferedBinaryReader(path))
            {
                while (reader.PeekChar() > -1)
                {
                    int currentUser = reader.ReadInt32();
                    var usersList   = new List <int>();
                    for (int i = reader.ReadInt32(); i > 0; i--)
                    {
                        int userId = reader.ReadInt32();
                        usersList.Add(userId);
                    }
                    _list.Add(new Tuple <int, List <int> >(currentUser, usersList));
                }
            }
        }
Пример #4
0
        public ThumbnailBlock(BufferedBinaryReader br)
        {
            this.width             = br.ReadInt32();
            this.height            = br.ReadInt32();
            this.bitDepth          = br.ReadUInt16();
            this.compressionType   = (PSPCompression)br.ReadUInt16();
            this.planeCount        = br.ReadUInt16();
            this.colorCount        = br.ReadUInt32();
            this.paletteEntryCount = br.ReadUInt32();
            this.channelCount      = br.ReadUInt16();

            this.channelBlocks = new ChannelSubBlock[this.channelCount];

            int index = 0;

            do
            {
                uint blockSig = br.ReadUInt32();
                if (blockSig != PSPConstants.blockIdentifier)
                {
                    throw new System.FormatException(Properties.Resources.InvalidBlockSignature);
                }
                PSPBlockID blockType = (PSPBlockID)br.ReadUInt16();
#pragma warning disable IDE0059 // Value assigned to symbol is never used
                uint chunkLength = br.ReadUInt32();
#pragma warning restore IDE0059 // Value assigned to symbol is never used

                switch (blockType)
                {
                case PSPBlockID.ColorPalette:
                    this.paletteSubBlock = new ColorPaletteBlock(br, PSPConstants.majorVersion5);
                    break;

                case PSPBlockID.Channel:
                    ChannelSubBlock block = new ChannelSubBlock(br, this.compressionType, PSPConstants.majorVersion5);
                    this.channelBlocks[index] = block;
                    index++;
                    break;
                }
            }while (index < this.channelCount);
        }
Пример #5
0
		private object ReadArray(BufferedBinaryReader reader, IType elemType)
		{
			Array arr = null;
			int n = reader.ReadInt32();
			for (int i = 0; i < n; ++i)
			{
				var val = ReadValue(reader, elemType);
				if (arr == null)
					arr = Array.CreateInstance(val.GetType(), n);
				arr.SetValue(val, i);
			}
			return arr;
		}
        internal GaussianLatLonGridDefinition(BufferedBinaryReader reader) : base(reader)
        {
            Angle             = reader.ReadUInt32();
            Subdivisionsangle = reader.ReadUInt32();
            if (Angle == 0)
            {
                Ratio = 1e-6;
            }
            else
            {
                Ratio = Angle / (double)Subdivisionsangle;
            }

            La1        = reader.ReadInt32() * Ratio;
            Lo1        = reader.ReadInt32() * Ratio;
            Resolution = reader.ReadUInt8();
            La2        = reader.ReadUInt32() * Ratio;
            Lo2        = reader.ReadUInt32() * Ratio;
            Dx         = reader.ReadUInt32() * Ratio;
            N          = reader.ReadUInt32();
            ScanMode   = reader.ReadUInt8();
        }
Пример #7
0
 internal TriangularGridBasedOnAnIcosahedronGridDefinition(BufferedBinaryReader reader) : base(reader)
 {
     N2          = reader.ReadUInt8();
     N3          = reader.ReadUInt8();
     Ni          = reader.ReadUInt16();
     Nd          = reader.ReadUInt8();
     PoleLat     = reader.ReadInt32() * 1e-6f;
     PoleLon     = reader.ReadUInt32() * 1e-6f;
     Lonofcenter = reader.ReadUInt32();
     Position    = reader.ReadUInt8();
     Order       = reader.ReadUInt8();
     ScanMode    = reader.ReadUInt8();
     N           = reader.ReadUInt32();
 }
Пример #8
0
        private static object ReadValue(ElementType type, BufferedBinaryReader reader)
        {
            switch (type)
            {
            case ElementType.Boolean:
                return(reader.ReadBoolean());

            case ElementType.Char:
                return(reader.ReadChar());

            case ElementType.Int8:
                return(reader.ReadSByte());

            case ElementType.UInt8:
                return(reader.ReadByte());

            case ElementType.Int16:
                return(reader.ReadInt16());

            case ElementType.UInt16:
                return(reader.ReadUInt16());

            case ElementType.Int32:
                return(reader.ReadInt32());

            case ElementType.UInt32:
                return(reader.ReadUInt32());

            case ElementType.Int64:
                return(reader.ReadInt64());

            case ElementType.UInt64:
                return(reader.ReadUInt64());

            case ElementType.Single:
                return(reader.ReadSingle());

            case ElementType.Double:
                return(reader.ReadDouble());

            case ElementType.String:
                return(Encoding.Unicode.GetString(reader.ToArray()));

            case ElementType.Class:
                return(null);

            default:
                return(reader.ToArray());
            }
        }
Пример #9
0
 internal SpaceViewPerspectiveOrOrthographicGridDefinition(BufferedBinaryReader reader) : base(reader)
 {
     Lap        = reader.ReadInt32();
     Lop        = reader.ReadUInt32();
     Resolution = reader.ReadUInt8();
     Dx         = reader.ReadUInt32();
     Dy         = reader.ReadUInt32();
     Xp         = reader.ReadUInt32() * 1e-3f;
     Yp         = reader.ReadUInt32() * 1e-3f;
     ScanMode   = reader.ReadUInt8();
     Angle      = reader.ReadUInt32();
     Altitude   = reader.ReadUInt32() * 1_000_000;
     Xo         = reader.ReadUInt32();
     Yo         = reader.ReadUInt32();
 }
Пример #10
0
        public DatabaseHeader(ref BufferedBinaryReader reader)
        {
            byte versionInfo = reader.ReadByte();

            Level                 = (EDatabaseLevel)(versionInfo & 0b0000_0111);
            Version               = (EDatabaseVersion)(versionInfo & 0b1111_1000);
            UpdateYear            = reader.ReadByte();
            UpdateMonth           = reader.ReadByte();
            UpdateDay             = reader.ReadByte();
            RecordCount           = reader.ReadInt32();
            HeaderLength          = reader.ReadInt16();
            RecordLength          = reader.ReadInt16();
            Reserved01            = reader.ReadBytes(2);
            IncompleteTransaction = reader.ReadByte();
            EncryptionFlag        = reader.ReadByte();
            Reserved02            = reader.ReadBytes(12);
            TableFlags            = (ETableFlags)reader.ReadByte();
            LanguageDriverId      = reader.ReadByte();
            EndOfHeaderMarker     = reader.ReadInt16();
        }
Пример #11
0
 public SEHBlock(BufferedBinaryReader reader, bool fatFormat)
 {
     if (fatFormat)
     {
         Flags         = (SEHFlags)reader.ReadInt32();
         TryOffset     = reader.ReadInt32();
         TryLength     = reader.ReadInt32();
         HandlerOffset = reader.ReadInt32();
         HandlerLength = reader.ReadInt32();
         Value         = reader.ReadInt32();
     }
     else
     {
         Flags         = (SEHFlags)reader.ReadInt16();
         TryOffset     = reader.ReadInt16();
         TryLength     = reader.ReadByte();
         HandlerOffset = reader.ReadInt16();
         HandlerLength = reader.ReadByte();
         Value         = reader.ReadInt32();
     }
 }
        public void Reset()
        {
            const string s             = "The quick brown fox jumped over the lazy dog.";
            string       expectedValue = s.Substring(4);
            string       observedValue;
            long         observedBufferPosition;
            byte         observedByte;

            using (var memoryStream = new MemoryStream())
            {
                using (var writer = new ExtendedBinaryWriter(memoryStream, Encoding.UTF8, true))
                {
                    writer.Write(Encoding.ASCII.GetBytes(s));
                }

                memoryStream.Position = 0;

                using (var reader = new BufferedBinaryReader(memoryStream))
                {
                    reader.ReadInt32();
                    observedBufferPosition = reader.BufferPosition;

                    reader.BufferPosition = 2;
                    observedByte          = reader.ReadByte();

                    memoryStream.Position = 4;
                    reader.Reset();

                    var bytes = reader.ReadBytes(s.Length - 4);
                    observedValue = Encoding.ASCII.GetString(bytes);
                }
            }

            Assert.Equal(expectedValue, observedValue);
            Assert.Equal((byte)'e', observedByte);
            Assert.Equal(4, observedBufferPosition);
        }
Пример #13
0
        internal ProductDefinition0000(BufferedBinaryReader reader, Discipline discipline) : base(
                reader, discipline)
        {
            GeneratingProcessIdentifier = reader.ReadUInt8();
            HoursAfter              = reader.ReadUInt16();
            MinutesAfter            = reader.ReadUInt8();
            ObservationalDataCutoff = TimeSpan.FromHours(HoursAfter) + TimeSpan.FromMinutes(MinutesAfter);
            TimeRangeUnit           = (TimeRangeUnit)reader.ReadUInt8();
            ForecastTime            = reader.ReadInt32();

            FirstFixedSurfaceType  = (FixedSurfaceType)reader.ReadUInt8();
            FirstFixedSurfaceValue = reader.ReadScaledValue();

            SecondFixedSurfaceType  = (FixedSurfaceType)reader.ReadUInt8();
            SecondFixedSurfaceValue = reader.ReadScaledValue();

            RegisterContent(ProductDefinitionContent.GeneratingProcessId, () => GeneratingProcessIdentifier);
            RegisterContent(ProductDefinitionContent.ObservationalDataCutoff, () => ObservationalDataCutoff);
            var forecastTime = CalculateTimeRangeFrom(TimeRangeUnit, ForecastTime);

            if (forecastTime.HasValue)
            {
                RegisterContent(ProductDefinitionContent.ForecastTime, () => forecastTime.Value);
            }

            RegisterContent(ProductDefinitionContent.FirstFixedSurfaceType, () => FirstFixedSurfaceType);
            if (FirstFixedSurfaceValue.HasValue)
            {
                RegisterContent(ProductDefinitionContent.FirstFixedSurfaceValue, () => FirstFixedSurfaceValue.Value);
            }
            RegisterContent(ProductDefinitionContent.SecondFixedSurfaceType, () => SecondFixedSurfaceType);
            if (SecondFixedSurfaceValue.HasValue)
            {
                RegisterContent(ProductDefinitionContent.SecondFixedSurfaceValue, () => SecondFixedSurfaceValue.Value);
            }
        }
Пример #14
0
        internal LatLonGridDefinition(BufferedBinaryReader reader) : base(reader)
        {
            Angle             = reader.ReadUInt32();
            SubdivisionsAngle = reader.ReadUInt32();
            double ratio;

            if (Angle == 0)
            {
                ratio = 1e-6;
            }
            else
            {
                ratio = Angle / (double)SubdivisionsAngle;
            }

            La1 = reader.ReadInt32() * ratio;
            Lo1 = reader.ReadInt32() * ratio;
            ResolutionAndComponent = (ResolutionAndComponent)reader.ReadUInt8();
            La2      = reader.ReadInt32() * ratio;
            Lo2      = reader.ReadInt32() * ratio;
            Dx       = reader.ReadInt32() * ratio;
            Dy       = reader.ReadInt32() * ratio;
            ScanMode = reader.ReadUInt8();
        }
Пример #15
0
 internal StretchedRotatedGaussianLatLonGridDefinition(BufferedBinaryReader reader) : base(reader)
 {
     PoleLat = reader.ReadInt32() * Ratio;
     PoleLon = reader.ReadUInt32() * Ratio;
     Factor  = reader.ReadUInt32();
 }
Пример #16
0
 internal RotatedSphericalHarmonicCoefficientsGridDefinition(BufferedBinaryReader reader) : base(reader)
 {
     SpLat         = reader.ReadInt32() * 1e-6f;
     SpLon         = reader.ReadUInt32() * 1e-6f;
     Rotationangle = reader.ReadUInt32();
 }
Пример #17
0
        /// <summary>
        /// Загрузка базы данных в память
        /// </summary>
        /// <returns></returns>
        public void Load()
        {
            string      filePath = Path.Combine(_environment.ContentRootPath, _dbFileName);
            BinGeoModel binModel;

            using (FileStream stream = new FileStream(filePath, FileMode.Open))
            {
                Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();

                using (BufferedBinaryReader bufferedReader = new BufferedBinaryReader(stream, 65536))
                {
                    stopwatch.Start();

                    bufferedReader.FillBuffer();

                    int    version         = bufferedReader.ReadInt32();
                    byte[] nameBytes       = bufferedReader.Read(0, 32);
                    ulong  timestamp       = bufferedReader.ReadUInt64();
                    int    records         = bufferedReader.ReadInt32();
                    uint   offsetRanges    = bufferedReader.ReadUInt32();
                    uint   offsetCities    = bufferedReader.ReadUInt32();
                    uint   offsetLocations = bufferedReader.ReadUInt32();

                    binModel = new BinGeoModel(version, nameBytes, timestamp, records, offsetRanges, offsetCities, offsetLocations);

                    int currentIndex = 0;
                    binModel.IpRangeCollection = new BinIpRange[binModel.RecordsCount];
                    while (bufferedReader.FillBuffer() && currentIndex < binModel.RecordsCount)
                    {
                        for (; currentIndex < binModel.RecordsCount && bufferedReader.NumBytesAvailable >= IpRangeBytesCount; currentIndex++)
                        {
                            binModel.IpRangeCollection[currentIndex] = new BinIpRange()
                            {
                                IpFrom        = bufferedReader.ReadUInt32(),
                                IpTo          = bufferedReader.ReadUInt32(),
                                LocationIndex = bufferedReader.ReadUInt32()
                            };
                        }
                    }

                    currentIndex = 0;
                    binModel.LocationCollection = new BinLocation[binModel.RecordsCount];
                    while (bufferedReader.FillBuffer() && currentIndex < binModel.RecordsCount)
                    {
                        for (; currentIndex < binModel.RecordsCount && bufferedReader.NumBytesAvailable >= LocationBytesCount; currentIndex++)
                        {
                            byte[] country      = bufferedReader.Read(0, 8);
                            byte[] region       = bufferedReader.Read(0, 12);
                            byte[] postal       = bufferedReader.Read(0, 12);
                            byte[] city         = bufferedReader.Read(0, 24);
                            byte[] organization = bufferedReader.Read(0, 32);
                            float  latitude     = bufferedReader.ReadSingle();
                            float  longitude    = bufferedReader.ReadSingle();

                            binModel.LocationCollection[currentIndex] = new BinLocation(country, region, postal, city, organization, latitude, longitude);
                        }
                    }

                    currentIndex     = 0;
                    binModel.Indexes = new uint[binModel.RecordsCount];
                    while (bufferedReader.FillBuffer() && currentIndex < binModel.RecordsCount)
                    {
                        for (; currentIndex < binModel.RecordsCount && bufferedReader.NumBytesAvailable >= IndexBytesCount; currentIndex++)
                        {
                            binModel.Indexes[currentIndex] = bufferedReader.ReadUInt32();
                        }
                    }

                    stopwatch.Stop();
                    DatabaseLoadedTimeMs = stopwatch.ElapsedMilliseconds;
                    _logger.LogInformation($"Database loading time: {stopwatch.ElapsedMilliseconds} ms");
                }

                // Отображение объектов сущностей двоичной базы в объекты бизнес сущностей
                GeoModel = _mapper.Map <GeoModel>(binModel);
            }
        }
Пример #18
0
        private static void getTopUrls(string input, string output)
        {
            List <Tuple <int, int> > allUrls = new List <Tuple <int, int> >();

            Dictionary <int, int> urlsCount = new Dictionary <int, int>();

            Stopwatch watch = new Stopwatch();

            watch.Start();

            using (BufferedBinaryReader reader = new BufferedBinaryReader(input))
            {
                HashSet <int> processedQueries = new HashSet <int>();

                while (reader.PeekChar() > -1)
                {
                    byte type = reader.ReadByte();

                    int session = reader.ReadInt32();

                    switch (type)
                    {
                    case 0:
                        // DAY
                        reader.ReadInt32();
                        int user = reader.ReadInt32();
                        break;

                    case 1:
                    case 2:
                    {
                        // TIME
                        reader.ReadInt32();
                        // SERPID
                        reader.ReadInt32();
                        // QUERYID
                        int  query_id = reader.ReadInt32();
                        bool process  = !processedQueries.Contains(query_id);
                        if (process)
                        {
                            processedQueries.Add(query_id);
                        }

                        // TERMS
                        int termsN = reader.ReadInt32();
                        for (int i = termsN; i > 0; i--)
                        {
                            int term = reader.ReadInt32();
                        }
                        // URLS & DOMAINS
                        for (int i = reader.ReadInt32(); i > 0; i--)
                        {
                            int url    = reader.ReadInt32();
                            int domain = reader.ReadInt32();
                            if (!process)
                            {
                                continue;
                            }

                            if (urlsCount.ContainsKey(url))
                            {
                                urlsCount[url]++;
                            }
                            else
                            {
                                urlsCount.Add(url, 1);
                            }
                        }
                        break;
                    }

                    case 3:
                    {
                        // TIME
                        reader.ReadInt32();
                        // SERPID
                        reader.ReadInt32();
                        // URLS
                        int url = reader.ReadInt32();
                        break;
                    }
                    }
                }
            }

            // przeniesienie z mapy do listy
            foreach (var element in urlsCount)
            {
                allUrls.Add(new Tuple <int, int>(element.Key, element.Value));
            }
            urlsCount.Clear();
            urlsCount = new Dictionary <int, int>();
            GC.Collect();

            watch.Stop();
            Console.WriteLine("... zakończono po {0} ({1})", watch.ElapsedMilliseconds, allUrls.Count);
            watch.Restart();

            // sortowanie po malejącej liczbie wystąpień
            allUrls.Sort((o1, o2) => { return(o2.Item2 - o1.Item2); });

            watch.Stop();
            Console.WriteLine("Zakończono sortowanie danych po " + watch.ElapsedMilliseconds);
            watch.Restart();

            // zostawienie top 1000 urli
            if (allUrls.Count > 1000)
            {
                allUrls.RemoveRange(1000, allUrls.Count - 1000);
            }

            watch.Stop();
            Console.WriteLine("Wyczyszczono liste po " + watch.ElapsedMilliseconds);
            watch.Restart();

            using (StreamWriter writer = new StreamWriter(output))
            {
                foreach (var element in allUrls)
                {
                    writer.WriteLine(element.Item1 + "\t" + element.Item2);
                }
            }

            watch.Stop();
            Console.WriteLine("Zakończono zapisywanie danych po " + watch.ElapsedMilliseconds);
        }
Пример #19
0
        private static void getTermsFromTop(string logFilename, string topFilename, StreamWriter output)
        {
            const int N = 100;
            List <Tuple <int, int> > terms = new List <Tuple <int, int> >();

            List <int>[]  queries          = new List <int> [N];
            HashSet <int> processedQueries = new HashSet <int>();

            for (int i = 0; i < N; i++)
            {
                queries[i] = new List <int>();
            }

            using (StreamReader reader = new StreamReader(topFilename))
            {
                string[] seps = new string[] { "\t" };

                for (int i = 0; i < N; i++)
                {
                    string   line  = reader.ReadLine();
                    string[] array = line.Split(seps, StringSplitOptions.None);
                    terms.Add(new Tuple <int, int>(Int32.Parse(array[0]), Int32.Parse(array[1])));
                }
            }

            List <int> sortedTerms = new List <int>();

            foreach (var term in terms)
            {
                sortedTerms.Add(term.Item1);
            }

            sortedTerms.Sort();

            using (BufferedBinaryReader reader = new BufferedBinaryReader(logFilename))
            {
                HashSet <int> procesedQueries = new HashSet <int>();

                while (reader.PeekChar() > -1)
                {
                    byte type = reader.ReadByte();

                    int session = reader.ReadInt32();

                    switch (type)
                    {
                    case 0:
                        // DAY
                        reader.ReadInt32();
                        // USER
                        reader.ReadInt32();
                        break;

                    case 1:
                    case 2:
                    {
                        // TIME
                        reader.ReadInt32();
                        // SERPID
                        reader.ReadInt32();
                        // QUERYID
                        int query_id = reader.ReadInt32();

                        bool process = !processedQueries.Contains(query_id);
                        if (process)
                        {
                            processedQueries.Add(query_id);
                        }
                        // TERMS
                        int termsN = reader.ReadInt32();
                        for (int i = termsN; i > 0; i--)
                        {
                            int term = reader.ReadInt32();
                            if (!process)
                            {
                                continue;
                            }

                            for (int index = 0; index < sortedTerms.Count; index++)
                            {
                                if (sortedTerms[index] > term)
                                {
                                    break;
                                }

                                if (sortedTerms[index] == term)
                                {
                                    queries[index].Add(query_id);
                                }
                            }
                        }
                        // URLS & DOMAINS
                        int n = reader.ReadInt32();
                        for (int i = n; i > 0; i--)
                        {
                            int url    = reader.ReadInt32();
                            int domain = reader.ReadInt32();
                        }
                        break;
                    }

                    case 3:
                    {
                        // TIME
                        reader.ReadInt32();
                        // SERPID
                        reader.ReadInt32();
                        // URLS
                        int url = reader.ReadInt32();
                        break;
                    }
                    }
                }
            }

            {
                output.WriteLine("Top " + terms.Count + " terms:");
                for (int i = 0; i < terms.Count; i++)
                {
                    output.WriteLine(terms[i].Item1 + "\t" + terms[i].Item2);
                }

                for (int i = 0; i < terms.Count; i++)
                {
                    output.WriteLine();
                    int index = sortedTerms.IndexOf(terms[i].Item1);

                    queries[index].Sort();

                    output.WriteLine(sortedTerms[index] + ":");
                    foreach (var query in queries[index])
                    {
                        output.WriteLine(query);
                    }
                }

                output.WriteLine();
            }
        }
Пример #20
0
 private protected GridPointEarthGridDefinition(BufferedBinaryReader reader) : base(reader)
 {
     La1        = reader.ReadInt32() * 1e-6;
     Lo1        = reader.ReadUInt32() * 1e-6;
     Resolution = reader.ReadUInt8();
 }
Пример #21
0
        public void Read()
        {
            var binaryReader = new BufferedBinaryReader(_binaryReader);

            Metadata    metadata    = new Metadata();
            QueryAction queryAction = new QueryAction();
            Click       click       = new Click();

            float length = binaryReader.reader.BaseStream.Length / 100.0f;

            int lineCounter = 0;

            _reader.onBeginRead();

            int type = binaryReader.PeekChar();

            while (type > -1)
            {
                if (++lineCounter % 100000 == 0)
                {
                    Console.Write("                 \rRead: {0} %\r",
                                  (binaryReader.reader.BaseStream.Position / length).ToString("0.000"));
                    if (lineCounter % 2000000 == 0)
                    {
                        GC.Collect();
                    }
                }

                switch (type)
                {
                case 0:
                {
                    metadata.type      = binaryReader.ReadByte();
                    metadata.sessionId = binaryReader.ReadInt32();
                    metadata.day       = binaryReader.ReadInt32();
                    metadata.userId    = binaryReader.ReadInt32();

                    _reader.onMetadata(metadata);
                    break;
                }

                case 1:
                case 2:
                {
                    queryAction.type      = binaryReader.ReadByte();
                    queryAction.sessionId = binaryReader.ReadInt32();
                    queryAction.time      = binaryReader.ReadInt32();
                    queryAction.serpid    = binaryReader.ReadInt32();
                    queryAction.queryId   = binaryReader.ReadInt32();

                    int nTerms = binaryReader.ReadInt32();
                    queryAction.nTerms = nTerms;
                    if (queryAction.terms == null || queryAction.terms.Length < nTerms)
                    {
                        queryAction.terms = new int[nTerms];
                    }

                    for (int i = 0; i < nTerms; i++)
                    {
                        queryAction.terms[i] = binaryReader.ReadInt32();
                    }

                    int nUrls = binaryReader.ReadInt32();
                    queryAction.nUrls = nUrls;
                    if (queryAction.urls == null || queryAction.urls.Length < nUrls)
                    {
                        queryAction.urls    = new int[nUrls];
                        queryAction.domains = new int[nUrls];
                    }

                    for (int i = 0; i < nUrls; i++)
                    {
                        queryAction.urls[i]    = binaryReader.ReadInt32();
                        queryAction.domains[i] = binaryReader.ReadInt32();
                    }

                    _reader.onQueryAction(queryAction);
                    break;
                }

                case 3:
                {
                    click.type      = binaryReader.ReadByte();
                    click.sessionId = binaryReader.ReadInt32();
                    click.time      = binaryReader.ReadInt32();
                    click.serpid    = binaryReader.ReadInt32();
                    click.urlId     = binaryReader.ReadInt32();

                    _reader.onClick(click);
                    break;
                }
                }

                type = binaryReader.PeekChar();
            }

            Console.Write("                  \r");

            _reader.onEndRead();
        }
Пример #22
0
		private object ReadValue(BufferedBinaryReader reader, IType type)
		{
			var st = type.SystemType();
			if (st != null)
			{
				switch (st.Code)
				{
					case SystemTypeCode.Boolean:
						return reader.ReadBoolean();
					case SystemTypeCode.Int8:
						return reader.ReadInt8();
					case SystemTypeCode.UInt8:
						return reader.ReadUInt8();
					case SystemTypeCode.Int16:
						return reader.ReadInt16();
					case SystemTypeCode.UInt16:
						return reader.ReadUInt16();
					case SystemTypeCode.Int32:
						return reader.ReadInt32();
					case SystemTypeCode.UInt32:
						return reader.ReadUInt32();
					case SystemTypeCode.Int64:
						return reader.ReadInt64();
					case SystemTypeCode.UInt64:
						return reader.ReadUInt64();
					case SystemTypeCode.Single:
						return reader.ReadSingle();
					case SystemTypeCode.Double:
						return reader.ReadDouble();
					case SystemTypeCode.Char:
						return reader.ReadChar();
					case SystemTypeCode.String:
						return reader.ReadCountedUtf8();
					case SystemTypeCode.Object:
						//boxed value type
						var e = (ElementType)reader.ReadInt8();
						return ReadValue(reader, e);
					case SystemTypeCode.Type:
						return ReadType(reader);
				}
			}

			if (type.TypeKind == TypeKind.Enum)
			{
				return ReadValue(reader, type.ValueType);
			}

			if (type.IsArray)
			{
				int numElem = reader.ReadInt32();
				Array arr = null;
				for (int i = 0; i < numElem; ++i)
				{
					var val = ReadValue(reader, type.ElementType);
					if (arr == null)
						arr = Array.CreateInstance(val.GetType(), numElem);
					arr.SetValue(val, i);
				}
				return arr;
			}

			return null;
		}
Пример #23
0
 internal StretchedRotatedSphericalHarmonicCoefficientsGridDefinition(BufferedBinaryReader reader) : base(reader)
 {
     PoleLat = reader.ReadInt32() * 1e-6f;
     PoleLon = reader.ReadUInt32() * 1e-6f;
     Factor  = reader.ReadSingle();
 }
Пример #24
0
    public VigObject FUN_2C17C(ushort param1, Dictionary <int, Type> param2, uint param3)
    {
        VigObject oVar1;
        int       iVar2;
        VigObject oVar3;

        byte[] aVar3;
        BufferedBinaryReader brVar4;
        ConfigContainer      psVar5;

        psVar5 = configContainers[param1];

        if ((short)psVar5.flag < 0 || (255 < (short)psVar5.objID && (param3 & 0x20) != 0))
        {
            if ((param3 & 1) == 0 || (short)psVar5.previous == -1)
            {
                oVar1 = null;
            }
            else
            {
                oVar1 = FUN_2C17C(psVar5.previous, param2, param3);
            }
        }
        else
        {
            if (param2.ContainsKey(param1))
            {
                oVar1 = FUN_2BF44(psVar5, param2[param1]);
            }
            else
            {
                oVar1 = FUN_2BF44(psVar5, typeof(VigObject));
            }

            oVar1.DAT_1A = (short)param1;
            oVar1.id     = (short)psVar5.objID;

            if ((param3 & 8) == 0)
            {
                oVar1.vAnim = null;
            }
            else
            {
                aVar3  = xobf.animations;
                brVar4 = null;

                if (aVar3.Length > 0)
                {
                    brVar4 = new BufferedBinaryReader(aVar3);
                    iVar2  = brVar4.ReadInt32(param1 * 4 + 4);

                    if (iVar2 != 0)
                    {
                        brVar4.Seek(iVar2, SeekOrigin.Begin);
                    }
                    else
                    {
                        brVar4 = null;
                    }
                }

                oVar1.vAnim = brVar4;
            }

            oVar1.DAT_4A = GameManager.instance.timer;

            if ((param3 & 1) != 0 && (short)psVar5.previous != -1)
            {
                oVar3       = FUN_2C17C(psVar5.previous, param2, param3);
                oVar1.child = oVar3;

                if (oVar3 != null)
                {
                    oVar3.parent = oVar1;
                    oVar1.child.ApplyTransformation();
                }
            }

            if ((param3 & 2) == 0 && (short)psVar5.next != -1)
            {
                oVar3        = FUN_2C17C(psVar5.next, param2, param3 | 33);
                oVar1.child2 = oVar3;

                if (oVar3 != null)
                {
                    oVar3.parent = oVar1;
                    oVar1.child2.ApplyTransformation();
                }
            }
        }

        return(oVar1);
    }
Пример #25
0
		private object ReadValue(BufferedBinaryReader reader, ElementType e)
		{
			switch (e)
			{
				case ElementType.Boolean:
					return reader.ReadBoolean();

				case ElementType.Char:
					return reader.ReadChar();

				case ElementType.Int8:
					return reader.ReadSByte();

				case ElementType.UInt8:
					return reader.ReadByte();

				case ElementType.Int16:
					return reader.ReadInt16();

				case ElementType.UInt16:
					return reader.ReadUInt16();

				case ElementType.Int32:
					return reader.ReadInt32();

				case ElementType.UInt32:
					return reader.ReadUInt32();

				case ElementType.Int64:
					return reader.ReadInt64();

				case ElementType.UInt64:
					return reader.ReadUInt64();

				case ElementType.Single:
					return reader.ReadSingle();

				case ElementType.Double:
					return reader.ReadDouble();

				case ElementType.String:
					return reader.ReadCountedUtf8();

				case ElementType.Object:
				case ElementType.CustomArgsBoxedObject:
					{
						var elem = (ElementType)reader.ReadInt8();
						return ReadValue(reader, elem);
					}

				case ElementType.CustomArgsEnum:
					{
						string enumTypeName = reader.ReadCountedUtf8();
						var enumType = FindType(enumTypeName);
						if (enumType == null)
						{
							//TODO:
							throw new BadMetadataException();
						}
						return ReadValue(reader, enumType);
					}

				case ElementType.CustomArgsType:
					return ReadType(reader);

				case ElementType.ArraySz:
					{
						var arrElemType = (ElementType)reader.ReadInt8();
						return ReadArray(reader, arrElemType);
					}

				default:
					throw new ArgumentOutOfRangeException();
			}
		}
 internal RotatedGaussianLatLonGridDefinition(BufferedBinaryReader reader) : base(reader)
 {
     SpLat         = reader.ReadInt32() * Ratio;
     SpLon         = reader.ReadUInt32() * Ratio;
     Rotationangle = reader.ReadUInt32();
 }
Пример #27
0
 internal RotatedLatLonGridDefinition(BufferedBinaryReader reader) : base(reader)
 {
     SpLat         = reader.ReadInt32() * 1e-6f;
     SpLon         = reader.ReadUInt32() * 1e-6f;
     Rotationangle = reader.ReadSingle();
 }
Пример #28
0
        public void CompareUsers()
        {
            double simSum   = 0;
            int    simCount = 0;
            //List<Tuple<UserId, List<Tuple<UserId, Similarity>>>>
            //matrix = new List<Tuple<int, List<Tuple<int, int>>>>();
            var count = users.Count;
            var path  = PathResolver.UserMatrixOutput;
            var path2 = PathResolver.UserMatrixOutputProcessed;

            using (var writer = new BinaryWriter(new FileStream(path, FileMode.CreateNew)))
            {
                for (int i = 0; i < count; i++)
                {
                    var list = new List <Tuple <int, int> >();
                    for (int j = i + 1; j < count; j++)
                    {
                        var res = CompareTwoUsers(users[i], users[j]);
                        if (res == 0)
                        {
                            continue;
                        }
                        list.Add(new Tuple <int, int>(j, res));
                        simSum += res;
                        simCount++;
                    }

                    //write UserId
                    writer.Write(list[i].Item1);
                    writer.Write(list.Count);
                    foreach (var element in list)
                    {
                        writer.Write(element.Item1);
                        writer.Write(element.Item2);
                    }
                    //matrix.Add(new Tuple<int, List<Tuple<int, int>>>(i,list));
                }
            }

            double minVal = 1.5 /* ?? */ * simSum / simCount;

            using (var writer = new BinaryWriter(new FileStream(path2, FileMode.CreateNew)))
                using (var reader = new BufferedBinaryReader(path))
                {
                    while (reader.PeekChar() > -1)
                    {
                        int currentUser = reader.ReadInt32();
                        var usersList   = new List <int>();
                        for (int i = reader.ReadInt32(); i > 0; i--)
                        {
                            int userId = reader.ReadInt32();
                            int sim    = reader.ReadInt32();
                            if (sim > minVal)
                            {
                                usersList.Add(userId);
                            }
                        }

                        if (usersList.Count > 0)
                        {
                            writer.Write(currentUser);
                            writer.Write(usersList.Count);
                            foreach (var userId in usersList)
                            {
                                writer.Write(userId);
                            }
                        }
                    }
                }
        }
Пример #29
0
        private bool getInfo(BufferedBinaryReader source, FileInfo info, ReadTagParams readTagParams)
        {
            // Get info from file
            bool result        = false;
            bool isValidHeader = false;

            // Check for ID3v2 (NB : this case should not even exist since OGG has its own native tagging system, and is not deemed compatible with ID3v2 according to the ID3 FAQ)
            source.Seek(sizeInfo.ID3v2Size, SeekOrigin.Begin);

            // Read global file header
            info.IdentificationHeader.ReadFromStream(source);

            if (info.IdentificationHeader.IsValid())
            {
                source.Seek(sizeInfo.ID3v2Size + info.IdentificationHeader.Segments + 27, SeekOrigin.Begin); // 27 being the size from 'ID' to 'Segments'

                // Read Vorbis or Opus stream info
                long position = source.Position;

                String headerStart = Utils.Latin1Encoding.GetString(source.ReadBytes(3));
                source.Seek(position, SeekOrigin.Begin);
                if (VORBIS_HEADER_ID.StartsWith(headerStart))
                {
                    contents = CONTENTS_VORBIS;
                    info.VorbisParameters.ID = Utils.Latin1Encoding.GetString(source.ReadBytes(7));
                    isValidHeader            = VORBIS_HEADER_ID.Equals(info.VorbisParameters.ID);

                    info.VorbisParameters.BitstreamVersion = source.ReadBytes(4);
                    info.VorbisParameters.ChannelMode      = source.ReadByte();
                    info.VorbisParameters.SampleRate       = source.ReadInt32();
                    info.VorbisParameters.BitRateMaximal   = source.ReadInt32();
                    info.VorbisParameters.BitRateNominal   = source.ReadInt32();
                    info.VorbisParameters.BitRateMinimal   = source.ReadInt32();
                    info.VorbisParameters.BlockSize        = source.ReadByte();
                    info.VorbisParameters.StopFlag         = source.ReadByte();
                }
                else if (OPUS_HEADER_ID.StartsWith(headerStart))
                {
                    contents = CONTENTS_OPUS;
                    info.OpusParameters.ID = Utils.Latin1Encoding.GetString(source.ReadBytes(8));
                    isValidHeader          = OPUS_HEADER_ID.Equals(info.OpusParameters.ID);

                    info.OpusParameters.Version            = source.ReadByte();
                    info.OpusParameters.OutputChannelCount = source.ReadByte();
                    info.OpusParameters.PreSkip            = source.ReadUInt16();
                    //info.OpusParameters.InputSampleRate = source.ReadUInt32();
                    info.OpusParameters.InputSampleRate = 48000; // Actual sample rate is hardware-dependent. Let's assume for now that the hardware ATL runs on supports 48KHz
                    source.Seek(4, SeekOrigin.Current);
                    info.OpusParameters.OutputGain = source.ReadInt16();

                    info.OpusParameters.ChannelMappingFamily = source.ReadByte();

                    if (info.OpusParameters.ChannelMappingFamily > 0)
                    {
                        info.OpusParameters.StreamCount        = source.ReadByte();
                        info.OpusParameters.CoupledStreamCount = source.ReadByte();

                        info.OpusParameters.ChannelMapping = new byte[info.OpusParameters.OutputChannelCount];
                        for (int i = 0; i < info.OpusParameters.OutputChannelCount; i++)
                        {
                            info.OpusParameters.ChannelMapping[i] = source.ReadByte();
                        }
                    }
                }

                if (isValidHeader)
                {
                    info.CommentHeaderStart = source.Position;
                    IList <long> pagePos = new List <long>();

                    // Reads all related Vorbis pages that describe Comment and Setup headers
                    // and concatenate their content into a single, continuous data stream
                    bool loop  = true;
                    bool first = true;
                    using (MemoryStream s = new MemoryStream())
                    {
                        // Reconstruct the whole Comment header from OGG pages to a MemoryStream
                        while (loop)
                        {
                            info.SetupHeaderEnd              = source.Position; // When the loop stops, cursor is starting to read a brand new page located after Comment _and_ Setup headers
                            info.CommentHeader.ID            = Utils.Latin1Encoding.GetString(source.ReadBytes(4));
                            info.CommentHeader.StreamVersion = source.ReadByte();
                            info.CommentHeader.TypeFlag      = source.ReadByte();
                            // 0 marks a new page
                            if (0 == info.CommentHeader.TypeFlag)
                            {
                                loop = first;
                            }
                            if (loop)
                            {
                                info.CommentHeader.AbsolutePosition = source.ReadUInt64();
                                info.CommentHeader.Serial           = source.ReadInt32();
                                info.CommentHeader.PageNumber       = source.ReadInt32();
                                info.CommentHeader.Checksum         = source.ReadUInt32();
                                info.CommentHeader.Segments         = source.ReadByte();
                                info.CommentHeader.LacingValues     = source.ReadBytes(info.CommentHeader.Segments);
                                s.Write(source.ReadBytes(info.CommentHeader.GetPageLength()), 0, info.CommentHeader.GetPageLength());
                                pagePos.Add(info.SetupHeaderEnd);
                            }
                            first = false;
                        }

                        if (readTagParams.PrepareForWriting) // Metrics to prepare writing
                        {
                            if (pagePos.Count > 1)
                            {
                                source.Position = pagePos[pagePos.Count - 2];
                            }
                            else
                            {
                                source.Position = pagePos[0];
                            }

                            // Determine the boundaries of 3rd header (Setup header) by searching from last-but-one page
                            if (StreamUtils.FindSequence(source, Utils.Latin1Encoding.GetBytes(VORBIS_SETUP_ID)))
                            {
                                info.SetupHeaderStart = source.Position - VORBIS_SETUP_ID.Length;
                                info.CommentHeaderEnd = info.SetupHeaderStart;

                                if (pagePos.Count > 1)
                                {
                                    int firstSetupPage = -1;
                                    for (int i = 1; i < pagePos.Count; i++)
                                    {
                                        if (info.CommentHeaderEnd < pagePos[i])
                                        {
                                            info.CommentHeaderSpanPages = i - 1;
                                            firstSetupPage = i - 1;
                                        }
                                        if (info.SetupHeaderEnd < pagePos[i])
                                        {
                                            info.SetupHeaderSpanPages = i - firstSetupPage;
                                        }
                                    }
                                    /// Not found yet => comment header takes up all pages, and setup header is on the end of the last page
                                    if (-1 == firstSetupPage)
                                    {
                                        info.CommentHeaderSpanPages = pagePos.Count;
                                        info.SetupHeaderSpanPages   = 1;
                                    }
                                }
                                else
                                {
                                    info.CommentHeaderSpanPages = 1;
                                    info.SetupHeaderSpanPages   = 1;
                                }
                            }
                        }

                        // Get total number of samples
                        info.Samples = getSamples(source);

                        // Read metadata from the reconstructed Comment header inside the memoryStream
                        if (readTagParams.ReadTag)
                        {
                            BinaryReader msr = new BinaryReader(s);
                            s.Seek(0, SeekOrigin.Begin);

                            string tagId;
                            bool   isValidTagHeader = false;
                            if (contents.Equals(CONTENTS_VORBIS))
                            {
                                tagId            = Utils.Latin1Encoding.GetString(msr.ReadBytes(7));
                                isValidTagHeader = (VORBIS_TAG_ID.Equals(tagId));
                            }
                            else if (contents.Equals(CONTENTS_OPUS))
                            {
                                tagId            = Utils.Latin1Encoding.GetString(msr.ReadBytes(8));
                                isValidTagHeader = (OPUS_TAG_ID.Equals(tagId));
                            }

                            if (isValidTagHeader)
                            {
                                vorbisTag.Clear();
                                vorbisTag.Read(msr, readTagParams);
                            }
                        }
                    } // using MemoryStream

                    result = true;
                }
            }

            return(result);
        }
Пример #30
0
    public new VigObject FUN_2C344(XOBF_DB param1, ushort param2, uint param3)
    {
        VigMesh              mVar1;
        int                  iVar2;
        VigObject            oVar3;
        BufferedBinaryReader brVar4;
        ConfigContainer      puVar5;

        puVar5 = param1.ini.configContainers[param2];

        if ((puVar5.flag & 0x7ff) == 0x7ff)
        {
            vMesh = null;
        }
        else
        {
            mVar1 = param1.FUN_1FD18(gameObject, puVar5.flag & 0x7ffU, true);
            vMesh = mVar1;
        }

        if (puVar5.colliderID < 0)
        {
            vCollider = null;
        }
        else
        {
            VigCollider collider = param1.cbbList[puVar5.colliderID];
            vCollider = new VigCollider(collider.buffer);
        }

        vData  = param1;
        DAT_1A = (short)param2;

        if ((param3 & 8) == 0)
        {
            vAnim = null;
        }
        else
        {
            brVar4 = new BufferedBinaryReader(param1.animations);

            if (brVar4.GetBuffer() != null)
            {
                iVar2 = brVar4.ReadInt32(param2 * 4 + 4);

                if (iVar2 != 0)
                {
                    brVar4.Seek(iVar2, SeekOrigin.Begin);
                }
                else
                {
                    brVar4 = null;
                }
            }
            else
            {
                brVar4 = null;
            }

            vAnim = brVar4;
        }

        DAT_4A = GameManager.instance.timer;

        if ((param3 & 2) == 0 && puVar5.next != 0xffff)
        {
            oVar3  = param1.ini.FUN_2C17C_3(puVar5.next, typeof(WheelChild), param3 | 0x21);
            child2 = oVar3;

            if (oVar3 != null)
            {
                oVar3.ApplyTransformation();
                child2.parent = this;
            }
        }
        else
        {
            child2 = null;
        }

        return(this);
    }