Example #1
0
    /// <summary>
    /// You can use 'Main' or 'MainAsync' it doesn`t matter.
    /// </summary>
    public static async Task MainAsync()
    {
        /// <summary>
        ///  This code is an example how you can get data from citavi.
        /// </summary>
        MainForm         mainForm   = Program.ActiveProjectShell.PrimaryMainForm;
        List <Reference> references = mainForm.GetFilteredReferences().ToList();

        try
        {
            /// <summary>
            /// GenericProgressDialog is huge customizable. You can use 'RunFunc()' or 'RunAction' instead of 'RunTask()'. They are much signatures with differente parameters you can use ;)
            /// </summary>
            await GenericProgressDialog.RunTask(mainForm, DoSomeThingWithReferencesOverALongPeriodAsync, references);
        }
        catch (OperationCanceledException)
        {
            // Here you can handle user cancelling if you use cancellationToken.ThrowIfCancellationRequested()
            DebugMacro.WriteLine("Cancelled");
            return;
        }
        catch (Exception)
        {
            // Here you can handle unexpected exceptions
            DebugMacro.WriteLine("Unexpected exception");
            return;
        }

        // Here you can handle stuff if the process finished
        DebugMacro.WriteLine("Completed");
    }
        public async static Task RunAsync(MainForm mainForm)
        {
            var referencesWithUrl = mainForm.GetFilteredReferences().Where(reference => !string.IsNullOrEmpty(reference?.OnlineAddress) && GetRemoteUriLocation(reference) != null).ToList();

            if (referencesWithUrl.Count == 0)
            {
                MessageBox.Show(mainForm, Resources.NoReferencesFoundedMessage, mainForm.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                return;
            }

            try
            {
                var result = await GenericProgressDialog.RunTask(mainForm, CheckReferencesAsync, referencesWithUrl);

                if (result.InvalidCount != 0)
                {
                    if (MessageBox.Show(string.Format(Resources.MacroResultMessage, referencesWithUrl.Count, result.ChangedCount, result.InvalidCount), mainForm.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes && result.InvalidReferences.Count > 0)
                    {
                        var filter = new ReferenceFilter(result.InvalidReferences, Resources.ReferenceInvalidFilterName, false);
                        mainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(new List <ReferenceFilter> {
                            filter
                        });
                    }
                }
                else
                {
                    MessageBox.Show(string.Format(Resources.MacroResultMessageWithoutSelection, referencesWithUrl.Count.ToString(), result.ChangedCount.ToString(), result.InvalidCount.ToString()), mainForm.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (OperationCanceledException) { }
        }
Example #3
0
        public async static void Run(MainForm mainForm, MacroSettings settings)
        {
            var referencesWithDoi = mainForm.GetFilteredReferences()
                                    .Where(reference => !string.IsNullOrEmpty(reference.PubMedId))
                                    .ToList();

            try
            {
                var mergedReferences = await GenericProgressDialog.RunTask(mainForm, RunAsync, Tuple.Create(mainForm.Project, referencesWithDoi, settings));

                if (mergedReferences.Count() != 0)
                {
                    if (MessageBox.Show(mainForm, UpdateBibliographicDataFromPubMedSearchResources.ProcessFinishWithChangesMessage.FormatString(mergedReferences.Count()), mainForm.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        var filter = new ReferenceFilter(mergedReferences, "References with locations from file", false);
                        mainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(new List <ReferenceFilter> {
                            filter
                        });
                    }
                }
                else
                {
                    MessageBox.Show(mainForm, UpdateBibliographicDataFromPubMedSearchResources.ProcessFinishWithoutChangesMessage, mainForm.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (OperationCanceledException)
            {
                // What exactly does Task.WhenAll do when a cancellation is requested? We don't know and are too lazy to find out ;-)
                // To be on the safe side, we catch a possible exception and return;
                return;
            }
        }
        public async static Task RunAsync(MainForm mainForm, string directory)
        {
            try
            {
                var results = await GenericProgressDialog.RunTask(mainForm, FetchReferencesByFileAsync, mainForm, directory);

                foreach (var result in results)
                {
                    var addedReferences = mainForm.Project.References.AddRange(result.References);
                    AddCategories(mainForm.Project, addedReferences, result.Path.Substring(directory.Length, result.Path.Length - directory.Length - Path.GetFileName(result.Path).Length));
                }

                MessageBox.Show(mainForm, Resource.MacroResultMessage.FormatString(results.Count), mainForm.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (OperationCanceledException) { }
        }
Example #5
0
        public async static void Run(MainForm mainForm)
        {
            var referencesWithUrl = mainForm.GetFilteredReferences()
                                    .Where(reference => !String.IsNullOrEmpty(reference.OnlineAddress))
                                    .ToList();

            if (referencesWithUrl.Count == 0)
            {
                MessageBox.Show(mainForm, CheckUrlAndSetDateResources.NoReferencesFoundedMessage, mainForm.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                return;
            }

            var         isCanceled = false;
            MacroResult result     = null;

            try
            {
                result = await GenericProgressDialog.RunTask(mainForm, CheckReferences, referencesWithUrl);
            }
            catch (OperationCanceledException)
            {
                isCanceled = true;
            }

            if (isCanceled)
            {
                return;
            }

            if (MessageBox.Show(string.Format(CheckUrlAndSetDateResources.MacroResultMessage, referencesWithUrl.Count.ToString(), result.ChangedCount.ToString(), result.InvalidCount.ToString()), mainForm.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes && result.InvalidReferences.Count > 0)
            {
                var filter = new ReferenceFilter(result.InvalidReferences, CheckUrlAndSetDateResources.ReferenceInvalidFilterName, false);
                mainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(new List <ReferenceFilter> {
                    filter
                });
            }
        }
        public static async Task RunAsync(MainForm mainForm, Project project)
        {
            if (project.ProjectType == ProjectType.DesktopCloud)
            {
                using (var cts = new CancellationTokenSource())
                {
                    try
                    {
                        await GenericProgressDialog.RunTask(mainForm, FetchAllAttributes, project, Resources.GenericDialogFetchAttributsTitle, null, cts);
                    }
                    catch (OperationCanceledException)
                    {
                        // What exactly does Task.WhenAll do when a cancellation is requested? We don't know and are too lazy to find out ;-)
                        // To be on the safe side, we catch a possible exception and return;
                        return;
                    }

                    // But probably, we will land and return here...
                    if (cts.IsCancellationRequested)
                    {
                        return;
                    }
                }

                var hasUnavailableAttachments = project.AllLocations.Any(location =>
                                                                         location.LocationType == LocationType.ElectronicAddress &&
                                                                         string.IsNullOrEmpty(location.Reference.Doi) &&
                                                                         location.Address.LinkedResourceType == LinkedResourceType.AttachmentRemote &&
                                                                         location.Address.Properties.ContentType.Equals("application/pdf", StringComparison.OrdinalIgnoreCase) &&
                                                                         location.Address.CachingStatus != CachingStatus.Available);

                if (hasUnavailableAttachments)
                {
                    MessageBox.Show(mainForm, Resources.UserMessageUnavailableAttachements, mainForm.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }


            var containers = (from location in project.AllLocations
                              where
                              location.LocationType == LocationType.ElectronicAddress &&
                              string.IsNullOrEmpty(location.Reference.Doi) &&
                              ((location.Address.LinkedResourceType == LinkedResourceType.AttachmentRemote &&
                                location.Address.CachingStatus == CachingStatus.Available) ||

                               location.Address.LinkedResourceType == LinkedResourceType.AttachmentFile ||
                               location.Address.LinkedResourceType == LinkedResourceType.AbsoluteFileUri ||
                               location.Address.LinkedResourceType == LinkedResourceType.RelativeFileUri
                              )
                              let path = location.Address.Resolve().GetLocalPathSafe()
                                         where
                                         File.Exists(path) &&
                                         Path.GetExtension(path).Equals(".pdf", StringComparison.OrdinalIgnoreCase)
                                         select new LocationContainer {
                Location = location, Path = path
            }).ToList();
            var isCanceled = false;

            try
            {
                await GenericProgressDialog.RunTask(mainForm, FindDois, containers);
            }
            catch (OperationCanceledException)
            {
                isCanceled = true;
            }

            if (!isCanceled)
            {
                MessageBox.Show(mainForm, Resources.ProcessFinishMessage, mainForm.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #7
0
    public static async Task Convert()
    {
        DirectoryInfo sourceFolder;
        DirectoryInfo targetRootFolder;

        using (FolderBrowserDialog fbd = new FolderBrowserDialog())
        {
            fbd.Description = "Quellordner der Citavi 5-Projekte";
            if (fbd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            sourceFolder = new DirectoryInfo(fbd.SelectedPath);

            fbd.Description = "Zielordner der Citavi 6-Projekte";
            if (fbd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            targetRootFolder = new DirectoryInfo(fbd.SelectedPath);
        }

        FileInfo[] projectFiles = sourceFolder.GetFiles("*.ctv5", SearchOption.AllDirectories);

        if (!projectFiles.Any())
        {
            MessageBox.Show("Keine Citavi 5-Projekte gefunden.");
            return;
        }

        CancellationTokenSource cts = new CancellationTokenSource();

        try
        {
            foreach (FileInfo projectFile in projectFiles)
            {
                List <DirectoryInfo> parentFolders = new List <DirectoryInfo>();
                DirectoryInfo        parentFolder  = projectFile.Directory.Parent;
                while (parentFolder.FullName != sourceFolder.FullName)
                {
                    parentFolders.Insert(0, parentFolder);
                    parentFolder = parentFolder.Parent;
                }

                DirectoryInfo targetFolder = targetRootFolder;
                foreach (DirectoryInfo di in parentFolders)
                {
                    targetFolder = new DirectoryInfo(Path.Combine(targetFolder.FullName, di.Name));
                    if (!targetFolder.Exists)
                    {
                        targetFolder.Create();
                    }
                }

                DesktopProjectConfiguration config = await DesktopProjectConfiguration.OpenAsync(Program.Engine, ProjectType.DesktopSQLite, projectFile.FullName, ignoreLicense : true, cancellationToken : CancellationToken.None);

                var projectFilePath = Program.Engine.Projects.CreateProjectFolders(targetFolder, Path.GetFileNameWithoutExtension(projectFile.Name));
                GenericProgressDialog.RunTask(Program.ActiveProjectShell.PrimaryMainForm, config.SQLiteProjectInfo.ConvertToCurrentVersionAsync, Program.Engine, projectFilePath, string.Format("Konvertiere {0}", projectFile.Name), null, cts);
                cts.Token.ThrowIfCancellationRequested();
            }

            MessageBox.Show(Program.ActiveProjectShell.PrimaryMainForm, "Alle Projekte wurden konvertiert.", "Citavi");
        }
        catch (OperationCanceledException x)
        {
            MessageBox.Show(Program.ActiveProjectShell.PrimaryMainForm, "Die Konvertierung wurde abgebrochen.", "Citavi");
        }
        catch (Exception x)
        {
            MessageBox.Show(Program.ActiveProjectShell.PrimaryMainForm, string.Format("Ein Fehler ist aufgetreten:\r\n\r\n{0}", x.Message), "Citavi", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }