コード例 #1
0
    public static void Main()
    {
        //EXPORT from C5
        string citaviVersion = SwissAcademic.Environment.InformationalVersion.ToString(4);

        DebugMacro.WriteLine(citaviVersion);
        if (!(citaviVersion.StartsWith("5") || citaviVersion.StartsWith("4.9.")))
        {
            return;
        }

        ProjectShell activeProjectShell = Program.ActiveProjectShell;

        if (activeProjectShell == null)
        {
            return;                                     //no open project shell
        }
        Project activeProject = Program.ActiveProjectShell.Project;

        if (activeProject == null)
        {
            return;
        }

        Form primaryMainForm = activeProjectShell.PrimaryMainForm;

        if (primaryMainForm == null)
        {
            return;
        }

        string xmlFile  = string.Empty;
        string ctv3File = string.Empty;

        string initialDirectory = Program.Engine.DesktopEngineConfiguration.GetFolderPath(CitaviFolder.Projects, activeProject);

        //ask for file name & path
        using (SaveFileDialog saveFileDialog = new SaveFileDialog())
        {
            saveFileDialog.Filter           = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
            saveFileDialog.InitialDirectory = initialDirectory;
            saveFileDialog.Title            = "Enter an XML file name for export of Citavi project data.";

            if (saveFileDialog.ShowDialog(primaryMainForm) != DialogResult.OK)
            {
                return;
            }
            xmlFile = saveFileDialog.FileName;
        }


        var compatibility = ProjectXmlExportCompatibility.Citavi4;

        ProjectToXml.Write(xmlFile, activeProject, CancellationToken.None, null, null, compatibility);
        MessageBox.Show("Finished");
    }
コード例 #2
0
        internal void OnProjectChanged()
        {
            if (_isChanged)
            {
                return;
            }

            _isChanged = true;
            ProjectShell.OnProjectChanged();
        }
コード例 #3
0
    public static void Main()
    {
        //Purpose:  If running under C4:    EXPORT of project data in XML
        //			If running under C3:    (RE)IMPORT of the same data

        ProjectShell activeProjectShell = Program.ActiveProjectShell;

        if (activeProjectShell == null)
        {
            return;                                     //no open project shell
        }
        Project activeProject = Program.ActiveProjectShell.Project;

        if (activeProject == null)
        {
            return;
        }

        Form primaryMainForm = activeProjectShell.PrimaryMainForm;

        if (primaryMainForm == null)
        {
            return;
        }

        string xmlFile          = string.Empty;
        string initialDirectory = Program.Engine.EngineInfo.GetFolderPath(CitaviFolder.Projects, activeProject);


        string citaviVersion = SwissAcademic.Environment.InformationalVersion.ToString(4);

        if (citaviVersion.StartsWith("4"))
        {
            //EXPORT

            //ask for file name & path
            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
            {
                saveFileDialog.Filter           = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
                saveFileDialog.InitialDirectory = initialDirectory;
                saveFileDialog.Title            = "Enter an XML file name for export of Citavi project data.";

                if (saveFileDialog.ShowDialog(primaryMainForm) != DialogResult.OK)
                {
                    return;
                }
                xmlFile = saveFileDialog.FileName;
            }

            //ProjectSaverXml.Save(xmlFile, activeProject, null, null);		//C3
            ProjectSaverXml.Save(xmlFile, Program.ActiveProjectShell.Project, new CancellationToken(false), null, null);                //C4

            MessageBox.Show("Finished");
        }
    }
コード例 #4
0
        public bool RemoveAssembly(AssemblyViewModel assemblyViewModel, bool ask)
        {
            if (ask)
            {
                bool?result = AppService.UI.ShowMessageDialog(
                    string.Format(SR.AskRemoveAssembly, assemblyViewModel.Caption),
                    MessageDialogType.Question,
                    false);

                if (!result.HasValue || !result.Value)
                {
                    return(false);
                }
            }

            int index = assemblyViewModel.Index;

            var projectAssembly = assemblyViewModel.ProjectAssembly;

            _project.Assemblies.Remove(projectAssembly);

            string filePath = projectAssembly.FilePath;

            _assemblyByFilePath.Remove(filePath);
            RemoveChild(assemblyViewModel);
            OnProjectChanged();
            ProjectShell.OnHierarchyChanged();

            if (ProjectShell.SelectedNode == assemblyViewModel)
            {
                if (index > 0)
                {
                    GetChild(index - 1).Show();
                }
                else
                {
                    Show();
                }
            }

            FireAssemblyRemoved(assemblyViewModel.Assembly);

            return(true);
        }
