コード例 #1
0
        public void SetZoneState1Test()
        {
            Address   zoneAddress = new Address(_deviceId, 2);                                              // Zone 2
            ZoneState zoneState   = new ZoneState(new Address(_deviceId, 5), true, 30, ZoneQuality.Online); // Source 5, Power On, Volume=30

            _protDriver.SetZoneState(zoneAddress, zoneState);
            Thread.Sleep(2000); // give control to worker thread

            Assert.IsTrue(_nuvoTelegramMock.TelegramList.Count >= 3);
            Assert.AreEqual(true, _nuvoTelegramMock.TelegramList.Contains("Z02ON"));
            Assert.AreEqual(true, _nuvoTelegramMock.TelegramList.Contains("Z02VOL55"));
            Assert.AreEqual(true, _nuvoTelegramMock.TelegramList.Contains("Z02SRC5"));
        }
コード例 #2
0
ファイル: UnitTest1.cs プロジェクト: jbct/LonoNet
        public void TestMethod1()
        {
            LonoNetClient client = new LonoNetClient(_clientId, _clientSecret, _authToken, _deviceId);
            var           login  = client.GetAccessToken(_authCode);

            ZoneState  zs = client.GetActiveZone();
            ZoneInfo   zi = client.GetAllZones();
            DeviceInfo di = client.GetDeviceInfo();

            client.SetZone(1, true);
            Thread.Sleep(10);
            client.SetZone(1, false);
        }
コード例 #3
0
        public void SetZoneState3Test()
        {
            Address   zoneAddress = new Address(_deviceId, 12);
            ZoneState zoneState   = new ZoneState(new Address(_deviceId, 6), true, 20, ZoneQuality.Online);

            _protDriver.SetZoneState(zoneAddress, zoneState);
            Thread.Sleep(2000); // give control to worker thread

            Assert.IsTrue(_nuvoTelegramMock.TelegramList.Count >= 3);
            Assert.AreEqual(true, _nuvoTelegramMock.TelegramList.Contains("Z12ON"));
            Assert.AreEqual(true, _nuvoTelegramMock.TelegramList.Contains("Z12VOL63"));
            Assert.AreEqual(true, _nuvoTelegramMock.TelegramList.Contains("Z12SRC6"));
        }
コード例 #4
0
        private void CheckZoneAccess(Model.Action action)
        {
            ZoneState zoneState = inventorizationRepository.GetZoneState(action.Inventorization, action.Zone);

            if (zoneState == null)
            {
                throw new ZoneAccessException(action.Zone, $"Зона не была открыта. Сначала откройте зону.");
            }
            if (zoneState.ClosedAt.HasValue && zoneState.ClosedAt.Value.ToUniversalTime() < DateTime.Now)
            {
                throw new ZoneAccessException(action.Zone, $"Зона закрыта. Выберите другую зону.");
            }
        }
