Пример #1
0
        public void UpdateVendorDevice(VendorDevice vendorDevice)
        {
            vendorDevice.UpdatedBy = GetCurrentUserID();
            vendorDevice.UpdatedOn = DateTime.UtcNow;

            DataContext.Table <VendorDevice>().UpdateRecord(vendorDevice);
        }
Пример #2
0
        void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
#if SILVERLIGHT
            Storyboard sb = new Storyboard();
            sb            = Application.Current.Resources["ButtonPressAnimation"] as Storyboard;
            sb.Completed += new EventHandler(delegate(object obj, EventArgs es) { sb.Stop(); });
            Storyboard.SetTarget(sb, ButtonSaveTransform);
            sb.Begin();
#endif
            if (IsValid())
            {
                VendorDevice vendorDevice = new VendorDevice();
                KeyValuePair <int, string> selectedVendor = (KeyValuePair <int, string>)ComboBoxVendor.SelectedItem;
                vendorDevice.VendorID    = selectedVendor.Key;
                vendorDevice.Name        = TextBoxName.Text.CleanText();
                vendorDevice.Description = TextBoxDescription.Text.CleanText();
                vendorDevice.URL         = TextBoxUrl.Text.CleanText();

                if (m_vendorDeviceID != 0 && m_inEditMode == true)
                {
                    vendorDevice.ID = m_vendorDeviceID;
                    SaveVendorDevice(vendorDevice, false);
                }
                else
                {
                    SaveVendorDevice(vendorDevice, true);
                }
            }
        }
Пример #3
0
        public void AddNewVendorDevice(VendorDevice vendorDevice)
        {
            vendorDevice.CreatedBy = GetCurrentUserID();
            vendorDevice.CreatedOn = DateTime.UtcNow;
            vendorDevice.UpdatedBy = vendorDevice.CreatedBy;
            vendorDevice.UpdatedOn = vendorDevice.CreatedOn;

            DataContext.Table <VendorDevice>().AddNewRecord(vendorDevice);
        }
Пример #4
0
 /// <summary>
 /// Initialization to be done before the initial call to <see cref="Load"/>.
 /// </summary>
 public override void Initialize()
 {
     base.Initialize();
     m_nodeLookupList = Node.GetLookupList(null);
     m_concentratorDeviceLookupList = Device.GetLookupList(null, DeviceType.Concentrator, true);
     m_companyLookupList            = Company.GetLookupList(null, true);
     m_historianLookupList          = TimeSeries.UI.DataModels.Historian.GetLookupList(null, true, false);
     m_interconnectionLookupList    = Interconnection.GetLookupList(null, true);
     m_protocolLookupList           = Protocol.GetLookupList(null, true);
     m_vendorDeviceLookupList       = VendorDevice.GetLookupList(null, true);
     m_timezoneLookupList           = CommonFunctions.GetTimeZones(true);
 }
Пример #5
0
 void ListBoxVendorDeviceList_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (ListBoxVendorDeviceList.SelectedIndex >= 0)
     {
         VendorDevice selectedVendorDevice = ListBoxVendorDeviceList.SelectedItem as VendorDevice;
         GridVendorDeviceDetail.DataContext = selectedVendorDevice;
         ComboBoxVendor.SelectedItem        = new KeyValuePair <int, string>(selectedVendorDevice.VendorID, selectedVendorDevice.VendorName);
         m_vendorDeviceID = selectedVendorDevice.ID;
         m_inEditMode     = true;
         ButtonSave.Tag   = "Update";
     }
 }
Пример #6
0
 public string SaveVendorDevice(VendorDevice vendorDevice, bool isNew)
 {
     try
     {
         return(CommonFunctions.SaveVendorDevice(null, vendorDevice, isNew));
     }
     catch (Exception ex)
     {
         CommonFunctions.LogException(null, "Service.SaveVendorDevice", ex);
         CustomServiceFault fault = new CustomServiceFault()
         {
             UserMessage = "Failed to Save Vendor Device Information", SystemMessage = ex.Message
         };
         throw new FaultException <CustomServiceFault>(fault);
     }
 }