コード例 #5
0
        private void AddAssembly(AssemblyViewModel assemblyViewModel)
        {
            var comparer = StringLogicalComparer.Default;
            int index    = 0;

            for (int i = 0; i < ChildCount; i++)
            {
                var existingViewModel = (AssemblyViewModel)GetChild(i);
                if (0 > comparer.Compare(assemblyViewModel.Caption, existingViewModel.Caption))
                {
                    break;
                }

                index++;
            }

            InsertChild(index, assemblyViewModel);
            ProjectShell.OnHierarchyChanged();
            FireAssemblyAdded(assemblyViewModel.Assembly);
        }
コード例 #6
0
        private void ChangeInput()
        {
            string filePath = AppService.UI.ShowOpenFileDialog(
                Constants.AssemblyFileFilter,
                SR.OpenFileCaption);

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            _projectAssembly.FilePath = filePath;
            OnProjectChanged();
            ProjectShell.Refresh();

            var assemblyViewModel = ProjectShell.Project.FindAssembly(filePath);

            if (assemblyViewModel != null)
            {
                assemblyViewModel.Show();
            }
        }
コード例 #7
0
    public static void Main()
    {
        ProjectShell activeProjectShell = Program.ActiveProjectShell;

        if (activeProjectShell == null)
        {
            return;                                     //no open project shell
        }
        Project targetProject = Program.ActiveProjectShell.Project;

        if (targetProject == null)
        {
            return;
        }

        Form primaryMainForm = activeProjectShell.PrimaryMainForm;

        if (primaryMainForm == null)
        {
            return;
        }

        string sourceCTV6File   = string.Empty;
        string initialDirectory = Program.Engine.DesktopEngineConfiguration.GetFolderPath(CitaviFolder.Projects);

        DebugMacro.WriteLine(initialDirectory);

        //System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop
        var openFileDialog = new OpenFileDialog()
        {
            Filter           = "Citavi Project Files|*.ctv6",
            CheckFileExists  = true,
            CheckPathExists  = true,
            Multiselect      = false,
            InitialDirectory = initialDirectory
        };

        if (openFileDialog.ShowDialog(primaryMainForm) != DialogResult.OK)
        {
            return;
        }

        string sourceProjectFile = openFileDialog.FileName;

        DebugMacro.WriteLine(sourceProjectFile);

        Project sourceProject = GetProject(sourceProjectFile).Result;

        if (sourceProject == null)
        {
            return;
        }


        IEnumerable <Category> targetCategories = targetProject.AllCategories.AsEnumerable <Category>();
        IEnumerable <Category> sourceCategories = sourceProject.AllCategories.AsEnumerable <Category>();

        foreach (Category targetCategory in targetCategories)
        {
            Category sourceCategory = sourceCategories.FindCategory(targetCategory);
            if (sourceCategory == null)
            {
                continue;
            }

            IEnumerable <KnowledgeItem> sourceCategoryKnowledgeItems = sourceCategory.KnowledgeItems.AsEnumerable <KnowledgeItem>();

            foreach (KnowledgeItem sourceKnowledgeItem in sourceCategoryKnowledgeItems)
            {
                //if exists in target KI collection, then move to bottom
                KnowledgeItem targetKnowledgeItem = targetCategory.KnowledgeItems.FindKnowledgeItem(sourceKnowledgeItem);
                if (targetKnowledgeItem == null)
                {
                    continue;
                }

                targetCategory.KnowledgeItems.MoveToBottom(targetKnowledgeItem);
            }
        }


        MessageBox.Show("Done");
    }