コード例 #5
0
        private void StoreWaterVariablesForNitrogenUptake(ZoneWaterAndN zoneWater)
        {
            ZoneState myZone = root.Zones.Find(z => z.Name == zoneWater.Zone.Name);

            if (myZone != null)
            {
                //store Water variables for N Uptake calculation
                //Old sorghum doesn't do actualUptake of Water until end of day
                myZone.StartWater           = new double[myZone.soil.Thickness.Length];
                myZone.AvailableSW          = new double[myZone.soil.Thickness.Length];
                myZone.PotentialAvailableSW = new double[myZone.soil.Thickness.Length];
                myZone.Supply = new double[myZone.soil.Thickness.Length];

                double[] kl = myZone.soil.KL(Plant.Name);

                if (root.Depth != myZone.Depth)
                {
                    myZone.Depth += 0;
                }
                var currentLayer           = Soils.Soil.LayerIndexOfDepth(myZone.Depth, myZone.soil.Thickness);
                var currentLayerProportion = Soils.Soil.ProportionThroughLayer(currentLayer, myZone.Depth, myZone.soil.Thickness);
                for (int layer = 0; layer <= currentLayer; ++layer)
                {
                    myZone.StartWater[layer] = myZone.soil.Water[layer];

                    myZone.AvailableSW[layer]          = myZone.soil.Water[layer] - myZone.soil.LL15mm[layer];
                    myZone.PotentialAvailableSW[layer] = myZone.soil.DULmm[layer] - myZone.soil.LL15mm[layer];

                    if (layer == currentLayer)
                    {
                        myZone.AvailableSW[layer]          *= currentLayerProportion;
                        myZone.PotentialAvailableSW[layer] *= currentLayerProportion;
                    }

                    var proportion = root.rootProportionInLayer(layer, myZone);
                    myZone.Supply[layer] = Math.Max(myZone.AvailableSW[layer] * kl[layer] * proportion, 0.0);
                }
                var totalAvail    = myZone.AvailableSW.Sum();
                var totalAvailPot = myZone.PotentialAvailableSW.Sum();
                var totalSupply   = myZone.Supply.Sum();
                WatSupply = totalSupply;
                //used for SWDef PhenologyStress table lookup
                SWAvailRatio = MathUtilities.Bound(MathUtilities.Divide(totalAvail, totalAvailPot, 1.0), 0.0, 10.0);

                //used for SWDef ExpansionStress table lookup
                SDRatio = MathUtilities.Bound(MathUtilities.Divide(totalSupply, WDemand, 1.0), 0.0, 10);

                //used for SwDefPhoto Stress
                PhotoStress = MathUtilities.Bound(MathUtilities.Divide(totalSupply, WDemand, 1.0), 0.0, 1.0);
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: ImfeldC/NuvoControl2
        /// <summary>
        /// Set zone status, connects to the end point address and sets a zone status.
        /// </summary>
        /// <param name="endPointAddress">Server end point address.</param>
        /// <param name="adr">Zone Address to set the status.</param>
        /// <param name="stateCommand">Command to send to zone.</param>
        private static void SetZoneState(EndpointAddress endPointAddress, Address adr, ZoneState stateCommand)
        {
            Console.WriteLine(">>> Setup M&C server ...");

            ILog _log = LogManager.GetCurrentClassLogger();
            IMonitorAndControl             pipeProxy      = null;
            IMonitorAndControlNotification serverCallback = new ServerCallback();

            try
            {
                int port    = FindPort();
                var binding = new WSDualHttpBinding("WSDualHttpBinding_IMonitorAndControl");
                binding.ClientBaseAddress = new Uri("http://" + NetworkHelper.getHostName() + ":" + port + "/");

                /*note the "DuplexChannelFactory".  This is necessary for Callbacks.
                 * A regular "ChannelFactory" won't work with callbacks.*/
                DuplexChannelFactory <IMonitorAndControl> pipeFactory =
                    new DuplexChannelFactory <IMonitorAndControl>(
                        new InstanceContext(serverCallback), binding, endPointAddress);
                try
                {
                    Console.WriteLine(">>>   creating channel to {0} with callback address {1}", endPointAddress.Uri.ToString(), binding.ClientBaseAddress.ToString());

                    //Open the channel to the server
                    pipeProxy = pipeFactory.CreateChannel();
                    pipeProxy.Connect();

                    // Get zone status
                    ZoneState state = pipeProxy.GetZoneState(adr);
                    Console.WriteLine(">>>   zone state: {0}", state.ToString());

                    // Get zone status
                    pipeProxy.SetZoneState(adr, stateCommand);
                }
                catch (Exception e)
                {
                    Console.WriteLine("SetZoneState - Exception: {0}", e.Message);
                    _log.Fatal(m => m("SetZoneState - Exception: {0}", e.Message));
                }
            }
            catch (FaultException <ArgumentException> exc)
            {
                Console.WriteLine("SetZoneState - FaultException: {0}", exc);
                _log.Fatal(m => m("SetZoneState - FaultException: {0}", exc));
            }
            catch (Exception exc)
            {
                Console.WriteLine("SetZoneState - Exception: {0}", exc);
                _log.Fatal(m => m("SetZoneState - Exception: {0}", exc));
            }
        }
コード例 #7
0
        private void StoreWaterVariablesForNitrogenUptake(ZoneWaterAndN zoneWater)
        {
            ZoneState myZone = root.Zones.Find(z => z.Name == zoneWater.Zone.Name);

            if (myZone != null)
            {
                var soilPhysical = myZone.Soil.FindChild <Soils.IPhysical>();
                var waterBalance = myZone.Soil.FindChild <ISoilWater>();

                //store Water variables for N Uptake calculation
                //Old sorghum doesn't do actualUptake of Water until end of day
                myZone.StartWater           = new double[soilPhysical.Thickness.Length];
                myZone.AvailableSW          = new double[soilPhysical.Thickness.Length];
                myZone.PotentialAvailableSW = new double[soilPhysical.Thickness.Length];
                myZone.Supply = new double[soilPhysical.Thickness.Length];

                var soilCrop = Soil.FindDescendant <SoilCrop>(plant.Name + "Soil");
                if (soilCrop == null)
                {
                    throw new Exception($"Cannot find a soil crop parameterisation called {plant.Name + "Soil"}");
                }

                double[] kl = soilCrop.KL;

                double[] llDep = MathUtilities.Multiply(soilCrop.LL, soilPhysical.Thickness);

                if (root.Depth != myZone.Depth)
                {
                    myZone.Depth += 0; // wtf??
                }
                var currentLayer = SoilUtilities.LayerIndexOfDepth(myZone.Physical.Thickness, myZone.Depth);
                for (int layer = 0; layer <= currentLayer; ++layer)
                {
                    myZone.StartWater[layer] = waterBalance.SWmm[layer];

                    myZone.AvailableSW[layer]          = Math.Max(waterBalance.SWmm[layer] - llDep[layer] * myZone.LLModifier[layer], 0) * myZone.RootProportions[layer];
                    myZone.PotentialAvailableSW[layer] = Math.Max(soilPhysical.DULmm[layer] - llDep[layer] * myZone.LLModifier[layer], 0) * myZone.RootProportions[layer];

                    var proportion = myZone.RootProportions[layer];
                    myZone.Supply[layer] = Math.Max(myZone.AvailableSW[layer] * kl[layer] * proportion, 0.0);
                }
                var totalAvail    = myZone.AvailableSW.Sum();
                var totalAvailPot = myZone.PotentialAvailableSW.Sum();
                var totalSupply   = myZone.Supply.Sum();
                WatSupply = totalSupply;

                //used for SWDef ExpansionStress table lookup
                SDRatio = MathUtilities.Bound(MathUtilities.Divide(totalSupply, WDemand, 1.0), 0.0, 10);
            }
        }
コード例 #8
0
        private bool ProcessTemperatureBasedOutput(ControllerState controllerState, ZoneState zoneState)
        {
            var temperatureData = _zoneTemperatureProvider.Provide(zoneState.Zone.ZoneId, controllerState);

            if (temperatureData == null)
            {
                Logger.Warning(Localization.NotificationMessage.NoTemperatureData.FormatWith(zoneState.Zone.TemperatureControlledZone.TemperatureSensorId, zoneState.Zone.Name));

                return(false);
            }

            var outputState = zoneState.EnableOutputs;

            if (DateTime.UtcNow - temperatureData.LastRead < TimeSpan.FromMinutes(5))
            {
                var setPoint = 0f;

                switch (zoneState.ControlMode)
                {
                case ZoneControlMode.LowOrDisabled:
                    setPoint = zoneState.Zone.TemperatureControlledZone.LowSetPoint;
                    break;

                case ZoneControlMode.HighOrEnabled:
                    setPoint = zoneState.Zone.TemperatureControlledZone.HighSetPoint;
                    break;

                case ZoneControlMode.Schedule:
                    if (zoneState.ScheduleState.DesiredTemperature.HasValue)
                    {
                        setPoint = zoneState.ScheduleState.DesiredTemperature.Value;
                    }

                    break;
                }

                outputState = _hysteresisProcessor.Process(temperatureData.AverageTemperature,
                                                           outputState,
                                                           setPoint,
                                                           zoneState.Zone.TemperatureControlledZone.Hysteresis);
            }
            else
            {
                outputState = false;

                Logger.Warning(Localization.NotificationMessage.TemperatureValueTooOld.FormatWith(zoneState.Zone.Name));
            }

            return(outputState);
        }
コード例 #9
0
        public override void Update(GameTime gameTime)
        {
            switch (_zoneState)
            {
            case ZoneState.None:
                break;

            case ZoneState.Spawn:
                Scale += 0.1f;
                if (Scale >= _scaleTarget)
                {
                    _zoneState = ZoneState.Active;
                }
                break;

            case ZoneState.Active:
                _timeSinceSpawn += (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (_timeSinceSpawn > _lifetime)
                {
                    _zoneState = ZoneState.Despawn;
                }
                break;

            case ZoneState.Despawn:
                Scale -= 0.1f;
                if (Scale <= 0.05f)
                {
                    _particleEffects.GenerateClusterParticles();
                    _particleEffects.ShatterParticles(50, 15);
                    _particleEffects.ExpandAndRotate();
                    _particleEffects.SetParticleEngineOneShot(4);

                    _zoneState      = ZoneState.Delete;
                    _timeSinceSpawn = 0;
                }
                break;

            case ZoneState.Delete:
                //_timeSinceSpawn
                this.Delete();

                break;

            default:
                break;
            }

            base.Update(gameTime);
        }
コード例 #10
0
        public void calculateFunctionTest3()
        {
            SleepFunction function = new SleepFunction(SimpleId.NewGuid(), new Address(100, 1),
                                                       new TimeSpan(1, 0, 0), new TimeSpan(14, 0, 0), new TimeSpan(18, 00, 00));
            ZoneServerMock zoneServerMock = new ZoneServerMock();
            Dictionary <int, IAudioDriver> audioDrivers = null;
            ConcreteSleepFunction          target       = new ConcreteSleepFunction(function, zoneServerMock, audioDrivers);

            Assert.AreEqual(1, zoneServerMock._monitoredZones.Count);   // 1 zone monitored

            // Distribute an 'old status. Simulate that the zone is ON since then.
            ZoneState oldState = new ZoneState(new Address(100, 1), true, 20, NuvoControl.Common.ZoneQuality.Online);

            oldState.LastUpdate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 00, 0);
            zoneServerMock.distributeZoneState(oldState);

            // test 11:00 -> not active, no action
            DateTime simTime1 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 11, 00, 0);

            target.calculateFunction(simTime1);
            Assert.AreEqual(0, zoneServerMock.ZoneStates.Count);       // 0 command issued

            // test 14:00 -> just active, switch off.
            DateTime simTime2 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 14, 00, 0);

            target.calculateFunction(simTime2);
            Assert.AreEqual(1, zoneServerMock.ZoneStates.Count);       // 1 command issued
            zoneServerMock.ClearZoneStateList();

            // test 16:00 -> active, switch off.
            DateTime simTime3 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 16, 00, 0);

            target.calculateFunction(simTime3);
            Assert.AreEqual(1, zoneServerMock.ZoneStates.Count);       // 1 command issued
            zoneServerMock.ClearZoneStateList();

            // test 18:00 -> still active, switch off.
            DateTime simTime4 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 18, 00, 0);

            target.calculateFunction(simTime4);
            Assert.AreEqual(1, zoneServerMock.ZoneStates.Count);       // 1 command issued
            zoneServerMock.ClearZoneStateList();

            // test 20:00 -> not active, no action
            DateTime simTime5 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 20, 00, 0);

            target.calculateFunction(simTime5);
            Assert.AreEqual(0, zoneServerMock.ZoneStates.Count);       // 0 command issued
        }
