Exemplo n.º 1
0
        public override void OnConfigure(INodeConfigurator c)
        {
            c.UseWindsorContainer();
            c.UseWindsorWcfProxyFactory();

            c.ForDataAccess().UseMongoDatabase(Configured.From.AppSettings("ConnectionString")).AsDomainStorage();

            c.OnStartupPerform<DataAccessConfiguration>();
            c.OnStartupPerform<WcfServicesRegistration>();
        }
Exemplo n.º 2
0
        public override void OnConfigure(INodeConfigurator c)
        {
            c.UseWindsorContainer();
            c.UseWindsorWcfProxyFactory();
            c.ForDataAccess().UseMongoDatabase(Configured.From.AppSettings("ConnectionString"))
                .AsInjectedContext(cc => cc.BoundToWebRequest());

            c.OnStartupPerform<QueryRegistration>();
            c.OnStartupPerform<WcfClientsRegistration>();
        }
Exemplo n.º 3
0
            public override void OnConfigure(INodeConfigurator c)
            {
                c.UseWindsorContainer();
                c.ForDataAccess()
                    .UseMongoDatabase("localhost:27001", "Anodyne-Testing")
                    .AsDomainStorage();
                c.ForDataAccess("ReadModel")
                    .UseMongoDatabase("localhost:27001", "Anodyne-Testing-Read")
                    .AsInjectedContext();

                c.OnStartupPerform(i =>
                    {
                        i.DataAccess.Default.OnNative(d => d.Drop());
                        i.DataAccess["ReadModel"].OnNative(d => d.Drop());
                    });
            }
Exemplo n.º 4
0
 public override void OnConfigure(INodeConfigurator c)
 {
     c.UseWindsorContainer();
     c.ForDataAccess().Use(new InMemoryDataAccessProvider()).AsDomainStorage();
 }
Exemplo n.º 5
0
    private static void Main(string[] args)
    {
      XmlConfigurator.Configure();

#if DEBUG
      //set log level to DEBUG
      var logLevel = Level.Debug;
      ((Hierarchy)LogManager.GetRepository()).Root.Level = logLevel;
      ((Hierarchy)LogManager.GetRepository()).RaiseConfigurationChanged(EventArgs.Empty);
#endif

      Console.WriteLine("-----------------------------------------");
      Console.WriteLine("HBus Console node version {0}", Assembly.GetExecutingAssembly().GetName().Version);
#if ARTIK_DEMO_LOCAL
      Console.WriteLine("ARTIK DEMO with local node");
#endif
#if ARTIK_DEMO_RASPBERRY
      Console.WriteLine("ARTIK DEMO with raspberry node");
#endif
      Console.WriteLine("-----------------------------------------");

      //Startup parameters
      Console.WriteLine("Configuring node.");
      var defaultConfig = Convert.ToBoolean(ConfigurationManager.AppSettings["node.defaultConfiguration"]);
      var xconfig = ConfigurationManager.AppSettings["node.configurationFile"];

      //Create configurator
      _configurator = new Nodes.Configuration.XmlConfigurator(xconfig);

      //Configure all global objects
      _configurator.Configure(defaultConfig);

      //Get the node
      _node = _configurator.Node;
      _bus = _configurator.Bus;
#if DEBUG
      //Add handlers to bus
      _bus.OnMessageReceived += (source, message) =>
      {
        Console.WriteLine("Received message from {0} to {1} = {2} ({3})", message.Source, message.Destination, message.Command, message.Flags);
      };
#endif

      //Configure remote sensors for demo porpouses
#if ARTIK_DEMO_LOCAL || ARTIK_DEMO_RASPBERRY
      var addr7 = Address.Parse(7);
      _extSensors = new List<Sensor>
      {
        new Sensor { Name = "SN701", Address = addr7 }, //arduino node DHT11 temperature
        new Sensor { Name = "SN702", Address = addr7 }, //arduino node DHT11 humidity
        new Sensor { Name = "SN703", Address = addr7 } //arduino node photoresistor light
    };
#endif
      //Add handlers to sensor events
      _node.OnSensorRead += (arg1, arg2) =>
      {
        Console.WriteLine("Sensor read from {0} : {1} = {2} @ {3}", arg1, arg2.Name, arg2.Value, arg2.Time);
      };

      Console.WriteLine("Reset node.");
      //Full reset
      _node.Reset(true);

      Console.WriteLine("Start node.");
      //Start node
      _node.Start();

      Console.WriteLine("Node {0} started", _node.Name);
      Console.WriteLine("Press i [enter] for info.");
      Console.WriteLine("Press x [enter] to exit.");

      #region local test section
      //Main loop
      while (true)
      {
        var w = Console.ReadLine();
        Pin pin;
        Device device;

        switch (w)
        {
          case "0":
            _bus.SendCommand(NodeCommands.CMD_PING, Address.HostAddress);
            break;

#if ARTIK_DEMO_LOCAL || ARTIK_DEMO_RASPBERRY
          #region input pins
          case "1":
            pin = _node.Pins[0];
            pin.Activate();
            break;
          case "2":
            pin = _node.Pins[1];
            pin.Activate();
            break;
          case "3":
            pin = _node.Pins[2];
            pin.Activate();
            break;
          case "4":
            pin = _node.Pins[3];
            pin.Activate();
            break;
          case "5":
            pin = _node.Pins[4];
            pin.Activate();
            break;
          case "6":
            pin = _node.Pins[5];
            pin.Activate();
            break;
          case "7":
            pin = _node.Pins[6];
            pin.Activate();
            break;
          case "8":
            pin = _node.Pins[7];
            pin.Activate();
            break;
          #endregion

          #region output pins
          case "q":
            pin = _node.Pins[8];
            pin.Activate();
            break;
          case "w":
            pin = _node.Pins[9];
            pin.Activate();
            break;
          case "e":
            pin = _node.Pins[10];
            pin.Activate();
            break;
          case "r":
            pin = _node.Pins[11];
            pin.Activate();
            break;
          #endregion
#endif

          #region devices
#if ARTIK_DEMO_LOCAL || ARTIK_DEMO_RASPBERRY
          case "t":
            device = _node.Devices[0];
            device.ExecuteAction(new DeviceAction { Device = device.Name, Action = "open" });
            break;
          case "y":
            device = _node.Devices[0];
            device.ExecuteAction(new DeviceAction { Device = device.Name, Action = "close" });
            break;
          case "u":
            device = _node.Devices[1];
            device.ExecuteAction(new DeviceAction { Device = device.Name, Action = "open" });
            break;
          case "i":
            device = _node.Devices[1];
            device.ExecuteAction(new DeviceAction { Device = device.Name, Action = "close" });
            break;
#endif
          #endregion

          #region sensors
#if ARTIK_DEMO_LOCAL || ARTIK_DEMO_RASPBERRY
          case "a":// local sensor
            readSensor(_node.Sensors[0]);
            break;
          case "s":// local sensor
            readSensor(_node.Sensors[1]);
            break;
          case "d"://remote sensor
            readSensor(_extSensors[0]);
            break;
          case "f"://remote sensor
            readSensor(_extSensors[1]);
            break;
          case "g"://remote sensor
            readSensor(_extSensors[2]);
            break;
#endif
          #endregion

          case "h":
            ShowHelp();
            break;

          case "x":
            Console.WriteLine("Closing node...");
            _node.Close();
            _node = null;

            Console.WriteLine("Bye.");
            return;
        }

      }

    }