コード例 #8
0
    public static void Main()
    {
        ProjectShell activeProjectShell = Program.ActiveProjectShell;

        if (activeProjectShell == null)
        {
            return;                             //no open project shell
        }
        Project activeProject = Program.ActiveProjectShell.Project;

        if (activeProject == null)
        {
            return;
        }

        Form primaryMainForm = activeProjectShell.PrimaryMainForm;

        if (primaryMainForm == null)
        {
            return;
        }

        string xmlFile          = string.Empty;
        string ctv5File         = string.Empty;
        string initialDirectory = Program.Engine.DesktopEngineConfiguration.GetFolderPath(CitaviFolder.Projects, activeProject);

        //(RE)IMPORT
        using (OpenFileDialog openFileDialog = new OpenFileDialog())
        {
            openFileDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
            openFileDialog.Title  = "Select an XML file with Citavi project data for import";

            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            xmlFile = openFileDialog.FileName;
            if (string.IsNullOrEmpty(xmlFile))
            {
                return;
            }
            if (!File.Exists(xmlFile))
            {
                return;
            }
        }


        using (SaveFileDialog saveFileDialog = new SaveFileDialog())
        {
            saveFileDialog.Filter           = "Citavi 5 files (*.ctv5)|*.ctv5";
            saveFileDialog.InitialDirectory = initialDirectory;
            saveFileDialog.Title            = "Enter a C5 file name to create a new C5 project with the imported data";

            if (saveFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            ctv5File = saveFileDialog.FileName;
        }

        if (string.IsNullOrEmpty(ctv5File))
        {
            return;
        }

        using (Project project = Program.Engine.Projects.Add(ProjectType.DesktopSQLite, ctv5File))
        {
            XmlToProject.Load(xmlFile, project);
            project.Save();
            project.Close();
        }

        MessageBox.Show("Import finished");
    }
コード例 #9
0
    public static void Main()
    {
        //****************************************************************************************************************
        // List Keywords for Each Category in a Text File
        // 1.0 -- 2015-07-30
        //

        // This macro writes a text file containing a list of all Keywords used in References assigned to a certain
        // category.
        //
        //
        // EDIT HERE
        // Variables to be changed by user


        // DO NOT EDIT BELOW THIS LINE
        // ****************************************************************************************************************

        ProjectShell activeProjectShell = Program.ActiveProjectShell;

        if (activeProjectShell == null)
        {
            return;                                     //no open project shell
        }
        Project activeProject = Program.ActiveProjectShell.Project;

        if (activeProject == null)
        {
            return;
        }

        Form primaryMainForm = activeProjectShell.PrimaryMainForm;

        if (primaryMainForm == null)
        {
            return;
        }

        if (Program.ProjectShells.Count == 0)
        {
            return;                                                     //no project open
        }
        string file = string.Empty;


        string initialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

        using (SaveFileDialog saveFileDialog = new SaveFileDialog())
        {
            saveFileDialog.Filter           = "Plain Text (*.txt)|*.txt|All files (*.*)|*.*";
            saveFileDialog.InitialDirectory = initialDirectory;
            saveFileDialog.Title            = "Enter a file name for the output file.";

            if (saveFileDialog.ShowDialog(primaryMainForm) != DialogResult.OK)
            {
                return;
            }
            file = saveFileDialog.FileName;
        }


        StreamWriter sw = null;

        try
        {
            sw = File.AppendText(file);
        }
        catch (Exception e)
        {
            DebugMacro.WriteLine("Error creating file: " + e.Message.ToString());
            return;
        }


        // write line with categories to file
        string headline = activeProject.Name + " -- Categories and Keywords ";

        headline = headline + "\n";
        sw.WriteLine(headline);


        //iterate over all references in the current filter (or over all, if there is no filter)
        List <Reference> references = Program.ActiveProjectShell.PrimaryMainForm.GetFilteredReferences();


        //reference to all Categories in the project
        Category[] allCategories = activeProject.AllCategories.ToArray();
        Array.Sort(allCategories);

        //reference to all Keywords in the project
        Keyword[] allKeywords = activeProject.Keywords.ToArray();
        Array.Sort(allKeywords);

        // abort if no categories/references present
        if (!allCategories.Any() || !references.Any() || !allKeywords.Any())
        {
            DebugMacro.WriteLine("No categories/keywords or references in current project.");
            return;
        }



        // check each category in turn and gather keywords

        foreach (Category category in allCategories)
        {
            List <Keyword> categoryKeywords = new List <Keyword>();

            foreach (Reference reference in references)
            {
                foreach (Category referenceCategory in reference.Categories)
                {
                    if (referenceCategory.Equals(category))
                    {
                        foreach (Keyword kw in reference.Keywords)
                        {
                            categoryKeywords.Add(kw);
                        }
                    }
                }
            }


            // Clean and Sort list of Keywords
            List <Keyword> categoryKeywordsUnique = categoryKeywords.Distinct().ToList();
            categoryKeywordsUnique.Sort();


            // write output to file

            sw.WriteLine(category.ToString() + "\n");

            if (categoryKeywordsUnique.Count > 0)
            {
                foreach (Keyword key in categoryKeywordsUnique)
                {
                    sw.WriteLine("\t" + key.ToString());
                }
            }
            else
            {
                sw.WriteLine("\t" + "---");
            }

            // clear Keywords for new Category
            categoryKeywords.Clear();
            categoryKeywordsUnique.Clear();
            sw.WriteLine("\n");
        }

        // close file
        sw.Close();

        // Message upon completion
        string message = "File written to " + file;

        MessageBox.Show(message, "Macro", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
コード例 #10
0
    public static void Main()
    {
        //****************************************************************************************************************
        // CSV-Table Showing the Categories for Each Title
        // 1.1 -- 2015-08-07
        //

        // This macro writes a tab delimited CSV file showing for each reference which categories are assigned to that
        // reference. Import the file into Excel using the "From text" function in the DATA tab.
        // In the variable "categoryPresent" you can set the text that occurs in a cell if a category is present
        // for a certain reference.
        //
        //
        // EDIT HERE
        // Variables to be changed by user

        string categoryPresent = "Yes.";         // string to put in table cell if category is present

        // DO NOT EDIT BELOW THIS LINE
        // ****************************************************************************************************************

        ProjectShell activeProjectShell = Program.ActiveProjectShell;

        if (activeProjectShell == null)
        {
            return;                                     //no open project shell
        }
        Project activeProject = Program.ActiveProjectShell.Project;

        if (activeProject == null)
        {
            return;
        }

        Form primaryMainForm = activeProjectShell.PrimaryMainForm;

        if (primaryMainForm == null)
        {
            return;
        }

        if (Program.ProjectShells.Count == 0)
        {
            return;                                                     //no project open
        }
        //iterate over all references in the current filter (or over all, if there is no filter)
        List <Reference> references = Program.ActiveProjectShell.PrimaryMainForm.GetFilteredReferences();



        //reference to all Categories in the project
        Category[] allCategories = activeProject.AllCategories.ToArray();
        Array.Sort(allCategories);

        // abort if no categories/references present
        if (!allCategories.Any() || !references.Any())
        {
            DebugMacro.WriteLine("No categories or references in current project.");
            return;
        }

        string file = string.Empty;


        string initialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

        using (SaveFileDialog saveFileDialog = new SaveFileDialog())
        {
            saveFileDialog.Filter           = "CSV files (*.csv, *.txt)|*.csv;*.txt|All files (*.*)|*.*";
            saveFileDialog.InitialDirectory = initialDirectory;
            saveFileDialog.Title            = "Enter a file name for the CSV file.";

            if (saveFileDialog.ShowDialog(primaryMainForm) != DialogResult.OK)
            {
                return;
            }
            file = saveFileDialog.FileName;
        }


        // create file, delete if already present
        StreamWriter sw = null;


        try
        {
            sw = File.AppendText(file);
        }
        catch (Exception e)
        {
            DebugMacro.WriteLine("Error creating file: " + e.Message.ToString());
            return;
        }


        // write line with categories to file
        string headline = "\t \t \t";

        foreach (Category category in allCategories)
        {
            string cString = category.ToString() + "\t";
            headline = headline + cString;
        }
        headline = headline + "\n";
        sw.WriteLine(headline);


        // check categories for each reference
        foreach (Reference reference in references)
        {
            // write author, year and title to file
            string author = reference.AuthorsOrEditorsOrOrganizations.ToString();
            string year   = reference.YearResolved.ToString();
            string title  = reference.Title.ToString();
            string line   = author + "\t" + year + "\t" + title + "\t";

            // iterate over all Categories and Categories of each reference and write
            // categoryPresent string to file if category is present
            Category[] referenceCategories = reference.Categories.ToArray();
            Array.Sort(referenceCategories);
            foreach (Category category in allCategories)
            {
                foreach (Category referenceCategory in referenceCategories)
                {
                    if (referenceCategory == category)
                    {
                        line = line + categoryPresent;
                    }
                }
                line = line + "\t";
            }
            line = line + "\n";
            sw.WriteLine(line);
        }

        // close file
        sw.Close();

        // Message upon completion
        string message = "CSV file written to " + file;

        MessageBox.Show(message, "Macro", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    public static void Main()
    {
        ProjectShell activeProjectShell = Program.ActiveProjectShell;

        if (activeProjectShell == null)
        {
            return;                                     //no open project shell
        }
        Project activeProject = Program.ActiveProjectShell.Project;

        if (activeProject == null)
        {
            return;
        }

        Form primaryMainForm = activeProjectShell.PrimaryMainForm;

        if (primaryMainForm == null)
        {
            return;
        }

        string xmlFile          = string.Empty;
        string ctv4File         = string.Empty;
        string initialDirectory = Program.Engine.EngineInfo.GetFolderPath(CitaviFolder.Projects, activeProject);

        //(RE)IMPORT
        using (OpenFileDialog openFileDialog = new OpenFileDialog())
        {
            openFileDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
            openFileDialog.Title  = "Select an XML file with Citavi project data for import";

            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            xmlFile = openFileDialog.FileName;
            if (string.IsNullOrEmpty(xmlFile))
            {
                return;
            }
            if (!File.Exists(xmlFile))
            {
                return;
            }
        }

        bool goOn = true;

        while (goOn)
        {
            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
            {
                saveFileDialog.Filter           = "CTV4 files (*.ctv4)|*.ctv4";
                saveFileDialog.InitialDirectory = initialDirectory;
                saveFileDialog.Title            = "Enter a CTV4 file name to create a new C4 project with the imported data";

                if (saveFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                ctv4File = saveFileDialog.FileName;
            }

            if (string.IsNullOrEmpty(ctv4File))
            {
                return;
            }

            if (File.Exists(ctv4File))
            {
                if (MessageBox.Show(string.Format("Do you want to overwrite the file {0}?", ctv4File), "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    goOn = false;
                }
            }
            else
            {
                goOn = false;
            }
        }

        ProjectCreationInfo pc = new ProjectCreationInfo();

        pc.FilePath = ctv4File;
        Program.Engine.Projects.RestoreFromXml(xmlFile, pc, null);

        MessageBox.Show("Finished");
    }
コード例 #12
0
    public static void Main()
    {
        //****************************************************************************************************************
        // List Inbound and Outbound Links for each Reference
        // 1.0 -- 2016-04-05
        //

        // This macro creates a csv file containing the numbers of reference each reference links to or is linked from.
        //
        // EDIT HERE
        // Variables to be changed by user


        // DO NOT EDIT BELOW THIS LINE
        // ****************************************************************************************************************

        ProjectShell activeProjectShell = Program.ActiveProjectShell;

        if (activeProjectShell == null)
        {
            return;                                     //no open project shell
        }
        Project activeProject = Program.ActiveProjectShell.Project;

        if (activeProject == null)
        {
            return;
        }

        Form primaryMainForm = activeProjectShell.PrimaryMainForm;

        if (primaryMainForm == null)
        {
            return;
        }

        if (Program.ProjectShells.Count == 0)
        {
            return;                                                     //no project open
        }
        string file = string.Empty;


        string initialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

        using (SaveFileDialog saveFileDialog = new SaveFileDialog())
        {
            saveFileDialog.Filter           = "Plain Text (*.txt)|*.txt|All files (*.*)|*.*";
            saveFileDialog.InitialDirectory = initialDirectory;
            saveFileDialog.Title            = "Enter a file name for the output file.";

            if (saveFileDialog.ShowDialog(primaryMainForm) != DialogResult.OK)
            {
                return;
            }
            file = saveFileDialog.FileName;
        }


        StreamWriter sw = null;

        try
        {
            sw = File.AppendText(file);
        }
        catch (Exception e)
        {
            DebugMacro.WriteLine("Error creating file: " + e.Message.ToString());
            return;
        }


        // write line with categories to file
        string headline = activeProject.Name + " -- Links to / links from ";

        headline = headline + "\n";
        sw.WriteLine(headline);
        string headers = "ShortTitle \t Outbound \t Inbound \n";

        sw.WriteLine(headers);


        //iterate over all references in the current filter (or over all, if there is no filter)
        List <Reference> references = Program.ActiveProjectShell.PrimaryMainForm.GetFilteredReferences();

        if (references.Count == 0)
        {
            return;
        }


        foreach (Reference reference in references)
        {
            var entityList     = reference.EntityLinks.ToList();
            int linksFromCount = entityList.Where(x => (x.Source.ToString() == reference.ShortTitle) && (x.Target.ToString() != reference.ShortTitle)).Count();
            int linksToCount   = entityList.Where(x => (x.Target.ToString() == reference.ShortTitle) && (x.Source.ToString() != reference.ShortTitle)).Count();
            sw.WriteLine(reference.ShortTitle + "\t" + linksFromCount.ToString() + "\t" + linksToCount.ToString() + "\n");
        }


        // close file
        sw.Close();

        // Message upon completion
        string message = "File written to " + file;

        MessageBox.Show(message, "Macro", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }