ARUP.IssueTracker.Classes.MySettings.Get C# (CSharp) Метод

Get() публичный статический Метод

public static Get ( string key ) : string
key string
Результат string
        public  static string Get(string key)
        {
            try
            {
                //used to switch the hardcoded server to CASE's or ARUP based on the existence of a file on disk or not
                if (key == "jiraserver")
                {
                    string serverfile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CASE", "ARUP Issue Tracker", "usecaseserver");
                    if (System.IO.File.Exists(serverfile))
                        return System.IO.File.ReadAllText(serverfile).Replace(" ","");
                    else
                        return _jiraserverarup;

                }
                if (key == "guidfield")
                {
                    if (System.IO.File.Exists(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CASE", "ARUP Issue Tracker", "usecaseserver")))
                        return "customfield_11600";
                    else
                        return "customfield_10900";

                }

                Configuration config = GetConfig();

                if (config == null)
                    return string.Empty;


                KeyValueConfigurationElement element = config.AppSettings.Settings[key];
                if (element != null)
                {
                    string value = element.Value;
                    if (!string.IsNullOrEmpty(value))
                        return value;
                }
                else
                {
                    config.AppSettings.Settings.Add(key, "");
                    config.Save(ConfigurationSaveMode.Modified);
                }
            }
            catch (System.Exception ex1)
            {
                MessageBox.Show("exception: " + ex1);
            }
            return string.Empty;
        }
        public static void Set(string key, string value)

Usage Example

Пример #1
0
        /// <summary>
        /// Arup accounts need to change password every 3 months. Remind users to change here otherwise an account would be locked out until login on Jira.
        /// </summary>
        /// <returns>Always return false if not an Arup account</returns>
        public static bool isActiveAccountPasswordChanged()
        {
            if (MySettings.Get("jiraserver").Trim() == _jiraserverarup)
            {
                string username = MySettings.Get("username").Trim();
                if (string.IsNullOrEmpty(username))
                {
                    return(false);
                }

                // get last saved time on user machine
                Configuration config = GetConfig();
                if (config == null)
                {
                    return(false);
                }
                DateTime currentTime   = DateTime.Now;
                long     lastSavedTime = (long)currentTime.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                foreach (string key in config.AppSettings.Settings.AllKeys)
                {
                    if (key.StartsWith("jiraaccount_"))
                    {
                        try
                        {
                            JiraAccount ac = SimpleJson.DeserializeObject <JiraAccount>(config.AppSettings.Settings[key].Value);
                            if (ac.username.Trim() == username && ac.jiraserver.Trim() == _jiraserverarup)
                            {
                                // fallback to old settings w/o password saved time
                                if (ac.savedTime == 0)
                                {
                                    ac.savedTime = GetWindowsAccountPasswordLastSetTime(ac.username, currentTime);
                                }

                                lastSavedTime = ac.savedTime;
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            return(false);
                        }
                    }
                }
                // find last changed time on AD
                long lastChangedTime = GetWindowsAccountPasswordLastSetTime(username, currentTime);
                // return true if lastChangedTime is later than lastSavedTime
                if (lastChangedTime > lastSavedTime)
                {
                    return(true);
                }
            }
            return(false);
        }
All Usage Examples Of ARUP.IssueTracker.Classes.MySettings::Get