Esempio n. 1
0
        public Collection <T> Select()
        {
            RouteFactory       routeFactory  = new RouteFactory();
            RouteTable <Route> instanceRoute = (RouteTable <Route>)routeFactory.GetRouteInstance();

            DriverFactory        driverFactory  = new DriverFactory();
            DriverTable <Driver> instanceDriver = (DriverTable <Driver>)driverFactory.GetDriverInstance();

            VehicleFactory         vehicleFactory  = new VehicleFactory();
            VehicleTable <Vehicle> instanceVehicle = (VehicleTable <Vehicle>)vehicleFactory.GetVehicleInstance();


            XDocument      xDoc       = XDocument.Load(Configuration.XMLFILEPATH);
            Collection <T> timetables = new Collection <T>();

            List <XElement> elements = xDoc.Descendants("Timetables").Descendants("Timetable").ToList();

            foreach (var element in elements)
            {
                Timetable timetable = new Timetable();
                timetable.id        = int.Parse(element.Attribute("id").Value);
                timetable.name      = element.Attribute("name").Value;
                timetable.departure = DateTime.Parse(element.Attribute("departure").Value);
                timetable.arrival   = DateTime.Parse(element.Attribute("arrival").Value);
                timetable.route     = instanceRoute.Select(int.Parse(element.Attribute("routeId").Value));
                timetable.driver    = instanceDriver.Select(int.Parse(element.Attribute("driverId").Value));
                timetable.vehicle   = instanceVehicle.Select(int.Parse(element.Attribute("vehicleId").Value));

                timetables.Add((T)timetable);
            }

            return(timetables);
        }
Esempio n. 2
0
        public WidgetsApp(
            Key key = null,
            GlobalKey <NavigatorState> navigatorKey     = null,
            RouteFactory onGenerateRoute                = null,
            RouteFactory onUnknownRoute                 = null,
            PageRouteFactory pageRouteBuilder           = null,
            List <NavigatorObserver> navigatorObservers = null,
            string initialRoute = null,
            Dictionary <string, WidgetBuilder> routes = null,
            TransitionBuilder builder = null,
            Window window             = null,
            TextStyle textStyle       = null,
            Widget home = null
            ) : base(key)
        {
            D.assert(window != null);
            routes                  = routes ?? new Dictionary <string, WidgetBuilder>();
            this.window             = window;
            this.home               = home;
            this.navigatorKey       = navigatorKey;
            this.onGenerateRoute    = onGenerateRoute;
            this.onUnknownRoute     = onUnknownRoute;
            this.pageRouteBuilder   = pageRouteBuilder;
            this.routes             = routes;
            this.navigatorObservers = navigatorObservers ?? new List <NavigatorObserver>();
            this.initialRoute       = initialRoute;
            this.builder            = builder;
            this.textStyle          = textStyle;

            D.assert(
                home == null ||
                !this.routes.ContainsKey(Navigator.defaultRouteName),
                "If the home property is specified, the routes table " +
                "cannot include an entry for \" / \", since it would be redundant."
                );

            D.assert(
                builder != null ||
                home != null ||
                this.routes.ContainsKey(Navigator.defaultRouteName) ||
                onGenerateRoute != null ||
                onUnknownRoute != null,
                "Either the home property must be specified, " +
                "or the routes table must include an entry for \"/\", " +
                "or there must be on onGenerateRoute callback specified, " +
                "or there must be an onUnknownRoute callback specified, " +
                "or the builder property must be specified, " +
                "because otherwise there is nothing to fall back on if the " +
                "app is started with an intent that specifies an unknown route."
                );

            D.assert(
                builder != null ||
                onGenerateRoute != null ||
                pageRouteBuilder != null,
                "If neither builder nor onGenerateRoute are provided, the " +
                "pageRouteBuilder must be specified so that the default handler " +
                "will know what kind of PageRoute transition to build."
                );
        }
Esempio n. 3
0
        /// <summary>
        /// Select the record for a name.
        /// </summary>
        //public  Timetable SelectForName(string pName, Database pDb = null)
        //{
        //    Database db;
        //    if (pDb == null)
        //    {
        //        db = new Database();
        //        db.Connect();
        //    }
        //    else
        //    {
        //        db = pDb;
        //    }

        //    SqlCommand command = db.CreateCommand(SQL_SELECT_NAME);

        //    command.Parameters.AddWithValue("@name", pName);
        //    SqlDataReader reader = db.Select(command);

        //    Collection<Timetable> timeTables = Read(reader);
        //    Timetable v = null;
        //    if (timeTables.Count == 1)
        //    {
        //        v = timeTables[0];
        //    }
        //    reader.Close();

        //    if (pDb == null)
        //    {
        //        db.Close();
        //    }

        //    return v;
        //}


        private Collection <T> Read(SqlDataReader reader)
        {
            RouteFactory       routeFactory  = new RouteFactory();
            RouteTable <Route> instanceRoute = (RouteTable <Route>)routeFactory.GetRouteInstance();

            VehicleFactory vehicleFactory  = new VehicleFactory();
            var            instanceVehicle = vehicleFactory.GetVehicleInstance();

            DriverFactory        driverFactory  = new DriverFactory();
            DriverTable <Driver> instanceDriver = (DriverTable <Driver>)driverFactory.GetDriverInstance();

            Collection <T> timeTables = new Collection <T>();

            while (reader.Read())
            {
                Timetable timeTable = new Timetable();
                int       i         = -1;
                timeTable.id        = reader.GetInt32(++i);
                timeTable.name      = reader.GetString(++i);
                timeTable.departure = reader.GetDateTime(++i);
                timeTable.arrival   = reader.GetDateTime(++i);
                var idRoute   = reader.GetInt32(++i);
                var idDriver  = reader.GetInt32(++i);
                var idVehicle = reader.GetInt32(++i);
                timeTable.route   = instanceRoute.Select(idRoute);
                timeTable.vehicle = instanceVehicle.Select(idVehicle);
                timeTable.driver  = instanceDriver.Select(idDriver);


                timeTables.Add((T)timeTable);
            }
            return(timeTables);
        }
Esempio n. 4
0
        public IEnumerable <Route> Get()
        {
            RouteFactory       routeFactory  = new RouteFactory();
            RouteTable <Route> instanceRoute = (RouteTable <Route>)routeFactory.GetRouteInstance();

            return(instanceRoute.Select());
        }
Esempio n. 5
0
        public Route Get(int id)
        {
            RouteFactory       routeFactory  = new RouteFactory();
            RouteTable <Route> instanceRoute = (RouteTable <Route>)routeFactory.GetRouteInstance();

            return(instanceRoute.Select(id));
        }
Esempio n. 6
0
        public static async Task <EdgeHubConnection> Create(
            IIdentity edgeHubIdentity,
            IEdgeHub edgeHub,
            ITwinManager twinManager,
            IConnectionManager connectionManager,
            RouteFactory routeFactory,
            IMessageConverter <TwinCollection> twinCollectionMessageConverter,
            VersionInfo versionInfo,
            IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache)
        {
            Preconditions.CheckNotNull(edgeHubIdentity, nameof(edgeHubIdentity));
            Preconditions.CheckNotNull(edgeHub, nameof(edgeHub));
            Preconditions.CheckNotNull(connectionManager, nameof(connectionManager));
            Preconditions.CheckNotNull(twinCollectionMessageConverter, nameof(twinCollectionMessageConverter));
            Preconditions.CheckNotNull(routeFactory, nameof(routeFactory));
            Preconditions.CheckNotNull(deviceScopeIdentitiesCache, nameof(deviceScopeIdentitiesCache));

            var edgeHubConnection = new EdgeHubConnection(
                edgeHubIdentity,
                twinManager,
                routeFactory,
                twinCollectionMessageConverter,
                versionInfo ?? VersionInfo.Empty,
                deviceScopeIdentitiesCache);

            await InitEdgeHub(edgeHubConnection, connectionManager, edgeHubIdentity, edgeHub);

            connectionManager.DeviceConnected    += edgeHubConnection.DeviceConnected;
            connectionManager.DeviceDisconnected += edgeHubConnection.DeviceDisconnected;
            Events.Initialized(edgeHubIdentity);
            return(edgeHubConnection);
        }
Esempio n. 7
0
 public MaterialApp(
     Key key = null,
     GlobalKey <NavigatorState> navigatorKey = null,
     Widget home = null,
     Dictionary <string, WidgetBuilder> routes = null,
     string initialRoute          = null,
     RouteFactory onGenerateRoute = null,
     RouteFactory onUnknownRoute  = null,
     List <NavigatorObserver> navigatorObservers = null,
     TransitionBuilder builder = null,
     string title                = "",
     Color color                 = null,
     ThemeData theme             = null,
     bool showPerformanceOverlay = false,
     Window window               = null) : base(key: key)
 {
     D.assert(window != null);
     this.window                 = window;
     this.navigatorKey           = navigatorKey;
     this.home                   = home;
     this.routes                 = routes ?? new Dictionary <string, WidgetBuilder>();
     this.initialRoute           = initialRoute;
     this.onGenerateRoute        = onGenerateRoute;
     this.onUnknownRoute         = onUnknownRoute;
     this.navigatorObservers     = navigatorObservers ?? new List <NavigatorObserver>();
     this.builder                = builder;
     this.title                  = title;
     this.color                  = color;
     this.theme                  = theme;
     this.showPerformanceOverlay = showPerformanceOverlay;
 }
