Exemplo n.º 1
0
        public ManageReferenceDatabaseForm(
            ReferenceDatabase activeNamespaces,
            ReferenceDatabase inactiveNamespaces)
        {
            InitializeComponent();

            _referenceManager   = ReferenceManager.GetInstance();
            _activeNamespaces   = activeNamespaces;
            _inactiveNamespaces = inactiveNamespaces;

            /*
             * Populate the list box with the database contents.
             */

            foreach (ReferenceNamespace ns in
                     _activeNamespaces.Values)
            {
                _checkedListBox.Items.Add(ns, true);
            }

            foreach (ReferenceNamespace ns in
                     _inactiveNamespaces.Values)
            {
                _checkedListBox.Items.Add(ns, false);
            }

            /*
             * Allow client apps to modify the form.
             */

            ManageReferenceDatabaseFormProxy.GetInstance().
            UpdateFormControls(Controls);
        }
Exemplo n.º 2
0
        public void TreeContainsAllBlobsTest()
        {
            Init();

            CreateFile("a.txt", "a content");
            CreateFile("b.txt", "b content");
            Program.Main(new string[] { "add", "a.txt", "b.txt" });
            Program.Main(new string[] { "commit", "First commit" });

            CreateFile("b.txt", "b modified content");
            Program.Main(new string[] { "add", "b.txt" });
            Program.Main(new string[] { "commit", "Second commit" });

            RelativePath aFilePath = new RelativePath("a.txt");

            Assert.True(Index.IsCommited(aFilePath));

            Branch headBranch = ReferenceDatabase.GetHead();
            Commit commit     = headBranch.LoadCommit();
            Tree   tree       = commit.LoadTree();
            Blob   blobA      = tree.FindAndLoadBlob("a.txt");
            Blob   blobB      = tree.FindAndLoadBlob("b.txt");

            Assert.Equal(blobA.FileName, "a.txt");
            Assert.Equal(blobA.FileContent, "a content");
            Assert.Equal(blobB.FileName, "b.txt");
            Assert.Equal(blobB.FileContent, "b modified content");
        }
Exemplo n.º 3
0
        public void CommitInNewBranch()
        {
            Init();

            CreateFile("z.txt", "");
            Program.Main(new string[] { "add", "z.txt" });
            Program.Main(new string[] { "commit", "Initial commit" });
            Program.Main(new string[] { "branch", "branch-1" });
            Program.Main(new string[] { "checkout", "branch-1" });

            // Create a commit in branch-1
            CreateFile("a.txt", "branch-1 content");
            Program.Main(new string[] { "add", "a.txt" });
            Program.Main(new string[] { "commit", "branch-1 commit" });

            Assert.Equal(
                ReferenceDatabase.GetHead().GetCommitKey(),
                ReferenceDatabase.GetBranch("branch-1").GetCommitKey()
                );

            Assert.Equal(
                ReferenceDatabase.GetBranch("branch-1").LoadCommit().Message.Trim(),
                "branch-1 commit"
                );
        }
Exemplo n.º 4
0
        private void StoreCommitAndAdvanceHeadBranch(Commit commit, TreeBuilder treeBuilder)
        {
            Branch  currentBranch = ReferenceDatabase.GetHead();
            HashKey newCommitKey  = ObjectDatabase.StoreCommitWithTreeHierarchy(commit, treeBuilder);

            currentBranch.SetCommitKey(newCommitKey);
        }
Exemplo n.º 5
0
        public void OneCommitWithSubTreeTest()
        {
            Init();

            CreateFile("a.txt", "a content");
            Directory.CreateDirectory("dir");
            CreateFile("dir/b.txt", "b content");
            Program.Main(new string[] { "add", "a.txt", "dir/b.txt" });
            Program.Main(new string[] { "commit", "First commit" });

            RelativePath bFilePath = new RelativePath("dir/b.txt");

            Assert.True(Index.IsCommited(bFilePath));

            Branch headBranch = ReferenceDatabase.GetHead();
            Commit commit     = headBranch.LoadCommit();
            Tree   tree       = commit.LoadTree();
            Blob   blobA      = tree.FindAndLoadBlob("a.txt");
            Blob   blobB      = tree.FindAndLoadBlob("dir/b.txt");

            Assert.Equal(blobA.FileName, "a.txt");
            Assert.Equal(blobA.FileContent, "a content");
            Assert.Equal(blobB.FileName, "b.txt");
            Assert.Equal(blobB.FilePath, "dir/b.txt");
            Assert.Equal(blobB.FileContent, "b content");
        }
