<commit_before>﻿//******************************************************************************************************
//  MenuCommand.cs - Gbtc
//
//  Copyright © 2010, Grid Protection Alliance.  All Rights Reserved.
//
//  Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
//  the NOTICE file distributed with this work for additional information regarding copyright ownership.
//  The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may
//  not use this file except in compliance with the License. You may obtain a copy of the License at:
//
//      http://www.opensource.org/licenses/eclipse-1.0.php
//
//  Unless agreed to in writing, the subject software distributed under the License is distributed on an
//  "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
//  License for the specific language governing permissions and limitations.
//
//  Code Modification History:
//  ----------------------------------------------------------------------------------------------------
//  03/25/2011 - <NAME>
//       Generated original version of source code.
//  05/13/2011 - <NAME>
//       Modified Execute() method to set main window's title property.
//
//******************************************************************************************************

using System;
using System.Reflection;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;

namespace TimeSeriesFramework.UI.Commands
{
    /// <summary>
    /// Exposes <see cref="ICommand"/> object to be used to handle menu item click event.
    /// </summary>
    public class MenuCommand : ICommand
    {
        #region [ Members ]

        // Fields
        private string m_roles;
        private string m_userControlAssembly;
        private string m_userControlPath;
        private string m_description;

        //Events

        /// <summary>
        /// Raises when value of <see cref="CanExecute"/> changes.
        /// </summary>
        public event EventHandler CanExecuteChanged;

        #endregion

        #region [ Properties ]

        /// <summary>
        /// Gets or sets comma seperated values of roles for which menuitem is visible.
        /// </summary>
        public string Roles
        {
            get
            {
                return m_roles;
            }
            set
            {
                m_roles = value;
            }
        }

        /// <summary>
        /// Gets or sets name of the assembly where user control belongs to.
        /// </summary>
        public string UserControlAssembly
        {
            get
            {
                return m_userControlAssembly;
            }
            set
            {
                m_userControlAssembly = value;
            }
        }

        /// <summary>
        /// Gets or sets name of the user control to be loaded.
        /// </summary>
        public string UserControlPath
        {
            get
            {
                return m_userControlPath;
            }
            set
            {
                m_userControlPath = value;
            }
        }

        /// <summary>
        /// Gets or sets the description of associated <see cref="MenuDataItem"/>.
        /// </summary>
        public string Description
        {
            get
            {
                return m_description;
            }
            set
            {
                m_description = value;
            }
        }

        #endregion

        #region [ Methods ]

        /// <summary>
        /// Evaluates if menu item should be visible to current user with access to <see cref="Roles"/>.
        /// </summary>
        /// <param name="parameter">
        /// Data used by the <see cref="MenuCommand"/>. If the <see cref="MenuCommand"/> does not require
        /// data to be passed, this object can be set to <c>null</c>.
        /// </param>
        /// <returns><c>true</c> if this <see cref="MenuCommand"/> can be executed; otherwise, <c>false</c>.</returns>
        public bool CanExecute(object parameter)
        {
            bool canExecute;
            if (string.IsNullOrEmpty(Roles) || Roles == "*")
                canExecute = true;
            else
                canExecute = Thread.CurrentPrincipal.IsInRole(Roles);

            //OnCanExecuteChanged();

            return canExecute;
        }

        /// <summary>
        /// Handles <see cref="ICommand"/> action. 
        /// Loads user control as defined in the <see cref="UserControlPath"/> property from assembly name set in the 
        /// <see cref="UserControlAssembly"/> property.
        /// </summary>
        /// <param name="parameter">
        /// Data used by the <see cref="MenuCommand"/>. If the <see cref="MenuCommand"/> does not require
        /// data to be passed, this object can be set to <c>null</c>.
        /// </param>
        public void Execute(object parameter)
        {
            UIElement frame = null;
            UIElement groupBox = null;
            CommonFunctions.GetFirstChild(Application.Current.MainWindow, typeof(System.Windows.Controls.Frame), ref frame);
            CommonFunctions.GetFirstChild(Application.Current.MainWindow, typeof(GroupBox), ref groupBox);

            if (frame != null)
            {
                Assembly assembly = Assembly.LoadFrom(m_userControlAssembly);
                UserControl userControl = Activator.CreateInstance(assembly.GetType(m_userControlPath)) as UserControl;

                if (userControl != null)
                {
                    ((System.Windows.Controls.Frame)frame).Navigate(userControl);

                    Run run = new Run();
                    run.FontWeight = FontWeights.Bold;
                    run.Foreground = new SolidColorBrush(Color.FromArgb(255, 25, 25, 200));
                    run.Text = m_description;

                    TextBlock txt = new TextBlock();
                    txt.Inlines.Add(run);

                    if (groupBox != null)
                        ((GroupBox)groupBox).Header = txt;
                }
                else
                    throw new InvalidOperationException("Failed to create user control " + m_userControlPath);
            }
        }

        /// <summary>
        /// Raises the <see cref="CanExecuteChanged"/> event.
        /// </summary>
        protected virtual void OnCanExecuteChanged()
        {
            if (CanExecuteChanged != null)
                CanExecuteChanged(this, EventArgs.Empty);
        }