Esempio n. 8
0
        private SubstitutionContext()
        {
            ThreadContext = new ThreadLocalContext();
            var callSpecificationFactory = CallSpecificationFactoryFactoryYesThatsRight.CreateCallSpecFactory();

            _callRouterResolver = new CallRouterResolver();

            var sequenceNumberGenerator = new SequenceNumberGenerator();

#pragma warning disable 618 // Obsolete
            SequenceNumberGenerator = sequenceNumberGenerator;
#pragma warning restore 618 // Obsolete

            RouteFactory = new RouteFactory(sequenceNumberGenerator, ThreadContext, callSpecificationFactory);

            var callInfoFactory           = new CallInfoFactory();
            var autoValueProvidersFactory = new AutoValueProvidersFactory();
            var substituteStateFactory    = new SubstituteStateFactory(callSpecificationFactory, callInfoFactory, autoValueProvidersFactory);
            var callRouterFactory         = new CallRouterFactory(ThreadContext, RouteFactory);
            var argSpecificationQueue     = new ArgumentSpecificationDequeue(ThreadContext.DequeueAllArgumentSpecifications);
            var dynamicProxyFactory       = new CastleDynamicProxyFactory(argSpecificationQueue);
            var delegateFactory           = new DelegateProxyFactory(dynamicProxyFactory);
            var proxyFactory = new ProxyFactory(delegateFactory, dynamicProxyFactory);
            SubstituteFactory = new SubstituteFactory(substituteStateFactory, callRouterFactory, proxyFactory);
        }
Esempio n. 9
0
 public MaterialApp(
     Key key = null,
     GlobalKey <NavigatorState> navigatorKey = null,
     Widget home = null,
     Dictionary <string, WidgetBuilder> routes = null,
     string initialRoute          = null,
     RouteFactory onGenerateRoute = null,
     InitialRouteListFactory onGenerateInitialRoutes = null,
     RouteFactory onUnknownRoute = null,
     List <NavigatorObserver> navigatorObservers = null,
     TransitionBuilder builder = null,
     string title = "",
     GenerateAppTitle onGenerateTitle = null,
     Color color         = null,
     ThemeData theme     = null,
     ThemeData darkTheme = null,
     ThemeMode themeMode = ThemeMode.system,
     Locale locale       = null,
     List <LocalizationsDelegate> localizationsDelegates       = null,
     LocaleListResolutionCallback localeListResolutionCallback = null,
     LocaleResolutionCallback localeResolutionCallback         = null,
     List <Locale> supportedLocales               = null,
     bool showPerformanceOverlay                  = false,
     bool checkerboardRasterCacheImages           = false,
     bool checkerboardOffscreenLayers             = false,
     bool debugShowCheckedModeBanner              = true,
     Dictionary <LogicalKeySet, Intent> shortcuts = null,
     Dictionary <LocalKey, ActionFactory> actions = null
     ) : base(key: key)
 {
     supportedLocales = supportedLocales ?? new List <Locale> {
         new Locale("en", "US")
     };
     this.navigatorKey                  = navigatorKey;
     this.home                          = home;
     this.routes                        = routes ?? new Dictionary <string, WidgetBuilder>();
     this.onGenerateInitialRoutes       = onGenerateInitialRoutes;
     this.initialRoute                  = initialRoute;
     this.onGenerateRoute               = onGenerateRoute;
     this.onUnknownRoute                = onUnknownRoute;
     this.navigatorObservers            = navigatorObservers ?? new List <NavigatorObserver>();
     this.builder                       = builder;
     this.title                         = title;
     this.onGenerateTitle               = onGenerateTitle;
     this.color                         = color;
     this.theme                         = theme;
     this.darkTheme                     = darkTheme;
     this.themeMode                     = themeMode;
     this.locale                        = locale;
     this.localizationsDelegates        = localizationsDelegates;
     this.localeListResolutionCallback  = localeListResolutionCallback;
     this.localeResolutionCallback      = localeResolutionCallback;
     this.supportedLocales              = supportedLocales;
     this.showPerformanceOverlay        = showPerformanceOverlay;
     this.checkerboardRasterCacheImages = checkerboardRasterCacheImages;
     this.checkerboardOffscreenLayers   = checkerboardOffscreenLayers;
     this.debugShowCheckedModeBanner    = debugShowCheckedModeBanner;
     this.shortcuts                     = shortcuts;
     this.actions                       = actions;
 }
Esempio n. 10
0
 // Use this for initialization
 void Start()
 {
     board        = new Board(4, 4, pBlockPrefab, transform);
     routeFactory = new RouteFactory();
     Debug.Log("Ready to setup route");
     routeFactory.setupRoute(board);
     Debug.Log("Starting a Main Game Script");
 }
Esempio n. 11
0
        public LocalConfigSource(RouteFactory routeFactory, IDictionary <string, string> routes, StoreAndForwardConfiguration storeAndForwardConfiguration)
        {
            Preconditions.CheckNotNull(routeFactory, nameof(routeFactory));
            Preconditions.CheckNotNull(routes, nameof(routes));
            Preconditions.CheckNotNull(storeAndForwardConfiguration, nameof(storeAndForwardConfiguration));
            IDictionary <string, RouteConfig> parsedRoutes = routes.ToDictionary(r => r.Key, r => new RouteConfig(r.Key, r.Value, routeFactory.Create(r.Value)));

            this.edgeHubConfig = new EdgeHubConfig(Constants.ConfigSchemaVersion.ToString(), new ReadOnlyDictionary <string, RouteConfig>(parsedRoutes), storeAndForwardConfiguration);
        }
Esempio n. 12
0
        public LocalConfigSource(RouteFactory routeFactory, IDictionary <string, string> routes, StoreAndForwardConfiguration storeAndForwardConfiguration)
        {
            Preconditions.CheckNotNull(routeFactory, nameof(routeFactory));
            Preconditions.CheckNotNull(routes, nameof(routes));
            Preconditions.CheckNotNull(storeAndForwardConfiguration, nameof(storeAndForwardConfiguration));
            IEnumerable <(string Name, string Value, Route Route)> parsedRoutes = routes.Select(r => (r.Key, r.Value, routeFactory.Create(r.Value)));

            this.edgeHubConfig = new EdgeHubConfig(Core.Constants.ConfigSchemaVersion.ToString(), parsedRoutes, storeAndForwardConfiguration);
        }
Esempio n. 13
0
 void RaiseEventIfSet(ICallRouter callRouter)
 {
     if (_getArgumentsForRaisingEvent.Value != null)
     {
         var routes = new RouteFactory();
         callRouter.SetRoute(x => routes.RaiseEvent(x, _getArgumentsForRaisingEvent.Value));
         _getArgumentsForRaisingEvent.Value = null;
     }
 }
Esempio n. 14
0
 public TwinConfigSource(EdgeHubConnection edgeHubConnection, string id, VersionInfo versionInfo, ITwinManager twinManager, Core.IMessageConverter <Twin> messageConverter, Core.IMessageConverter <TwinCollection> twinCollectionMessageConverter, RouteFactory routeFactory)
 {
     this.edgeHubConnection = Preconditions.CheckNotNull(edgeHubConnection, nameof(edgeHubConnection));
     this.id                             = Preconditions.CheckNotNull(id, nameof(id));
     this.twinManager                    = Preconditions.CheckNotNull(twinManager, nameof(twinManager));
     this.twinMessageConverter           = Preconditions.CheckNotNull(messageConverter, nameof(messageConverter));
     this.twinCollectionMessageConverter = twinCollectionMessageConverter;
     this.routeFactory                   = Preconditions.CheckNotNull(routeFactory, nameof(routeFactory));
     this.versionInfo                    = versionInfo ?? VersionInfo.Empty;
 }
Esempio n. 15
0
 public Navigator(Key key = null, string initialRoute = null,
                  RouteFactory onGenerateRoute       = null, RouteFactory onUnknownRoute = null,
                  List <NavigatorObserver> observers = null) : base(key)
 {
     D.assert(onGenerateRoute != null);
     this.initialRoute    = initialRoute;
     this.onUnknownRoute  = onUnknownRoute;
     this.onGenerateRoute = onGenerateRoute;
     this.observers       = observers ?? new List <NavigatorObserver>();
 }
Esempio n. 16
0
 EdgeHubConnection(IModuleIdentity edgeHubIdentity,
                   ITwinManager twinManager,
                   RouteFactory routeFactory,
                   IMessageConverter <TwinCollection> twinCollectionMessageConverter,
                   IMessageConverter <Twin> twinMessageConverter,
                   VersionInfo versionInfo)
 {
     this.edgeHubIdentity = edgeHubIdentity;
     this.twinManager     = twinManager;
     this.twinCollectionMessageConverter = twinCollectionMessageConverter;
     this.twinMessageConverter           = twinMessageConverter;
     this.routeFactory = routeFactory;
     this.versionInfo  = versionInfo ?? VersionInfo.Empty;
 }
        static ConfigurationRouteTableProvider()
        {
            _factories = new Dictionary <string, RouteFactory>(StringComparer.OrdinalIgnoreCase);

            _factories.Add("ignore", descriptor => new IgnoredRoute(descriptor.Url));
            _factories.Add("page", descriptor => new WebFormRoute(descriptor.Url,
                                                                  descriptor.Attributes.GetValue <string>("page")));

            _defaultFactory = descriptor => {
                Precondition.Require(descriptor.HandlerType, () => Error.ArgumentNull("handlerType"));
                IRouteHandler handler = (IRouteHandler)ServiceLocator.Instance.GetService(descriptor.HandlerType);

                return(new Route(descriptor.Url, handler));
            };
        }
		static ConfigurationRouteTableProvider()
		{
			_factories = new Dictionary<string, RouteFactory>(StringComparer.OrdinalIgnoreCase);

			_factories.Add("ignore", descriptor => new IgnoredRoute(descriptor.Url));
			_factories.Add("page", descriptor => new WebFormRoute(descriptor.Url, 
				descriptor.Attributes.GetValue<string>("page")));

			_defaultFactory = descriptor => {
				Precondition.Require(descriptor.HandlerType, () => Error.ArgumentNull("handlerType"));
				IRouteHandler handler = (IRouteHandler)ServiceLocator.Instance.GetService(descriptor.HandlerType);

				return new Route(descriptor.Url, handler);
			};	
		}