Exemplo n.º 6
0
        public void SecondCommitSubTreePointsToFirstCommitSubTree()
        {
            Init();

            CreateFile("a.txt", "a content");
            Directory.CreateDirectory("dir");
            CreateFile("dir/b.txt", "b content");
            Program.Main(new string[] { "add", "a.txt", "dir/b.txt" });
            Program.Main(new string[] { "commit", "First commit" });

            CreateFile("a.txt", "a modified content");
            Program.Main(new string[] { "add", "a.txt" });
            Program.Main(new string[] { "commit", "Second commit" });

            RelativePath aFilePath = new RelativePath("a.txt");

            Assert.True(Index.IsCommited(aFilePath));

            Branch headBranch   = ReferenceDatabase.GetHead();
            Commit secondCommit = headBranch.LoadCommit();
            Tree   secondTree   = secondCommit.LoadTree();
            Blob   secondBlobB  = secondTree.FindAndLoadBlob("dir/b.txt");

            Commit firstCommit = secondCommit.LoadParent();
            Tree   firstTree   = firstCommit.LoadTree();
            Blob   firstBlobB  = firstTree.FindAndLoadBlob("dir/b.txt");

            Assert.Equal(firstBlobB, secondBlobB);
        }
Exemplo n.º 7
0
        public override void Process()
        {
            Branch headBranch = ReferenceDatabase.GetHead();

            for (Commit commit = headBranch.LoadCommit(); commit != null; commit = commit.LoadParent())
            {
                PrintCommit(commit);
            }
        }
Exemplo n.º 8
0
        private Commit CreateCommit(TreeBuilder treeBuilder)
        {
            Commit commit = new Commit(
                parentKey: ReferenceDatabase.GetHead().GetCommitKey(),
                treeKey: treeBuilder.GetChecksum(),
                message: _message
                );

            return(commit);
        }
        public IQueryable <Background> Backgrounds([ScopedService] ReferenceDatabase database, IResolverContext context)
        {
            IQueryable <Background> query = database.Backgrounds;

            var applied = query
                          .Filter(context)
                          .Sort(context)
                          .Project(context);

            return(applied);
        }
Exemplo n.º 10
0
        private void ManageNamespacesButton_Click(
            object sender, EventArgs e)
        {
            ManageReferenceDatabaseForm f =
                new ManageReferenceDatabaseForm(
                    _activeNamespaces, _inactiveNamespaces);

            f.ShowDialog();

            _activeNamespaces   = f.ActiveNamespaces;
            _inactiveNamespaces = f.InactiveNamespaces;
        }
Exemplo n.º 11
0
        public override void Process()
        {
            if (!ProcessArgs())
            {
                return;
            }

            HashKey currentCommitKey = ReferenceDatabase.GetHead().GetCommitKey();

            ReferenceDatabase.CreateBranch(_branchName, currentCommitKey);

            PrintSuccess();
        }
Exemplo n.º 12
0
        public void GeneratedDatabaseShouldMatchChangescriptedDatabase_Test()
        {
            //TODO: config
            string result;

            using (var refDb = new ReferenceDatabase("localhost\\SQL2017", "ServerDatabase_Ref", "server", "test"))
            {
                refDb.RemoveAllDatabaseContent();
                refDb.CreateDatabase();
                refDb.ApplyChangescripts();
                var service = DI.Container.Resolve <IDatabaseCompareService>();
                result = service.CompareDatabasesAndGenerateChangescripts("ServerDatabase_Ref", "ServerDatabase_Test");
            }

            Assert.IsTrue(string.IsNullOrEmpty(result), $"Test and reference database are different.{Environment.NewLine}{result}");
        }
Exemplo n.º 13
0
        public void CreateOneBranchAfterCommitTest()
        {
            Init();

            CreateFile("a.txt", "a content");
            Program.Main(new string[] { "add", "a.txt" });
            Program.Main(new string[] { "commit", "First commit" });
            Program.Main(new string[] { "branch", "new-branch" });

            Branch headBranch = ReferenceDatabase.GetHead();

            Assert.Equal(headBranch.Name, "master");
            Branch newBranch = ReferenceDatabase.GetBranch("new-branch");

            Assert.Equal(headBranch.GetCommitKey(), newBranch.GetCommitKey());
        }
