private static void MakeInternal(IZetboxContext ctx, ImportedFile obj, File doc) { // Clone blob, so it could be deleted doc.Blob = ctx.Find<Blob>(ctx.CreateBlob(ctx.GetFileInfo(obj.Blob.ID), obj.Blob.MimeType)); doc.Name = obj.Name; ctx.Delete(obj); }
private static void MakeInternal(IZetboxContext ctx, ImportedFile obj, File doc) { // Clone blob, so it could be deleted doc.Blob = ctx.Find <Blob>(ctx.CreateBlob(ctx.GetFileInfo(obj.Blob.ID), obj.Blob.MimeType)); doc.Name = obj.Name; ctx.Delete(obj); }
protected virtual void CreateTestData() { data = new MemoryStream(); var sw = new StreamWriter(data); sw.Write(txt_data); using (IZetboxContext ctx = GetContext()) { var blob = ctx.Find <Blob>(ctx.CreateBlob(data, filename, mimetype)); ctx.SubmitChanges(); blob_id = blob.ID; } }
public Zetbox.App.Base.Blob SetBlobStream(Guid version, IZetboxContext ctx, Stream blob, string filename, string mimetype) { if (ctx == null) { throw new ArgumentNullException("ctx"); } if (blob == null) { throw new ArgumentNullException("blob"); } ZetboxGeneratedVersionAttribute.Check(version); var id = ctx.CreateBlob(blob, filename, mimetype); var obj = ctx.Find <Zetbox.App.Base.Blob>(id); ctx.SubmitChanges(); return(obj); }
public void Import(IZetboxContext ctx, Account account, string fileName) { List <ImportedTransaction> importedTransactions = Read(fileName); var min = importedTransactions.Min(i => i.Date).AddDays(-7); var max = importedTransactions.Max(i => i.Date).AddDays(7); var transactions = ctx.GetQuery <Transaction>() .Where(i => i.Account == account) .Where(i => i.Date >= min && i.Date <= max) .ToLookup(k => k.ImportHash); foreach (var impTx in importedTransactions) { if (!transactions.Contains(impTx.ImportHash)) { var newTx = ctx.Create <Transaction>(); newTx.Account = account; newTx.Date = impTx.Date; newTx.Amount = impTx.Ammount; newTx.Comment = impTx.Text; newTx.ImportHash = impTx.ImportHash; foreach (var receipt in impTx.Receipts) { var file = ctx.Create <at.dasz.DocumentManagement.File>(); file.IsFileReadonly = true; file.Name = string.Format("Receipt {0}.txt", impTx.Date.ToShortDateString()); using (var stream = new MemoryStream()) using (var sw = new StreamWriter(stream)) { sw.Write(receipt); sw.Flush(); stream.Seek(0, SeekOrigin.Begin); file.Blob = ctx.Find <Blob>(ctx.CreateBlob(stream, file.Name, "text/plain")); } newTx.Documents.Add(file); } } } }