Esempio n. 19
0
        public void routeFromSpec()
        {
            EdgeRouteSpec specAD = new EdgeRouteSpec() { FromNumber = 0, ToNumber = 3 };
            RouteFactory<string> factory = new RouteFactory<string>();
            Assert.Throws<InvalidOperationException>(delegate { factory.newRouteFromSpec(specAD); });
            factory.masterNodeList = list;
            EdgeRoute routeAD = factory.newRouteFromSpec(specAD);
            Assert.AreSame(list.getValueNodesByValue("A").First(), routeAD.startNode);
            Assert.AreSame(list.getValueNodesByValue("D").First(), routeAD.connectedNodes.Last());

            EdgeRouteSpec specCD = (routeCD as EdgeRoute).ToEdgeRouteSpec();
            Assert.AreEqual(2, specCD.FromNumber);
            Assert.AreEqual(3, specCD.ToNumber);
            Assert.AreEqual(0, specCD.RequisiteFromNumber);
        }
Esempio n. 20
0
        public static HttpConfiguration Configure(IODataRepository oDataRepository, IMappingLogger logger)
        {
            var config              = new HttpConfiguration();
            var routeFactory        = new RouteFactory(oDataRepository, logger);
            var controllerActivator = new ControllerActivator(
                oDataRepository,
                config.Services.GetService(typeof(IHttpControllerActivator)).As <IHttpControllerActivator>());

            ConfigureServices(config, controllerActivator);
            ConfigureRoutes(config, routeFactory);
            ConfigureBindings(config);

            config.AddODataQueryFilter();
            return(config);
        }
Esempio n. 21
0
 internal EdgeHubConnection(
     IIdentity edgeHubIdentity,
     ITwinManager twinManager,
     RouteFactory routeFactory,
     IMessageConverter <TwinCollection> twinCollectionMessageConverter,
     VersionInfo versionInfo,
     IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache)
 {
     this.edgeHubIdentity = edgeHubIdentity;
     this.twinManager     = twinManager;
     this.twinCollectionMessageConverter = twinCollectionMessageConverter;
     this.routeFactory = routeFactory;
     this.versionInfo  = versionInfo ?? VersionInfo.Empty;
     this.deviceScopeIdentitiesCache = deviceScopeIdentitiesCache;
 }
		public static void RegisterFactory(string routeType, RouteFactory factory)
		{
			Precondition.Defined(routeType, () => Error.ArgumentNull("routeType"));
			Precondition.Require(factory, () => Error.ArgumentNull("factory"));

			_lock.AcquireWriterLock(Timeout.Infinite);

			try
			{
				_factories[routeType] = factory;
			}
			finally
			{
				_lock.ReleaseWriterLock();
			}
		}
        public static void RegisterFactory(string routeType, RouteFactory factory)
        {
            Precondition.Defined(routeType, () => Error.ArgumentNull("routeType"));
            Precondition.Require(factory, () => Error.ArgumentNull("factory"));

            _lock.AcquireWriterLock(Timeout.Infinite);

            try
            {
                _factories[routeType] = factory;
            }
            finally
            {
                _lock.ReleaseWriterLock();
            }
        }
Esempio n. 24
0
        public CupertinoApp(
            Key key = null,
            GlobalKey <NavigatorState> navigatorKey = null,
            Widget home = null,
            CupertinoThemeData theme = null,
            Dictionary <string, WidgetBuilder> routes = null,
            string initialRoute          = null,
            RouteFactory onGenerateRoute = null,
            RouteFactory onUnknownRoute  = null,
            List <NavigatorObserver> navigatorObservers = null,
            TransitionBuilder builder = null,
            string title = "",
            GenerateAppTitle onGenerateTitle = null,
            Color color   = null,
            Locale locale = null,
            List <LocalizationsDelegate <CupertinoLocalizations> > localizationsDelegates = null,
            LocaleListResolutionCallback localeListResolutionCallback = null,
            LocaleResolutionCallback localeResolutionCallback         = null,
            List <Locale> supportedLocales = null,
            bool showPerformanceOverlay    = false
            ) : base(key: key)
        {
            D.assert(title != null);

            supportedLocales = supportedLocales ?? new List <Locale> {
                new Locale("en", "US")
            };
            this.navigatorKey                 = navigatorKey;
            this.home                         = home;
            this.theme                        = theme;
            this.routes                       = routes ?? new Dictionary <string, WidgetBuilder>();
            this.initialRoute                 = initialRoute;
            this.onGenerateRoute              = onGenerateRoute;
            this.onUnknownRoute               = onUnknownRoute;
            this.navigatorObservers           = navigatorObservers ?? new List <NavigatorObserver>();
            this.builder                      = builder;
            this.title                        = title;
            this.onGenerateTitle              = onGenerateTitle;
            this.color                        = color;
            this.locale                       = locale;
            this.localizationsDelegates       = localizationsDelegates;
            this.localeListResolutionCallback = localeListResolutionCallback;
            this.localeResolutionCallback     = localeResolutionCallback;
            this.supportedLocales             = supportedLocales;
            this.showPerformanceOverlay       = showPerformanceOverlay;
        }
Esempio n. 25
0
        public static async Task <EdgeHubConnection> Create(
            IClientCredentials edgeHubCredentials,
            IEdgeHub edgeHub,
            ITwinManager twinManager,
            IConnectionManager connectionManager,
            ICloudProxy cloudProxy,
            RouteFactory routeFactory,
            IMessageConverter <TwinCollection> twinCollectionMessageConverter,
            IMessageConverter <Twin> twinMessageConverter,
            VersionInfo versionInfo,
            IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache
            )
        {
            Preconditions.CheckNotNull(edgeHubCredentials, nameof(edgeHubCredentials));
            Preconditions.CheckNotNull(edgeHub, nameof(edgeHub));
            Preconditions.CheckNotNull(connectionManager, nameof(connectionManager));
            Preconditions.CheckNotNull(cloudProxy, nameof(cloudProxy));
            Preconditions.CheckNotNull(twinCollectionMessageConverter, nameof(twinCollectionMessageConverter));
            Preconditions.CheckNotNull(twinMessageConverter, nameof(twinMessageConverter));
            Preconditions.CheckNotNull(routeFactory, nameof(routeFactory));
            Preconditions.CheckNotNull(deviceScopeIdentitiesCache, nameof(deviceScopeIdentitiesCache));

            var edgeHubConnection = new EdgeHubConnection(
                edgeHubCredentials.Identity as IModuleIdentity, twinManager, routeFactory,
                twinCollectionMessageConverter, twinMessageConverter,
                versionInfo ?? VersionInfo.Empty,
                deviceScopeIdentitiesCache
                );

            IDeviceProxy deviceProxy = new EdgeHubDeviceProxy(edgeHubConnection);
            await connectionManager.AddDeviceConnection(edgeHubCredentials);

            connectionManager.BindDeviceProxy(edgeHubCredentials.Identity, deviceProxy);

            await edgeHub.AddSubscription(edgeHubCredentials.Identity.Id, DeviceSubscription.DesiredPropertyUpdates);

            await edgeHub.AddSubscription(edgeHubCredentials.Identity.Id, DeviceSubscription.Methods);

            // Clear out all the reported devices.
            await edgeHubConnection.ClearDeviceConnectionStatuses();

            connectionManager.DeviceConnected    += edgeHubConnection.DeviceConnected;
            connectionManager.DeviceDisconnected += edgeHubConnection.DeviceDisconnected;
            Events.Initialized(edgeHubCredentials.Identity);
            return(edgeHubConnection);
        }
        private RouteBase CreateRoute(RouteDescriptor descriptor,
                                      IValueSet defaults, IValueSet tokens,
                                      IEnumerable <IRouteConstraint> constraints)
        {
            RouteFactory factory = GetRouteFactory(descriptor.Type);
            Route        route   = factory(descriptor);

            route.Defaults.Merge(defaults);
            route.Tokens.Merge(tokens);
            route.SecureConnection = descriptor.Attributes
                                     .GetValue <SecureConnectionOption>("secure");

            foreach (IRouteConstraint constraint in constraints)
            {
                route.Constraints.Add(constraint);
            }

            return(route);
        }
