Ejemplo n.º 1
0
        public static AdrFile Save(AdrDirectory directory, AdrEntry entry)
        {
            entry.Number = directory.GetNextAdrNo();
            var filePath = directory.GetAdrFilePath(entry.Number, entry.Title);

            using (var stream = File.OpenWrite(filePath))
            {
                new AdrEntryWriter(stream).Write(entry);
            }

            return(new AdrFile(filePath, entry));
        }
Ejemplo n.º 2
0
        private static int New(NewOptions opts)
        {
            var directory = new AdrDirectory(opts.Directory);
            var newEntry  = AdrEntry.CreateNew(opts.Title);
            var current   = AdrFile.Save(directory, newEntry);

            Console.WriteLine("Created {0}", current.FilePath);

            if (opts.SupersedesAdr != null)
            {
                var referenced = directory.GetRecord(opts.SupersedesAdr.Value);
                if (referenced != null)
                {
                    current.Entry.AppendStatus($"Supersedes {referenced.AsLink()}");
                    referenced.Entry.AppendStatus($"Superseded by {current.AsLink()}");
                    current.Save();
                    referenced.Save();
                }
                else
                {
                    Console.WriteLine("{0} not found", opts.SupersedesAdr);
                    return(1);
                }
            }

            if (opts.AmendsAdr != null)
            {
                var referenced = directory.GetRecord(opts.AmendsAdr.Value);
                if (referenced != null)
                {
                    current.Entry.AppendStatus($"Amends {referenced.AsLink()}");
                    referenced.Entry.AppendStatus($"Amended by {current.AsLink()}");
                    current.Save();
                    referenced.Save();
                }
                else
                {
                    Console.WriteLine("{0} not found", opts.AmendsAdr);
                    return(1);
                }
            }

            return(0);
        }