public List <T> AddNew <T>(IEnumerable <T> datas) where T : class, IData { List <T> result = new List <T>(); foreach (IData data in datas) { CheckInterface(data.GetType()); IFile file = (IFile)data; string filename = CreateSystemPath(Path.Combine(file.FolderPath, file.FileName)); FileSystemFile fileSystemFile = Activator.CreateInstance(_fileSystemFileTypeWithInterface) as FileSystemFile; fileSystemFile.SetDataSourceId(_context.CreateDataSourceId(new FileSystemFileDataId(filename), _fileInterfaceType)); fileSystemFile.FolderPath = file.FolderPath; fileSystemFile.FileName = file.FileName; fileSystemFile.SystemPath = filename; using (C1StreamReader streamReader = new C1StreamReader(file.GetReadStream())) { using (C1StreamWriter streamWriter = new C1StreamWriter(fileSystemFile.GetNewWriteStream())) { streamWriter.Write(streamReader.ReadToEnd()); } } FileSystemFileStreamManager.WriteFileToDisk(fileSystemFile); result.Add(fileSystemFile as T); } return(result); }
public StaticFile(string fullPath, DataProviderContext context, string storeId, string providerRoot) { string websitePath = PathUtil.GetWebsitePath(fullPath); string providerRelativePath = websitePath.Substring(providerRoot.Length - 1); Id = CalculateId(providerRelativePath); DownloadUrl = websitePath; FileName = Path.GetFileName(providerRelativePath); FolderPath = Path.GetDirectoryName(providerRelativePath).Replace("\\", "/"); StoreId = storeId; DataSourceId = context.CreateDataSourceId(new MediaDataId { Id = this.Id, MediaType = MediaElementType.File }, typeof(IMediaFile)); CreationTime = DateTime.MinValue; LastWriteTime = DateTime.MinValue; Length = 0; }
public StaticFolder(string fullPath, DataProviderContext context, string storeId, string providerRoot) { string websitePath = PathUtil.GetWebsitePath(fullPath); string providerRelativePath = websitePath.Substring(providerRoot.Length - 1); Id = CalculateId(providerRelativePath); StoreId = storeId; DataSourceId = context.CreateDataSourceId(new MediaDataId { Id = this.Id, MediaType = MediaElementType.Folder }, typeof(IMediaFileFolder)); Description = ""; Title = System.IO.Path.GetFileName(providerRelativePath); StoreId = storeId; Path = providerRelativePath; KeyPath = storeId + ":" + Id; CompositePath = storeId + ":" + providerRelativePath; }
public T GetData <T>(IDataId dataId) where T : class, IData { var folderId = dataId as FacebookMediaFolderId; if (folderId != null) { using (var data = new DataConnection(PublicationScope.Published)) { var album = data.Get <IFacebookAlbum>().Single(a => a.Id == folderId.Id); var id = new FacebookMediaFolderId { Id = album.Id }; var dataSourceId = _context.CreateDataSourceId(id, typeof(IMediaFileFolder)); return((new FacebookMediaFolder(album, Store.Id, dataSourceId)) as T); } } var fileId = dataId as FacebookMediaFileId; if (fileId != null) { using (var data = new DataConnection(PublicationScope.Published)) { var photo = data.Get <IFacebookPhoto>().Single(p => p.Id == fileId.Id); var album = data.Get <IFacebookAlbum>().Single(a => a.Id == fileId.AlbumId); var dataSourceId = _context.CreateDataSourceId(new FacebookMediaFileId { Id = photo.Id, AlbumId = album.Id }, typeof(IMediaFile)); return((new FacebookMediaFile(photo, album, Store.Id, dataSourceId)) as T); } } var photoId = dataId as FacebookPhotoId; if (photoId != null) { using (var data = new DataConnection(PublicationScope.Published)) { var album = data.Get <IFacebookAlbum>().SingleOrDefault(a => a.AlbumId == photoId.AlbumId); if (album != null) { var token = album.AccessToken; var client = new FacebookClient(token); dynamic photo = client.Get(photoId.Id); var id = new FacebookPhotoId { Id = photo.Id, AlbumId = album.AlbumId }; var facebookPhoto = new FacebookPhoto(_context.CreateDataSourceId(id, typeof(IFacebookPhoto))) { Id = photo.id, AlbumId = album.AlbumId, Title = photo.name ?? String.Empty }; return(facebookPhoto as T); } } } return(default(T)); }