Esempio n. 27
0
 public CupertinoTabView(
     Key key = null,
     WidgetBuilder builder = null,
     GlobalKey <NavigatorState> navigatorKey = null,
     string defaultTitle = null,
     Dictionary <string, WidgetBuilder> routes = null,
     RouteFactory onGenerateRoute = null,
     RouteFactory onUnknownRoute  = null,
     List <NavigatorObserver> navigatorObservers = null
     ) : base(key: key)
 {
     this.builder            = builder;
     this.navigatorKey       = navigatorKey;
     this.defaultTitle       = defaultTitle;
     this.routes             = routes;
     this.onGenerateRoute    = onGenerateRoute;
     this.onUnknownRoute     = onUnknownRoute;
     this.navigatorObservers = navigatorObservers ?? new List <NavigatorObserver>();
 }
Esempio n. 28
0
 public void SetUp()
 {
     nodeList = new MasterNodeList<string>();
     vn = nodeList.newValueNodeFromValue("A");
     vn2 = nodeList.newValueNodeFromValue("B");
     vn3 = nodeList.newValueNodeFromValue("C");
     edge = new Edge() {
         link = new DirectedPair()
         {
             from = vn,
             to = vn2
         }
     };
     edge2 = new Edge()
     {
         link = new DirectedPair()
         {
             from = vn3,
             to = vn
         }
     };
     routeFactory = new RouteFactory<string>();
     routeFactory.newRouteFromEdge(edge);
 }
Esempio n. 29
0
        public static EdgeHubConfig GetEdgeHubConfig(EdgeHubDesiredProperties desiredProperties, RouteFactory routeFactory)
        {
            Preconditions.CheckNotNull(desiredProperties, nameof(desiredProperties));

            ValidateSchemaVersion(desiredProperties.SchemaVersion);

            var routes = new Dictionary <string, RouteConfig>();

            if (desiredProperties.Routes != null)
            {
                foreach (KeyValuePair <string, RouteConfiguration> inputRoute in desiredProperties.Routes)
                {
                    try
                    {
                        Route route = routeFactory.Create(inputRoute.Value.Route, inputRoute.Value.Priority, inputRoute.Value.TimeToLiveSecs);
                        routes.Add(inputRoute.Key, new RouteConfig(inputRoute.Key, inputRoute.Value.Route, route));
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException($"Error parsing route {inputRoute.Key} - {ex.Message}", ex);
                    }
                }
            }

            return(new EdgeHubConfig(desiredProperties.SchemaVersion, new ReadOnlyDictionary <string, RouteConfig>(routes), desiredProperties.StoreAndForwardConfiguration));
        }
