Esempio n. 1
0
        private async void AddSchedule()
        {
            GXSchedule m = new GXSchedule();

            m.Name = "Minutely";
            GXDateTime dt = new GXDateTime(DateTime.Now.Date);

            dt.Skip = DateTimeSkips.Year | DateTimeSkips.Month | DateTimeSkips.Day | DateTimeSkips.Hour | DateTimeSkips.Minute;
            m.Start = dt.ToFormatString();
            UpdateSchedule us = new UpdateSchedule();

            us.Schedules.Add(m);
            GXSchedule h = new GXSchedule();

            h.Name  = "Hourly";
            dt.Skip = DateTimeSkips.Year | DateTimeSkips.Month | DateTimeSkips.Day | DateTimeSkips.Hour;
            h.Start = dt.ToFormatString();
            us.Schedules.Add(h);
            GXSchedule d = new GXSchedule();

            d.Name  = "Daily";
            dt.Skip = DateTimeSkips.Year | DateTimeSkips.Month | DateTimeSkips.Day;
            d.Start = dt.ToFormatString();
            us.Schedules.Add(d);
            using (HttpClient client = new HttpClient())
            {
                using (HttpResponseMessage response = await client.PostAsJsonAsync(ServerAddress + "/api/schedule/UpdateSchedule", us))
                {
                    Helpers.CheckStatus(response);
                    UpdateScheduleResponse r = await response.Content.ReadAsAsync <UpdateScheduleResponse>();
                }
            }
        }
Esempio n. 2
0
        private void AddSchedule(GXDbConnection connection)
        {
            List <GXSchedule> list = new List <GXSchedule>();
            GXSchedule        m    = new GXSchedule();

            m.Name = "Minutely";
            GXDateTime dt = new GXDateTime(DateTime.Now.Date);

            dt.Skip = DateTimeSkips.Year | DateTimeSkips.Month | DateTimeSkips.Day | DateTimeSkips.Hour | DateTimeSkips.Minute;
            m.Start = dt.ToFormatString();
            list.Add(m);
            GXSchedule h = new GXSchedule();

            h.Name  = "Hourly";
            dt.Skip = DateTimeSkips.Year | DateTimeSkips.Month | DateTimeSkips.Day | DateTimeSkips.Hour;
            h.Start = dt.ToFormatString();
            list.Add(h);
            GXSchedule d = new GXSchedule();

            d.Name  = "Daily";
            dt.Skip = DateTimeSkips.Year | DateTimeSkips.Month | DateTimeSkips.Day;
            d.Start = dt.ToFormatString();
            list.Add(d);
            connection.Insert(GXInsertArgs.InsertRange(list));
        }