Пример #7
0
        void SaveVendorDevice(VendorDevice vendorDevice, bool isNew)
        {
            SystemMessages sm;

            try
            {
                string result = CommonFunctions.SaveVendorDevice(null, vendorDevice, isNew);

                sm = new SystemMessages(new Message()
                {
                    UserMessage = result, SystemMessage = string.Empty, UserMessageType = MessageType.Success
                },
                                        ButtonType.OkOnly);
                sm.Owner = Window.GetWindow(this);
                sm.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                sm.ShowPopup();

                GetVendorDevices();
                //ClearForm();

                //make this newly added or updated item as default selected. So user can click initialize right away.
                ListBoxVendorDeviceList.SelectedItem = ((List <VendorDevice>)ListBoxVendorDeviceList.ItemsSource).Find(c => c.Name == vendorDevice.Name);
            }
            catch (Exception ex)
            {
                CommonFunctions.LogException(null, "WPF.SaveVendorDevice", ex);
                sm = new SystemMessages(new Message()
                {
                    UserMessage = "Failed to Save Vendor Device Information", SystemMessage = ex.Message, UserMessageType = MessageType.Error
                },
                                        ButtonType.OkOnly);
                sm.Owner = Window.GetWindow(this);
                sm.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                sm.ShowPopup();
            }
        }
Пример #8
0
 public void UpdateVendorDevice(VendorDevice vendorDevice)
 {
     DataContext.Table <VendorDevice>().UpdateRecord(vendorDevice);
 }
Пример #9
0
 public void AddNewVendorDevice(VendorDevice vendorDevice)
 {
     DataContext.Table <VendorDevice>().AddNewRecord(vendorDevice);
 }
