Пример #1
0
        /// <summary>
        /// Links an existing record with a new one
        /// </summary>
        /// <param name="linkedRecordNumber">the number of the linked record</param>
        /// <param name="newRecord">the new record</param>
        /// <param name="link">the link details</param>
        internal void LinksAdr(AdrEntry newRecord, AdrLink link)
        {
            if (newRecord is null)
            {
                throw new ArgumentNullException(nameof(newRecord));
            }

            if (link is null)
            {
                throw new ArgumentNullException(nameof(link));
            }

            AdrEntry linkedRecord = this.SearchAdr(link.Number);

            this.LinksAdr(linkedRecord, newRecord, link);
        }
Пример #2
0
        /// <summary>
        /// Try to parse the given link
        /// </summary>
        /// <param name="link">the link to parse</param>
        /// <returns><code>true</code> if parsed successfully, <code>false</code> otherwise</returns>
        public static bool TryParse(string link, out AdrLink adrLink)
        {
            bool res = false;

            adrLink = null;

            if (string.IsNullOrEmpty(link))
            {
                throw new System.ArgumentException($"'{nameof(link)}' cannot be null or empty", nameof(link));
            }

            try
            {
                var tokens = link.Split(':', System.StringSplitOptions.RemoveEmptyEntries);

                if (tokens.Count() == 3)
                {
                    int number = 0;

                    if (int.TryParse(tokens[0], out number))
                    {
                        adrLink = new AdrLink()
                        {
                            Number                 = number,
                            LinkDescription        = tokens[1],
                            ReverseLinkDescription = tokens[2]
                        };

                        res = true;
                    }
                }
            }
            catch (System.Exception)
            {
                // nop
                res = false;
            }

            return(res);
        }
Пример #3
0
        /// <summary>
        /// Links an existing record with a new one
        /// </summary>
        /// <param name="linkedRecord">the linked record</param>
        /// <param name="newRecord">the new record</param>
        /// <param name="link">the link details</param>
        private void LinksAdr(AdrEntry linkedRecord, AdrEntry newRecord, AdrLink link)
        {
            if (linkedRecord is null)
            {
                throw new ArgumentNullException(nameof(linkedRecord));
            }

            if (newRecord is null)
            {
                throw new ArgumentNullException(nameof(newRecord));
            }

            if (link is null)
            {
                throw new ArgumentNullException(nameof(link));
            }

            FileUtils.InsertTextToFile(
                newRecord.File.FullName,
                "## Context",
                new[] {
                $"{link.LinkDescription}: [{linkedRecord.Title}]({linkedRecord.File.Name})",
                string.Empty
            },
                FileUtils.TextInsertionMode.Prepend
                );

            FileUtils.InsertTextToFile(
                linkedRecord.File.FullName,
                "## Context",
                new[] {
                string.Empty,
                $"{link.ReverseLinkDescription}: [{newRecord.Title}]({newRecord.File.Name})",
                string.Empty
            },
                FileUtils.TextInsertionMode.Prepend
                );
        }