/// <summary> /// Seeds Configuration Data /// </summary> /// <param name="dataClientConfig"></param> /// <returns></returns> private async Task ConfigurationDataDemoAsync(Config.DataClientConfig dataClientConfig) { try { using (DataClient dataClient = new DataClient(dataClientConfig)) { if (dataClient.ConfigurationData != null) { ConfigurationData configurationData = dataClient.ConfigurationData; // Explicit loading. When the entity is first read, related data isn't retrieved. // Example code that retrieves the related data. It impacts retrieval performance hence only use if it's needed. await configurationData.Clients.Include(client => client.ClientSpots).LoadAsync(); await configurationData.ClientSpots.Include(clientSpot => clientSpot.Zones) .Include(clientSpot => clientSpot.LocationDevices) .Include(clientSpot => clientSpot.DisplayEndpoints) .Include(clientSpot => clientSpot.Notifications) .Include(clientSpot => clientSpot.Coupons).LoadAsync(); await configurationData.Zones.Include(zone => zone.LocationDevices) .Include(zone => zone.DisplayEndpoints).LoadAsync(); await configurationData.LocationDevices.Include(locationDevice => locationDevice.LocationDeviceNotifications).LoadAsync(); await configurationData.DisplayEndpoints.Include(displayEndpoint => displayEndpoint.DisplayEndpointNotifications).LoadAsync(); await configurationData.Notifications.Include(notification => notification.Coupons) .Include(notification => notification.LocationDeviceNotifications) .Include(notification => notification.DisplayEndpointNotifications).LoadAsync(); ///////// DB seeding with demo content ///////// // Look for any Clients if (configurationData.Clients.Any()) { string log = "Total Client found: " + configurationData.Clients.LongCount() + " | " + "Total ClientSpot found: " + configurationData.ClientSpots.LongCount() + " | " + "Total Zone found: " + configurationData.Zones.LongCount() + " | " + "Total LocationDevice found: " + configurationData.LocationDevices.LongCount() + " | " + "Total DisplayEndpoint found: " + configurationData.DisplayEndpoints.LongCount() + " | " + "Total Notification found: " + configurationData.Notifications.LongCount() + " | " + "Total Coupon found: " + configurationData.Coupons.LongCount() + " | " + "Total User found: " + configurationData.Users.LongCount(); Context.Logger.LogLine("[ConfigurationData Summary]"); Context.Logger.LogLine(log); return; // DB has been seeded already } // DB save operation Context.Logger.LogLine("[Adding contents for ConfigurationData]"); // Adding Clients var clients = new Client[] { new Client { Name = "Demo Mart", PhoneNumber = "001-123-4567", Address = "US" } }; foreach (Client client in clients) { configurationData.Clients.Add(client); } Context.Logger.LogLine("1 Client added"); // Adding ClientSpots var clientSpots = new ClientSpot[] { new ClientSpot { ClientID = clients[0].ClientID, Name = "DemoMart Seattle Store", PhoneNumber = "001-123-4567", Address = "Seattle, US" }, new ClientSpot { ClientID = clients[0].ClientID, Name = "DemoMart LA Store", PhoneNumber = "001-123-4567", Address = "LA, US" } }; foreach (ClientSpot clientSpot in clientSpots) { configurationData.ClientSpots.Add(clientSpot); } Context.Logger.LogLine("2 ClientSpots added"); // Adding Zones var zones = new Zone[] { new Zone { ClientSpotID = clientSpots[0].ClientSpotID, Name = "Pseudo Zone" }, new Zone { ClientSpotID = clientSpots[0].ClientSpotID, Name = "Demo Entrance Zone (Scenario #1)" }, new Zone { ClientSpotID = clientSpots[0].ClientSpotID, Name = "Demo Bakery Zone (Scenario #2)" }, new Zone { ClientSpotID = clientSpots[0].ClientSpotID, Name = "Demo Electronics Zone (Scenario #3)" } }; foreach (Zone zone in zones) { configurationData.Zones.Add(zone); } Context.Logger.LogLine("4 Zones added"); // SAVING the changes into physical DB await configurationData.SaveChangesAsync(); // Adding LocationDevices var locationDevices = new LocationDevice[] { new LocationDevice { ClientSpotID = clientSpots[0].ClientSpotID, ZoneID = zones[0].ZoneID, Type = LocationDeviceType.IBeacon, DeviceID = "pseudo-uuid" }, new LocationDevice { ClientSpotID = clientSpots[0].ClientSpotID, ZoneID = zones[1].ZoneID, Type = LocationDeviceType.IBeacon, DeviceID = "11111111-1111-1111-1111-111111111111" }, new LocationDevice { ClientSpotID = clientSpots[0].ClientSpotID, ZoneID = zones[2].ZoneID, Type = LocationDeviceType.IBeacon, DeviceID = "22222222-2222-2222-2222-222222222222" }, new LocationDevice { ClientSpotID = clientSpots[0].ClientSpotID, ZoneID = zones[3].ZoneID, Type = LocationDeviceType.IBeacon, DeviceID = "33333333-3333-3333-3333-333333333333" }, new LocationDevice { ClientSpotID = clientSpots[0].ClientSpotID, ZoneID = zones[3].ZoneID, Type = LocationDeviceType.IBeacon, DeviceID = "44444444-4444-4444-4444-444444444444" } }; foreach (LocationDevice locationDevice in locationDevices) { configurationData.LocationDevices.Add(locationDevice); } Context.Logger.LogLine("5 LocationDevices added"); // Adding DisplayEndpoints var displayEndpoints = new DisplayEndpoint[] { new DisplayEndpoint { ClientSpotID = clientSpots[0].ClientSpotID, ZoneID = zones[0].ZoneID, Name = "Pseudo Display" }, new DisplayEndpoint { ClientSpotID = clientSpots[0].ClientSpotID, ZoneID = zones[1].ZoneID, Name = "Demo Display 1" }, new DisplayEndpoint { ClientSpotID = clientSpots[0].ClientSpotID, ZoneID = zones[2].ZoneID, Name = "Demo Display 2" }, new DisplayEndpoint { ClientSpotID = clientSpots[0].ClientSpotID, ZoneID = zones[3].ZoneID, Name = "Demo Display 3" } }; foreach (DisplayEndpoint displayEndpoint in displayEndpoints) { configurationData.DisplayEndpoints.Add(displayEndpoint); } Context.Logger.LogLine("4 DisplayEndpoints added"); // Adding Notifications var notifications = new Notification[] { new Notification { ClientSpotID = clientSpots[0].ClientSpotID, Name = "Pseduo Notification", Timeout = 10, ContentMimeType = MimeType.ImagePng, ContentSubject = "Pseduo Notification", ContentCaption = "Pseduo advertisement", ContentBody = "http://www.abc.com/images/img1.png" }, new Notification { ClientSpotID = clientSpots[0].ClientSpotID, Name = "Demo Notification 1 (Scenario #1)", SortOrder = 1, Timeout = 20, ShowProgressBar = false, ContentMimeType = MimeType.ImagePng, ContentSubject = "Welcome Greetings", ContentCaption = "Welcome to DemoMart Seattle Store!", ContentBody = "https://s3.amazonaws.com/hwconscious/notifications/demo_mart/welcome.png" }, new Notification { ClientSpotID = clientSpots[0].ClientSpotID, Name = "Demo Notification 2 (Scenario #2)", SortOrder = 1, Timeout = 10, ContentMimeType = MimeType.ImageJpg, ContentSubject = "Advertisement for Doughnut", ContentCaption = "4 Delicious Doughnuts", ContentBody = "https://s3.amazonaws.com/hwconscious/notifications/demo_mart/doughnut.jpg" }, new Notification { ClientSpotID = clientSpots[0].ClientSpotID, Name = "Demo Notification 3 (Scenario #2)", SortOrder = 2, Timeout = 10, ContentMimeType = MimeType.ImageJpg, ContentSubject = "Advertisement for Croissant", ContentCaption = "Croissant for breakfast needs", ContentBody = "https://s3.amazonaws.com/hwconscious/notifications/demo_mart/croissant.jpg" }, new Notification { ClientSpotID = clientSpots[0].ClientSpotID, Name = "Demo Notification 4 (Scenario #2)", SortOrder = 3, Timeout = 10, ContentMimeType = MimeType.VideoMp4, ContentSubject = "Advertisement for Coke", ContentCaption = "Taste the Feeling", ContentBody = "https://s3.amazonaws.com/hwconscious/notifications/demo_mart/coke.mp4" }, new Notification { ClientSpotID = clientSpots[0].ClientSpotID, Name = "Demo Notification 5 (Scenario #3)", Timeout = 10, ContentMimeType = MimeType.ImageJpeg, ContentSubject = "Advertisement for Iron", ContentCaption = "Steam Iron", ContentBody = "https://s3.amazonaws.com/hwconscious/notifications/demo_mart/iron.jpeg" }, new Notification { ClientSpotID = clientSpots[0].ClientSpotID, Name = "Demo Notification 6 (Scenario #3)", Timeout = 10, ContentMimeType = MimeType.ImageJpeg, ContentSubject = "Advertisement for Smartphone", ContentCaption = "Extraordinary performance", ContentBody = "https://s3.amazonaws.com/hwconscious/notifications/demo_mart/smart-phone.jpeg" } }; foreach (Notification notification in notifications) { configurationData.Notifications.Add(notification); } Context.Logger.LogLine("7 Notifications added"); // SAVING the changes into physical DB await configurationData.SaveChangesAsync(); // Adding LocationDeviceNotifications var displayEndpointNotifications = new DisplayEndpointNotification[] { new DisplayEndpointNotification { DisplayEndpointID = displayEndpoints[0].DisplayEndpointID, NotificationID = notifications[0].NotificationID }, new DisplayEndpointNotification { DisplayEndpointID = displayEndpoints[1].DisplayEndpointID, NotificationID = notifications[1].NotificationID }, new DisplayEndpointNotification { DisplayEndpointID = displayEndpoints[2].DisplayEndpointID, NotificationID = notifications[2].NotificationID }, new DisplayEndpointNotification { DisplayEndpointID = displayEndpoints[2].DisplayEndpointID, NotificationID = notifications[3].NotificationID }, new DisplayEndpointNotification { DisplayEndpointID = displayEndpoints[2].DisplayEndpointID, NotificationID = notifications[4].NotificationID } }; foreach (DisplayEndpointNotification displayEndpointNotification in displayEndpointNotifications) { configurationData.DisplayEndpointNotifications.Add(displayEndpointNotification); } Context.Logger.LogLine("5 DisplayEndpointNotifications added"); // Adding LocationDeviceNotifications var locationDeviceNotifications = new LocationDeviceNotification[] { new LocationDeviceNotification { LocationDeviceID = locationDevices[3].LocationDeviceID, NotificationID = notifications[5].NotificationID }, new LocationDeviceNotification { LocationDeviceID = locationDevices[4].LocationDeviceID, NotificationID = notifications[6].NotificationID } }; foreach (LocationDeviceNotification locationDeviceNotification in locationDeviceNotifications) { configurationData.LocationDeviceNotifications.Add(locationDeviceNotification); } Context.Logger.LogLine("2 LocationDeviceNotifications added"); // Adding Coupons var coupons = new Coupon[] { new Coupon { ClientSpotID = clientSpots[0].ClientSpotID, NotificationID = notifications[0].NotificationID, Name = "Pseduo Coupon", CouponCode = "00000000000", Description = "Save $0.00", DiscountCents = 0.0 }, new Coupon { ClientSpotID = clientSpots[0].ClientSpotID, NotificationID = notifications[2].NotificationID, Name = "Doughnut Coupon", CouponCode = "09876543210", Description = "SAVE $1.99", DiscountCents = 199.0 }, new Coupon { ClientSpotID = clientSpots[0].ClientSpotID, NotificationID = notifications[3].NotificationID, Name = "Croissant Coupon", CouponCode = "92186293264", Description = "SAVE $0.49", DiscountCents = 49.0 }, new Coupon { ClientSpotID = clientSpots[0].ClientSpotID, NotificationID = notifications[4].NotificationID, Name = "Coke Coupon", CouponCode = "97294957293", Description = "SAVE $0.20", DiscountCents = 20.0 } }; foreach (Coupon coupon in coupons) { configurationData.Coupons.Add(coupon); } Context.Logger.LogLine("4 Coupons added"); // Adding Users var users = new User[] { new User { Type = UserType.Registered, Name = "Pseduo User", Email = "*****@*****.**" }, new User { Type = UserType.Registered, Name = "Demo User", Email = "*****@*****.**" }, new User { Type = UserType.Guest } }; foreach (User user in users) { configurationData.Users.Add(user); } Context.Logger.LogLine("3 Users added"); // SAVING the changes into physical DB await configurationData.SaveChangesAsync(); } } } catch (Exception ex) { Context.Logger.LogLine("ConfigurationData ERROR: " + ex.Message); } }