Exemplo n.º 14
0
        private bool ProcessArgs()
        {
            if (_args.Length != 1)
            {
                PrintHelp();
                return(false);
            }

            _branch = ReferenceDatabase.GetBranch(_args[0]);
            if (_branch == null)
            {
                Console.WriteLine($"{_args[0]} does not specify any branch name");
                return(false);
            }

            return(true);
        }
Exemplo n.º 15
0
        public override void Process()
        {
            if (!ProcessArgs())
            {
                return;
            }

            Index.Update();

            if (!_branch.LoadCommit().Checkout())
            {
                PrintError();
                return;
            }

            ReferenceDatabase.SetHead(_branch);
            PrintSuccess();
        }
Exemplo n.º 16
0
        private void reloadNamespacesButton_Click(
            object sender, EventArgs e)
        {
            if (MessageBox.Show(String.Format("{0}\r\n{1}",
                                              Resources.OptionsReloadWarningMessage1,
                                              Resources.OptionsReloadWarningMessage2),
                                Resources.OptionsReloadWarningTitle,
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Warning) == DialogResult.OK)
            {
                CreateReferenceDatabaseForm form =
                    new CreateReferenceDatabaseForm();

                // Clear the MessageBox
                Refresh();

                form.ShowDialog();

                /*
                 * The form is now populated with the reloaded
                 * database. We need to update the local copies
                 * for editing.
                 */

                ReferenceDatabase database = form.ReferenceDatabase;

                _activeNamespaces.Clear();
                _inactiveNamespaces.Clear();

                foreach (String ns in database.Keys)
                {
                    if (database[ns].Name.StartsWith("System"))
                    {
                        _activeNamespaces[ns] = database[ns];
                    }
                    else
                    {
                        _inactiveNamespaces[ns] = database[ns];
                    }
                }
            }
        }
Exemplo n.º 17
0
        public void DoCommitCommandAndIntrospectFromBranch()
        {
            Init();

            CreateFile("a.txt", "a content");
            Program.Main(new string[] { "add", "a.txt" });
            Program.Main(new string[] { "commit", "Commit message" });

            RelativePath aFilePath = new RelativePath("a.txt");

            Assert.True(Index.IsCommited(aFilePath));

            Branch headBranch = ReferenceDatabase.GetHead();
            Commit commit     = headBranch.LoadCommit();
            Tree   tree       = commit.LoadTree();
            Blob   blobA      = tree.FindAndLoadBlob("a.txt");

            Assert.Equal(blobA.FileName, "a.txt");
            Assert.Equal(blobA.FileContent, "a content");
        }
Exemplo n.º 18
0
        private void OkButton_Click(object sender, EventArgs e)
        {
            /*
             * Recreate the database from the list.
             */

            _activeNamespaces   = new ReferenceDatabase();
            _inactiveNamespaces = new ReferenceDatabase();

            foreach (ReferenceNamespace ns in _checkedListBox.Items)
            {
                if (_checkedListBox.CheckedItems.Contains(ns))
                {
                    _activeNamespaces[ns.Name] = ns;
                }
                else
                {
                    _inactiveNamespaces[ns.Name] = ns;
                }
            }
        }
Exemplo n.º 19
0
        private SearchResult[] SearchEntity <TEntity>(ReferenceDatabase database, string searchTerm)
            where TEntity : BaseEntity, ISearchableEntity, INamedEntity
        {
            IQueryable <TEntity> query = database.Set <TEntity>();

            Expression <Func <TEntity, bool> > combinedPredicate = (e) => e.SearchVector.Matches(searchTerm);

            foreach (PropertyInfo property in typeof(TEntity).GetSearchableCollectionProperties())
            {
                query             = query.Include(property.Name);
                combinedPredicate = combinedPredicate.Or(CollectionSearchExpression.Create <TEntity>(property.PropertyType.GetGenericArguments()[0], property, searchTerm));
            }

            foreach (PropertyInfo property in typeof(TEntity).GetSearchableSingularProperties())
            {
                query             = query.Include(property.Name);
                combinedPredicate = combinedPredicate.Or(SingularSearchExpression.Create <TEntity>(property, searchTerm));
            }

            return(query.Where(combinedPredicate).Select(e => new SearchResult(e.Id, e.Name, typeof(TEntity).Name)).ToArray());
        }
