示例#1
0
        public static string GetName(ReferenceIdentifier ReferenceIdentifierEnum)
        {
            switch (ReferenceIdentifierEnum)
            {
            case ReferenceIdentifier.LOCL:
                return("Uncalibrated local clock");

            case ReferenceIdentifier.PPS:
                return("Atomic clock or other pulse-per-second source");

            case ReferenceIdentifier.ACTS:
                return("NIST dialup modem service");

            case ReferenceIdentifier.USNO:
                return("USNO modem service");

            case ReferenceIdentifier.PTB:
                return("PTB (Germany) modem service");

            case ReferenceIdentifier.TDF:
                return("Allouis (France) Radio 164 kHz");

            case ReferenceIdentifier.DCF:
                return("Mainflingen (Germany) Radio 77.5 kHz");

            case ReferenceIdentifier.MSF:
                return("Rugby (UK) Radio 60 kHz");

            case ReferenceIdentifier.WWV:
                return("Ft. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz");

            case ReferenceIdentifier.WWVB:
                return("Boulder (US) Radio 60 kHz");

            case ReferenceIdentifier.CHU:
                return("Ottawa (Canada) Radio 3330, 7335, 14670 kHz");

            case ReferenceIdentifier.LORC:
                return("LORAN-C radionavigation system");

            case ReferenceIdentifier.OMEG:
                return("OMEGA radionavigation system");

            case ReferenceIdentifier.GPS:
                return("Global Positioning Service");

            case ReferenceIdentifier.GOES:
                return("Geostationary Orbit Environment Satellite");

            default:
                return(ReferenceIPAddress((uint)ReferenceIdentifierEnum));
            }
        }