コード例 #11
0
        /// <summary>
        /// Change the volume of a specified zone.
        /// </summary>
        /// <param name="zoneId">Zone id</param>
        /// <param name="adjVolume">Delta Volume</param>
        /// <returns>Zone state, after the command has been performed.</returns>
        private ZoneState AdjustVolume(Address zoneId, int adjVolume)
        {
            MonitorAndControlClient mcProxy = getMCProxy();

            mcProxy.Connect();

            ZoneState zoneState = mcProxy.GetZoneState(zoneId);

            zoneState.Volume = zoneState.Volume + adjVolume;
            mcProxy.SetZoneState(zoneId, zoneState);
            zoneState = mcProxy.GetZoneState(zoneId);

            mcProxy.Disconnect();
            return(zoneState);
        }
コード例 #12
0
        /// <summary>
        /// Changes the source of a specified zone.
        /// </summary>
        /// <param name="zoneId">Zone id, to specify zone</param>
        /// <param name="sourceId">Source id, tp specify source</param>
        /// <returns>Zone state, after the command has been performed.</returns>
        public ZoneState SwitchSource(Address zoneId, Address sourceId)
        {
            MonitorAndControlClient mcProxy = getMCProxy();

            mcProxy.Connect();

            ZoneState zoneState = mcProxy.GetZoneState(zoneId);

            zoneState.Source = sourceId;
            mcProxy.SetZoneState(zoneId, zoneState);
            zoneState = mcProxy.GetZoneState(zoneId);

            mcProxy.Disconnect();
            return(zoneState);
        }
