예제 #1
0
        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);
        }
예제 #2
0
        private T BuildNewFileSystemFile <T>(DataSourceId dataSourceId, string localPath, string fullPath) where T : class, IData
        {
            FileSystemFile fileSystemFile = Activator.CreateInstance(_fileSystemFileTypeWithInterface) as FileSystemFile;

            fileSystemFile.SetDataSourceId(dataSourceId);
            fileSystemFile.FolderPath = Path.GetDirectoryName(localPath);
            fileSystemFile.FileName   = Path.GetFileName(localPath);
            fileSystemFile.SystemPath = fullPath;

            return(fileSystemFile as T);
        }