Exemplo n.º 20
0
        private static void GitMain(string[] args)
        {
            Command command = Cli.ParseCommand(args);

            if (command == null)
            {
                PrintHelp();
                Environment.Exit(1);
            }

            if (!(command is InitCommand) && !IsRepositoryInitialized())
            {
                Console.Error.WriteLine("No git repository initialized, exiting...");
                Environment.Exit(1);
            }

            command.Process();

            Index.Dispose();
            ReferenceDatabase.Dispose();
        }
Exemplo n.º 21
0
        public void TwoCommitsCheckoutToLastBranchTest()
        {
            Init();

            CreateFile("a.txt", "a content");
            Program.Main(new string[] { "add", "a.txt" });
            Program.Main(new string[] { "commit", "First commit" });
            Program.Main(new string[] { "branch", "branch-1" });

            CreateFile("a.txt", "modified content");
            Program.Main(new string[] { "add", "a.txt" });
            Program.Main(new string[] { "commit", "Second commit" });
            Program.Main(new string[] { "branch", "branch-2" });

            Program.Main(new string[] { "checkout", "branch-2" });

            Tree headTree  = ReferenceDatabase.GetHead().LoadCommit().LoadTree();
            Blob aFileBlob = headTree.FindAndLoadBlob("a.txt");

            Assert.Equal(aFileBlob.FileContent, "modified content");
        }
        protected override void Configure(IObjectTypeDescriptor <Query> descriptor)
        {
            foreach (PropertyInfo property in typeof(ReferenceDatabase).GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (property.Name == nameof(ReferenceDatabase.Backgrounds))
                {
                    continue;
                }

                if (property.PropertyType.IsAssignableTo(typeof(DbSet <>)) || property.PropertyType.IsGenericType == false)
                {
                    continue;
                }

                Type genericType = property.PropertyType.GetGenericArguments().First();
                if (genericType.IsAssignableTo(typeof(BaseEntity)) == false)
                {
                    continue;
                }

                //TODO: Try and get a hold of the injected naming convention here.
                string fieldName = char.ToLowerInvariant(property.Name[0]) + property.Name.Substring(1);

                Console.WriteLine("Root: " + fieldName);

                IObjectFieldDescriptor field = descriptor
                                               .Field(fieldName)
                                               .Type(genericType)
                                               .UseDbContext <ReferenceDatabase>()
                                               .UseOffsetPaging(typeof(ObjectType <>).MakeGenericType(genericType))
                                               .UseProjection(genericType)
                                               .UseFiltering(genericType)
                                               .UseSorting(genericType)
                                               .Resolve((context) =>
                {
                    ReferenceDatabase database = context.Resolver <ReferenceDatabase>();
                    return(property.GetValue(database));
                });
            }
        }
Exemplo n.º 23
0
        public void CommitRemovedFile()
        {
            Init();

            CreateFile("a.txt", "a content");
            Program.Main(new string[] { "add", "a.txt" });
            Program.Main(new string[] { "commit", "First commit" });

            System.IO.File.Delete("a.txt");
            Program.Main(new string[] { "add", "a.txt" });
            Program.Main(new string[] { "commit", "Second commit" });

            RelativePath aFilePath = new RelativePath("a.txt");

            Assert.False(Index.ContainsFile(aFilePath));

            Branch headBranch = ReferenceDatabase.GetHead();
            Commit commit     = headBranch.LoadCommit();
            Tree   tree       = commit.LoadTree();

            Assert.Null(tree.FindAndLoadBlob("a.txt"));
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (stoppingToken.IsCancellationRequested == false)
            {
                try
                {
                    using (ReferenceDatabase context = Factory.CreateDbContext())
                    {
                        IEnumerable <string> appliedMigrations = await context.Database.GetAppliedMigrationsAsync();

                        if (appliedMigrations.Any() == false)
                        {
                            await context.Database.MigrateAsync();
                        }

                        DatabaseState = DatabaseState.Ready;
                        Logger.LogInformation("Database state set to ready.");
                    }
                }
                catch (NpgsqlException exception) when(exception.InnerException != null && exception.InnerException is SocketException)
                {
                    Logger.LogInformation("Socket exception on database connection. Interpreting as 'database not ready'.");

                    //Retry next loop.
                    //Because we run on pre-emptible nodes, this can happen after it's been running successfully for hours, so we do have to potentially reset the state to Unready.

                    DatabaseState = DatabaseState.Unready;
                    Logger.LogInformation("Database state set to unready.");
                }
                catch (Exception exception)
                {
                    Logger.LogCritical(exception, $"Something went wrong in the background service `{nameof(MigrationService)}`.");
                    ApplicationLifetime.StopApplication();
                }

                await Task.Delay(10000);
            }
        }
