public void TestUpdateFileSqlite() { var connection = new SQLiteConnection($"Data Source={GetFileNameDb()}"); connection.Open(); using (var conn = connection) { var builder = conn.GetScriptBuild(); var archive = new ArchiveModel() { Content = Properties.Resources.conduites_1 }; var createTableScript = builder.GetCreateTableCommand <ArchiveModel>(); conn.Execute(createTableScript); conn.Insert <ArchiveModel>(archive); var modelForUpdate = conn.Select <ArchiveModel>(c => c.Id == 1).FirstOrDefault(); var bytes = (Byte[])new ImageConverter().ConvertTo(Properties.Resources.wwf_logo_design, typeof(Byte[])); modelForUpdate.Content = bytes; conn.Update <ArchiveModel>(modelForUpdate); conn.Execute("drop table [ArchiveModel]"); conn.ReleaseMemory(); conn.Close(); GC.Collect(); GC.WaitForPendingFinalizers(); } }
/// <summary> /// InsertArchiveBase64. /// </summary> /// <param name="bindingModel"></param> /// <returns></returns> public async Task <Boolean> InsertArchiveBase64(ArchiveBase64BindingModel bindingModel) { Boolean result = false; ArchiveModel model = null; Guid archiveId = Guid.NewGuid(); String archivePath = String.Format(ConstantsConfiguration.PATH_IMAGES, archiveId); try { File.WriteAllBytes(archivePath, Convert.FromBase64String(bindingModel.Base64)); if (!(File.ReadAllBytes(archivePath) is null)) { model = new ArchiveModel(archiveId, bindingModel.ArchiveType, bindingModel); result = await this._archiveRepository.InsertArchive(model); if (!result) { File.Delete(archivePath); } } } catch (Exception exception) { if (!(File.ReadAllBytes(archivePath) is null)) { File.Delete(archivePath); } throw exception; } return(result); }
public static ArchiveModel GetModel() { ArchiveModel model = new ArchiveModel(); foreach (var client in clients) { model.clients.Add(client.Key, client.Value.GetModel()); } foreach (var off in pendingOffers) { model.pendingOffers.Add(off.Key, off.Value.GetModel()); } foreach (var off in completedOffers) { model.completedOffers.Add(off.Key, off.Value.GetModel()); } foreach (var book in books) { model.books.Add(book.Key, book.Value.GetModel()); } model.amounts = amounts; foreach (var request in requests) { model.requests.Add(request.GetModel()); } return(model); }
public async Task <ActionResult <ArchiveResultModel> > DeleteArchivedFiles([FromBody] ArchiveModel archiveModel) { var archiveResultModel = new ArchiveResultModel(); if (archiveModel == null) { archiveResultModel.Success = false; archiveResultModel.ErrorMessage = ErrorMessage.Null.ToString(); return(BadRequest(archiveResultModel)); } if (archiveModel.StartDate == null || archiveModel.EndDate == null) { archiveResultModel.Success = false; archiveResultModel.ErrorMessage = ErrorMessage.Null.ToString(); return(BadRequest(archiveResultModel)); } var deleteResult = await _archiveManager.DeleteArchivedFiles(DateTimeOffset.Parse(archiveModel.StartDate), DateTimeOffset.Parse(archiveModel.EndDate)); archiveResultModel.Success = deleteResult.WasSuccessful; if (!deleteResult.WasSuccessful) { archiveResultModel.ErrorMessage = deleteResult.ErrorMessage.ToString(); return(BadRequest(archiveResultModel)); } return(Ok(archiveResultModel)); }
/// <summary> /// 重複リストボックス /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DuplicateListBox_SelectedIndexChanged(object sender, EventArgs e) { var selectedBook = new BookModel((String)DuplicateListBox.SelectedItem); var books = shelf.Books.Where((b) => b.Hash == selectedBook.Hash); books = books.Where(b => Path.GetFullPath(b.FilePath).ToLower() != Path.GetFullPath(selectedBook.FilePath).ToLower()); if (books.Count() == 0) { File1Textbox.Text = string.Empty; return; } File1Textbox.Text = books.FirstOrDefault().FilePath; using (var archiveBook = new ArchiveModel(selectedBook.FilePath)) { archiveBook.ResizeHeight = this.pictureBox1.Height; archiveBook.ResizeWidth = this.pictureBox1.Width; archiveBook.DrawHeight = this.pictureBox1.Height; archiveBook.DrawWidth = this.pictureBox1.Width; archiveBook.PageIndex = selectedBook.CoverFileIndex; this.pictureBox1.Image = archiveBook.PagePicture; } using (var archiveBook = new ArchiveModel(books.FirstOrDefault().FilePath)) { archiveBook.ResizeHeight = this.pictureBox2.Height; archiveBook.ResizeWidth = this.pictureBox2.Width; archiveBook.DrawHeight = this.pictureBox2.Height; archiveBook.DrawWidth = this.pictureBox2.Width; archiveBook.PageIndex = books.FirstOrDefault().CoverFileIndex; this.pictureBox2.Image = archiveBook.PagePicture; } }
/// <summary>リストビュー 選択インデックス変更イベント</summary> /// <param name="sender">発生元オブジェクト</param> /// <param name="e">イベント情報</param> private void BookmarkListView_SelectedIndexChanged(object sender, EventArgs e) { var model = this.GetSelectedModel(); var filePath = this.Books.Where(c => c.Hash == model?.Hash).FirstOrDefault()?.FilePath; if (filePath == null) { this.picCover.Image = null; return; } try { var archiveBook = new ArchiveModel(filePath, this.picCover.Height, this.picCover.Width) { PageIndex = model.PageIndex }; this.picCover.Image = archiveBook.PagePicture; this.picCover.Tag = model; } catch (Exception) { this.picCover.Image = null; } }
public void DatabaseManager_AddEntry_ShouldWork() { try { ArchiveModel model = new ArchiveModel() { ID = new Random().Next(1000000), Path = "Bla", LastArchivingDate = DateTime.Now.AddDays(-1), ArchivingIntervalInHours = 41, }; DatabaseManager manager = new DatabaseManager(); manager.AddEnty(model); List <IArchiveModel> returnedModelList = manager.GetAllEntries(); Assert.AreEqual(1, returnedModelList.Count); IArchiveModel returnedModel = returnedModelList[0]; Assert.AreEqual(model.ID, returnedModel.ID); Assert.AreEqual(model.Path, returnedModel.Path); Assert.AreEqual(model.LastArchivingDate?.ToString("yyyy-MM-dd HH:mm:ss"), returnedModel.LastArchivingDate?.ToString("yyyy-MM-dd HH:mm:ss")); Assert.AreEqual(model.ArchivingIntervalInHours, returnedModel.ArchivingIntervalInHours); } finally { DisposeDataBase(); } }
private void smiCoverPaste_Click(object sender, EventArgs e) { //クリップボードにあるデータの取得 System.Drawing.Image img = Clipboard.GetImage(); var model = (BookModel)this.picCover.Tag; if (img != null) { var a = new ArchiveModel(model.FilePath); a.SetCover(img); try { model.CoverFileIndex = 0; using (var archiveBook = new ArchiveModel(model.FilePath)) { archiveBook.ResizeHeight = this.picCover.Height; archiveBook.ResizeWidth = this.picCover.Width; archiveBook.DrawHeight = this.picCover.Height; archiveBook.DrawWidth = this.picCover.Width; archiveBook.PageIndex = model.CoverFileIndex; this.picCover.Image = archiveBook.PagePicture; } } catch (Exception ex) { this.picCover.Image = null; } } }
public IHttpActionResult PutArchiveModel(int id, ArchiveModel archiveModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != archiveModel.pId) { return(BadRequest()); } db.Entry(archiveModel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ArchiveModelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task ArchiveLogFilesByCategory_ExecuteLessThan5Seconds(string startTime, string endTime, string category, long expectedMaxExecutionTime) { // Arrange var archiveModel = new ArchiveModel(); archiveModel.StartDate = startTime; archiveModel.EndDate = endTime; archiveModel.Category = category; IArchiveManager archiveManager = new ArchiveManager(archiveService, folderHandlerService); ArchiveController archiveController = new ArchiveController(archiveManager); // Act var timer = Stopwatch.StartNew(); var actualResult = await archiveController.ArchiveLogFilesByCategory(archiveModel); timer.Stop(); var actualExecutionTime = timer.ElapsedMilliseconds; Debug.WriteLine("Actual Execution Time: " + actualExecutionTime); // Assert Assert.IsTrue(actualExecutionTime <= expectedMaxExecutionTime); }
public void UploadFiles(IEnumerable <HttpPostedFileBase> files, ArchiveModel archive) { if (archive != null && !string.IsNullOrEmpty(archive.Id)) { CloudBlobContainer container = GetCloudBlobContainer(); container.CreateIfNotExists(); container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); foreach (var file in files) { if (file != null && file.ContentLength > 0) { var ext = Path.GetExtension(file.FileName); var fileName = Path.GetFileNameWithoutExtension(file.FileName) + "_" + Guid.NewGuid().ToString() + ext; CloudBlockBlob blob = container.GetBlockBlobReference(fileName); blob.UploadFromStream(file.InputStream); ArchiveFilesModel fm = new ArchiveFilesModel(); fm.ArchiveId = archive.Id; fm.FilePath = fileName; fm.Id = Guid.NewGuid().ToString(); _db.ArchiveFiles.Add(fm); _db.SaveChanges(); } } } }
public ActionResult Recover([Bind(Include = "Id," + "FName," + "LName," + "SYear," + "Status," + "")] ArchiveModel data) { var myData = new StudentModel(data); if (!ModelState.IsValid) { // Send back for edit return(View(data)); } if (data == null) { // Send to Error page return(RedirectToAction("Error", new { route = "Home", action = "Error" })); } if (string.IsNullOrEmpty(data.Id)) { // Send back for Edit return(View(data)); } StudentBackend.Create(myData); ArchiveBackend.Delete(data.Id); return(RedirectToAction("ArchivePage")); }
/// <summary>詳細表示:イメージ変更イベント</summary> /// <param name="sender">発生元オブジェクト</param> /// <param name="e">イベントデータ</param> private void DetailList_CoverImagePaint(object sender, ItemEventArgs <BookModel> e) { Debug.Print($"DetailList_CoverImagePaint:Start:{e.Item.CoverFileIndex}"); this.sslInfomation.Text = Resources.Information.FormatWith(this.DetailList.Books.SearchedItems.Count, this.shelf.Books.Count); if (e.Item == null || File.Exists(e.Item.FilePath) == false) { this.picCover.Image = null; return; } try { using (var archiveBook = new ArchiveModel(e.Item.FilePath)) { archiveBook.ResizeHeight = this.picCover.Height; archiveBook.ResizeWidth = this.picCover.Width; archiveBook.DrawHeight = this.picCover.Height; archiveBook.DrawWidth = this.picCover.Width; archiveBook.PageIndex = e.Item.CoverFileIndex; this.picCover.Image = archiveBook.PagePicture; this.picCover.Tag = e.Item; } } catch (Exception ex) { this.picCover.Image = null; } Debug.Print("DetailList_CoverImagePaint:End"); }
public void TestInsertAndSelectFileSqlite() { var connection = new SQLiteConnection($"Data Source={GetFileNameDb()}"); connection.Open(); using (var conn = connection) { var builder = conn.GetScriptBuild(); var archive = new ArchiveModel() { Content = Properties.Resources.conduites_1 }; var createTableScript = builder.GetCreateTableCommand <ArchiveModel>(); conn.Execute(createTableScript); conn.Insert <ArchiveModel>(archive); var files = conn.GetAll <ArchiveModel>(); conn.Execute("drop table [ArchiveModel]"); conn.ReleaseMemory(); conn.Close(); GC.Collect(); GC.WaitForPendingFinalizers(); } }
public ActionResult Create(int id, ArchiveModel arMVC) { arMVC.document_id = id; if (!ModelState.IsValid || arMVC.document_id == 0) { RedirectToAction("Create"); } //document doc = new document(); // doc = scd.GetById(id); int id_user = 1; archivage ar = new archivage(); ar.document_id = arMVC.document_id; ar.user_id = id_user; ar.version = arMVC.version; sc.Add(ar); sc.Commit(); // Sauvgarde de l'image return(RedirectToAction("index")); }
// GET: Archive public ActionResult Archive(int?CategoryNo) { ArchiveModel model = new ArchiveModel(); model.News = from us in news.GetAll() where (us.CategoryId == CategoryNo || us.Category.ParentId == CategoryNo) select us; model.Category = from cat in category.GetAll() where (cat.ParentId == CategoryNo) select cat; return(View(model)); }
public void CreateArchiveOption(int id, string compressionLevel) { var archiveModel = new ArchiveModel { Id = id, CompressionLevel = compressionLevel }; _archiveContext.ArchiveOptions.Add(archiveModel); _archiveContext.SaveChanges(); }
public static void SerializeArchive(ArchiveModel model, string path) { string json = JsonConvert.SerializeObject(model); using (StreamWriter sw = new StreamWriter(path)) { sw.WriteLine(json); } }
public ActionResult Upload(IEnumerable <HttpPostedFileBase> files, ArchiveModel model) { if (model != null && files.Any()) { var arc = _archive.CreateArchive(model); _archive.UploadFiles(files, arc); } return(RedirectToAction("Index")); }
public async Task Listen() { Console.WriteLine("Archive listener started listen:"); Trace.TraceError("Archive listener started listen"); while (true) { var messages = Queue.GetMessages(CountMessages, TimeSpan.FromHours(InvisibleTime)); Parallel.ForEach(messages, async message => { try { ArchiveModel archiveModel = JsonConvert.DeserializeObject <ArchiveModel>(message.AsString); Console.WriteLine(message.AsString); byte[] outputZIP; using (MemoryStream outputMemStream = new MemoryStream()) { using (ZipOutputStream zipStream = new ZipOutputStream(outputMemStream)) { zipStream.SetLevel(3); string entryLocateName = ""; foreach (var fileSystemId in archiveModel.FileSystemsId) { FileSystemDTO fileSystem = _fileSystemService.Get(fileSystemId); if (fileSystem != null) { await ZipArchivingFileSystemTreeAsync(fileSystem, zipStream, archiveModel.UserId, entryLocateName); } } zipStream.IsStreamOwner = false; zipStream.Close(); outputMemStream.Position = 0; outputZIP = outputMemStream.ToArray(); } } await UploadFileInBlocksAsync(outputZIP, archiveModel.Id); Queue.DeleteMessage(message); } catch (Exception ex) { Trace.TraceError(ex.InnerException.Message); } }); } }
public IHttpActionResult GetArchiveModel(int id) { ArchiveModel archiveModel = db.ArchiveModel.Find(id); if (archiveModel == null) { return(NotFound()); } return(Ok(archiveModel)); }
/// <summary> /// Update all attributes to be what is passed in /// </summary> /// <param name="data"></param> /// <returns>Null or updated data</returns> public ArchiveModel Update(ArchiveModel data) { if (data == null) { return(null); } var myReturn = DataSource.Update(data); return(myReturn); }
public void ArchvieModel_ArchivingIntervalInHours_Property_Test() { int expectedInterval = 0; ArchiveModel model = new ArchiveModel(); Assert.AreEqual(expectedInterval, model.ArchivingIntervalInHours); expectedInterval = 42; model.ArchivingIntervalInHours = expectedInterval; Assert.AreEqual(expectedInterval, model.ArchivingIntervalInHours); }
public void ArchiveModel_LastArchivingDate_Property_Test() { DateTime? expectedDateTime = null; ArchiveModel model = new ArchiveModel(); Assert.AreEqual(expectedDateTime, model.LastArchivingDate); expectedDateTime = DateTime.Now; model.LastArchivingDate = expectedDateTime; Assert.AreEqual(expectedDateTime, model.LastArchivingDate); }
public void ArchiveModel_Path_Property_Test() { string expectedPath = ""; ArchiveModel model = new ArchiveModel(); Assert.AreEqual(expectedPath, model.Path); expectedPath = "TestPath"; model.Path = expectedPath; Assert.AreEqual(expectedPath, model.Path); }
public void ArchiveModel_ID_Property_Test() { int expectedID = 0; ArchiveModel model = new ArchiveModel(); Assert.AreEqual(expectedID, model.ID); expectedID = 4221; model.ID = expectedID; Assert.AreEqual(expectedID, model.ID); }
public IHttpActionResult PostArchiveModel(ArchiveModel archiveModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.ArchiveModel.Add(archiveModel); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = archiveModel.pId }, archiveModel)); }
/// <summary> /// Update all attributes to be what is passed in /// </summary> /// <param name="data"></param> /// <returns>Null or updated data</returns> public ArchiveModel Update(ArchiveModel data) { if (data == null) { return(null); } var myReturn = ArchiveList.Find(n => n.Id == data.Id); myReturn.Update(data); return(myReturn); }
/// <summary> /// This opens up the archive a current student screen /// </summary> /// <param name="id"></param> /// <returns></returns> // GET: Admin/Archive public ActionResult Archive(string id = null) { var targetStudent = StudentBackend.Read(id); if (targetStudent == null) { RedirectToAction("Error", "Home", "Invalid Record"); } var data = new ArchiveModel(targetStudent); return(View(data)); }
/// <summary> Return all closed Events </summary> public IActionResult Archive() { var model = new ArchiveModel { User = HttpContext.GetUser() }; using (var context = ContextHelper.OpenContext()) { var userEvents = context.GetUserEvents(model.User.UserId).ToList(); model.Events = userEvents.Where(x => x.Status == EventStatus.Closed).ToList(); } return(View(model)); }