예제 #1
0
        /// <summary>
        ///     Adds tag to the tags collection if it already isnt there.
        ///     If the tag is in database, than it returns empty string, otherwise the commited tag.
        /// </summary>
        private static String AddTagToSettings(String tag, bool isDatabaseFavorite)
        {
            if (AutoCaseTags)
            {
                tag = ToTitleCase(tag);
            }
            if (Tags(isDatabaseFavorite).Contains(tag))
            {
                return(String.Empty);
            }

            if (!isDatabaseFavorite)
            {
                GetSection().Tags.AddByName(tag);
                SaveImmediatelyIfRequested();
            }
            else
            {
                using (TerminalsObjectContext dc = TerminalsObjectContext.Create())
                {
                    dc.Groups.AddObject(new Sql.Groups()
                    {
                        Name = tag
                    });
                    dc.SaveChanges();
                }
            }

            return(tag);
        }
예제 #2
0
        /// <summary>
        ///     Removes the tag from settings, but doesnt send the Tag removed event
        /// </summary>
        private static String DeleteTagFromSettings(String tagToDelete, bool isDatabaseFavorite)
        {
            if (AutoCaseTags)
            {
                tagToDelete = ToTitleCase(tagToDelete);
            }

            if (!isDatabaseFavorite)
            {
                GetSection().Tags.DeleteByName(tagToDelete);
                SaveImmediatelyIfRequested();
            }
            else
            {
                using (TerminalsObjectContext dc = TerminalsObjectContext.Create())
                {
                    Sql.Groups group = dc.Groups.Where(x => x.Name == tagToDelete).FirstOrDefault();

                    dc.Groups.DeleteObject(group);
                    dc.SaveChanges();
                }
            }

            return(tagToDelete);
        }
예제 #3
0
        public override void Load(string filter = null)
        {
            // This prevents SharpDevelop and Visual Studio from both an exception in design mode for controls using this HistoryTreeView and from crashing when opening the
            // designer for this class.
            if (LicenseManager.UsageMode == LicenseUsageMode.Runtime)
            {
                if (!string.IsNullOrEmpty(filter))
                {
                    // Clear all the tags
                    this.loader.ClearTags();

                    // Filter the untagged node
                    FilterTags(Settings.UNTAGGED_NODENAME, filter);

                    using (TerminalsObjectContext dc = TerminalsObjectContext.Create())
                    {
                        // Filter all other tags
                        foreach (var group in dc.Groups)
                        {
                            FilterTags(group.Name, filter);
                        }
                    }
                }
                else
                {
                    // Don't filter load all tags
                    this.loader.LoadTags(true);
                }
            }
        }
예제 #4
0
        public static FavoriteConfigurationElementCollection GetFavorites(bool isDatabaseFavorite)
        {
            if (!isDatabaseFavorite)
            {
                TerminalsConfigurationSection section = GetSection();
                if (section != null)
                {
                    return(section.Favorites);
                }
            }
            else
            {
                FavoriteConfigurationElementCollection collection = new FavoriteConfigurationElementCollection();

                using (TerminalsObjectContext dc = TerminalsObjectContext.Create())
                {
                    if (dc == null)
                    {
                        return(null);
                    }

                    foreach (var connection in dc.Connections)
                    {
                        FavoriteConfigurationElement favorite = connection.ToFavorite();
                        collection.Add(favorite);
                    }
                }

                return(collection);
            }

            return(null);
        }
예제 #5
0
 private static void EditFavoriteInSettings(FavoriteConfigurationElement favorite, string oldName)
 {
     if (!favorite.IsDatabaseFavorite)
     {
         TerminalsConfigurationSection section = GetSection();
         section.Favorites[oldName] = favorite.Clone() as FavoriteConfigurationElement;
         SaveImmediatelyIfRequested();
     }
     else
     {
         using (TerminalsObjectContext dc = TerminalsObjectContext.Create())
         {
             Sql.Connections connection = favorite.ToConnection(dc, dc.Connections.Where(x => x.Name == oldName).FirstOrDefault());
             dc.SaveChanges();
         }
     }
 }
예제 #6
0
        /// <summary>
        ///     Gets alphabeticaly sorted array of tags resolved from Tags store
        /// </summary>
        public static string[] Tags(bool isDatabaseFavorite)
        {
            if (!isDatabaseFavorite)
            {
                List <string> tags = GetSection().Tags.ToList();
                tags.Sort();
                return(tags.ToArray());
            }

            string[] groups;

            using (TerminalsObjectContext dc = TerminalsObjectContext.Create())
            {
                groups =
                    (from g in dc.Groups
                     orderby g.Name
                     select g.Name).ToArray <string>();
            }

            return(groups);
        }
예제 #7
0
        /// <summary>
        ///     Adds favorite to the database, but doesnt fire the changed event
        /// </summary>
        private static void AddFavoriteToSettings(FavoriteConfigurationElement favorite)
        {
            if (!favorite.IsDatabaseFavorite)
            {
                GetSection().Favorites.Add(favorite);
                SaveImmediatelyIfRequested();
            }
            else
            {
                using (TerminalsObjectContext dc = TerminalsObjectContext.Create())
                {
                    Connections connection = favorite.ToConnection(dc);

                    if (!dc.Connections.Contains(connection))
                    {
                        dc.Connections.AddObject(connection);
                    }

                    dc.SaveChanges();
                }
            }
        }
예제 #8
0
        private static void DeleteFavoriteFromSettings(string name, bool isDatabaseFavorite)
        {
            if (!isDatabaseFavorite)
            {
                GetSection().Favorites.Remove(name);
                SaveImmediatelyIfRequested();
            }
            else
            {
                using (TerminalsObjectContext dc = TerminalsObjectContext.Create())
                {
                    Sql.Connections connection = dc.Connections.Where(x => x.Name == name).FirstOrDefault();

                    if (connection != null)
                    {
                        dc.Connections.DeleteObject(connection);
                    }

                    dc.SaveChanges();
                }
            }

            DeleteFavoriteButton(name);
        }