protected override AISTek.DataFlow.Shared.Classes.FileLink SaveFilePerform(AISTek.DataFlow.Shared.Classes.IRepository repository) { var buffer = Encoding.UTF8.GetBytes(Path); var id = repository.UploadNew(Name, new MemoryStream(buffer)); var link = new FileLink { Id = id, Name = Name, Metadata = Metadata }; return link; }
public override FileLink SaveFile(IRepository repository) { var id = repository.CreateNew(Name); var link = new FileLink { Id = id }; Link = link; return link; }
protected override FileLink SaveFilePerform(IRepository repository) { using (var stream = new FileStream(Path, FileMode.Open)) { var id = repository.UploadNew(Name, stream); var link = new FileLink { Id = id, Name = Name, Metadata = Metadata }; return link; } }
public override FileLink SaveFile(IRepository repository) { using (var stream = new FileStream(Path, FileMode.Open)) { var id = repository.UploadNew(Name, stream); var link = new FileLink { Id = id, Name = Name }; Link = link; return link; } }
private string ReadFile(FileLink l) { Func<FileLink, string> readPath = (link) => { using (Perfomance.Trace(traceMessage + ": Read input file").BindToConsole()) using (var reader = new StreamReader(Repository.Download(link.Id), Encoding.UTF8, false, 4096)) return reader.ReadToEnd(); }; return System.IO.File.ReadAllText(readPath(l)); }
private string ReadFile(FileLink link) { using (Perfomance.Trace(traceMessage + ": Read input file").BindToConsole()) { using (var reader = new StreamReader(Repository.Download(link.Id) ,Encoding.Default, false, 4096)) { var text = reader.ReadToEnd(); return text; } } }
static void Main() { while (true) { Console.Write("Enter file's size (MB): "); int size; if (!int.TryParse(Console.ReadLine(), out size)) return; using (var client = new RepositoryClientFactory().CreateClient()) { Console.WriteLine("Connecting..."); client.Open(); for (var i = 0; i < 1; i++) { Stream stream = null; using (stream) { string data; using (Perfomance.Trace("Generating data stream...").BindToConsole()) { data = GenerateRandomString(size * 1024 * 1024); stream = WriteString(data); } // Write Guid id; using (Perfomance.Trace("client.Upload").BindToConsole()) { id = client.UploadNew("test", stream); } // Read all var link = new FileLink { Id = id }; Stream download; using (Perfomance.Trace("client.Download").BindToConsole()) { download = client.Download(link.Id); } var readString = ReadString(download); Console.WriteLine(readString == data ? "Pass" : "Fail"); } } } } }
private void CreateButton_Click(object sender, RoutedEventArgs _) { try { using (var client = new RepositoryClientFactory().CreateClient()) { client.Open(); for (var i = 0; i < 5; i++) { var data = GenerateRandomString(16 * 1024 * 1024); // Create var id = client.CreateNew("testFile"); var link = new FileLink { Id = id }; // Write using (var stream = WriteString(data)) { Action<string, long> onCompleted = (msg, ms) => MessageBox.Show(string.Format("{0} in {1} ms", msg, ms)); using (Perfomance.Trace("client.Upload").BindToCallback(onCompleted)) { client.Upload(link.Id, stream); } // Read all Stream download; using (Perfomance.Trace("client.Download").BindToCallback(onCompleted)) { download = client.Download(link.Id); } MessageBox.Show(ReadString(download) == data ? "Pass" : "Fail", "All file"); } } } } catch (WebException e) { var data = e.Response.GetResponseStream().ReadToBuffer(); var str = Encoding.Default.GetString(data); MessageBox.Show(str); ErrorView.Show(e); } }
protected override FileLink SaveFilePerform(IRepository repository) { var id = repository.CreateNew(Name); var link = new FileLink { Id = id, Metadata = Metadata }; return link; }
/// <summary> /// Converts object of data transfer class <see cref="FileLink"/> /// into an instance of class <see cref="DataModel.FileLink"/>. /// </summary> /// <param name="link"> /// An object to convert. /// </param> /// <returns> /// An instance of <see cref="DataModel.FileLink"/> that corresponds value of <paramref name="link"/> /// </returns> public DataModel.FileLink FromContract(FileLink link) { return new DataModel.FileLink(link.Id, link.Name, link.Metadata); }
/// <summary> /// Initializes new instance of <see cref="File"/>. /// </summary> /// <param name="link"> /// An instance of <see cref="FileLink"/> class that contains file's reference. /// </param> public File(FileLink link) { Id = link.Id; Name = link.Name; }