Пример #1
0
        /// <summary>
        ///     Adds or replaces a SearchIndex for the given repositoryID
        /// </summary>
        /// <param name="gitHubRepositoryId">The RepositoryId to add/change the search index.</param>
        /// <param name="index">The search index string.</param>
        public void InsertOrUpdateIndex(long gitHubRepositoryId, string index)
        {
            SearchIndex existing = SearchIndex.Find(gitHubRepositoryId);
            if (existing == null)
            {
                SearchIndex.Add(new SearchIndex {GitHubRepositoryId = gitHubRepositoryId, SearchString = index});
                return;
            }

            existing.SearchString = index;
        }
Пример #2
0
        /// <summary>
        /// Check in or check out the file.
        /// </summary>
        public override void Execute()
        {
            Project project = App.Instance.SalesForceApp.CurrentProject;

            if (project != null)
            {
                if (project.IsDownloadingSymbols)
                {
                    throw new Exception("The search index is currently being updated by the Reload symbols process.  Please wait for this to complete and then try again.");
                }

                SourceFileNode[] nodes = GetSelectedNodes();
                if (nodes.Length > 0)
                {
                    List <SourceFile> files = new List <SourceFile>();
                    foreach (SourceFileNode node in nodes)
                    {
                        files.Add(node.SourceFile);
                    }

                    using (App.Wait("Updating search index."))
                    {
                        byte[] package = project.Client.Meta.GetSourceFileContentAsPackage(files);
                        using (SearchIndex searchIndex = new SearchIndex(project.SearchFolder, true))
                        {
                            using (PackageContent packageContent = new PackageContent(package))
                            {
                                foreach (SourceFile file in files)
                                {
                                    string content = packageContent.GetContent(file);
                                    if (content != null)
                                    {
                                        searchIndex.Add(
                                            file.Id,
                                            file.FileName,
                                            file.FileType.Name,
                                            file.Name,
                                            content);
                                    }
                                }
                            }
                        }
                    }

                    App.MessageUser(
                        "The search index has been updated.",
                        "Search Index",
                        System.Windows.MessageBoxImage.Information,
                        new string[] { "OK" });
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Reload the document.
        /// </summary>
        /// <returns>true if the document was reloaded.</returns>
        public override bool Reload()
        {
            try
            {
                _suspendAutoCheckout = true;

                bool canReload = true;
                if (IsDirty)
                {
                    canReload = (App.MessageUser(
                                     "You have unsaved changes which will be lost.  Do you want to proceed?",
                                     "Data Loss",
                                     System.Windows.MessageBoxImage.Warning,
                                     new string[] { "Yes", "No" }) == "Yes");
                }

                if (canReload)
                {
                    using (App.Wait("Refreshing document."))
                    {
                        _serverContent  = Project.Client.Meta.GetSourceFileContent(File);
                        View.Text       = _serverContent.ContentValue;
                        View.IsReadOnly = _serverContent.IsGenerated;
                        View.SetErrors(null);
                        IsDirty = false;

                        // update search index
                        if (!Project.IsDownloadingSymbols)
                        {
                            using (SearchIndex searchIndex = new SearchIndex(Project.SearchFolder, true))
                            {
                                searchIndex.Add(
                                    File.Id,
                                    File.FileName,
                                    File.FileType.Name,
                                    File.Name,
                                    _serverContent.ContentValue);
                            }
                        }
                    }
                }

                return(canReload);
            }
            finally
            {
                _suspendAutoCheckout = false;
            }
        }
Пример #4
0
        /// <summary>
        /// Save changes made to the content.
        /// </summary>
        public override void Save()
        {
            if (!IsDirty)
            {
                return;
            }

            try
            {
                // check for conflict first
                string currentTimeStamp = null;
                using (App.Wait("Checking for conflicts..."))
                    currentTimeStamp = Project.Client.Meta.GetSourceFileContentLastModifiedTimeStamp(File);
                if (currentTimeStamp != _serverContent.LastModifiedTimeStamp)
                {
                    if (App.MessageUser(
                            "This file has been modified since you opened it.  If you continue you will overwrite the current file on the server which may result in the loss of someone else's changes.  Do you want to proceed?",
                            "Conflict",
                            System.Windows.MessageBoxImage.Warning,
                            new string[] { "Yes", "No" }) != "Yes")
                    {
                        return;
                    }
                }

                using (App.Wait("Saving..."))
                {
                    // save changes
                    SalesForceError[] errors = Project.Client.Meta.SaveSourceFileContent(
                        File,
                        View.Text,
                        _serverContent.MetadataValue);

                    // display errors
                    List <string> errorMessages = new List <string>();
                    foreach (SalesForceError error in errors)
                    {
                        errorMessages.Add(error.ToString());
                    }
                    View.SetErrors(errorMessages);

                    // update content
                    if (errors.Length == 0)
                    {
                        currentTimeStamp = Project.Client.Meta.GetSourceFileContentLastModifiedTimeStamp(File);
                        _serverContent   = new SourceFileContent(
                            File.FileType.Name,
                            View.Text,
                            currentTimeStamp);

                        IsDirty = false;
                    }

                    // update search index
                    if (!Project.IsDownloadingSymbols)
                    {
                        using (SearchIndex searchIndex = new SearchIndex(Project.SearchFolder, true))
                        {
                            searchIndex.Add(
                                File.Id,
                                File.FileName,
                                File.FileType.Name,
                                File.Name,
                                _serverContent.ContentValue);
                        }
                    }
                }
            }
            catch (Exception err)
            {
                App.HandleException(err);
            }
        }