Esempio n. 30
0
        protected override void Load(ContainerBuilder builder)
        {
            // IMessageConverter<IRoutingMessage>
            builder.Register(c => new RoutingMessageConverter())
            .As <Core.IMessageConverter <IRoutingMessage> >()
            .SingleInstance();

            // IRoutingPerfCounter
            builder.Register(
                c =>
            {
                Routing.PerfCounter = NullRoutingPerfCounter.Instance;
                return(Routing.PerfCounter);
            })
            .As <IRoutingPerfCounter>()
            .AutoActivate()
            .SingleInstance();

            // IRoutingUserAnalyticsLogger
            builder.Register(
                c =>
            {
                Routing.UserAnalyticsLogger = NullUserAnalyticsLogger.Instance;
                return(Routing.UserAnalyticsLogger);
            })
            .As <IRoutingUserAnalyticsLogger>()
            .AutoActivate()
            .SingleInstance();

            // IRoutingUserMetricLogger
            builder.Register(
                c =>
            {
                Routing.UserMetricLogger = NullRoutingUserMetricLogger.Instance;
                return(Routing.UserMetricLogger);
            })
            .As <IRoutingUserMetricLogger>()
            .AutoActivate()
            .SingleInstance();

            // IMessageConverter<Message>
            builder.Register(c => new DeviceClientMessageConverter())
            .As <Core.IMessageConverter <Message> >()
            .SingleInstance();

            // IMessageConverter<Twin>
            builder.Register(c => new TwinMessageConverter())
            .As <Core.IMessageConverter <Twin> >()
            .SingleInstance();

            // IMessageConverter<TwinCollection>
            builder.Register(c => new TwinCollectionMessageConverter())
            .As <Core.IMessageConverter <TwinCollection> >()
            .SingleInstance();

            // IMessageConverterProvider
            builder.Register(
                c => new MessageConverterProvider(
                    new Dictionary <Type, IMessageConverter>()
            {
                { typeof(Message), c.Resolve <Core.IMessageConverter <Message> >() },
                { typeof(Twin), c.Resolve <Core.IMessageConverter <Twin> >() },
                { typeof(TwinCollection), c.Resolve <Core.IMessageConverter <TwinCollection> >() }
            }))
            .As <IMessageConverterProvider>()
            .SingleInstance();

            // IDeviceConnectivityManager
            builder.Register(
                c =>
            {
                var edgeHubCredentials = c.ResolveNamed <IClientCredentials>("EdgeHubCredentials");
                IDeviceConnectivityManager deviceConnectivityManager = this.experimentalFeatures.DisableConnectivityCheck
                            ? new NullDeviceConnectivityManager()
                            : new DeviceConnectivityManager(this.connectivityCheckFrequency, TimeSpan.FromMinutes(2), edgeHubCredentials.Identity) as IDeviceConnectivityManager;
                return(deviceConnectivityManager);
            })
            .As <IDeviceConnectivityManager>()
            .SingleInstance();

            // IDeviceClientProvider
            builder.Register(
                c =>
            {
                IClientProvider underlyingClientProvider        = new ClientProvider();
                IClientProvider connectivityAwareClientProvider = new ConnectivityAwareClientProvider(underlyingClientProvider, c.Resolve <IDeviceConnectivityManager>());
                return(connectivityAwareClientProvider);
            })
            .As <IClientProvider>()
            .SingleInstance();

            // Task<ICloudConnectionProvider>
            builder.Register(
                async c =>
            {
                var productInfoStore               = await c.Resolve <Task <IProductInfoStore> >();
                var messageConverterProvider       = c.Resolve <IMessageConverterProvider>();
                var clientProvider                 = c.Resolve <IClientProvider>();
                var tokenProvider                  = c.ResolveNamed <ITokenProvider>("EdgeHubClientAuthTokenProvider");
                var credentialsCacheTask           = c.Resolve <Task <ICredentialsCache> >();
                var edgeHubCredentials             = c.ResolveNamed <IClientCredentials>("EdgeHubCredentials");
                var deviceScopeIdentitiesCacheTask = c.Resolve <Task <IDeviceScopeIdentitiesCache> >();
                var proxy = c.Resolve <Option <IWebProxy> >();
                IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache = await deviceScopeIdentitiesCacheTask;
                ICredentialsCache credentialsCache = await credentialsCacheTask;
                ICloudConnectionProvider cloudConnectionProvider = new CloudConnectionProvider(
                    messageConverterProvider,
                    this.connectionPoolSize,
                    clientProvider,
                    this.upstreamProtocol,
                    tokenProvider,
                    deviceScopeIdentitiesCache,
                    credentialsCache,
                    edgeHubCredentials.Identity,
                    this.cloudConnectionIdleTimeout,
                    this.closeCloudConnectionOnIdleTimeout,
                    this.operationTimeout,
                    this.useServerHeartbeat,
                    proxy,
                    productInfoStore);
                return(cloudConnectionProvider);
            })
            .As <Task <ICloudConnectionProvider> >()
            .SingleInstance();

            // IIdentityProvider
            builder.Register(_ => new IdentityProvider(this.iotHubName))
            .As <IIdentityProvider>()
            .SingleInstance();

            // Task<IConnectionManager>
            builder.Register(
                async c =>
            {
                var cloudConnectionProviderTask = c.Resolve <Task <ICloudConnectionProvider> >();
                var credentialsCacheTask        = c.Resolve <Task <ICredentialsCache> >();
                var identityProvider            = c.Resolve <IIdentityProvider>();
                var deviceConnectivityManager   = c.Resolve <IDeviceConnectivityManager>();
                ICloudConnectionProvider cloudConnectionProvider = await cloudConnectionProviderTask;
                ICredentialsCache credentialsCache   = await credentialsCacheTask;
                IConnectionManager connectionManager = new ConnectionManager(
                    cloudConnectionProvider,
                    credentialsCache,
                    identityProvider,
                    deviceConnectivityManager,
                    this.maxConnectedClients,
                    this.closeCloudConnectionOnDeviceDisconnect);
                return(connectionManager);
            })
            .As <Task <IConnectionManager> >()
            .SingleInstance();

            // Task<IEndpointFactory>
            builder.Register(
                async c =>
            {
                var messageConverter = c.Resolve <Core.IMessageConverter <IRoutingMessage> >();
                IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >();
                return(new EndpointFactory(connectionManager, messageConverter, this.edgeDeviceId, this.maxUpstreamBatchSize, this.upstreamFanOutFactor) as IEndpointFactory);
            })
            .As <Task <IEndpointFactory> >()
            .SingleInstance();

            // Task<RouteFactory>
            builder.Register(async c => new EdgeRouteFactory(await c.Resolve <Task <IEndpointFactory> >()) as RouteFactory)
            .As <Task <RouteFactory> >()
            .SingleInstance();

            // RouterConfig
            builder.Register(c => new RouterConfig(Enumerable.Empty <Route>()))
            .As <RouterConfig>()
            .SingleInstance();

            if (!this.isStoreAndForwardEnabled)
            {
                // EndpointExecutorConfig
                builder.Register(
                    c =>
                {
                    RetryStrategy defaultRetryStrategy = new FixedInterval(0, TimeSpan.FromSeconds(1));
                    TimeSpan defaultRevivePeriod       = TimeSpan.FromHours(1);
                    TimeSpan defaultTimeout            = TimeSpan.FromSeconds(60);
                    return(new EndpointExecutorConfig(defaultTimeout, defaultRetryStrategy, defaultRevivePeriod, true));
                })
                .As <EndpointExecutorConfig>()
                .SingleInstance();

                // IEndpointExecutorFactory
                builder.Register(c => new SyncEndpointExecutorFactory(c.Resolve <EndpointExecutorConfig>()))
                .As <IEndpointExecutorFactory>()
                .SingleInstance();

                // Task<Router>
                builder.Register(
                    async c =>
                {
                    var endpointExecutorFactory = c.Resolve <IEndpointExecutorFactory>();
                    var routerConfig            = c.Resolve <RouterConfig>();
                    Router router = await Router.CreateAsync(Guid.NewGuid().ToString(), this.iotHubName, routerConfig, endpointExecutorFactory);
                    return(router);
                })
                .As <Task <Router> >()
                .SingleInstance();

                // Task<ITwinManager>
                builder.Register(
                    async c =>
                {
                    if (!this.useV1TwinManager)
                    {
                        var messageConverterProvider         = c.Resolve <IMessageConverterProvider>();
                        IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >();
                        ITwinManager twinManager             = new PassThroughTwinManager(connectionManager, messageConverterProvider);
                        return(twinManager);
                    }
                    else
                    {
                        var messageConverterProvider         = c.Resolve <IMessageConverterProvider>();
                        IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >();
                        return(TwinManager.CreateTwinManager(connectionManager, messageConverterProvider, Option.None <IStoreProvider>()));
                    }
                })
                .As <Task <ITwinManager> >()
                .SingleInstance();
            }
            else
            {
                // EndpointExecutorConfig
                builder.Register(
                    c =>
                {
                    // Endpoint executor config values -
                    // ExponentialBackoff - minBackoff = 1s, maxBackoff = 60s, delta (used to add randomness to backoff) - 1s (default)
                    // Num of retries = int.MaxValue(we want to keep retrying till the message is sent)
                    // Revive period - period for which the endpoint should be considered dead if it doesn't respond - 1 min (we want to try continuously till the message expires)
                    // Timeout - time for which we want for the ack from the endpoint = 30s
                    // TODO - Should the number of retries be tied to the Store and Forward ttl? Not
                    // doing that right now as that value can be changed at runtime, but these settings
                    // cannot. Need to make the number of retries dynamically configurable for that.
                    TimeSpan minWait            = TimeSpan.FromSeconds(1);
                    TimeSpan maxWait            = TimeSpan.FromSeconds(60);
                    TimeSpan delta              = TimeSpan.FromSeconds(1);
                    int retries                 = int.MaxValue;
                    RetryStrategy retryStrategy = new ExponentialBackoff(retries, minWait, maxWait, delta);
                    TimeSpan timeout            = TimeSpan.FromSeconds(30);
                    TimeSpan revivePeriod       = TimeSpan.FromSeconds(30);
                    return(new EndpointExecutorConfig(timeout, retryStrategy, revivePeriod));
                })
                .As <EndpointExecutorConfig>()
                .SingleInstance();

                // Task<ICheckpointStore>
                builder.Register(
                    async c =>
                {
                    var dbStoreProvider              = await c.Resolve <Task <IDbStoreProvider> >();
                    IStoreProvider storeProvider     = new StoreProvider(dbStoreProvider);
                    ICheckpointStore checkpointStore = CheckpointStore.Create(storeProvider);
                    return(checkpointStore);
                })
                .As <Task <ICheckpointStore> >()
                .SingleInstance();

                // Task<IMessageStore>
                builder.Register(
                    async c =>
                {
                    var checkpointStore          = await c.Resolve <Task <ICheckpointStore> >();
                    var dbStoreProvider          = await c.Resolve <Task <IDbStoreProvider> >();
                    IStoreProvider storeProvider = new StoreProvider(dbStoreProvider);
                    IMessageStore messageStore   = new MessageStore(storeProvider, checkpointStore, this.storeAndForwardConfiguration.TimeToLive, this.checkEntireQueueOnCleanup);
                    return(messageStore);
                })
                .As <Task <IMessageStore> >()
                .SingleInstance();

                // Task<IEndpointExecutorFactory>
                builder.Register(
                    async c =>
                {
                    var endpointExecutorConfig = c.Resolve <EndpointExecutorConfig>();
                    var messageStore           = await c.Resolve <Task <IMessageStore> >();
                    IEndpointExecutorFactory endpointExecutorFactory = new StoringAsyncEndpointExecutorFactory(endpointExecutorConfig, new AsyncEndpointExecutorOptions(10, TimeSpan.FromSeconds(10)), messageStore);
                    return(endpointExecutorFactory);
                })
                .As <Task <IEndpointExecutorFactory> >()
                .SingleInstance();

                // Task<Router>
                builder.Register(
                    async c =>
                {
                    var checkpointStore         = await c.Resolve <Task <ICheckpointStore> >();
                    var routerConfig            = c.Resolve <RouterConfig>();
                    var endpointExecutorFactory = await c.Resolve <Task <IEndpointExecutorFactory> >();
                    return(await Router.CreateAsync(Guid.NewGuid().ToString(), this.iotHubName, routerConfig, endpointExecutorFactory, checkpointStore));
                })
                .As <Task <Router> >()
                .SingleInstance();

                // Task<ITwinManager>
                builder.Register(
                    async c =>
                {
                    if (this.useV1TwinManager)
                    {
                        var dbStoreProvider                  = await c.Resolve <Task <IDbStoreProvider> >();
                        var messageConverterProvider         = c.Resolve <IMessageConverterProvider>();
                        IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >();
                        return(TwinManager.CreateTwinManager(connectionManager, messageConverterProvider, Option.Some <IStoreProvider>(new StoreProvider(dbStoreProvider))));
                    }
                    else
                    {
                        var messageConverterProvider  = c.Resolve <IMessageConverterProvider>();
                        var deviceConnectivityManager = c.Resolve <IDeviceConnectivityManager>();
                        var connectionManagerTask     = c.Resolve <Task <IConnectionManager> >();
                        IEntityStore <string, TwinStoreEntity> entityStore = await this.GetTwinStore(c);
                        IConnectionManager connectionManager = await connectionManagerTask;
                        ITwinManager twinManager             = StoringTwinManager.Create(
                            connectionManager,
                            messageConverterProvider,
                            entityStore,
                            deviceConnectivityManager,
                            new ReportedPropertiesValidator(),
                            this.minTwinSyncPeriod,
                            this.reportedPropertiesSyncFrequency);
                        return(twinManager);
                    }
                })
                .As <Task <ITwinManager> >()
                .SingleInstance();
            }

            // IClientCredentials "EdgeHubCredentials"
            builder.Register(
                c =>
            {
                var identityFactory = c.Resolve <IClientCredentialsFactory>();
                IClientCredentials edgeHubCredentials = this.connectionString.Map(cs => identityFactory.GetWithConnectionString(cs)).GetOrElse(
                    () => identityFactory.GetWithIotEdged(this.edgeDeviceId, this.edgeModuleId));
                return(edgeHubCredentials);
            })
            .Named <IClientCredentials>("EdgeHubCredentials")
            .SingleInstance();

            // Task<IInvokeMethodHandler>
            builder.Register(
                async c =>
            {
                IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >();
                return(new InvokeMethodHandler(connectionManager) as IInvokeMethodHandler);
            })
            .As <Task <IInvokeMethodHandler> >()
            .SingleInstance();

            // Task<ISubscriptionProcessor>
            builder.Register(
                async c =>
            {
                var connectionManagerTask = c.Resolve <Task <IConnectionManager> >();
                if (this.experimentalFeatures.DisableCloudSubscriptions)
                {
                    return(new LocalSubscriptionProcessor(await connectionManagerTask) as ISubscriptionProcessor);
                }
                else
                {
                    var invokeMethodHandlerTask              = c.Resolve <Task <IInvokeMethodHandler> >();
                    var deviceConnectivityManager            = c.Resolve <IDeviceConnectivityManager>();
                    IConnectionManager connectionManager     = await connectionManagerTask;
                    IInvokeMethodHandler invokeMethodHandler = await invokeMethodHandlerTask;
                    return(new SubscriptionProcessor(connectionManager, invokeMethodHandler, deviceConnectivityManager) as ISubscriptionProcessor);
                }
            })
            .As <Task <ISubscriptionProcessor> >()
            .SingleInstance();

            // Task<IEdgeHub>
            builder.Register(
                async c =>
            {
                var routingMessageConverter = c.Resolve <Core.IMessageConverter <IRoutingMessage> >();
                var routerTask                = c.Resolve <Task <Router> >();
                var twinManagerTask           = c.Resolve <Task <ITwinManager> >();
                var invokeMethodHandlerTask   = c.Resolve <Task <IInvokeMethodHandler> >();
                var connectionManagerTask     = c.Resolve <Task <IConnectionManager> >();
                var subscriptionProcessorTask = c.Resolve <Task <ISubscriptionProcessor> >();
                Router router                                = await routerTask;
                ITwinManager twinManager                     = await twinManagerTask;
                IConnectionManager connectionManager         = await connectionManagerTask;
                IInvokeMethodHandler invokeMethodHandler     = await invokeMethodHandlerTask;
                ISubscriptionProcessor subscriptionProcessor = await subscriptionProcessorTask;
                IEdgeHub hub = new RoutingEdgeHub(
                    router,
                    routingMessageConverter,
                    connectionManager,
                    twinManager,
                    this.edgeDeviceId,
                    invokeMethodHandler,
                    subscriptionProcessor);
                return(hub);
            })
            .As <Task <IEdgeHub> >()
            .SingleInstance();

            // Task<ConfigUpdater>
            builder.Register(
                async c =>
            {
                IMessageStore messageStore = this.isStoreAndForwardEnabled ? await c.Resolve <Task <IMessageStore> >() : null;
                var storageSpaceChecker    = c.Resolve <IStorageSpaceChecker>();
                var edgeHubCredentials     = c.ResolveNamed <IClientCredentials>("EdgeHubCredentials");
                RouteFactory routeFactory  = await c.Resolve <Task <RouteFactory> >();
                Router router            = await c.Resolve <Task <Router> >();
                var twinManagerTask      = c.Resolve <Task <ITwinManager> >();
                var twinMessageConverter = c.Resolve <Core.IMessageConverter <Twin> >();
                var twinManager          = await twinManagerTask;
                var configUpdater        = new ConfigUpdater(router, messageStore, this.configUpdateFrequency, storageSpaceChecker);
                return(configUpdater);
            })
            .As <Task <ConfigUpdater> >()
            .SingleInstance();

            // Task<IConfigSource>
            builder.Register <Task <IConfigSource> >(
                async c =>
            {
                RouteFactory routeFactory = await c.Resolve <Task <RouteFactory> >();
                if (this.useTwinConfig)
                {
                    var edgeHubCredentials             = c.ResolveNamed <IClientCredentials>("EdgeHubCredentials");
                    var twinCollectionMessageConverter = c.Resolve <Core.IMessageConverter <TwinCollection> >();
                    var twinMessageConverter           = c.Resolve <Core.IMessageConverter <Twin> >();
                    var twinManagerTask                  = c.Resolve <Task <ITwinManager> >();
                    var edgeHubTask                      = c.Resolve <Task <IEdgeHub> >();
                    ITwinManager twinManager             = await twinManagerTask;
                    IEdgeHub edgeHub                     = await edgeHubTask;
                    IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >();
                    IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache = await c.Resolve <Task <IDeviceScopeIdentitiesCache> >();

                    var edgeHubConnection = await EdgeHubConnection.Create(
                        edgeHubCredentials.Identity,
                        edgeHub,
                        twinManager,
                        connectionManager,
                        routeFactory,
                        twinCollectionMessageConverter,
                        this.versionInfo,
                        deviceScopeIdentitiesCache);

                    return(new TwinConfigSource(edgeHubConnection, edgeHubCredentials.Identity.Id, this.versionInfo, twinManager, twinMessageConverter, twinCollectionMessageConverter, routeFactory));
                }
                else
                {
                    return(new LocalConfigSource(routeFactory, this.routes, this.storeAndForwardConfiguration));
                }
            })
            .As <Task <IConfigSource> >()
            .SingleInstance();

            // Task<IConnectionProvider>
            builder.Register(
                async c =>
            {
                var connectionManagerTask              = c.Resolve <Task <IConnectionManager> >();
                var edgeHubTask                        = c.Resolve <Task <IEdgeHub> >();
                IConnectionManager connectionManager   = await connectionManagerTask;
                IEdgeHub edgeHub                       = await edgeHubTask;
                IConnectionProvider connectionProvider = new ConnectionProvider(connectionManager, edgeHub, this.messageAckTimeout);
                return(connectionProvider);
            })
            .As <Task <IConnectionProvider> >()
            .SingleInstance();

            base.Load(builder);
        }
