コード例 #1
0
        public int PostIrrigationProgram(IrrigationProgram p)
        {
            string            data     = JsonConvert.SerializeObject(p);
            string            response = Post("irrigationprograms", data);
            IrrigationProgram program  = JsonConvert.DeserializeObject <IrrigationProgram>(response);

            return(program.Id);
        }
コード例 #2
0
        public async Task <Uri> PutIrrigationProgram(IrrigationProgram p)
        {
            HttpResponseMessage response = await client.PutAsJsonAsync(string.Format("irrigationprograms/{0}", p.Id), p);

            response.EnsureSuccessStatusCode();

            // return URI of the created resource.
            return(response.Headers.Location);
        }
コード例 #3
0
        public async Task <int> PostIrrigationProgram(IrrigationProgram p)
        {
            IrrigationProgram   program  = null;
            HttpResponseMessage response = await client.PostAsJsonAsync("irrigationprograms", p);

            if (response.IsSuccessStatusCode)
            {
                program = await response.Content.ReadAsAsync <IrrigationProgram>();
            }
            return(program.Id);
        }
コード例 #4
0
        public IrrigationProgram(int id, string name, DateTime start, int duration, int solenoidId, HardwareService hw, DataService data)
        {
            Id         = id;
            Name       = name;
            Start      = start;
            Duration   = duration;
            SolenoidId = solenoidId;

            hardwareService  = hw;
            dataService      = data;
            DataSolenoid     = dataService.Solenoids.AsQueryable <Solenoid>().Where(s => s.Id == solenoidId).First <Solenoid>();
            HardwareSolenoid = hardwareService.Solenoids.AsQueryable <ISolenoid>().Where(s => s.Id == solenoidId).First <ISolenoid>();

            HardwarePumpSolenoid                           = hardwareService.PumpSolenoid;
            DataPumpSolenoid                               = dataService.Solenoids
                                              RequiresPump = DataSolenoid.RequiresPump;


            Data.IrrigationProgram program = new Data.IrrigationProgram()
            {
                Name         = Name,
                Start        = Start,
                Duration     = Duration,
                DeviceId     = data.device.Id,
                SolenoidName = DataSolenoid.Name,
                SolenoidId   = DataSolenoid.Id,
                RequiresPump = DataSolenoid.RequiresPump
            };
            dataService.dataServer.PutIrrigationProgram(program);

            //start irrigating
            HardwareSolenoid.On();
            DataSolenoid.Value = 1;
            dataService.dataServer.PutSolenoid(DataSolenoid);

            if (RequiresPump)
            {
                hardwareService.PumpSolenoid.On();
            }

            //report to the server
            DataSolenoid.Value = 1;
            dataService.dataServer.PutSolenoid(DataSolenoid);
        }
コード例 #5
0
 public void PutIrrigationProgram(IrrigationProgram p)
 {
     string data     = JsonConvert.SerializeObject(p);
     string response = Put(string.Format("irrigationprograms/{0}", p.Id), data);
 }