コード例 #13
0
        /// <summary>
        /// Switches a zone, specified by its zone id, either on or off (depending on its current state).
        /// </summary>
        /// <param name="zoneId">Zone Id</param>
        /// <returns>Zone state, after the switch command has been performed.</returns>
        public ZoneState SwitchZone(Address zoneId)
        {
            MonitorAndControlClient mcProxy = getMCProxy();

            mcProxy.Connect();

            ZoneState zoneState = mcProxy.GetZoneState(zoneId);

            zoneState.PowerStatus = !zoneState.PowerStatus;
            mcProxy.SetZoneState(zoneId, zoneState);
            zoneState = mcProxy.GetZoneState(zoneId);

            mcProxy.Disconnect();
            return(zoneState);
        }
コード例 #14
0
 private void InitializeZones()
 {
     try
     {
         foreach (ZoneControl zoneCtrl in _zoneControlByAddress.Values)
         {
             ZoneState zoneState = _monitorAndControlProxy.GetZoneState(zoneCtrl.Zone.Id);
             zoneCtrl.ZoneState = zoneState;
         }
     }
     catch (Exception)
     {
         _monitorAndControlProxy.Abort();
     }
 }
コード例 #15
0
ファイル: UnitTest1.cs プロジェクト: jbct/LonoNet
        public void TestMethod2()
        {
            LonoNetClient client = new LonoNetClient(_clientId, _clientSecret, _deviceId);
            string        url    = client.BuildAuthorizationUrl("http://localhost", "write");
            // Launch url
            // set _authCode to value returned in url
            var login = client.GetAccessToken(_authCode);

            ZoneState  zs = client.GetActiveZone();
            ZoneInfo   zi = client.GetAllZones();
            DeviceInfo di = client.GetDeviceInfo();

            client.SetZone(1, true);
            Thread.Sleep(10);
            client.SetZone(1, false);
        }
