/// <summary> /// Initialize connection. /// </summary> /// <returns>Returns connected device. Null if connection alreay exists.</returns> GXDevice InitializeConnection(GXSchedule schedule, GXDevice device) { lock (device.SyncRoot) { bool connected = (device.Status & DeviceStates.Connected) != 0; if (!connected) { int pos = -1; do { try { device.Connect(); //Increase count in case connection failed. if ((device.Status & DeviceStates.Connected) == 0) { ++pos; Thread.Sleep(schedule.ConnectionFailWaitTime); } } catch (Exception Ex) { device.NotifyError(schedule, Ex); ++pos; Thread.Sleep(schedule.ConnectionFailWaitTime); } } while ((device.Status & DeviceStates.Connected) == 0 && pos < schedule.ConnectionFailTryCount); if ((device.Status & DeviceStates.Connected) == 0) { throw new Exception(Resources.ConnectionFailed); } return device; } return null; } }
/// <summary> /// Default constructor /// </summary> public GXScheduleEventArgs(GXSchedule schedule, ScheduleState status) : base(schedule) { Status = status; }
public GXScheduleEditorDlg(GXSchedule scheduleItem, GXDeviceList deviceList) { InitializeComponent(); try { if (scheduleItem == null) { scheduleItem = new GXSchedule(); scheduleItem.ScheduleStartTime = DateTime.Now; scheduleItem.ScheduleEndTime = DateTime.MaxValue; scheduleItem.TransactionStartTime = DateTime.MinValue; scheduleItem.TransactionEndTime = DateTime.MaxValue; } m_DeviceList = deviceList; m_ScheduleItem = scheduleItem; if (System.Globalization.DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek == DayOfWeek.Sunday) { Point TmpLoc = new Point(DaySunCb.Location.X, DaySunCb.Location.Y); DaySunCb.Location = DayMonCb.Location; DayMonCb.Location = DayTueCb.Location; DayTueCb.Location = DayWedCb.Location; DayWedCb.Location = DayThuCb.Location; DayThuCb.Location = DayFriCb.Location; DayFriCb.Location = DaySatCb.Location; DaySatCb.Location = TmpLoc; } FillEnums(); UpdateResouces(); NameTb.Text = m_ScheduleItem.Name; if (m_ScheduleItem.TransactionStartTime != DateTime.MinValue) { TransactionStartTimeTp.Value = m_ScheduleItem.TransactionStartTime; } else { TransactionStartTimeTp.Checked = false; } if (m_ScheduleItem.TransactionEndTime != DateTime.MaxValue) { TransactionEndTimeTp.Value = m_ScheduleItem.TransactionEndTime; } //Has to be done to uncheck, known issue in .NET TransactionEndTimeTp.Checked = true; //Has to be done to uncheck, known issue in .NET TransactionEndTimeTp.Checked = m_ScheduleItem.TransactionEndTime != DateTime.MaxValue; if (m_ScheduleItem.TransactionEndTime != DateTime.MaxValue) { TransactionEndTimeTp.Value = m_ScheduleItem.TransactionEndTime; } if (m_ScheduleItem.TransactionCount == 0) { TransactionCountCb.Checked = false; TransactionCountTb.Text = ""; } else { TransactionCountCb.Checked = true; TransactionCountTb.Text = m_ScheduleItem.TransactionCount.ToString(); } UpdateFrequencyTp.Value = new DateTime(((long)m_ScheduleItem.UpdateInterval) * 10000000 + UpdateFrequencyTp.MinDate.Ticks); RepeatModeCb.SelectedItem = ScheduleRepeatToString(m_ScheduleItem.RepeatMode); DayOfMonthTb.Text = m_ScheduleItem.DayOfMonth.ToString(); IntervalTb.Text = m_ScheduleItem.Interval.ToString(); ActionCb.SelectedItem = ScheduleActionToString(m_ScheduleItem.Action); if (m_ScheduleItem.ScheduleStartTime != DateTime.MinValue) { ScheduleStartDateTp.Value = m_ScheduleItem.ScheduleStartTime; } if (m_ScheduleItem.ScheduleEndTime != DateTime.MaxValue) { ScheduleEndDateTp.Value = m_ScheduleItem.ScheduleEndTime; } ScheduleEndDateTp.Checked = true; //Has to be done to uncheck, known issue in .NET ScheduleEndDateTp.Checked = m_ScheduleItem.ScheduleEndTime != DateTime.MaxValue; UpdateTargetCheckTree(); ErrorWaitTimeTp.Value = new DateTime(ErrorWaitTimeTp.MinDate.Ticks + ((long)m_ScheduleItem.FailWaitTime) * 10000); //ErrorWaitTimeTp.Value. = m_ScheduleItem.FailWaitTime/1000.0; ErrorTryCountTb.Text = m_ScheduleItem.FailTryCount.ToString(); ConnectionDelayTimeTp.Value = new DateTime(ConnectionDelayTimeTp.MinDate.Ticks + ((long)m_ScheduleItem.ConnectionDelayTime) * 10000); MaxThreadCountTb.Text = m_ScheduleItem.MaxThreadCount.ToString(); //ConnectionFailWaitTimeTb.Text = Convert.ToString(m_ScheduleItem.ConnectionFailWaitTime/1000.0); ConnectionFailWaitTimeTp.Value = new DateTime(ConnectionFailWaitTimeTp.MinDate.Ticks + ((long)m_ScheduleItem.ConnectionFailWaitTime) * 10000); ConnectionFailTryCountTb.Text = m_ScheduleItem.ConnectionFailTryCount.ToString(); if (m_ScheduleItem.DayOfWeeks == null) { DayMonCb.Checked = DayTueCb.Checked = DayWedCb.Checked = DayThuCb.Checked = DayFriCb.Checked = DaySatCb.Checked = DaySunCb.Checked = false; } else { System.Collections.Generic.List<DayOfWeek> list = new System.Collections.Generic.List<DayOfWeek>(); list.AddRange(m_ScheduleItem.DayOfWeeks); DayMonCb.Checked = list.Contains(DayOfWeek.Monday); DayTueCb.Checked = list.Contains(DayOfWeek.Tuesday); DayWedCb.Checked = list.Contains(DayOfWeek.Wednesday); DayThuCb.Checked = list.Contains(DayOfWeek.Thursday); DayFriCb.Checked = list.Contains(DayOfWeek.Friday); DaySatCb.Checked = list.Contains(DayOfWeek.Saturday); DaySunCb.Checked = list.Contains(DayOfWeek.Sunday); } OKBtn.Enabled = (m_ScheduleItem.Status & ScheduleState.Run) == 0; } catch (Exception Ex) { GXCommon.ShowError(this, Ex); } }
/// <summary> /// Update selected target(s) from tree. /// </summary> /// <returns>Returns true if atleast one item is selected.</returns> private bool SetScheduleTarget(GXSchedule scheduleItem, TreeNode deviceListNode) { scheduleItem.Items.Clear(); scheduleItem.ExcludedItems.Clear(); //Get included and excluded items from the tree Queue q = new Queue(); q.Enqueue(deviceListNode); while (q.Count > 0) { TreeNode Node = (TreeNode)q.Dequeue(); if ((Node.Parent == null || !Node.Parent.Checked) && Node.Checked) { scheduleItem.Items.Add(Node.Tag); } if (Node.Parent != null && Node.Parent.Checked && !Node.Checked) { scheduleItem.ExcludedItems.Add(Node.Tag); } foreach (TreeNode ChildNode in Node.Nodes) { q.Enqueue(ChildNode); } } return (scheduleItem.Items.Count > 0); }
void DeviceTransaction(GXSchedule schedule, GXDevice device, bool read) { try { ThreadPool.QueueUserWorkItem(new WaitCallback(SendDataThread), new object[] { this, schedule, device, read }); } catch (Exception Ex) { throw Ex; } }
private void AddScheduleItem(GXSchedule item) { ListViewItem it = new ListViewItem(item.Name); it.SubItems.Add(GXScheduleEditorDlg.ScheduleRepeatToString(item.RepeatMode)); //Next run time DateTime NextDate = item.NextScheduledDate; if (NextDate > DateTime.MinValue) { it.SubItems.Add(NextDate.ToString()); } else { it.SubItems.Add(string.Empty); } //Last run time if (item.Statistics.LastRunTime > DateTime.MinValue) { it.SubItems.Add(item.Statistics.LastRunTime.ToString()); } else { it.SubItems.Add(string.Empty); } //Progress it.SubItems.Add(string.Empty); it.Tag = item; it.ImageIndex = (int)((item.Status & ScheduleState.Run) != 0 ? ScheduleImages.ScheduleItemStart : ScheduleImages.ScheduleItemStop); Schedules.Items.Add(it); ScheduleToTreeNode[item] = it; }