コード例 #1
0
        private Dictionary <EventClassification, int> GetEventTypeLookup(DbAdapterContainer dbAdapterContainer)
        {
            MeterData.EventTypeDataTable eventTypeTable      = new MeterData.EventTypeDataTable();
            EventClassification          eventClassification = default(EventClassification);

            foreach (EventClassification classification in Enum.GetValues(typeof(EventClassification)))
            {
                eventTypeTable.AddEventTypeRow(classification.ToString(), classification.ToString());
            }

            BulkLoader bulkLoader = new BulkLoader();

            bulkLoader.Connection     = dbAdapterContainer.Connection;
            bulkLoader.CommandTimeout = dbAdapterContainer.CommandTimeout;

            bulkLoader.MergeTableFormat = "MERGE INTO {0} AS Target " +
                                          "USING {1} AS Source " +
                                          "ON Source.Name = Target.Name " +
                                          "WHEN NOT MATCHED THEN " +
                                          "    INSERT (Name, Description) " +
                                          "    VALUES (Source.Name, Source.Description);";

            bulkLoader.Load(eventTypeTable);

            dbAdapterContainer.GetAdapter <EventTypeTableAdapter>().Fill(eventTypeTable);

            return(Enumerable.Select(eventTypeTable
                                     .Where(row => Enum.TryParse(row.Name, out eventClassification)), row => Tuple.Create(eventClassification, row.ID))
                   .ToDictionary(tuple => tuple.Item1, tuple => tuple.Item2));
        }
コード例 #2
0
        private Dictionary <EventClassification, int> GetEventTypeLookup(DbAdapterContainer dbAdapterContainer)
        {
            MeterData.EventTypeDataTable eventTypeTable      = new MeterData.EventTypeDataTable();
            EventClassification          eventClassification = default(EventClassification);

            foreach (EventClassification classification in Enum.GetValues(typeof(EventClassification)))
            {
                eventTypeTable.AddEventTypeRow(classification.ToString(), classification.ToString());
            }

            BulkLoader bulkLoader = new BulkLoader();

            bulkLoader.Connection     = dbAdapterContainer.Connection;
            bulkLoader.CommandTimeout = dbAdapterContainer.CommandTimeout;

            bulkLoader.MergeTableFormat = "MERGE INTO {0} AS Target " +
                                          "USING {1} AS Source " +
                                          "ON Source.Name = Target.Name " +
                                          "WHEN NOT MATCHED THEN " +
                                          "    INSERT (Name, Description) " +
                                          "    VALUES (Source.Name, Source.Description);";

            bulkLoader.Load(eventTypeTable);

            dbAdapterContainer.GetAdapter <EventTypeTableAdapter>().Fill(eventTypeTable);

            return(eventTypeTable
                   .Where(row => Enum.TryParse(row.Name, out eventClassification))
                   .Select(row => new { EventClassification = eventClassification, row.ID })
                   .ToList()
                   .GroupBy(obj => obj.EventClassification)
                   .ToDictionary(grouping => grouping.Key, grouping =>
            {
                if (grouping.Count() > 1)
                {
                    Log.Warn($"Found duplicate event type: {grouping.Key}");
                }

                return grouping.First().ID;
            }));
        }