Exemplo n.º 6
0
 /// <summary>
 /// Called when Node needs to be configured.
 /// </summary>
 /// <param name="c">Configuration builder</param>
 public abstract void OnConfigure(INodeConfigurator c);
Exemplo n.º 7
0
        public Node(INodeConfigurator configurator)
        {
            _configurator = configurator;

            //Bus controller
            _bus = _configurator.Bus;
            _bus.CommandReceived += OnCommandReceived;
            _bus.AckReceived += OnAckReceived;

            //Hardware Abstraction Layer
            _hal = _configurator.Hal;

            //Scheduler
            _scheduler = _configurator.Scheduler;

            //Private members
            _pinSubscribers = new Dictionary<string, Pin>();
            _deviceSubscribers = new Dictionary<string, Device>();
            _sensorSubscribers = new List<SensorSubscriber>();
            _nodeSubscribers = new Dictionary<Address, byte>();

            //Public configuration
            Status = new NodeStatusInfo
            {
                Mask = 0,
                NodeStatus = NodeStatusValues.Reset,
                BusStatus = _bus.Status,
                LastError = 0,
                TotalErrors = 0,
                Time = 0,
                LastActivatedInput = string.Empty,
                LastActivatedOutput = string.Empty
            };
            //TODO: Add autostart property
            //if (AutoStart) {
            //Configure node
            //if (LoadConfiguration(false))
            //{
            //    //Full reset node
            //    Reset(true);
            //}
            //}
            //else
            //_bus.Open();    //Only bus start

            Log.Debug("Node created");
        }
Exemplo n.º 8
0
        public Node()
        {
            _configurator = null;

            //Bus controller
            _bus = null;

            //Hardware Abstraction Layer
            _hal = null;

            //Scheduler
            _scheduler = null;

            //Private members
            _pinSubscribers = new Dictionary<string, Pin>();
            _deviceSubscribers = new Dictionary<string, Device>();
            _sensorSubscribers = new List<SensorSubscriber>();
            _nodeSubscribers = new Dictionary<Address, byte>();

            //Public configuration
            Status = new NodeStatusInfo
            {
                Mask = 0,
                NodeStatus = NodeStatusValues.Unknown,
                BusStatus = BusStatus.Reset,
                LastError = 0,
                TotalErrors = 0,
                Time = 0,
                LastActivatedInput = string.Empty,
                LastActivatedOutput = string.Empty
            };

            Log.Debug("Empty node created");
        }