Ejemplo n.º 1
0
        private static FileInfo GetFile(AbsoluteUri urn)
        {
            if (null == urn)
            {
                throw new ArgumentNullException("urn");
            }

            var dir = new DirectoryInfo(urn.ToPath(FileRepositoryConfiguration.Directory()).FullName);

            return(dir.Exists
                       ? dir.GetFiles("*.record", SearchOption.TopDirectoryOnly).FirstOrDefault()
                       : null);
        }
Ejemplo n.º 2
0
        public void Save(FileSystemInfo root)
        {
            if (null == root)
            {
                throw new ArgumentNullException("root");
            }

            if (string.IsNullOrEmpty(Headers["urn"]))
            {
                throw new InvalidOperationException("The record URN must be specified.");
            }

            if (string.IsNullOrEmpty(Headers["key"]))
            {
                throw new InvalidOperationException("The record key must be specified.");
            }

            AbsoluteUri urn  = Headers["urn"];
            var         file = new FileInfo(Path.Combine(
                                                urn.ToPath(root).FullName,
                                                "{0}.record".FormatWith(Headers["key"])));

            if (null != file.Directory && !file.Directory.Exists)
            {
                file.Directory.Create();
            }

            using (var stream = file.Open(FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.WriteLine("urn: {0}".FormatWith(Headers["urn"]));
                    writer.WriteLine("key: {0}".FormatWith(Headers["key"]));
                    writer.WriteLine("etag: {0}".FormatWith(Headers["etag"]));
                    writer.WriteLine("created: {0}".FormatWith(Headers["created"]));
                    writer.WriteLine("modified: {0}".FormatWith(Headers["modified"]));
                    writer.WriteLine("cacheability: {0}".FormatWith(Headers["cacheability"]));
                    writer.WriteLine("expiration: {0}".FormatWith(Headers["expiration"]));
                    writer.WriteLine("status: {0}".FormatWith(Headers["status"]));
                    writer.WriteLine(string.Empty);
                    if (null != Body)
                    {
                        writer.Write(Body);
                    }
                }
            }

            Location = file;
        }