        #endregion
    }
}
<commit_msg>Modifed TimeSeriesFramework.UI.Commands.MenuCommand to use the absolute path of dll's when loading user controls.<commit_after>﻿//******************************************************************************************************
//  MenuCommand.cs - Gbtc
//
//  Copyright © 2010, Grid Protection Alliance.  All Rights Reserved.
//
//  Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
//  the NOTICE file distributed with this work for additional information regarding copyright ownership.
//  The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may
//  not use this file except in compliance with the License. You may obtain a copy of the License at:
//
//      http://www.opensource.org/licenses/eclipse-1.0.php
//
//  Unless agreed to in writing, the subject software distributed under the License is distributed on an
//  "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
//  License for the specific language governing permissions and limitations.
//
//  Code Modification History:
//  ----------------------------------------------------------------------------------------------------
//  03/25/2011 - <NAME>
//       Generated original version of source code.
//  05/13/2011 - <NAME>
//       Modified Execute() method to set main window's title property.
//
//******************************************************************************************************

using System;
using System.Reflection;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using TVA.IO;

namespace TimeSeriesFramework.UI.Commands
{
    /// <summary>
    /// Exposes <see cref="ICommand"/> object to be used to handle menu item click event.
    /// </summary>
    public class MenuCommand : ICommand
    {
        #region [ Members ]

        // Fields
        private string m_roles;
        private string m_userControlAssembly;
        private string m_userControlPath;
        private string m_description;

        //Events

        /// <summary>
        /// Raises when value of <see cref="CanExecute"/> changes.
        /// </summary>
        public event EventHandler CanExecuteChanged;

        #endregion

        #region [ Properties ]

        /// <summary>
        /// Gets or sets comma seperated values of roles for which menuitem is visible.
        /// </summary>
        public string Roles
        {
            get
            {
                return m_roles;
            }
            set
            {
                m_roles = value;
            }
        }

        /// <summary>
        /// Gets or sets name of the assembly where user control belongs to.
        /// </summary>
        public string UserControlAssembly
        {
            get
            {
                return m_userControlAssembly;
            }
            set
            {
                m_userControlAssembly = value;
            }
        }

        /// <summary>
        /// Gets or sets name of the user control to be loaded.
        /// </summary>
        public string UserControlPath
        {
            get
            {
                return m_userControlPath;
            }
            set
            {
                m_userControlPath = value;
            }
        }

        /// <summary>
        /// Gets or sets the description of associated <see cref="MenuDataItem"/>.
        /// </summary>
        public string Description
        {
            get
            {
                return m_description;
            }
            set
            {
                m_description = value;
            }
        }

        #endregion

        #region [ Methods ]

        /// <summary>
        /// Evaluates if menu item should be visible to current user with access to <see cref="Roles"/>.
        /// </summary>
        /// <param name="parameter">
        /// Data used by the <see cref="MenuCommand"/>. If the <see cref="MenuCommand"/> does not require
        /// data to be passed, this object can be set to <c>null</c>.
        /// </param>
        /// <returns><c>true</c> if this <see cref="MenuCommand"/> can be executed; otherwise, <c>false</c>.</returns>
        public bool CanExecute(object parameter)
        {
            bool canExecute;
            if (string.IsNullOrEmpty(Roles) || Roles == "*")
                canExecute = true;
            else
                canExecute = Thread.CurrentPrincipal.IsInRole(Roles);

            //OnCanExecuteChanged();

            return canExecute;
        }

        /// <summary>
        /// Handles <see cref="ICommand"/> action. 
        /// Loads user control as defined in the <see cref="UserControlPath"/> property from assembly name set in the 
        /// <see cref="UserControlAssembly"/> property.
        /// </summary>
        /// <param name="parameter">
        /// Data used by the <see cref="MenuCommand"/>. If the <see cref="MenuCommand"/> does not require
        /// data to be passed, this object can be set to <c>null</c>.
        /// </param>
        public void Execute(object parameter)
        {
            UIElement frame = null;
            UIElement groupBox = null;
            CommonFunctions.GetFirstChild(Application.Current.MainWindow, typeof(System.Windows.Controls.Frame), ref frame);
            CommonFunctions.GetFirstChild(Application.Current.MainWindow, typeof(GroupBox), ref groupBox);

            if (frame != null)
            {
                Assembly assembly = Assembly.LoadFrom(FilePath.GetAbsolutePath(m_userControlAssembly));
                UserControl userControl = Activator.CreateInstance(assembly.GetType(m_userControlPath)) as UserControl;

                if (userControl != null)
                {
                    ((System.Windows.Controls.Frame)frame).Navigate(userControl);

                    Run run = new Run();
                    run.FontWeight = FontWeights.Bold;
                    run.Foreground = new SolidColorBrush(Color.FromArgb(255, 25, 25, 200));
                    run.Text = m_description;

                    TextBlock txt = new TextBlock();
                    txt.Inlines.Add(run);

                    if (groupBox != null)
                        ((GroupBox)groupBox).Header = txt;
                }
                else
                    throw new InvalidOperationException("Failed to create user control " + m_userControlPath);
            }
        }

        /// <summary>
        /// Raises the <see cref="CanExecuteChanged"/> event.
        /// </summary>
        protected virtual void OnCanExecuteChanged()
        {
            if (CanExecuteChanged != null)
                CanExecuteChanged(this, EventArgs.Empty);
        }

        #endregion
    }
}

{'fraction_non_alphanumeric': 0.13574531728509365, 'fraction_numerical': 0.004842959903140802, 'mean_word_length': 1.5182926829268293, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3756713', 'n_tokens_mistral': 3472, 'n_tokens_neox': 3239, 'n_words': 1030}