internal ISupportingFile CreateSupportingFileFromStoragePath(string fileName, string storagePath) { SupportingFileFactory fileFactory = new SupportingFileFactory(this, Guid.NewGuid().ToString(), fileName, 1); _factoriesById[fileFactory.FileId] = fileFactory; ISupportingFile file = fileFactory.CreateSupportingFile(new Uri(UrlHelper.CreateUrlFromPath(storagePath)), fileName, CreateUniqueFileNameToken(fileName), true); return file; }
internal ISupportingFile CreateSupportingFileFromStoragePath(string fileName, string storagePath) { SupportingFileFactory fileFactory = new SupportingFileFactory(this, Guid.NewGuid().ToString(), fileName, 1); _factoriesById[fileFactory.FileId] = fileFactory; ISupportingFile file = fileFactory.CreateSupportingFile(new Uri(UrlHelper.CreateUrlFromPath(storagePath)), fileName, CreateUniqueFileNameToken(fileName), true); return(file); }
internal VersionedSupportingFile(SupportingFileFactory fileFactory, int version, Uri fileUri, string fileName, string fileNameUniqueToken, bool embedded, BlogPostSettingsBag fileProperties) { _fileFactory = fileFactory; _fileVersion = version; _fileUri = fileUri; _fileName = fileName; _embedded = embedded; _properties = fileProperties; _fileNameUniqueToken = fileNameUniqueToken; }
public ISupportingFile CreateSupportingFile(string fileName, string fileNameUniqueToken, Stream s) { string storagePath = _fileStorage.CreateFile(fileName); using (Stream outStream = new FileStream(storagePath, FileMode.OpenOrCreate, FileAccess.Write)) StreamHelper.Transfer(s, outStream); SupportingFileFactory fileFactory = new SupportingFileFactory(this, Guid.NewGuid().ToString(), fileName, 1); _factoriesById[fileFactory.FileId] = fileFactory; ISupportingFile file = fileFactory.CreateSupportingFile(new Uri(UrlHelper.CreateUrlFromPath(storagePath)), fileName, fileNameUniqueToken, true); return file; }
public ISupportingFile AddLinkedSupportingFileReference(Uri sourceUri) { ISupportingFile file = GetFileByUri(sourceUri); if (file == null) { string fileName = Path.GetFileName(sourceUri.LocalPath); SupportingFileFactory fileFactory = new SupportingFileFactory(this, Guid.NewGuid().ToString(), fileName, 1); _factoriesById[fileFactory.FileId] = fileFactory; file = fileFactory.CreateSupportingFile(sourceUri, fileName, CreateUniqueFileNameToken(fileName + "_linked"), false); } return file; }
public ISupportingFile AddLinkedSupportingFileReference(Uri sourceUri) { ISupportingFile file = GetFileByUri(sourceUri); if (file == null) { string fileName = Path.GetFileName(sourceUri.LocalPath); SupportingFileFactory fileFactory = new SupportingFileFactory(this, Guid.NewGuid().ToString(), fileName, 1); _factoriesById[fileFactory.FileId] = fileFactory; file = fileFactory.CreateSupportingFile(sourceUri, fileName, CreateUniqueFileNameToken(fileName + "_linked"), false); } return(file); }
public ISupportingFile CreateSupportingFile(string fileName, string fileNameUniqueToken, Stream s) { string storagePath = _fileStorage.CreateFile(fileName); using (Stream outStream = new FileStream(storagePath, FileMode.OpenOrCreate, FileAccess.Write)) StreamHelper.Transfer(s, outStream); SupportingFileFactory fileFactory = new SupportingFileFactory(this, Guid.NewGuid().ToString(), fileName, 1); _factoriesById[fileFactory.FileId] = fileFactory; ISupportingFile file = fileFactory.CreateSupportingFile(new Uri(UrlHelper.CreateUrlFromPath(storagePath)), fileName, fileNameUniqueToken, true); return(file); }
internal SupportingFileFactory CreateSupportingFile(string id, string fileName, int nextVersion) { SupportingFileFactory fileFactory = (SupportingFileFactory)_factoriesById[id]; if (fileFactory == null) { fileFactory = new SupportingFileFactory(this, id, fileName, nextVersion); _factoriesById[fileFactory.FileId] = fileFactory; } else { throw new Exception("File already exists"); } return fileFactory; }
internal SupportingFileFactory CreateSupportingFile(string id, string fileName, int nextVersion) { SupportingFileFactory fileFactory = (SupportingFileFactory)_factoriesById[id]; if (fileFactory == null) { fileFactory = new SupportingFileFactory(this, id, fileName, nextVersion); _factoriesById[fileFactory.FileId] = fileFactory; } else { throw new Exception("File already exists"); } return(fileFactory); }
public void ReadFileVersionData(XmlTextReader reader, SupportingFileFactory fileFactory) { Debug.Assert(reader.LocalName == ATTACHED_FILE_VERSION_ELEMENT, "Xml reader is improperly positioned"); int depth = 0; string fileName = reader.GetAttribute(ATTACHED_FILE_NAME); string fileNameUniqueToken = reader.GetAttribute(ATTACHED_FILE_NAME_UNIQUETOKEN); if (fileNameUniqueToken == null) //necessary for interim Wave2 M1 builds fileNameUniqueToken = _fileService.CreateUniqueFileNameToken(fileName); string fileVersionString = reader.GetAttribute(ATTACHED_FILE_VERSION_ATTRIBUTE); int fileVersion = -1; if (fileVersionString != null) fileVersion = Int32.Parse(fileVersionString, CultureInfo.InvariantCulture); bool embedded = bool.Parse(reader.GetAttribute(ATTACHED_FILE_EMBEDDED_ATTRIBUTE)); string fileUriString = reader.GetAttribute(ATTACHED_FILE_URI_ATTRIBUTE); //fixup the reference path if (embedded) fileUriString = _supportingFilePersister.LoadFilesAndFixupReferences(new string[] { fileUriString })[0]; BlogPostSettingsBag settings = new BlogPostSettingsBag(); if (!reader.IsEmptyElement) { depth = 1; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { bool isEmptyElement = reader.IsEmptyElement; depth++; if (reader.LocalName == SETTINGS_BAG_ELEMENT) { ReadBlogPostSettingsBag(reader, settings); //this element was completely handled, and the stack was reset to its end element, //so unset the depth and re-start the loop depth--; continue; } if (isEmptyElement) depth--; } else if (reader.NodeType == XmlNodeType.EndElement) { depth--; } if (depth == 0) break; } } fileFactory.CreateSupportingFile(new Uri(UrlHelper.CreateUrlFromPath(fileUriString)), fileVersion, fileName, fileNameUniqueToken, embedded, settings); Debug.Assert(depth == 0 && reader.LocalName == ATTACHED_FILE_VERSION_ELEMENT, "Xmlreader is unexpectedly positioned (probably read to far!)"); }
public void ReadUploadInfoData(XmlTextReader reader, SupportingFileFactory fileFactory) { Debug.Assert(reader.LocalName == ATTACHED_FILE_UPLOAD_ELEMENT, "Xml reader is improperly positioned"); int depth = 0; string contextId = reader.GetAttribute(ATTACHED_FILE_UPLOAD_CONTEXT_ATTRIBUTE); string uploadUri = reader.GetAttribute(ATTACHED_FILE_UPLOAD_URI_ATTRIBUTE); string uploadVersionString = reader.GetAttribute(ATTACHED_FILE_UPLOAD_VERSION_ATTRIBUTE); int uploadVersion = -1; if (uploadVersionString != null) uploadVersion = Int32.Parse(uploadVersionString, CultureInfo.InvariantCulture); //fixup the reference path BlogPostSettingsBag settings = new BlogPostSettingsBag(); if (!reader.IsEmptyElement) { depth = 1; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { bool isEmptyElement = reader.IsEmptyElement; depth++; if (reader.LocalName == SETTINGS_BAG_ELEMENT) { ReadBlogPostSettingsBag(reader, settings); //this element was completely handled, and the stack was reset to its end element, //so unset the depth and re-start the loop depth--; continue; } if (isEmptyElement) depth--; } else if (reader.NodeType == XmlNodeType.EndElement) { depth--; } if (depth == 0) break; } } Trace.Assert(uploadUri != null, "Informational: UploadUri is null"); fileFactory.AddUploadInfo(contextId, uploadVersion, uploadUri == null ? null : new Uri(uploadUri), settings); Debug.Assert(depth == 0 && reader.LocalName == ATTACHED_FILE_UPLOAD_ELEMENT, "Xmlreader is unexpectedly positioned (probably read to far!)"); }
public bool IsReferenced(SupportingFileFactory fileFactory) { return filesById[fileFactory.FileId] != null; }
private void ShowFileProperties(SupportingFileFactory.VersionedSupportingFile file) { ResetDataSet(); if (file != null) { AddData("id", file.FileId); AddData("version", file.FileVersion.ToString(CultureInfo.InvariantCulture)); AddData("name", file.FileName); AddData("nameUniqueToken", file.FileNameUniqueToken); AddData("embedded", file.Embedded.ToString()); AddData("localPath", UrlHelper.SafeToAbsoluteUri(file.FileUri)); AddSettings("", file.Settings); foreach (string uploadContext in file.GetAllUploadContexts()) { ISupportingFileUploadInfo uploadInfo = file.GetUploadInfo(uploadContext); string prefix = "upload." + uploadContext + "."; AddData(prefix + "version", uploadInfo.UploadedFileVersion.ToString(CultureInfo.InvariantCulture)); AddData(prefix + "uri", UrlHelper.SafeToAbsoluteUri(uploadInfo.UploadUri)); AddSettings(prefix, uploadInfo.UploadSettings); } } }
public bool IsReferenced(SupportingFileFactory fileFactory) { return(filesById[fileFactory.FileId] != null); }