Exemplo n.º 25
0
 private void CreateAllFilesAndDirectories()
 {
     CreateDirectory(ObjectDatabase.DefaultPath);
     CreateFile(Index.IndexPath);
     ReferenceDatabase.Init();
 }
Exemplo n.º 26
0
        public CodeAssistOptionsPage()
        {
            Name      = Constants.UI_OPTIONS_CODE_ASSIST_PAGE;
            PageText  = Resources.OptionsPageText;
            GroupText = Resources.OptionsGroupText;

            _settingsManager  = SettingsManager.GetInstance();
            _referenceManager = ReferenceManager.GetInstance();

            _referenceGroupBox      = new GroupBox();
            _manageNamespacesButton = new Button();
            _reloadNamespacesButton = new Button();

            Controls.Add(_referenceGroupBox);

            ApplicationManager applicationManager =
                ApplicationManager.GetInstance();

            _disableColorization = applicationManager.ClientProfile.HaveFlag(
                ClientFlags.CodeAssistDotNetDisableColorization);

            bool enableReload = !applicationManager.ClientProfile.HaveFlag(
                ClientFlags.CodeAssistDotNetDisableReloadDatabase);

            if (!_disableColorization)
            {
                _colorizeGroupBox           = new GroupBox();
                _colorizeTypesCheckBox      = new CheckBox();
                _colorizeVariablesCheckBox  = new CheckBox();
                _colorizeOnActivateCheckBox = new CheckBox();
                _colorizeOnLookupCheckBox   = new CheckBox();

                Controls.Add(_colorizeGroupBox);
            }

            #region Form Layout

            _referenceGroupBox.Controls.Add(_manageNamespacesButton);

            if (enableReload)
            {
                _referenceGroupBox.Controls.Add(_reloadNamespacesButton);
            }

            _referenceGroupBox.Location = new Point(0, 0);
            _referenceGroupBox.Name     = m_referenceGroupBox;
            _referenceGroupBox.TabIndex = 0;
            _referenceGroupBox.TabStop  = false;
            _referenceGroupBox.Text     = Resources.OptionsReferenceGroupBox;
            _referenceGroupBox.Size     = new Size(430, 100);

            _manageNamespacesButton.Name     = m_manageNamespacesButton;
            _manageNamespacesButton.Size     = new Size(98, 23);
            _manageNamespacesButton.TabIndex = 1;
            _manageNamespacesButton.Text     = Resources.OptionsManageNamespacesButton;
            _manageNamespacesButton.UseVisualStyleBackColor = true;

            if (enableReload)
            {
                _manageNamespacesButton.Location = new Point(111, 40);
            }
            else
            {
                _manageNamespacesButton.Location = new Point(166, 40);
            }

            if (enableReload)
            {
                _reloadNamespacesButton.Name     = m_reloadNamespacesButton;
                _reloadNamespacesButton.Size     = new Size(98, 23);
                _reloadNamespacesButton.TabIndex = 2;
                _reloadNamespacesButton.Text     = Resources.OptionsReloadNamespacesButton;
                _reloadNamespacesButton.UseVisualStyleBackColor = true;
                _reloadNamespacesButton.Location = new Point(221, 40);
            }

            if (!_disableColorization)
            {
                _colorizeGroupBox.Controls.Add(_colorizeTypesCheckBox);
                _colorizeGroupBox.Controls.Add(_colorizeVariablesCheckBox);
                _colorizeGroupBox.Controls.Add(_colorizeOnActivateCheckBox);
                _colorizeGroupBox.Controls.Add(_colorizeOnLookupCheckBox);
                _colorizeGroupBox.Location = new Point(0, 110);
                _colorizeGroupBox.Name     = m_colorizeGroupBox;
                _colorizeGroupBox.Size     = new Size(430, 140);
                _colorizeGroupBox.TabIndex = 3;
                _colorizeGroupBox.TabStop  = false;
                _colorizeGroupBox.Text     = Resources.OptionsColorizeGroupBox;

                _colorizeTypesCheckBox.AutoSize = true;
                _colorizeTypesCheckBox.Location = new Point(19, 31);
                _colorizeTypesCheckBox.Name     = m_colorizeTypesCheckBox;
                _colorizeTypesCheckBox.TabIndex = 4;
                _colorizeTypesCheckBox.Text     = Resources.OptionsColorizeTypes;
                _colorizeTypesCheckBox.UseVisualStyleBackColor = true;

                _colorizeVariablesCheckBox.AutoSize = true;
                _colorizeVariablesCheckBox.Location = new Point(19, 54);
                _colorizeVariablesCheckBox.Name     = m_colorizeVariablesCheckBox;
                _colorizeVariablesCheckBox.TabIndex = 5;
                _colorizeVariablesCheckBox.Text     = Resources.OptionsColorizeVariables;
                _colorizeVariablesCheckBox.UseVisualStyleBackColor = true;

                _colorizeOnActivateCheckBox.AutoSize = true;
                _colorizeOnActivateCheckBox.Location = new Point(19, 77);
                _colorizeOnActivateCheckBox.Name     = m_colorizeOnActivateCheckBox;
                _colorizeOnActivateCheckBox.TabIndex = 6;
                _colorizeOnActivateCheckBox.Text     = Resources.OptionsColorizeOnActivate;
                _colorizeOnActivateCheckBox.UseVisualStyleBackColor = true;

                _colorizeOnLookupCheckBox.AutoSize = true;
                _colorizeOnLookupCheckBox.Location = new Point(19, 100);
                _colorizeOnLookupCheckBox.Name     = m_colorizeOnLookupCheckBox;
                _colorizeOnLookupCheckBox.TabIndex = 7;
                _colorizeOnLookupCheckBox.Text     = Resources.OptionsColorizeOnLookup;
                _colorizeOnLookupCheckBox.UseVisualStyleBackColor = true;
            }

            #endregion

            _manageNamespacesButton.Click +=
                new EventHandler(ManageNamespacesButton_Click);

            if (enableReload)
            {
                _reloadNamespacesButton.Click +=
                    new EventHandler(reloadNamespacesButton_Click);
            }

            if (!_disableColorization)
            {
                _colorizeTypesCheckBox.Checked =
                    _settingsManager.ColorizeTypes;
                _colorizeVariablesCheckBox.Checked =
                    _settingsManager.ColorizeVariables;
                _colorizeOnActivateCheckBox.Checked =
                    _settingsManager.ColorizeOnActivate;
                _colorizeOnLookupCheckBox.Checked =
                    _settingsManager.ColorizeOnLookup;
            }

            /*
             * Copy the reference database to allow chnages to be
             * abandoned on exit if required. Not a full copy as
             * we're not copying the lists but as these won't change
             * we can just copy them as references.
             */

            _activeNamespaces   = new ReferenceDatabase();
            _inactiveNamespaces = new ReferenceDatabase();

            foreach (ReferenceNamespace ns in
                     _referenceManager.ActiveNamespaces.Values)
            {
                _activeNamespaces[ns.Name] = ns;
            }

            foreach (ReferenceNamespace ns in
                     _referenceManager.InactiveNamespaces.Values)
            {
                _inactiveNamespaces[ns.Name] = ns;
            }
        }