Esempio n. 31
0
        protected override void Load(ContainerBuilder builder)
        {
            // IMessageConverter<IRoutingMessage>
            builder.Register(c => new RoutingMessageConverter())
            .As <Core.IMessageConverter <IRoutingMessage> >()
            .SingleInstance();

            // IRoutingPerfCounter
            builder.Register(
                c =>
            {
                Routing.PerfCounter = NullRoutingPerfCounter.Instance;
                return(Routing.PerfCounter);
            })
            .As <IRoutingPerfCounter>()
            .AutoActivate()
            .SingleInstance();

            // IRoutingUserAnalyticsLogger
            builder.Register(
                c =>
            {
                Routing.UserAnalyticsLogger = NullUserAnalyticsLogger.Instance;
                return(Routing.UserAnalyticsLogger);
            })
            .As <IRoutingUserAnalyticsLogger>()
            .AutoActivate()
            .SingleInstance();

            // IRoutingUserMetricLogger
            builder.Register(
                c =>
            {
                Routing.UserMetricLogger = NullRoutingUserMetricLogger.Instance;
                return(Routing.UserMetricLogger);
            })
            .As <IRoutingUserMetricLogger>()
            .AutoActivate()
            .SingleInstance();

            // IMessageConverter<Message>
            builder.Register(c => new DeviceClientMessageConverter())
            .As <Core.IMessageConverter <Message> >()
            .SingleInstance();

            // IMessageConverter<Twin>
            builder.Register(c => new TwinMessageConverter())
            .As <Core.IMessageConverter <Twin> >()
            .SingleInstance();

            // IMessageConverter<TwinCollection>
            builder.Register(c => new TwinCollectionMessageConverter())
            .As <Core.IMessageConverter <TwinCollection> >()
            .SingleInstance();

            // IMessageConverterProvider
            builder.Register(
                c => new MessageConverterProvider(new Dictionary <Type, IMessageConverter>()
            {
                { typeof(Message), c.Resolve <Core.IMessageConverter <Message> >() },
                { typeof(Twin), c.Resolve <Core.IMessageConverter <Twin> >() },
                { typeof(TwinCollection), c.Resolve <Core.IMessageConverter <TwinCollection> >() }
            }))
            .As <IMessageConverterProvider>()
            .SingleInstance();

            // IDeviceConnectivityManager
            builder.Register(
                c =>
            {
                IDeviceConnectivityManager deviceConnectivityManager = new DeviceConnectivityManager(this.connectivityCheckFrequency, TimeSpan.FromMinutes(2));
                return(deviceConnectivityManager);
            })
            .As <IDeviceConnectivityManager>()
            .SingleInstance();

            // IDeviceClientProvider
            builder.Register(c =>
            {
                IClientProvider underlyingClientProvider        = new ClientProvider();
                IClientProvider connectivityAwareClientProvider = new ConnectivityAwareClientProvider(underlyingClientProvider, c.Resolve <IDeviceConnectivityManager>());
                return(connectivityAwareClientProvider);
            })
            .As <IClientProvider>()
            .SingleInstance();

            // Task<ICloudConnectionProvider>
            builder.Register(
                async c =>
            {
                var messageConverterProvider = c.Resolve <IMessageConverterProvider>();
                var clientProvider           = c.Resolve <IClientProvider>();
                var tokenProvider            = c.ResolveNamed <ITokenProvider>("EdgeHubClientAuthTokenProvider");
                IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache = await c.Resolve <Task <IDeviceScopeIdentitiesCache> >();
                ICloudConnectionProvider cloudConnectionProvider       = new CloudConnectionProvider(
                    messageConverterProvider,
                    this.connectionPoolSize,
                    clientProvider,
                    this.upstreamProtocol,
                    tokenProvider,
                    deviceScopeIdentitiesCache,
                    TimeSpan.FromMinutes(60));
                return(cloudConnectionProvider);
            })
            .As <Task <ICloudConnectionProvider> >()
            .SingleInstance();

            // Task<ICredentialsStore>
            builder.Register(async c =>
            {
                if (this.cacheTokens)
                {
                    IKeyValueStore <string, string> encryptedStore = await c.ResolveNamed <Task <IKeyValueStore <string, string> > >("EncryptedStore");
                    return(new TokenCredentialsStore(encryptedStore));
                }
                else
                {
                    return(new NullCredentialsStore() as ICredentialsStore);
                }
            })
            .As <Task <ICredentialsStore> >()
            .SingleInstance();

            // Task<IConnectionManager>
            builder.Register(
                async c =>
            {
                ICloudConnectionProvider cloudConnectionProvider = await c.Resolve <Task <ICloudConnectionProvider> >();
                IConnectionManager connectionManager             = new ConnectionManager(cloudConnectionProvider, this.maxConnectedClients);
                return(connectionManager);
            })
            .As <Task <IConnectionManager> >()
            .SingleInstance();

            // Task<IEndpointFactory>
            builder.Register(async c =>
            {
                var messageConverter = c.Resolve <Core.IMessageConverter <IRoutingMessage> >();
                IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >();
                return(new EndpointFactory(connectionManager, messageConverter, this.edgeDeviceId) as IEndpointFactory);
            })
            .As <Task <IEndpointFactory> >()
            .SingleInstance();

            // Task<RouteFactory>
            builder.Register(async c => new EdgeRouteFactory(await c.Resolve <Task <IEndpointFactory> >()) as RouteFactory)
            .As <Task <RouteFactory> >()
            .SingleInstance();

            // RouterConfig
            builder.Register(c => new RouterConfig(Enumerable.Empty <Route>()))
            .As <RouterConfig>()
            .SingleInstance();

            if (!this.isStoreAndForwardEnabled)
            {
                // EndpointExecutorConfig
                builder.Register(
                    c =>
                {
                    RetryStrategy defaultRetryStrategy = new FixedInterval(0, TimeSpan.FromSeconds(1));
                    TimeSpan defaultRevivePeriod       = TimeSpan.FromHours(1);
                    TimeSpan defaultTimeout            = TimeSpan.FromSeconds(60);
                    return(new EndpointExecutorConfig(defaultTimeout, defaultRetryStrategy, defaultRevivePeriod, true));
                })
                .As <EndpointExecutorConfig>()
                .SingleInstance();

                // IEndpointExecutorFactory
                builder.Register(c => new SyncEndpointExecutorFactory(c.Resolve <EndpointExecutorConfig>()))
                .As <IEndpointExecutorFactory>()
                .SingleInstance();

                // Task<Router>
                builder.Register(
                    async c =>
                {
                    var endpointExecutorFactory = c.Resolve <IEndpointExecutorFactory>();
                    var routerConfig            = c.Resolve <RouterConfig>();
                    Router router = await Router.CreateAsync(Guid.NewGuid().ToString(), this.iotHubName, routerConfig, endpointExecutorFactory);
                    return(router);
                })
                .As <Task <Router> >()
                .SingleInstance();

                // Task<ITwinManager>
                builder.Register(async c =>
                {
                    var messageConverterProvider         = c.Resolve <IMessageConverterProvider>();
                    IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >();
                    return(TwinManager.CreateTwinManager(connectionManager, messageConverterProvider, Option.None <IStoreProvider>()));
                })
                .As <Task <ITwinManager> >()
                .SingleInstance();
            }
            else
            {
                // EndpointExecutorConfig
                builder.Register(
                    c =>
                {
                    // Endpoint executor config values -
                    // ExponentialBackoff - minBackoff = 1s, maxBackoff = 60s, delta (used to add randomness to backoff) - 1s (default)
                    // Num of retries = int.MaxValue(we want to keep retrying till the message is sent)
                    // Revive period - period for which the endpoint should be considered dead if it doesn't respond - 1 min (we want to try continuously till the message expires)
                    // Timeout - time for which we want for the ack from the endpoint = 30s
                    // TODO - Should the number of retries be tied to the Store and Forward ttl? Not
                    // doing that right now as that value can be changed at runtime, but these settings
                    // cannot. Need to make the number of retries dynamically configurable for that.

                    TimeSpan minWait            = TimeSpan.FromSeconds(1);
                    TimeSpan maxWait            = TimeSpan.FromSeconds(60);
                    TimeSpan delta              = TimeSpan.FromSeconds(1);
                    int retries                 = int.MaxValue;
                    RetryStrategy retryStrategy = new ExponentialBackoff(retries, minWait, maxWait, delta);
                    TimeSpan timeout            = TimeSpan.FromSeconds(30);
                    TimeSpan revivePeriod       = TimeSpan.FromSeconds(30);
                    return(new EndpointExecutorConfig(timeout, retryStrategy, revivePeriod));
                })
                .As <EndpointExecutorConfig>()
                .SingleInstance();

                // ICheckpointStore
                builder.Register(c => CheckpointStore.Create(c.Resolve <IDbStoreProvider>()))
                .As <ICheckpointStore>()
                .SingleInstance();

                // IMessageStore
                builder.Register(
                    c =>
                {
                    var checkpointStore          = c.Resolve <ICheckpointStore>();
                    var dbStoreProvider          = c.Resolve <IDbStoreProvider>();
                    IStoreProvider storeProvider = new StoreProvider(dbStoreProvider);
                    IMessageStore messageStore   = new MessageStore(storeProvider, checkpointStore, TimeSpan.MaxValue);
                    return(messageStore);
                })
                .As <IMessageStore>()
                .SingleInstance();

                // IEndpointExecutorFactory
                builder.Register(
                    c =>
                {
                    var endpointExecutorConfig = c.Resolve <EndpointExecutorConfig>();
                    var messageStore           = c.Resolve <IMessageStore>();
                    IEndpointExecutorFactory endpointExecutorFactory = new StoringAsyncEndpointExecutorFactory(endpointExecutorConfig, new AsyncEndpointExecutorOptions(10, TimeSpan.FromSeconds(10)), messageStore);
                    return(endpointExecutorFactory);
                })
                .As <IEndpointExecutorFactory>()
                .SingleInstance();

                // Task<Router>
                builder.Register(
                    async c =>
                {
                    var checkpointStore         = c.Resolve <ICheckpointStore>();
                    var routerConfig            = c.Resolve <RouterConfig>();
                    var endpointExecutorFactory = c.Resolve <IEndpointExecutorFactory>();
                    return(await Router.CreateAsync(Guid.NewGuid().ToString(), this.iotHubName, routerConfig, endpointExecutorFactory, checkpointStore));
                })
                .As <Task <Router> >()
                .SingleInstance();

                // Task<ITwinManager>
                builder.Register(async c =>
                {
                    var dbStoreProvider                  = c.Resolve <IDbStoreProvider>();
                    var messageConverterProvider         = c.Resolve <IMessageConverterProvider>();
                    IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >();
                    return(TwinManager.CreateTwinManager(connectionManager, messageConverterProvider, Option.Some <IStoreProvider>(new StoreProvider(dbStoreProvider))));
                })
                .As <Task <ITwinManager> >()
                .SingleInstance();
            }

            // IClientCredentials "EdgeHubCredentials"
            builder.Register(
                c =>
            {
                var identityFactory = c.Resolve <IClientCredentialsFactory>();
                IClientCredentials edgeHubCredentials = this.connectionString.Map(cs => identityFactory.GetWithConnectionString(cs)).GetOrElse(
                    () => identityFactory.GetWithIotEdged(this.edgeDeviceId, this.edgeModuleId));
                return(edgeHubCredentials);
            })
            .Named <IClientCredentials>("EdgeHubCredentials")
            .SingleInstance();

            // Task<ICloudProxy> "EdgeHubCloudProxy"
            builder.Register(
                async c =>
            {
                var edgeHubCredentials = c.ResolveNamed <IClientCredentials>("EdgeHubCredentials");
                IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >();
                Try <ICloudProxy> cloudProxyTry      = await connectionManager.CreateCloudConnectionAsync(edgeHubCredentials);
                if (!cloudProxyTry.Success)
                {
                    throw new EdgeHubConnectionException("Edge hub is unable to connect to IoT Hub", cloudProxyTry.Exception);
                }

                ICloudProxy cloudProxy = cloudProxyTry.Value;
                return(cloudProxy);
            })
            .Named <Task <ICloudProxy> >("EdgeHubCloudProxy")
            .SingleInstance();

            // Task<IInvokeMethodHandler>
            builder.Register(async c =>
            {
                IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >();
                return(new InvokeMethodHandler(connectionManager) as IInvokeMethodHandler);
            })
            .As <Task <IInvokeMethodHandler> >()
            .SingleInstance();

            // Task<IEdgeHub>
            builder.Register(
                async c =>
            {
                var routingMessageConverter = c.Resolve <Core.IMessageConverter <IRoutingMessage> >();
                var routerTask              = c.Resolve <Task <Router> >();
                var twinManagerTask         = c.Resolve <Task <ITwinManager> >();
                var invokeMethodHandlerTask = c.Resolve <Task <IInvokeMethodHandler> >();
                var connectionManagerTask   = c.Resolve <Task <IConnectionManager> >();
                Router router                            = await routerTask;
                ITwinManager twinManager                 = await twinManagerTask;
                IConnectionManager connectionManager     = await connectionManagerTask;
                IInvokeMethodHandler invokeMethodHandler = await invokeMethodHandlerTask;
                IEdgeHub hub = new RoutingEdgeHub(router, routingMessageConverter,
                                                  connectionManager, twinManager, this.edgeDeviceId, invokeMethodHandler);
                return(hub);
            })
            .As <Task <IEdgeHub> >()
            .SingleInstance();

            // Task<ConfigUpdater>
            builder.Register(
                async c =>
            {
                IMessageStore messageStore = this.isStoreAndForwardEnabled ? c.Resolve <IMessageStore>() : null;
                Router router     = await c.Resolve <Task <Router> >();
                var configUpdater = new ConfigUpdater(router, messageStore);
                return(configUpdater);
            })
            .As <Task <ConfigUpdater> >()
            .SingleInstance();

            // Task<IConfigSource>
            builder.Register(
                async c =>
            {
                RouteFactory routeFactory = await c.Resolve <Task <RouteFactory> >();
                if (this.useTwinConfig)
                {
                    var edgeHubCredentials             = c.ResolveNamed <IClientCredentials>("EdgeHubCredentials");
                    var twinCollectionMessageConverter = c.Resolve <Core.IMessageConverter <TwinCollection> >();
                    var twinMessageConverter           = c.Resolve <Core.IMessageConverter <Twin> >();
                    ITwinManager twinManager           = await c.Resolve <Task <ITwinManager> >();
                    ICloudProxy cloudProxy             = await c.ResolveNamed <Task <ICloudProxy> >("EdgeHubCloudProxy");
                    IEdgeHub edgeHub = await c.Resolve <Task <IEdgeHub> >();
                    IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >();
                    IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache = await c.Resolve <Task <IDeviceScopeIdentitiesCache> >();
                    IConfigSource edgeHubConnection = await EdgeHubConnection.Create(
                        edgeHubCredentials,
                        edgeHub,
                        twinManager,
                        connectionManager,
                        cloudProxy,
                        routeFactory,
                        twinCollectionMessageConverter,
                        twinMessageConverter,
                        this.versionInfo,
                        deviceScopeIdentitiesCache
                        );
                    return(edgeHubConnection);
                }
                else
                {
                    return(new LocalConfigSource(routeFactory, this.routes, this.storeAndForwardConfiguration));
                }
            })
            .As <Task <IConfigSource> >()
            .SingleInstance();

            // Task<IConnectionProvider>
            builder.Register(
                async c =>
            {
                IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >();
                IEdgeHub edgeHub = await c.Resolve <Task <IEdgeHub> >();
                IConnectionProvider connectionProvider = new ConnectionProvider(connectionManager, edgeHub);
                return(connectionProvider);
            })
            .As <Task <IConnectionProvider> >()
            .SingleInstance();

            base.Load(builder);
        }