示例#2
0
        public byte[] ToBytes()
        {
            var bytes = new byte[48];

            bytes.Initialize();

            bytes[0] = (byte)((uint)LI << 6 | (uint)VersionNumber << 3 | (uint)Mode);
            bytes[1] = Stratum;
            bytes[2] = PollInterval;
            bytes[3] = Precision;

            RootDelay.CopyTo(bytes, 4);
            RootDispersion.CopyTo(bytes, 8);
            ReferenceIdentifier.Select(c => (byte)c).ToArray().CopyTo(bytes, 12);
            ReferenceTimestamp.ToBytes().CopyTo(bytes, 16);
            OriginateTimestamp.ToBytes().CopyTo(bytes, 24);
            ReceiveTimestamp.ToBytes().CopyTo(bytes, 32);
            TransmitTimestamp.ToBytes().CopyTo(bytes, 40);

            return(bytes);
        }
 public static string GetName(ReferenceIdentifier ReferenceIdentifierEnum)
 {
     switch (ReferenceIdentifierEnum)
     {
         case ReferenceIdentifier.LOCL:
             return "Uncalibrated local clock";
         case ReferenceIdentifier.PPS:
             return "Atomic clock or other pulse-per-second source";
         case ReferenceIdentifier.ACTS:
             return "NIST dialup modem service";
         case ReferenceIdentifier.USNO:
             return "USNO modem service";
         case ReferenceIdentifier.PTB:
             return "PTB (Germany) modem service";
         case ReferenceIdentifier.TDF:
             return "Allouis (France) Radio 164 kHz";
         case ReferenceIdentifier.DCF:
             return "Mainflingen (Germany) Radio 77.5 kHz";
         case ReferenceIdentifier.MSF:
             return "Rugby (UK) Radio 60 kHz";
         case ReferenceIdentifier.WWV:
             return "Ft. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz";
         case ReferenceIdentifier.WWVB:
             return "Boulder (US) Radio 60 kHz";
         case ReferenceIdentifier.CHU:
             return "Ottawa (Canada) Radio 3330, 7335, 14670 kHz";
         case ReferenceIdentifier.LORC:
             return "LORAN-C radionavigation system";
         case ReferenceIdentifier.OMEG:
             return "OMEGA radionavigation system";
         case ReferenceIdentifier.GPS:
             return "Global Positioning Service";
         case ReferenceIdentifier.GOES:
             return "Geostationary Orbit Environment Satellite";
         default:
             return ReferenceIPAddress((uint)ReferenceIdentifierEnum);
     }
 }
    public static async void Main()
    {
        //****************************************************************************************************************
        // UPDATE BIBLIOGRAPHIC DATA FROM PMID OR DOI-SEARCH
        // Version 2.4 -- 2019-12-06
        //			-- updated to work with Citavi 6 (only version 6.3.15 or newer!)
        //
        // This macro iterates through the references in a selection ("filter").
        // If they have a PMID or DOI or ISBN, it downloads bibliographical data and owverwrites the reference's data.
        //
        // PMID is given priority over DOI , i.e. if both are present, data will be loaded from PubMed, then
        // Crossref. then the selected catalogues.
        //
        //
        // EDIT HERE
        // Variables to be changed by user

        bool overwriteAbstract        = false;     // if true, existing Abstract will be replaced
        bool overwriteTableOfContents = false;     // if true, existing TOC will be replaced
        bool overwriteKeywords        = false;     // if true, existing Keywords will be replaced
        bool clearNotes = true;                    // if true, Notes field will be emptied

        bool useIsbn = true;                       // if true, the ISBN field will also be used to query data

        int wait = 4;                              // timeout in seconds

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

        if (!Program.ProjectShells.Any())
        {
            return;                                     //no project open
        }
        if (IsBackupAvailable() == false)
        {
            return;                                     //user wants to backup his/her project first
        }
        int counter = 0;

        try
        {
            List <Reference>             references    = Program.ActiveProjectShell.PrimaryMainForm.GetFilteredReferences();
            SwissAcademic.Citavi.Project activeProject = Program.ActiveProjectShell.Project;

            foreach (Reference reference in references)
            {
                if (String.IsNullOrEmpty(reference.PubMedId) &&
                    String.IsNullOrEmpty(reference.Doi) &&
                    String.IsNullOrEmpty(reference.Isbn.ToString()))
                {
                    continue;
                }

                DebugMacro.WriteLine("Checking reference " + reference.ShortTitle);

                var cts = new CancellationTokenSource(TimeSpan.FromSeconds(wait));

                Reference lookedUpReference = null;

                if (!String.IsNullOrEmpty(reference.PubMedId))
                {
                    try
                    {
                        ReferenceIdentifier refIdentPmid = new ReferenceIdentifier()
                        {
                            Value = reference.PubMedId, Type = ReferenceIdentifierType.PubMedId
                        };
                        var identifierSupport = new ReferenceIdentifierSupport();
                        lookedUpReference = await identifierSupport.FindReferenceAsync(activeProject, refIdentPmid, cts.Token);
                    }
                    catch (System.OperationCanceledException e)
                    {
                        DebugMacro.WriteLine("Timeout.");
                        continue;
                    }
                    catch (Exception e)
                    {
                        DebugMacro.WriteLine("An error occured: " + e.ToString());
                        continue;
                    }
                }
                else if (!String.IsNullOrEmpty(reference.Doi))
                {
                    try
                    {
                        ReferenceIdentifier refIdentDoi = new ReferenceIdentifier()
                        {
                            Value = reference.Doi, Type = ReferenceIdentifierType.Doi
                        };
                        var identifierSupport = new ReferenceIdentifierSupport();
                        lookedUpReference = await identifierSupport.FindReferenceAsync(activeProject, refIdentDoi, cts.Token);
                    }
                    catch (System.OperationCanceledException e)
                    {
                        DebugMacro.WriteLine("Timeout.");
                        continue;
                    }
                    catch (Exception e)
                    {
                        DebugMacro.WriteLine("An error occured: " + e.ToString());
                        continue;
                    }
                }
                else if (!String.IsNullOrEmpty(reference.Isbn.ToString()) && useIsbn)
                {
                    try
                    {
                        ReferenceIdentifier refIdentIsbn = new ReferenceIdentifier()
                        {
                            Value = reference.Isbn, Type = ReferenceIdentifierType.Isbn
                        };
                        var identifierSupport = new ReferenceIdentifierSupport();
                        lookedUpReference = await identifierSupport.FindReferenceAsync(activeProject, refIdentIsbn, cts.Token);
                    }
                    catch (System.OperationCanceledException e)
                    {
                        DebugMacro.WriteLine("Timeout.");
                        continue;
                    }
                    catch (Exception e)
                    {
                        DebugMacro.WriteLine("An error occured: " + e.ToString());
                        continue;
                    }
                }

                // if nothing is found, move on
                if (lookedUpReference == null)
                {
                    continue;
                }


                //merge reference & lookedUpReference, overwriting bibliographic data of the former
                List <ReferencePropertyId> omitData = new List <ReferencePropertyId>();
                omitData.Add(ReferencePropertyId.CoverPath);
                omitData.Add(ReferencePropertyId.Locations);


                if (!overwriteAbstract)
                {
                    omitData.Add(ReferencePropertyId.Abstract);
                }
                if (!overwriteTableOfContents)
                {
                    omitData.Add(ReferencePropertyId.TableOfContents);
                }
                if (!overwriteKeywords)
                {
                    omitData.Add(ReferencePropertyId.Keywords);
                }

                reference.MergeReference(lookedUpReference, true, omitData.ToArray());

                counter++;

                if (!string.IsNullOrEmpty(reference.Notes) && clearNotes)
                {
                    reference.Notes = string.Empty;                                                         //empty notes field
                }
                if (activeProject.Engine.Settings.BibTeXCitationKey.IsTeXEnabled)
                {
                    reference.BibTeXKey = activeProject.BibTeXKeyAssistant.GenerateKey(reference);
                }
                if (activeProject.Engine.Settings.BibTeXCitationKey.IsCitationKeyEnabled)
                {
                    reference.CitationKey = activeProject.CitationKeyAssistant.GenerateKey(reference);
                }
            }
        } //end try

        finally
        {
            MessageBox.Show(string.Format("Macro has finished execution.\r\n{0} references were updated.", counter.ToString()), "Citavi", MessageBoxButtons.OK, MessageBoxIcon.Information);
        } //end finally
    }     //end main()