Exemplo n.º 27
0
 public SearchService(ReferenceDatabase database)
 {
     Database = database;
 }
        /*
         * Populate the database property with the namespaces
         * from the Global Assembly Cache.
         */

        private void CreateReferenceDatabase()
        {
            List <string> assemblyList = new List <string>();

            string gac = Path.Combine(
                Environment.SystemDirectory, @"..\assembly\GAC");
            string gac32 = Path.Combine(
                Environment.SystemDirectory, @"..\assembly\GAC_32");
            string gac64 = Path.Combine(
                Environment.SystemDirectory, @"..\assembly\GAC_64");
            string gacMSIL = Path.Combine(
                Environment.SystemDirectory, @"..\assembly\GAC_MSIL");

            assemblyList.AddRange(GetGACAssemblies(gac));
            assemblyList.AddRange(GetGACAssemblies(gac32));
            assemblyList.AddRange(GetGACAssemblies(gac64));
            assemblyList.AddRange(GetGACAssemblies(gacMSIL));

            _referenceDatabase = new ReferenceDatabase();

            _progressBar.Maximum = assemblyList.Count;
            _progressBar.Step    = 1;

            foreach (string name in assemblyList)
            {
                _progressBar.PerformStep();

                Assembly assembly = CodeAssistTools.LoadAssembly(name);
                if (assembly == null)
                {
                    continue;
                }

                try
                {
                    foreach (Type type in assembly.GetTypes())
                    {
                        if (!type.IsPublic)
                        {
                            continue;
                        }

                        string ns = type.Namespace;
                        if (String.IsNullOrEmpty(ns))
                        {
                            continue;
                        }

                        if (!_referenceDatabase.ContainsKey(ns))
                        {
                            _referenceDatabase[ns] = new ReferenceNamespace(ns);
                        }

                        _referenceDatabase[ns].AddAssembly(name);
                    }
                }
                catch
                {
                    // Ignore unloadable assemblies
                }

                Refresh();
            }
        }
Exemplo n.º 29
0
 private void PrintCurrentBranch()
 {
     Console.WriteLine($"On branch {ReferenceDatabase.GetHead().Name}");
 }
Exemplo n.º 30
0
        public override void Save()
        {
            /*
             * Save the registry settings.
             */

            if (!_disableColorization)
            {
                _settingsManager.ColorizeTypes =
                    _colorizeTypesCheckBox.Checked;
                _settingsManager.ColorizeVariables =
                    _colorizeVariablesCheckBox.Checked;
                _settingsManager.ColorizeOnActivate =
                    _colorizeOnActivateCheckBox.Checked;
                _settingsManager.ColorizeOnLookup =
                    _colorizeOnLookupCheckBox.Checked;

                _settingsManager.Save();
            }

            /*
             * Write the reference database if it has been updated.
             */

            if (_activeNamespaces == null || _inactiveNamespaces == null)
            {
                return;
            }

            /*
             * Sanitize the lists first.
             */

            /*
             * Make sure we don't have any namespaces without assemblies.
             * (Not sure if that could happen but better safe than sorry.)
             */

            Dictionary <string, ReferenceNamespace> cleanActiveNamespaces =
                new Dictionary <string, ReferenceNamespace>();

            foreach (string key in _activeNamespaces.Keys)
            {
                if (_activeNamespaces[key].AssemblyList.Count > 0)
                {
                    cleanActiveNamespaces[key] = _activeNamespaces[key];
                }
            }

            /*
             * Check for any empty namespaces and also dump any '@'
             * referenced assemblies so they don't build up.
             */

            ReferenceDatabase cleanInactiveNamespaces =
                new ReferenceDatabase();

            foreach (string key in _inactiveNamespaces.Keys)
            {
                ReferenceNamespace ns = new ReferenceNamespace(key);

                foreach (string s in _inactiveNamespaces[key].AssemblyList)
                {
                    if (!s.StartsWith("@"))
                    {
                        ns.AddAssembly(s);
                    }
                }

                if (ns.AssemblyList.Count > 0)
                {
                    cleanInactiveNamespaces[ns.Name] = ns;
                }
            }

            /*
             * Write the data to the database file.
             */

            string path = _referenceManager.ReferenceDatabasePath;

            StreamWriter sw = null;

            try
            {
                sw = new StreamWriter(path);

                foreach (string key in cleanActiveNamespaces.Keys)
                {
                    sw.WriteLine("+" + key);

                    foreach (string assmembly in
                             cleanActiveNamespaces[key].AssemblyList)
                    {
                        sw.WriteLine(assmembly);
                    }
                }

                foreach (string key in cleanInactiveNamespaces.Keys)
                {
                    sw.WriteLine("-" + key);

                    foreach (string assmembly in
                             cleanInactiveNamespaces[key].AssemblyList)
                    {
                        sw.WriteLine(assmembly);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("{0}:\r\n{1}",
                                              Resources.CreateDbErrorMessage,
                                              ex.Message),
                                Resources.CreateDbErrorTitle,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
            }

            /*
             * Reread the database.
             */

            ReferenceManager.GetInstance().LoadReferenceDatabaseFromFile();
        }