Esempio n. 32
0
 public EdgeHubConfigParser(RouteFactory routeFactory, BrokerPropertiesValidator validator)
 {
     this.routeFactory = Preconditions.CheckNotNull(routeFactory, nameof(routeFactory));
     this.validator    = Preconditions.CheckNotNull(validator, nameof(validator));
 }
Esempio n. 33
0
        static ReadOnlyDictionary <string, RouteConfig> ParseRoutesWithPriority(IDictionary <string, RouteSpec> routeSpecs, RouteFactory routeFactory)
        {
            var routes = new Dictionary <string, RouteConfig>();

            foreach (KeyValuePair <string, RouteSpec> inputRoute in routeSpecs)
            {
                try
                {
                    Route route = routeFactory.Create(inputRoute.Value.Route, inputRoute.Value.Priority, inputRoute.Value.TimeToLiveSecs);
                    routes.Add(inputRoute.Key, new RouteConfig(inputRoute.Key, inputRoute.Value.Route, route));
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException($"Error parsing route {inputRoute.Key} - {ex.Message}", ex);
                }
            }

            return(new ReadOnlyDictionary <string, RouteConfig>(routes));
        }
Esempio n. 34
0
        public WidgetsApp(
            Key key = null,
            GlobalKey <NavigatorState> navigatorKey         = null,
            RouteFactory onGenerateRoute                    = null,
            InitialRouteListFactory onGenerateInitialRoutes = null,
            RouteFactory onUnknownRoute = null,
            List <NavigatorObserver> navigatorObservers = null,
            string initialRoute = null,
            PageRouteFactory pageRouteBuilder = null,
            Widget home = null,
            Dictionary <string, WidgetBuilder> routes = null,
            TransitionBuilder builder = null,
            string title = "",
            GenerateAppTitle onGenerateTitle = null,
            TextStyle textStyle = null,
            Color color         = null,
            Locale locale       = null,
            List <LocalizationsDelegate> localizationsDelegates       = null,
            LocaleListResolutionCallback localeListResolutionCallback = null,
            LocaleResolutionCallback localeResolutionCallback         = null,
            List <Locale> supportedLocales     = null,
            bool showPerformanceOverlay        = false,
            bool checkerboardRasterCacheImages = false,
            bool checkerboardOffscreenLayers   = false,
            bool showSemanticsDebugger         = false,
            bool debugShowWidgetInspector      = false,
            bool debugShowCheckedModeBanner    = true,
            InspectorSelectButtonBuilder inspectorSelectButtonBuilder = null,
            Dictionary <LogicalKeySet, Intent> shortcuts = null,
            Dictionary <LocalKey, ActionFactory> actions = null
            ) : base(key: key)
        {
            routes           = routes ?? new Dictionary <string, WidgetBuilder>();
            supportedLocales = supportedLocales ?? new List <Locale> {
                new Locale("en", "US")
            };
            window = Window.instance;
            D.assert(routes != null);
            D.assert(color != null);
            D.assert(supportedLocales != null && supportedLocales.isNotEmpty());
            this.home                          = home;
            this.navigatorKey                  = navigatorKey;
            this.onGenerateRoute               = onGenerateRoute;
            this.onGenerateInitialRoutes       = onGenerateInitialRoutes;
            this.onUnknownRoute                = onUnknownRoute;
            this.pageRouteBuilder              = pageRouteBuilder;
            this.routes                        = routes;
            this.navigatorObservers            = navigatorObservers ?? new List <NavigatorObserver>();
            this.initialRoute                  = initialRoute;
            this.builder                       = builder;
            this.textStyle                     = textStyle;
            this.locale                        = locale;
            this.localizationsDelegates        = localizationsDelegates;
            this.localeListResolutionCallback  = localeListResolutionCallback;
            this.localeResolutionCallback      = localeResolutionCallback;
            this.supportedLocales              = supportedLocales;
            this.showPerformanceOverlay        = showPerformanceOverlay;
            this.checkerboardOffscreenLayers   = checkerboardOffscreenLayers;
            this.checkerboardRasterCacheImages = checkerboardRasterCacheImages;
            this.showSemanticsDebugger         = showSemanticsDebugger;
            this.debugShowWidgetInspector      = debugShowWidgetInspector;
            this.debugShowCheckedModeBanner    = debugShowCheckedModeBanner;
            this.onGenerateTitle               = onGenerateTitle;
            this.title                         = title;
            this.color                         = color;
            this.inspectorSelectButtonBuilder  = inspectorSelectButtonBuilder;
            this.shortcuts                     = shortcuts;
            this.actions                       = actions;

            D.assert(
                home == null ||
                onGenerateInitialRoutes == null,
                () => "If onGenerateInitialRoutes is specifiied, the home argument will be redundant."
                );
            D.assert(
                home == null ||
                !this.routes.ContainsKey(key: Navigator.defaultRouteName),
                () => "If the home property is specified, the routes table " +
                "cannot include an entry for \" / \", since it would be redundant."
                );

            D.assert(
                builder != null ||
                home != null ||
                this.routes.ContainsKey(key: Navigator.defaultRouteName) ||
                onGenerateRoute != null ||
                onUnknownRoute != null,
                () => "Either the home property must be specified, " +
                "or the routes table must include an entry for \"/\", " +
                "or there must be on onGenerateRoute callback specified, " +
                "or there must be an onUnknownRoute callback specified, " +
                "or the builder property must be specified, " +
                "because otherwise there is nothing to fall back on if the " +
                "app is started with an intent that specifies an unknown route."
                );
            D.assert(
                home != null ||
                routes.isNotEmpty() ||
                onGenerateRoute != null ||
                onUnknownRoute != null
                ||
                builder != null &&
                navigatorKey == null &&
                initialRoute == null &&
                navigatorObservers.isEmpty(), () =>
                "If no route is provided using " +
                "home, routes, onGenerateRoute, or onUnknownRoute, " +
                "a non-null callback for the builder property must be provided, " +
                "and the other navigator-related properties, " +
                "navigatorKey, initialRoute, and navigatorObservers, " +
                "must have their initial values " +
                "(null, null, and the empty list, respectively).");

            D.assert(
                builder != null ||
                onGenerateRoute != null ||
                pageRouteBuilder != null,
                () => "If neither builder nor onGenerateRoute are provided, the " +
                "pageRouteBuilder must be specified so that the default handler " +
                "will know what kind of PageRoute transition to build."
                );
        }