コード例 #16
0
        /// <summary>
        /// Command handler for volume down command.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void VolumeDownCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            lock (this)
            {
                _zoneState.CommandUnacknowledged = true;
                ZoneState cmdState = new ZoneState(_zoneState);
                cmdState.Volume -= 5;
                if (cmdState.Volume < ZoneState.VOLUME_MINVALUE)
                {
                    cmdState.Volume = ZoneState.VOLUME_MINVALUE;
                }
                NotifyPropertyChanged(new PropertyChangedEventArgs(""));

                ServiceProxy.MonitorAndControlProxy.SetZoneState(_activeZone.Id, cmdState);
            }
        }
コード例 #17
0
 /// <summary>
 /// Private method to send notification 'onZoneStatusUpdate'
 /// </summary>
 /// <param name="e">Parameters received from underlying layer.</param>
 private void notifyZoneStatusUpdate(ConreteProtocolEventArgs e)
 {
     if (onZoneStatusUpdate != null)
     {
         try
         {
             ZoneState zoneState = new ZoneState(new Address(e.DeviceId, (int)e.Command.SourceId), (e.Command.PowerStatus == EZonePowerStatus.ZoneStatusON ? true : false),
                                                 NuvoEssentiaCommand.calcVolume2NuvoControl(e.Command.VolumeLevel), ZoneQuality.Online);
             onZoneStatusUpdate(this, new ProtocolZoneUpdatedEventArgs(new Address(e.DeviceId, (int)e.Command.ZoneId), zoneState, e));
         }
         catch (Exception ex)
         {
             _log.Fatal(m => m("Exception occured at forwarding event 'onZoneStatusUpdate' to Device {0} and Zone {1} (Command='{2}')! Exception={3}", e.DeviceId, e.Command.ZoneId, e.Command.ToString(), ex.ToString()));
         }
     }
 }
コード例 #18
0
ファイル: RootShapeSemiCircle.cs プロジェクト: hol430/ApsimX
        private double CalcRootAreaSemiCircleMaize(ZoneState zone, double top, double bottom, double hDist)
        {
            if (zone.RootFront == 0.0)
            {
                return(0.0);
            }

            // get the area occupied by roots in a semi-circular section between top and bottom
            double SDepth, areaLayer;

            // intersection of roots and Section
            if (zone.RootFront <= hDist)
            {
                SDepth = 0.0;
            }
            else
            {
                SDepth = Math.Sqrt(MathUtilities.Bound(Math.Pow(zone.RootFront, 2) - Math.Pow(hDist, 2), 0, 1000000));
            }

            // Rectangle - SDepth past bottom of this area
            if (SDepth >= bottom)
            {
                areaLayer = (bottom - top) * hDist;
            }
            else               // roots Past top
            {
                double Theta   = 2 * Math.Acos(MathUtilities.Divide(Math.Max(top, SDepth), zone.RootFront, 0));
                double topArea = (Math.Pow(zone.RootFront, 2) / 2.0 * (Theta - Math.Sin(Theta))) / 2.0;

                // bottom down
                double bottomArea = 0;
                if (zone.RootFront > bottom)
                {
                    Theta      = 2 * Math.Acos(bottom / zone.RootFront);
                    bottomArea = (Math.Pow(zone.RootFront, 2) / 2.0 * (Theta - Math.Sin(Theta))) / 2.0;
                }
                // rectangle
                if (SDepth > top)
                {
                    topArea += (SDepth - top) * hDist;
                }
                areaLayer = topArea - bottomArea;
            }
            return(areaLayer);
        }
コード例 #19
0
 public HttpResponseMessage ReopenZone(Guid inventorization, [FromUri] int number)
 {
     try
     {
         ZoneModel zone       = _zoneRepository.GetZone(number);
         ZoneState state      = _inventorizationRepository.GetZoneState(inventorization, number);
         var       userClaims = Request.GetOwinContext().Authentication.User;
         _inventorizationRepository.OpenZone(inventorization, zone.Id, Guid.Parse(userClaims.Claims.Single(x => x.Type == ClaimTypes.Sid).Value));
         state = _inventorizationRepository.GetZoneState(inventorization, number);
         return(Request.CreateResponse(HttpStatusCode.OK, zone));
     }
     catch (Exception ex)
     {
         _logger.Error(ex, $"Open zone error. Zone code:{Environment.NewLine} {JsonConvert.SerializeObject(number)}. InventorizationId: {inventorization}");
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
     }
 }
コード例 #20
0
ファイル: ZoneStateTests.cs プロジェクト: Alyoshak/NightLight
        public void GetCurrentTime_Tests()
        {
            //arrange
            var state = new ZoneState()
            {
                DayOfWeek = DayOfWeek.Monday,
                Time      = new TimeSpan(5, 0, 0)
            };
            var now = Convert.ToDateTime("1/27/2015 4:00PM");

            //act
            var currentTimeBefore = state.GetCurrentTime(ZoneDirection.Before, now);
            var currentTimeAfter  = state.GetCurrentTime(ZoneDirection.After, now);

            //assert
            Assert.AreEqual(Convert.ToDateTime("1/26/2015 5:00"), currentTimeBefore);
            Assert.AreEqual(Convert.ToDateTime("2/2/2015 5:00"), currentTimeAfter);
        }
コード例 #21
0
        public Zone(Texture2D texture, Vector2 position, float rotation, Color color, Game game, World world)
            : base(texture, position, rotation, DrawingHelper.DrawingLevel.Medium, game, world, false)
        {
            Color = color;

            RigidBody.CollisionCategories = Category.Cat5;
            RigidBody.CollidesWith        = Category.All;// ^ Category.Cat9;

            _zoneState = ZoneState.Spawn;
            Library.Audio.PlaySoundEffect(Library.Audio.SoundEffects.ZoneExpand);

            Scale            = 0.05f;
            Alpha            = 0.5f;
            _scaleTarget     = 1.0f;
            _particleEffects = new ParticleEngine(100, Library.Particle.trailTexture, position, color * 0.05f, Vector2.Zero, 5.0f, 0.0f, 0.5f, DrawingHelper.DrawingLevel.Medium, game);
            SyncedGameCollection.ComponentCollection.Add(_particleEffects);
            _victims = new List <IVictim>();
        }
コード例 #22
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="zones"></param>
        /// <param name="sources"></param>
        public ZoneContext(List <ZoneGraphic> zones, List <SourceGraphic> sources)
        {
            _synchronizationContext = SynchronizationContext.Current;

            this._zones      = zones;
            this._activeZone = zones[0];
            this._zoneState  = new ZoneState();
            this._sources    = sources.ToArray().ToList();
            _viewSources     = (ListCollectionView)CollectionViewSource.GetDefaultView(this._sources);

            CommandBinding binding = new CommandBinding(CustomCommands.VolumeUp, VolumeUpCommand_Executed, VolumeUpCommand_CanExecute);

            _bindings.Add(binding);
            binding = new CommandBinding(CustomCommands.VolumeDown, VolumeDownCommand_Executed, VolumeDownCommand_CanExecute);
            _bindings.Add(binding);
            binding = new CommandBinding(CustomCommands.Power, PowerCommand_Executed, PowerCommand_CanExecute);
            _bindings.Add(binding);
        }
コード例 #23
0
    private void SetState(ZoneState state)
    {
        _currentState = state;

        switch (state)
        {
        case ZoneState.Movihg:
            progressSlider.gameObject.SetActive(true);
            timeToStartZone.gameObject.SetActive(false);
            break;

        case ZoneState.Wait:
        default:
            progressSlider.gameObject.SetActive(false);
            timeToStartZone.gameObject.SetActive(true);
            break;
        }
    }
コード例 #24
0
    public void SetFireSystemData(float startTime, float endTime, ZoneState state)
    {
        StopAllCoroutines();

        switch (state)
        {
        case ZoneState.Movihg:
            StartCoroutine(StartProgress(endTime, startTime));
            break;

        case ZoneState.Wait:
        default:
            StartCoroutine(StartTimer(endTime - startTime));
            break;
        }

        SetState(state);
    }
コード例 #25
0
 /// <summary>
 /// Public method to set a zone state, according to a zone state object passed in.
 /// </summary>
 /// <param name="zoneAddress">Zone Adress, containing device and zone id.</param>
 /// <param name="zoneState">Zone state, which shall be applied.</param>
 public void SetZoneState(Address zoneAddress, ZoneState zoneState)
 {
     if (zoneState.PowerStatus)
     {
         INuvoEssentiaCommand command = new NuvoEssentiaCommand(
             ENuvoEssentiaCommands.SetZoneStatus,
             convertAddressZone2EssentiaZone(zoneAddress),
             convertAddressSource2EssentiaSource(zoneState.Source),
             NuvoEssentiaCommand.calcVolume2NuvoEssentia(zoneState.Volume));
         sendCommandToDevice(zoneAddress, command);
     }
     else
     {
         INuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(
             ENuvoEssentiaCommands.TurnZoneOFF,
             convertAddressZone2EssentiaZone(zoneAddress));
         sendCommandToDevice(zoneAddress, command);
     }
 }
コード例 #26
0
 public void CloseZone(ZoneState state, Guid userId)
 {
     using (var conn = new NpgsqlConnection(_connectionString))
     {
         conn.Open();
         using (var cmd = new NpgsqlCommand())
         {
             cmd.Connection  = conn;
             cmd.CommandText = @"UPDATE public.""ZoneStates"" 
                 SET ""ClosedAt"" = @date, ""ClosedBy"" = @user
                 WHERE ""InventorizationId"" = @id AND ""ZoneId"" = @zoneId";
             cmd.Parameters.Add(new NpgsqlParameter("zoneId", state.ZoneId));
             cmd.Parameters.Add(new NpgsqlParameter("id", state.InventorizationId));
             cmd.Parameters.Add(new NpgsqlParameter("date", DateTime.UtcNow));
             cmd.Parameters.Add(new NpgsqlParameter("user", userId));
             cmd.ExecuteNonQuery();
         }
     }
 }
コード例 #27
0
ファイル: RootShapeCylindre.cs プロジェクト: RobZys/ApsimX
        /// <summary>Calculates the root area for a layer of soil</summary>
        public void CalcRootProportionInLayers(ZoneState zone)
        {
            zone.RootArea = (zone.RightDist + zone.LeftDist) * zone.Depth / 1e6;
            for (int layer = 0; layer < zone.soil.Thickness.Length; layer++)
            {
                double prop;
                double top = layer == 0 ? 0 : MathUtilities.Sum(zone.soil.Thickness, 0, layer - 1);

                if (zone.Depth < top)
                {
                    prop = 0;
                }
                else
                {
                    prop = zone.soil.ProportionThroughLayer(layer, zone.Depth);
                }
                zone.RootProportions[layer] = prop;
            }
        }
