Esempio n. 1
0
        public async Task<bool> SaveScheduleAsync(ScheduleModelProxy schedule)
        {
            var dict = new Dictionary<string, object>();
            var properties = new Dictionary<string, object>();

            if (schedule.ScheduleID != Guid.Empty)
            {
                // Only supported when creating a new schedule
                properties.Add("startTime", schedule.StartTime.ToUniversalTime());

                if (schedule.ExpiryTime.HasValue)
                    properties.Add("startTime", schedule.ExpiryTime.Value.ToUniversalTime());
            }

            properties.Add("isEnabled", schedule.IsEnabled);

            if (schedule.ScheduleID != Guid.Empty)
            {
                // Only supported when creating a new schedule
                if ((schedule.Model as Schedule).DayInterval > 0)
                {
                    properties.Add("frequency", "day");
                    properties.Add("interval", (schedule.Model as Schedule).DayInterval);
                }
                else if ((schedule.Model as Schedule).HourInterval > 0)
                {
                    properties.Add("frequency", "hour");
                    properties.Add("interval", (schedule.Model as Schedule).HourInterval);
                }
                else
                    properties.Add("frequency", "onetime");
            }

            dict.Add("properties", properties);

            if (schedule.ScheduleID == Guid.Empty)
            {
                // New variable
                await SendRequestAsync("schedules/" + schedule.Name.ToUrlSafeString(), HttpMethod.Put, JsonConvert.SerializeObject(dict), "application/json");
            }
            else
            {
                await SendRequestAsync("schedules/" + schedule.Name.ToUrlSafeString(), new HttpMethod("PATCH"), JsonConvert.SerializeObject(dict), "application/json");
            }

            return true;
        }
Esempio n. 2
0
 public Task<bool> SaveScheduleAsync(ScheduleModelProxy schedule)
 {
     throw new NotImplementedException("Schedules not supported yet.");
 }
Esempio n. 3
0
        public Task<bool> SaveScheduleAsync(ScheduleModelProxy schedule)
        {
            Logger.DebugFormat("SaveSmaSchedule(...)");

            var context = GetConnection();
            var rawSchedule = schedule.Model as SMA.Schedule;

            if (schedule.ScheduleID == Guid.Empty)
            {
                context.AddToSchedules(rawSchedule);
            }
            else
            {
                var foundSchedule = context.Schedules.Where(s => s.ScheduleID == schedule.ScheduleID).FirstOrDefault();

                if (foundSchedule == null)
                {
                    // The variable doesn't exist
                    // NOTE: This suggests that the schedule may be created in another
                    // environment and then reconnected to another SMA instance. How should this be handled?
                    context.AddToSchedules(rawSchedule);
                }

                foundSchedule.Name = schedule.Name;

                context.UpdateObject(foundSchedule);
            }

            context.SaveChanges();

            return new Task<bool>(() =>
            {
                return true;
            });
        }