예제 #1
0
파일: Measurements.cs 프로젝트: xj0229/gsf
        private void Searcher_MatchesFound(object sender, EventArgs <IEnumerable <DataModels.Measurement> > e)
        {
            try
            {
                foreach (DataModels.Measurement measurement in e.Argument)
                {
                    ItemsKeys.Add(measurement.SignalID);
                }

                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    if (ItemsSource.Count == 0)
                    {
                        Load();
                    }
                    else
                    {
                        if (ItemsSource.Count < ItemsPerPage)
                        {
                            e.Argument.Take(ItemsPerPage - ItemsSource.Count).ToList()
                            .ForEach(measurement => ItemsSource.Add(measurement));
                        }

                        GeneratePages();
                    }
                }));
            }
            catch (Exception ex)
            {
                CommonFunctions.LogException(null, "Search " + DataModelName, ex);
            }
        }
 /// <summary> set value to ssesion </summary>
 public static void Set <T>(this IDictionary <object, object> items, ItemsKeys key, T value)
 {
     try
     {
         var keyName = key.GetAttribute <DisplayAttribute>().Name;
         // int value
         if (typeof(T) == typeof(int))
         {
             items[keyName] = Convert.ToInt32(value);
         }
         // string value
         else if (typeof(T) == typeof(string))
         {
             items[keyName] = value.ToString();
         }
         // object
         else
         {
             items[keyName] = JsonConvert.SerializeObject(value);
         }
     }
     catch (Exception ex)
     {
         Log.Logger.ErrorEx(ex);
     }
 }