コード例 #28
0
 public HttpResponseMessage CloseZone(Guid inventorization, [FromBody] ZoneVM zone)
 {
     try
     {
         ZoneState state = _inventorizationRepository.GetZoneState(inventorization, zone.ZoneId);
         if (state != null)
         {
             var userClaims = Request.GetOwinContext().Authentication.User;
             _inventorizationRepository.CloseZone(state, Guid.Parse(userClaims.Claims.Single(x => x.Type == ClaimTypes.Sid).Value));
             return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "Ok" }));
         }
         return(Request.CreateResponse(HttpStatusCode.Forbidden, new { Result = "Error", Reason = "Зона не была открыта" }));
     }
     catch (Exception ex)
     {
         _logger.Error(ex, $"Open zone error. Zone: {zone.ZoneId}. InventorizationId: {inventorization}");
     }
     return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "Ok" }));
 }
コード例 #29
0
        private ZoneDetailsProviderResult.TemperatureSettings GetTemperatureSettings(ZoneState zone, ControllerState controllerState)
        {
            if (!zone.Zone.IsTemperatureControlled())
            {
                return(null);
            }

            var temperatureControlledZone = zone.Zone.TemperatureControlledZone;

            return(new ZoneDetailsProviderResult.TemperatureSettings
            {
                HightSetPoint = temperatureControlledZone.HighSetPoint,
                LowSetPoint = temperatureControlledZone.LowSetPoint,
                Hysteresis = temperatureControlledZone.Hysteresis,
                PlotData = _zoneTemperatureProvider.Provide(zone.Zone.ZoneId, controllerState)
                           .HistoricalReads
                           .ToDictionary(x => x.Item1,
                                         x => x.Item2)
            });
        }
コード例 #30
0
ファイル: RootShapeSemiCircle.cs プロジェクト: lie112/ApsimX
        /// <summary>Calculates the proportion of the layer's volume occupied by roots.</summary>
        public double CalcRootProportion(ZoneState zone, int layer)
        {
            var physical = zone.Soil.FindChild <Soils.IPhysical>();

            double top    = layer == 0 ? 0 : MathUtilities.Sum(physical.Thickness, 0, layer - 1);
            double bottom = top + physical.Thickness[layer];

            if (zone.Depth < top)
            {
                return(0);
            }

            double rootArea = CalcRootAreaSemiCircleMaize(zone, top, bottom, zone.RightDist); // Right side

            rootArea += CalcRootAreaSemiCircleMaize(zone, top, bottom, zone.LeftDist);        // Left Side

            double soilArea = (zone.RightDist + zone.LeftDist) * (bottom - top);

            return(Math.Max(0.0, MathUtilities.Divide(rootArea, soilArea, 0.0)));
        }
コード例 #31
0
ファイル: Root.cs プロジェクト: hol353/ApsimX
        private new void OnSimulationCommencing(object sender, EventArgs e)
        {
            Soil soil = Apsim.Find(this, typeof(Soil)) as Soil;
            if (soil == null)
                throw new Exception("Cannot find soil");
            if (soil.Crop(Plant.Name) == null)
                throw new Exception("Cannot find a soil crop parameterisation for " + Plant.Name);

            PlantZone = new ZoneState(soil, 0, InitialDM.Value, Plant.Population, MaximumNConc.Value);
            Zones = new List<ZoneState>();
            base.OnSimulationCommencing(sender, e);
        }
コード例 #32
0
ファイル: Root.cs プロジェクト: hol353/ApsimX
        /// <summary>Initialise all zones.</summary>
        private void InitialiseZones()
        {
            Zones.Clear();
            Zones.Add(PlantZone);
            if (ZoneRootDepths.Count != ZoneNamesToGrowRootsIn.Count ||
                ZoneRootDepths.Count != ZoneInitialDM.Count)
                throw new Exception("The root zone variables (ZoneRootDepths, ZoneNamesToGrowRootsIn, ZoneInitialDM) need to have the same number of values");

            for (int i = 0; i < ZoneNamesToGrowRootsIn.Count; i++)
            {
                Zone zone = Apsim.Find(this, ZoneNamesToGrowRootsIn[i]) as Zone;
                if (zone != null)
                {
                    Soil soil = Apsim.Find(zone, typeof(Soil)) as Soil;
                    if (soil == null)
                        throw new Exception("Cannot find soil in zone: " + zone.Name);
                    if (soil.Crop(Plant.Name) == null)
                        throw new Exception("Cannot find a soil crop parameterisation for " + Plant.Name);
                    ZoneState newZone = new ZoneState(soil, ZoneRootDepths[i], ZoneInitialDM[i], Plant.Population, MaximumNConc.Value);
                    Zones.Add(newZone);
                }
            }
        }