Esempio n. 35
0
        public void SetUp()
        {
            list = new MasterNodeList<string>();
            nodeA = list.newValueNodeFromValue("A");
            nodeB = list.newValueNodeFromValue("B");
            nodeC = list.newValueNodeFromValue("C");
            nodeD = list.newValueNodeFromValue("D");
            nodeD2 = list.newValueNodeFromValue("D");
            nodeD3 = list.newValueNodeFromValue("D");

            routeFactory = new RouteFactory<string>();

            edgeAB = new Edge()
            {
                link = new DirectedPair()
                {
                    from = nodeA,
                    to = nodeB
                }
            };
            edgeBC = new Edge()
            {
                link = new DirectedPair()
                {
                    from = nodeB,
                    to = nodeC
                }
            };
            edgeCD = new Edge()
            {
                link = new DirectedPair()
                {
                    from = nodeC,
                    to = nodeD
                },
                requisiteLink = new DirectedPair()
                {
                    from = nodeA,
                    to = nodeB
                }
            };
            edgeBD = new Edge()
            {
                link = new DirectedPair()
                {
                    from = nodeB,
                    to = nodeD
                },
                requisiteLink = new DirectedPair()
                {
                    from = nodeA,
                    to = nodeB
                }
            };
            edgeBD2 = new Edge()
            {
                link = new DirectedPair()
                {
                    from = nodeB,
                    to = nodeD2
                },
                requisiteLink = new DirectedPair()
                {
                    from = nodeC,
                    to = nodeB
                }
            };

            edgeCB = new Edge()
            {
                link = new DirectedPair()
                {
                    from = nodeC,
                    to = nodeB
                }
            };
            routeCB = routeFactory.newRouteFromEdge(edgeCB);
            routeAB = routeFactory.newRouteFromEdge(edgeAB);
            routeBC = routeFactory.newRouteFromEdge(edgeBC);
            routeCD = routeFactory.newRouteFromEdge(edgeCD);

            routeBD = routeFactory.newRouteFromEdge(edgeBD);
            routeBD2 = routeFactory.newRouteFromEdge(edgeBD2);

            routeABC = routeFactory.newRouteFromConnectedRoutes(routeAB, routeBC);

            routeABCD = routeFactory.newRouteFromConnectedRoutes(routeABC, routeCD);
        }