예제 #3
0
        /// <summary>
        /// Deletes associated <see cref="Adapter"/> record.
        /// </summary>
        public override void Delete()
        {
            if (CanDelete && Confirm("Are you sure you want to delete \'" + GetCurrentItemName() + "\'?", "Delete " + DataModelName))
            {
                try
                {
                    if (OnBeforeDeleteCanceled())
                    {
                        throw new OperationCanceledException("Delete was canceled.");
                    }

                    int    currentItemKey = GetCurrentItemKey();
                    string result         = Adapter.Delete(null, m_adapterType, GetCurrentItemKey());
                    ItemsKeys.Remove(currentItemKey);

                    OnDeleted();

                    Load();
                    DisplayStatusMessage(result);
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                    {
                        Popup(ex.Message + Environment.NewLine + "Inner Exception: " + ex.InnerException.Message, "Delete " + DataModelName + " Exception:", MessageBoxImage.Error);
                        CommonFunctions.LogException(null, "Delete " + DataModelName, ex.InnerException);
                    }
                    else
                    {
                        Popup(ex.Message, "Delete " + DataModelName + " Exception:", MessageBoxImage.Error);
                        CommonFunctions.LogException(null, "Delete " + DataModelName, ex);
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Loads collection of <see cref="Device"/> information stored in the database.
        /// </summary>
        /// <remarks>This method is overridden because MethodInfo.Invoke in the base class did not like optional parameters.</remarks>
        public override void Load()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            List <int> pageKeys;

            try
            {
                if (OnBeforeLoadCanceled())
                {
                    throw new OperationCanceledException("Load was canceled.");
                }

                if ((object)ItemsKeys == null)
                {
                    ItemsKeys = Device.LoadKeys(null, 0, m_searchText, SortMember, SortDirection);

                    if ((object)SortSelector != null)
                    {
                        if (SortDirection == "ASC")
                        {
                            ItemsKeys = ItemsKeys.OrderBy(SortSelector).ToList();
                        }
                        else
                        {
                            ItemsKeys = ItemsKeys.OrderByDescending(SortSelector).ToList();
                        }
                    }

                    if (string.IsNullOrEmpty(m_searchText))
                    {
                        AllKeys = ItemsKeys;
                    }
                }

                pageKeys    = ItemsKeys.Skip((CurrentPageNumber - 1) * ItemsPerPage).Take(ItemsPerPage).ToList();
                ItemsSource = Device.Load(null, pageKeys);

                OnLoaded();
            }
            catch (Exception ex)
            {
                if ((object)ex.InnerException != null)
                {
                    Popup(ex.Message + Environment.NewLine + "Inner Exception: " + ex.InnerException.Message, "Load Devices Exception:", MessageBoxImage.Error);
                    CommonFunctions.LogException(null, "Load Devices", ex.InnerException);
                }
                else
                {
                    Popup(ex.Message, "Load Devices Exception:", MessageBoxImage.Error);
                    CommonFunctions.LogException(null, "Load Devices", ex);
                }
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }
예제 #5
0
        /// <summary>
        /// Load output stream device phasors.
        /// </summary>
        public override void Load()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            List <int> pageKeys = null;

            try
            {
                if (OnBeforeLoadCanceled())
                {
                    throw new OperationCanceledException("Load was canceled.");
                }

                // Load keys if LoadKeys method exists in data model
                if ((object)ItemsKeys == null)
                {
                    ItemsKeys = OutputStreamDevicePhasor.LoadKeys(null, m_outputStreamDeviceID, SortMember, SortDirection);

                    if ((object)SortSelector != null)
                    {
                        if (SortDirection == "ASC")
                        {
                            ItemsKeys = ItemsKeys.OrderBy(SortSelector).ToList();
                        }
                        else
                        {
                            ItemsKeys = ItemsKeys.OrderByDescending(SortSelector).ToList();
                        }
                    }
                }

                // Extract a single page of keys
                pageKeys = ItemsKeys.Skip((CurrentPageNumber - 1) * ItemsPerPage).Take(ItemsPerPage).ToList();

                // If we were able to extract a page of keys, load only that page.
                // Otherwise, load the whole recordset.
                ItemsSource = OutputStreamDevicePhasor.Load(null, pageKeys);

                OnLoaded();
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    Popup(ex.Message + Environment.NewLine + "Inner Exception: " + ex.InnerException.Message, "Load " + DataModelName + " Exception:", MessageBoxImage.Error);
                    CommonFunctions.LogException(null, "Load " + DataModelName, ex.InnerException);
                }
                else
                {
                    Popup(ex.Message, "Load " + DataModelName + " Exception:", MessageBoxImage.Error);
                    CommonFunctions.LogException(null, "Load " + DataModelName, ex);
                }
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }
예제 #6
0
파일: Measurements.cs 프로젝트: xj0229/gsf
        /// <summary>
        /// Loads collection of <see cref="GSF.TimeSeries.UI.DataModels.Measurement"/> defined in the database.
        /// </summary>
        public override void Load()
        {
            List <Guid> pageKeys;

            try
            {
                if (!m_searching)
                {
                    Mouse.OverrideCursor = Cursors.Wait;
                }

                if ((object)ItemsKeys == null)
                {
                    ItemsKeys = DataModels.Measurement.LoadSignalIDs(null, FilterExpression, SortMember, SortDirection);

                    if ((object)SortSelector != null)
                    {
                        if (SortDirection == "ASC")
                        {
                            ItemsKeys = ItemsKeys.OrderBy(SortSelector).ToList();
                        }
                        else
                        {
                            ItemsKeys = ItemsKeys.OrderByDescending(SortSelector).ToList();
                        }
                    }

                    AllKeys = ItemsKeys;
                }

                pageKeys    = ItemsKeys.Skip((CurrentPageNumber - 1) * ItemsPerPage).Take(ItemsPerPage).ToList();
                ItemsSource = DataModels.Measurement.LoadFromKeys(null, pageKeys);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    Popup(ex.Message + Environment.NewLine + "Inner Exception: " + ex.InnerException.Message, "Load " + DataModelName + " Exception:", MessageBoxImage.Error);
                    CommonFunctions.LogException(null, "Load " + DataModelName, ex.InnerException);
                }
                else
                {
                    Popup(ex.Message, "Load " + DataModelName + " Exception:", MessageBoxImage.Error);
                    CommonFunctions.LogException(null, "Load " + DataModelName, ex);
                }
            }
            finally
            {
                if (!m_searching)
                {
                    Mouse.OverrideCursor = null;
                }
            }
        }
 /// <summary> set value to ssesion </summary>
 public static void Set(this IDictionary <object, object> items, ItemsKeys key, string value)
 {
     try
     {
         var keyName = key.GetAttribute <DisplayAttribute>().Name;
         items[keyName] = value;
     }
     catch (Exception ex)
     {
         Log.Logger.ErrorEx(ex);
     }
 }
예제 #8
0
        /// <summary>
        /// Load output stream device phasors.
        /// </summary>
        public override void Load()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            List <int> pageKeys = null;

            try
            {
                if (OnBeforeLoadCanceled())
                {
                    throw new OperationCanceledException("Load was canceled.");
                }

                if ((object)ItemsKeys == null)
                {
                    ItemsKeys = OutputStreamDeviceDigital.LoadKeys(null, m_outputStreamDeviceID, SortMember, SortDirection);

                    if ((object)SortSelector != null)
                    {
                        if (SortDirection == "ASC")
                        {
                            ItemsKeys = ItemsKeys.OrderBy(SortSelector).ToList();
                        }
                        else
                        {
                            ItemsKeys = ItemsKeys.OrderByDescending(SortSelector).ToList();
                        }
                    }
                }

                pageKeys    = ItemsKeys.Skip((CurrentPageNumber - 1) * ItemsPerPage).Take(ItemsPerPage).ToList();
                ItemsSource = OutputStreamDeviceDigital.Load(null, pageKeys);
                CurrentItem.OutputStreamDeviceID = m_outputStreamDeviceID;
                OnLoaded();
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    Popup(ex.Message + Environment.NewLine + "Inner Exception: " + ex.InnerException.Message, "Load " + DataModelName + " Exception:", MessageBoxImage.Error);
                    CommonFunctions.LogException(null, "Load " + DataModelName, ex.InnerException);
                }
                else
                {
                    Popup(ex.Message, "Load " + DataModelName + " Exception:", MessageBoxImage.Error);
                    CommonFunctions.LogException(null, "Load " + DataModelName, ex);
                }
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }
예제 #9
0
        /// <summary>
        /// Loads collection of <see cref="PowerCalculation"/> information stored in the database.
        /// </summary>
        /// <remarks>This method is overridden because MethodInfo.Invoke in the base class did not like optional parameters.</remarks>
        public override void Load()
        {
            Mouse.OverrideCursor = Cursors.Wait;

            try
            {
                if (OnBeforeLoadCanceled())
                {
                    throw new OperationCanceledException("Load was canceled.");
                }

                if (ItemsKeys == null || m_filterChanged)
                {
                    ItemsKeys       = Phasor.LoadKeys(null, PhasorTypeFilter);
                    m_filterChanged = false;

                    if ((object)SortSelector != null)
                    {
                        if (SortDirection == "ASC")
                        {
                            ItemsKeys = ItemsKeys.OrderBy(SortSelector).ToList();
                        }
                        else
                        {
                            ItemsKeys = ItemsKeys.OrderByDescending(SortSelector).ToList();
                        }
                    }
                }

                var pageKeys = ItemsKeys.Skip((CurrentPageNumber - 1) * ItemsPerPage).Take(ItemsPerPage).ToList();
                ItemsSource = Phasor.Load(null, pageKeys);

                OnLoaded();
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    Popup(ex.Message + Environment.NewLine + "Inner Exception: " + ex.InnerException.Message, "Load Phasors Exception:", MessageBoxImage.Error);
                    CommonFunctions.LogException(null, "Load Phasors", ex.InnerException);
                }
                else
                {
                    Popup(ex.Message, "Load Phasors Exception:", MessageBoxImage.Error);
                    CommonFunctions.LogException(null, "Load Phasors", ex);
                }
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }
        /// <summary> get value from ssesion </summary>
        public static string Get(this IDictionary <object, object> items, ItemsKeys key)
        {
            try
            {
                var keyName = key.GetAttribute <DisplayAttribute>().Name;
                var value   = items[keyName];
                return(value.ToString());
            }
            catch (Exception ex)
            {
                Log.Logger.ErrorEx(ex);
            }

            return(string.Empty);
        }
예제 #11
0
        /// <summary>
        /// Loads collection of <see cref="Adapter"/> defined in the database.
        /// </summary>
        public override void Load()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            List <int> pageKeys;

            try
            {
                if ((object)ItemsKeys == null)
                {
                    ItemsKeys = Adapter.LoadIDs(null, m_adapterType, SortMember, SortDirection);

                    if ((object)SortSelector != null)
                    {
                        if (SortDirection == "ASC")
                        {
                            ItemsKeys = ItemsKeys.OrderBy(SortSelector).ToList();
                        }
                        else
                        {
                            ItemsKeys = ItemsKeys.OrderByDescending(SortSelector).ToList();
                        }
                    }
                }

                pageKeys         = ItemsKeys.Skip((CurrentPageNumber - 1) * ItemsPerPage).Take(ItemsPerPage).ToList();
                ItemsSource      = Adapter.Load(null, m_adapterType, pageKeys);
                CurrentItem.Type = m_adapterType;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    Popup(ex.Message + Environment.NewLine + "Inner Exception: " + ex.InnerException.Message, "Load " + DataModelName + " Exception:", MessageBoxImage.Error);
                    CommonFunctions.LogException(null, "Load " + DataModelName, ex.InnerException);
                }
                else
                {
                    Popup(ex.Message, "Load " + DataModelName + " Exception:", MessageBoxImage.Error);
                    CommonFunctions.LogException(null, "Load " + DataModelName, ex);
                }
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }
예제 #12
0
        /// <summary>
        /// Deletes <see cref="OutputStreamDevice"/>.
        /// </summary>
        public override void Delete()
        {
            //base.Delete();
            if (CanDelete && Confirm("Are you sure you want to delete \'" + GetCurrentItemName() + "\'?", "Delete " + DataModelName))
            {
                try
                {
                    if (OnBeforeDeleteCanceled())
                    {
                        throw new OperationCanceledException("Delete was canceled.");
                    }

                    int    currentItemKey = GetCurrentItemKey();
                    string result         = OutputStreamDevice.Delete(null, m_outputStreamID, CurrentItem.Acronym);
                    ItemsKeys.Remove(currentItemKey);

                    OnDeleted();

                    Load();

                    Popup(result, "Delete " + DataModelName, MessageBoxImage.Information);
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                    {
                        Popup(ex.Message + Environment.NewLine + "Inner Exception: " + ex.InnerException.Message, "Delete " + DataModelName + " Exception:", MessageBoxImage.Error);
                        CommonFunctions.LogException(null, "Delete " + DataModelName, ex.InnerException);
                    }
                    else
                    {
                        Popup(ex.Message, "Delete " + DataModelName + " Exception:", MessageBoxImage.Error);
                        CommonFunctions.LogException(null, "Delete " + DataModelName, ex);
                    }
                }
            }
        }
        /// <summary> get value from session </summary>
        public static T Get <T>(this IDictionary <object, object> items, ItemsKeys key)
        {
            var result = default(T);

            try
            {
                var keyName = key.GetAttribute <DisplayAttribute>().Name;

                if (!items.Keys.Contains(keyName))
                {
                    Log.Logger.ErrorCall($"Get session key {keyName}: not exist in session!");
                    return(result);
                }

                // int value
                if (typeof(T) == typeof(int))
                {
                    result = (T)Convert.ChangeType(items[keyName], typeof(T));
                }
                // string value
                else if (typeof(T) == typeof(string))
                {
                    result = (T)Convert.ChangeType(items[keyName], typeof(T));
                }
                // object
                else
                {
                    result = JsonConvert.DeserializeObject <T>(items[keyName].ToString());
                }
            }
            catch (Exception ex)
            {
                Log.Logger.ErrorEx(ex);
            }

            return(result);
        }
        /// <summary> Define if not contains ont key and string.IsNullOrEmpty </summary>
        public static bool Contains(this IDictionary <object, object> items, ItemsKeys key)
        {
            var keyName = key.GetAttribute <DisplayAttribute>().Name;

            return(items.Keys.Contains(keyName));
        }