Esempio n. 3
0
 /// <summary>
 /// Edit execution time.
 /// </summary>
 private void TimeEditBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (Time.SelectedItems.Count == 1)
         {
             GXDLMSActionSchedule target  = Target as GXDLMSActionSchedule;
             List <GXDateTime>    entries = new List <GXDateTime>();
             if (target.ExecutionTime != null)
             {
                 entries.AddRange(target.ExecutionTime);
             }
             ListViewItem  li  = Time.SelectedItems[0];
             GXDateTime    it  = (GXDateTime)li.Tag;
             GXDateTimeDlg dlg = new GXDateTimeDlg(it);
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 li.SubItems[0].Text = it.ToFormatString();
                 errorProvider1.SetError(Time, Properties.Resources.ValueChangedTxt);
                 target.ExecutionTime = entries.ToArray();
                 Target.UpdateDirty(4, target.ExecutionTime);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message, "Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 4
0
 public void WriteElementString(string name, GXDateTime value)
 {
     if (value != null && value != DateTime.MinValue)
     {
         writer.WriteElementString(name, value.ToFormatString(System.Globalization.CultureInfo.InvariantCulture));
     }
 }
Esempio n. 5
0
 public void WriteElementString(string name, GXDateTime value)
 {
     if (value != null && value != DateTime.MinValue)
     {
         writer.WriteElementString(name, value.ToFormatString());
     }
 }
 public GXDateTimeDlg(GXDateTime time)
 {
     InitializeComponent();
     StartTime          = time;
     StartTimeTb.Text   = StartTime.ToFormatString();
     EndTimeLbl.Visible = NowEndBtn.Visible = EndTimeTb.Visible = false;
 }
Esempio n. 7
0
 static public string ConvertDLMS2String(object data)
 {
     if (data is DateTime)
     {
         DateTime dt = (DateTime)data;
         if (dt == DateTime.MinValue)
         {
             return("");
         }
         return(dt.ToString());
     }
     if (data is GXDateTime)
     {
         GXDateTime dt = (GXDateTime)data;
         return(dt.ToFormatString());
     }
     if (data is byte[])
     {
         return(BitConverter.ToString((byte[])data).Replace("-", " "));
     }
     if (!(data is string) && (data is Array || data is System.Collections.IEnumerable))
     {
         return(ArrayToString(data));
     }
     return(Convert.ToString(data));
 }
 public GXDateTimeDlg(GXDateTime startTime, GXDateTime endTime)
 {
     InitializeComponent();
     StartTime        = startTime;
     EndTime          = endTime;
     StartTimeTb.Text = StartTime.ToFormatString();
     EndTimeTb.Text   = EndTime.ToFormatString();
 }
Esempio n. 9
0
 public SchedultDlg(GXSchedule s)
 {
     InitializeComponent();
     Target = s;
     if (s.Id != 0)
     {
         IdTb.Text = s.Id.ToString();
     }
     else
     {
         GXDateTime d = new GXDateTime();
         d.Skip  = DateTimeSkips.Year | DateTimeSkips.Month | DateTimeSkips.Day;
         s.Start = d.ToFormatString();
     }
     NameTb.Text = s.Name;
     TimeTb.Text = s.Start;
 }
Esempio n. 10
0
 public void WriteElementString(string name, GXDateTime value, int index)
 {
     if (value != null && value != DateTime.MinValue)
     {
         string str;
         if (UseMeterTime)
         {
             str = value.ToFormatMeterString(System.Globalization.CultureInfo.InvariantCulture);
         }
         else
         {
             str = value.ToFormatString(System.Globalization.CultureInfo.InvariantCulture);
         }
         writer.WriteElementString(name, str);
     }
     else if (!IgnoreDefaultValues)
     {
         writer.WriteElementString(name, "");
     }
 }
Esempio n. 11
0
 private async void DoWork(object state)
 {
     _logger.LogWarning("Timed Background Service is working.");
     try
     {
         DateTime now = DateTime.Now;
         ListSchedulesResponse list = null;
         using (System.Net.Http.HttpResponseMessage response = await Helpers.client.PostAsJsonAsync(Startup.ServerAddress + "/api/schedule/ListSchedules", new ListSchedules()))
         {
             Helpers.CheckStatus(response);
             list = await response.Content.ReadAsAsync <ListSchedulesResponse>();
         }
         List <GXTask> tasks = new List <GXTask>();
         foreach (GXSchedule it in list.Schedules)
         {
             GXDateTime dt = new GXDateTime(it.Start);
             if (it.ExecutionTime == DateTime.MinValue)
             {
                 it.ExecutionTime = now;
             }
             if (Equals(dt, now))
             {
                 _logger.LogTrace("+");
                 foreach (GXObject obj in it.Objects)
                 {
                     foreach (GXAttribute a in obj.Attributes)
                     {
                         GXTask t = new GXTask()
                         {
                             Object   = obj,
                             TaskType = TaskType.Read,
                             Index    = a.Index
                         };
                         tasks.Add(t);
                     }
                 }
                 it.ExecutionTime = now;
                 UpdateScheduleExecutionTime us = new UpdateScheduleExecutionTime();
                 us.Id   = it.Id;
                 us.Time = now;
                 using (System.Net.Http.HttpResponseMessage response = await Helpers.client.PostAsJsonAsync(Startup.ServerAddress + "/api/schedule/UpdateScheduleExecutionTime", us))
                 {
                     Helpers.CheckStatus(response);
                     UpdateScheduleExecutionTime r = await response.Content.ReadAsAsync <UpdateScheduleExecutionTime>();
                 }
             }
             else if (now.Minute == 0)
             {
                 Console.WriteLine(dt.ToFormatString());
                 Console.WriteLine(now.ToString());
             }
         }
         if (tasks.Count != 0)
         {
             AddTask at = new AddTask();
             at.Actions = tasks.ToArray();
             using (System.Net.Http.HttpResponseMessage response = await Helpers.client.PostAsJsonAsync(Startup.ServerAddress + "/api/task/AddTask", at))
             {
                 Helpers.CheckStatus(response);
             }
         }
     }
     catch (Exception ex)
     {
         _logger.LogInformation(ex.Message);
     }
 }