Esempio n. 1
0
        public TagIdNameMap()
        {
            IdToNameMap = new Dictionary <int, string>();
            NameToIdMap = new Dictionary <string, Dictionary <int, int> >();

            var mapFileName = String.Format("Stream_AllPipe_CustomerTagMap.dts.gz");

            using (var fileStream = new FileStream(mapFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (var zipStream = new GZipStream(fileStream, CompressionMode.Decompress))
                {
                    using (var dtsReader = new DtsReader(zipStream))
                    {
                        var schema         = DsvUtilities.GetDsvTable("StripeMapFiles__15_3.dsv", "CustomerTagMap_Stripe");
                        var columnMetadata = MapFileUtils.ValidateSchema(schema, dtsReader);

                        foreach (var line in dtsReader.ReadAllLines())
                        {
                            var record = new TagToCustomerRecord(columnMetadata, line);

                            if (!IdToNameMap.ContainsKey(record.TagId))
                            {
                                IdToNameMap.Add(record.TagId, record.TagName);
                            }

                            Dictionary <int, int> customerIdToTagId;
                            if (!NameToIdMap.TryGetValue(record.TagName, out customerIdToTagId))
                            {
                                customerIdToTagId = new Dictionary <int, int>();
                                customerIdToTagId.Add(record.CustomerId, record.TagId);

                                NameToIdMap.Add(record.TagName, customerIdToTagId);
                            }
                            else if (!customerIdToTagId.ContainsKey(record.CustomerId))
                            {
                                customerIdToTagId.Add(record.CustomerId, record.TagId);
                            }
                        }
                    }
                }
            }
        }
        public TagToCustomerRecord(IReadOnlyDictionary <string, int> columnMetadata, IList <object> row)
        {
            if (_tagIdOrdinal == -1)
            {
                _tagIdOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "TagId");
            }

            if (_customerIdOrdinal == -1)
            {
                _customerIdOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "CustomerId");
            }

            if (_tagNameOrdinal == -1)
            {
                _tagNameOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "TagName");
            }

            TagId      = (int)row[_tagIdOrdinal];
            CustomerId = (int)row[_customerIdOrdinal];
            TagName    = (string)row[_tagNameOrdinal];
        }