Пример #10
0
        public void SendEmail(string acronym)
        {
            Device device = QueryDevice(acronym);

            // Get Device State and other Information
            AlarmDevice alarmDevice = DataContext.Table <AlarmDevice>().QueryRecordWhere("DeviceID = {0}", device.ID);

            string  stateName = "Unknown State";
            string  vendorName = "Unspecified";
            string  deviceType = "Unspecified";
            string  contactList = "None Defined";
            string  connectionString = "settings=none";
            string  parentAcronym = "";
            decimal longitude = 0.0M, latitude = 0.0M;
            int     framesPerSecond = 30;
            int?    vendorDeviceID  = device.VendorDeviceID;

            if (device.ParentID.HasValue)
            {
                int parentID = device.ParentID.Value;

                // If this is a concentrator child, get connection string of parent
                Device parentDevice = DataContext.Table <Device>().QueryRecordWhere("ID = {0}", parentID);

                if ((object)parentDevice != null)
                {
                    parentAcronym = parentDevice.Acronym;

                    string childConnectionString = connectionString;

                    // Settings in child connection string are not common
                    if (string.IsNullOrWhiteSpace(childConnectionString))
                    {
                        childConnectionString = "";
                    }
                    else
                    {
                        childConnectionString = string.Format("; childDevice={0}; {1}", acronym, childConnectionString);
                    }

                    connectionString = string.Format("parentDevice={0}; {1}{2}", parentDevice.Acronym, parentDevice.ConnectionString, childConnectionString);
                    vendorDeviceID   = vendorDeviceID ?? parentDevice.VendorDeviceID;
                }
            }

            if ((object)alarmDevice != null)
            {
                AlarmState alarmState = DataContext.Table <AlarmState>().QueryRecordWhere("ID = {0}", alarmDevice.StateID);
                if (!string.IsNullOrEmpty(alarmState?.State))
                {
                    stateName = alarmState.State;
                }
            }

            if (device.Longitude.HasValue)
            {
                longitude = device.Longitude.Value;
            }

            if (device.Latitude.HasValue)
            {
                latitude = device.Latitude.Value;
            }

            if (device.FramesPerSecond.HasValue)
            {
                framesPerSecond = device.FramesPerSecond.Value;
            }



            VendorDevice vendorDevice = DataContext.Table <VendorDevice>().QueryRecordWhere("ID = {0}", vendorDeviceID);

            if ((object)vendorDevice != null)
            {
                if (!string.IsNullOrEmpty(vendorDevice?.Name))
                {
                    deviceType = vendorDevice.Name;
                }

                Vendor vendor = DataContext.Table <Vendor>().QueryRecordWhere("ID = {0}", vendorDevice.VendorID);

                if (!string.IsNullOrEmpty(vendor?.Name))
                {
                    vendorName = vendor.Name;
                }
            }

            if (!String.IsNullOrEmpty(device.ContactList))
            {
                contactList = device.ContactList;
            }

            if (!String.IsNullOrEmpty(device.ConnectionString))
            {
                connectionString = device.ConnectionString;
            }

            // ready Email to be send. Load settings from ConfigFile Only
            string            emailServer                 = Mail.DefaultSmtpServer;
            string            emailSender                 = string.Format("{0}@{1}.local", Environment.UserName, Environment.UserDomainName);
            string            emailRecipients             = "";
            ConfigurationFile config                      = ConfigurationFile.Current;
            CategorizedSettingsElementCollection settings = config.Settings["deviceStatusNotification"];

            settings.Add("EmailServer", emailServer, "SMTP server to use for sending the email notifications.");
            settings.Add("EmailSender", emailSender, "Email address to be used for sending the email notifications.");
            settings.Add("EmailRecipients", emailRecipients, "Email addresses (comma or semicolon delimited) where the email notifications are to be sent.");
            emailServer     = settings["EmailServer"].ValueAs(emailServer);
            emailSender     = settings["EmailSender"].ValueAs(emailSender);
            emailRecipients = settings["EmailRecipients"].ValueAs(emailRecipients);

            if (string.IsNullOrEmpty(emailRecipients))
            {
                throw new ArgumentNullException("EmailRecipients");
            }

            Mail briefMessage    = new Mail(emailRecipients, emailSender, emailServer);
            Mail detailedMessage = new Mail(emailSender, emailSender, emailServer);

            briefMessage.Subject    = $"{acronym} {stateName}";
            detailedMessage.Subject = $"{acronym} {stateName}";
            detailedMessage.Body    = $"{acronym} is in {stateName} state. Please issue a field ticket to investigate\r\n\r\n";
            detailedMessage.Body   += $"Device Acronym: {acronym}\r\n";
            detailedMessage.Body   += $"Device Name: {device?.Name}\r\n";
            detailedMessage.Body   += $"Make: {vendorName}\r\n";
            detailedMessage.Body   += $"Model: {deviceType}\r\n";
            detailedMessage.Body   += $"Latitude: {latitude}\r\n";
            detailedMessage.Body   += $"Longitude: {longitude}\r\n";
            detailedMessage.Body   += $"Frames per Second: {framesPerSecond}\r\n";
            detailedMessage.Body   += $"Contacts: {contactList}\r\n";
            detailedMessage.Body   += $"Connection String:\r\n";
            detailedMessage.Body   += $"\t{String.Join("\r\n\t", connectionString.Split(';').Select(s => s.Trim()))}\r\n\r\n";
            detailedMessage.Body   += $"Last collected Statistics:\r\n";

            detailedMessage.Body += GenerateStatsTable(acronym, parentAcronym);
            foreach (string recipient in emailRecipients.Replace(" ", "").Split(';', ','))
            {
                string[] addressParts = recipient.Split(':');
                if (addressParts.Length > 1)
                {
                    if (string.Compare(addressParts[1], "sms", true) == 0)
                    {
                        // A brief message is to be sent.
                        briefMessage.ToRecipients = addressParts[0];
                        briefMessage.Send();
                    }
                }
                else
                {
                    // A detailed message is to be sent.
                    detailedMessage.ToRecipients = recipient;
                    detailedMessage.Send();
                }
            }
        }
Пример #11
0
 void SaveVendorDevice(VendorDevice vendorDevice, bool isNew)
 {
     m_client.SaveVendorDeviceAsync(vendorDevice, isNew);
 }
Пример #12
0
 void SaveVendorDevice(VendorDevice vendorDevice, bool isNew)
 {
     m_client.SaveVendorDeviceAsync(vendorDevice, isNew);
 }