PageRenderTime 59ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/InstantImageUploader/ViewModels/CaptureWindowViewModel.cs

https://bitbucket.org/ugaya40/instant-image-uploader
C# | 142 lines | 118 code | 24 blank | 0 comment | 15 complexity | 19a4d102c3e45c43130ac093af41c5b6 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.ComponentModel;
  6. using Livet;
  7. using Livet.Commands;
  8. using Livet.Messaging;
  9. using Livet.Messaging.IO;
  10. using Livet.Messaging.Windows;
  11. using InstantImageUploader.Models;
  12. using System.Windows;
  13. namespace InstantImageUploader.ViewModels
  14. {
  15. public class CaptureWindowViewModel : ViewModel
  16. {
  17. public CaptureWindowViewModel()
  18. {
  19. IsCaptureMode = true;
  20. if (ImageUploaderApplication.Current != null)
  21. {
  22. ImageUploaderApplication.Current.FailedImageUpload += (sender, e) =>
  23. {
  24. if(!string.IsNullOrEmpty(e.MessageForUser))
  25. {
  26. Messenger.Raise(new InformationMessage(e.MessageForUser, "エラー", System.Windows.MessageBoxImage.Error, "Error"));
  27. }
  28. };
  29. ImageUploaderApplication.Current.SuccessImageUpload += (sender, e) =>
  30. {
  31. if(!string.IsNullOrEmpty(e.MessageForUser))
  32. {
  33. Messenger.Raise(new InformationMessage(e.MessageForUser, "アップロード成功", System.Windows.MessageBoxImage.Error, "Success"));
  34. }
  35. };
  36. }
  37. }
  38. #region SendImageCommand
  39. private ListenerCommand<string> _SendImageCommand;
  40. public ListenerCommand<string> SendImageCommand
  41. {
  42. get
  43. {
  44. if (_SendImageCommand == null)
  45. {
  46. _SendImageCommand = new ListenerCommand<string>(SendImage);
  47. }
  48. return _SendImageCommand;
  49. }
  50. }
  51. public void SendImage(string parameter)
  52. {
  53. ImageUploaderApplication.Current.Upload(parameter);
  54. }
  55. #endregion
  56. #region IsCaptureMode変更通知プロパティ
  57. private bool _IsCaptureMode;
  58. public bool IsCaptureMode
  59. {
  60. get
  61. { return _IsCaptureMode; }
  62. set
  63. {
  64. if (_IsCaptureMode == value)
  65. return;
  66. _IsCaptureMode = value;
  67. RaisePropertyChanged("IsCaptureMode");
  68. }
  69. }
  70. #endregion
  71. #region ExitCommand
  72. private ViewModelCommand _ExitCommand;
  73. public ViewModelCommand ExitCommand
  74. {
  75. get
  76. {
  77. if (_ExitCommand == null)
  78. {
  79. _ExitCommand = new ViewModelCommand(Exit);
  80. }
  81. return _ExitCommand;
  82. }
  83. }
  84. public void Exit()
  85. {
  86. ImageUploaderApplication.Current.Exit();
  87. }
  88. #endregion
  89. #region InitializeCommand
  90. private ViewModelCommand _InitializeCommand;
  91. public ViewModelCommand InitializeCommand
  92. {
  93. get
  94. {
  95. if (_InitializeCommand == null)
  96. {
  97. _InitializeCommand = new ViewModelCommand(Initialize);
  98. }
  99. return _InitializeCommand;
  100. }
  101. }
  102. public void Initialize()
  103. {
  104. if (ImageUploaderApplication.Current.ActiveUploader == null)
  105. {
  106. return;
  107. }
  108. if (ImageUploaderApplication.Current.ActiveUploader.IsNeedSetting)
  109. {
  110. IsCaptureMode = false;
  111. Messenger.Raise(new TransitionMessage("Setting") { WindowType = ImageUploaderApplication.Current.ActiveUploader.SettingWindowType });
  112. ImageUploaderApplication.Current.Exit();
  113. }
  114. ImageUploaderApplication.Current.ActiveUploader.Initialize();
  115. }
  116. #endregion
  117. }
  118. }