aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.PMR/Integration/DirectSynchronizationRequest.cs
blob: ef2ae14c070c855d311b084898c0f01d293ba4b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: DirectSynchronizationRequest.proto
#pragma warning disable 1591, 0612, 3021
#region Designer generated code

using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
namespace Tango.PMR.Integration {

  /// <summary>Holder for reflection information generated from DirectSynchronizationRequest.proto</summary>
  public static partial class DirectSynchronizationRequestReflection {

    #region Descriptor
    /// <summary>File descriptor for DirectSynchronizationRequest.proto</summary>
    public static pbr::FileDescriptor Descriptor {
      get { return descriptor; }
    }
    private static pbr::FileDescriptor descriptor;

    static DirectSynchronizationRequestReflection() {
      byte[] descriptorData = global::System.Convert.FromBase64String(
          string.Concat(
            "CiJEaXJlY3RTeW5jaHJvbml6YXRpb25SZXF1ZXN0LnByb3RvEhVUYW5nby5Q",
            "TVIuSW50ZWdyYXRpb24iHgocRGlyZWN0U3luY2hyb25pemF0aW9uUmVxdWVz",
            "dEIhCh9jb20udHdpbmUudGFuZ28ucG1yLmludGVncmF0aW9uYgZwcm90bzM="));
      descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
          new pbr::FileDescriptor[] { },
          new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
            new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Integration.DirectSynchronizationRequest), global::Tango.PMR.Integration.DirectSynchronizationRequest.Parser, null, null, null, null)
          }));
    }
    #endregion

  }
  #region Messages
  public sealed partial class DirectSynchronizationRequest : pb::IMessage<DirectSynchronizationRequest> {
    private static readonly pb::MessageParser<DirectSynchronizationRequest> _parser = new pb::MessageParser<DirectSynchronizationRequest>(() => new DirectSynchronizationRequest());
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public static pb::MessageParser<DirectSynchronizationRequest> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Tango.PMR.Integration.DirectSynchronizationRequestReflection.Descriptor.MessageTypes[0]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public DirectSynchronizationRequest() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public DirectSynchronizationRequest(DirectSynchronizationRequest other) : this() {
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public DirectSynchronizationRequest Clone() {
      return new DirectSynchronizationRequest(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public override bool Equals(object other) {
      return Equals(other as DirectSynchronizationRequest);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public bool Equals(DirectSynchronizationRequest other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      return true;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public override int GetHashCode() {
      int hash = 1;
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public void WriteTo(pb::CodedOutputStream output) {
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public int CalculateSize() {
      int size = 0;
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public void MergeFrom(DirectSynchronizationRequest other) {
      if (other == null) {
        return;
      }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public void MergeFrom(pb::CodedInputStream input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            input.SkipLastField();
            break;
        }
      }
    }

  }

  #endregion

}

#endregion Designer generated code
"w"> && _selectedUserPlace.Address != null) { SetUserPlace(value); } } } private Place _selectedOrganizationPlace; public Place SelectedOrganizationPlace { get { return _selectedOrganizationPlace; } set { _selectedOrganizationPlace = value; if (_selectedOrganizationPlace != null && _selectedOrganizationPlace.Address != null) { SetOrganizationPlace(value); } } } public RelayCommand ManageOrganizationCommand { get; set; } public RelayCommand BackToOrganizationsCommand { get; set; } public RelayCommand ManageUserCommand { get; set; } public RelayCommand SaveOrganizationCommand { get; set; } public RelayCommand AddOrganizationCommand { get; set; } public RelayCommand RemoveOrganizationCommand { get; set; } public RelayCommand BackToManagedOrganizationCommand { get; set; } public RelayCommand<Role> RemoveRoleCommand { get; set; } public RelayCommand SaveManagedUserCommand { get; set; } public RelayCommand AddUserCommand { get; set; } public RelayCommand RemoveUserCommand { get; set; } public MainViewVM(UsersAndRolesNavigationManager navigation, INotificationProvider notification) { _navigation = navigation; _notification = notification; LoadOrganizations(); ManageOrganizationCommand = new RelayCommand(LoadSelectedOrganization, () => SelectedOrganization != null); BackToOrganizationsCommand = new RelayCommand(BackToOrganizations); ManageUserCommand = new RelayCommand(LoadSelectedUser, () => SelectedUser != null); SaveOrganizationCommand = new RelayCommand(SaveOrganization); AddOrganizationCommand = new RelayCommand(AddOrganization); RemoveOrganizationCommand = new RelayCommand(RemoveOrganization, () => SelectedOrganization != null); BackToManagedOrganizationCommand = new RelayCommand(BackToManagedOrganization); RemoveRoleCommand = new RelayCommand<Role>(RemoveUserRole); SaveManagedUserCommand = new RelayCommand(SaveManagedUser); AddUserCommand = new RelayCommand(AddNewUser); RemoveUserCommand = new RelayCommand(RemoveSelectedUser, () => SelectedUser != null); } private async void AddOrganization() { String name = _notification.ShowTextInput("Enter organization name", "Name"); if (!String.IsNullOrWhiteSpace(name)) { using (_notification.PushTaskItem("Adding new organization...")) { Organization org = new Organization(); org.Name = name; org.Address = new Address(); org.Contact = new Contact(); _organizationsContext.Organizations.Add(org); await org.SaveAsync(_organizationsContext); Organizations = _organizationsContext.Organizations.ToObservableCollection(); SelectedOrganization = org; LoadSelectedOrganization(); } } } private async void RemoveOrganization() { if (_notification.ShowQuestion("Are you sure you want to remove " + SelectedOrganization.Name + " organization?")) { using (_notification.PushTaskItem("Removing organization...")) { await SelectedOrganization.DeleteCascadeAsync(_organizationsContext); LoadOrganizations(); } } } private async void SaveOrganization() { using (_notification.PushTaskItem("Saving organization address and contact...")) { await ManagedOrganization.SaveAsync(_manageContext); LoadOrganizations(); SelectedOrganization = Organizations.SingleOrDefault(x => x.Guid == ManagedOrganization.Guid); } } private void LoadSelectedUser() { using (_notification.PushTaskItem("Loading user details...")) { Task.Factory.StartNew(() => { _userContext = ObservablesContext.CreateDefault(); Roles = _userContext.Roles.ToObservableCollection(); ManagedUser = _userContext.Users.SingleOrDefault(x => x.Guid == SelectedUser.Guid); ManagedUserRoles = ManagedUser.Roles.ToObservableCollection(); InvokeUI(() => _navigation.NavigateTo(UsersAndRolesNavigationView.UserManagementView)); }); } } private void BackToOrganizations() { _navigation.NavigateTo(UsersAndRolesNavigationView.OrganizationSelectionView); } private void BackToManagedOrganization() { _navigation.NavigateTo(UsersAndRolesNavigationView.OrganizationManagementView); } private void RemoveUserRole(Role role) { ManagedUserRoles.Remove(role); foreach (var userRole in ManagedUser.UsersRoles.Where(x => x.Role == role).ToList()) { userRole.DefferedDelete(_userContext); } } private async void SaveManagedUser() { try { ManagedUser.Validate(_userContext); } catch (Exception ex) { _notification.ShowError(ex.Message); return; } using (_notification.PushTaskItem("Saving user details...")) { await ManagedUser.SaveAsync(_userContext); LoadSelectedOrganization(); } } private void LoadSelectedOrganization() { using (_notification.PushTaskItem("Loading organization...")) { Task.Factory.StartNew(() => { _manageContext = ObservablesContext.CreateDefault(); ManagedOrganization = _manageContext.Organizations.SingleOrDefault(x => x.Guid == SelectedOrganization.Guid); InvokeUI(() => _navigation.NavigateTo(UsersAndRolesNavigationView.OrganizationManagementView)); }); } } private void LoadOrganizations() { _organizationsContext = ObservablesContext.CreateDefault(); _organizationsContext.Configuration.LazyLoadingEnabled = false; _organizationsContext.Users.ToList(); _organizationsContext.Contacts.ToList(); _organizationsContext.Addresses.ToList(); _organizationsContext.Machines.ToList(); Organizations = _organizationsContext.Organizations.ToObservableCollection(); } public void OnDropRole(Role role) { ManagedUser.UsersRoles.Add(new UsersRole() { Role = role, RoleGuid = role.Guid, User = ManagedUser, UserGuid = ManagedUser.Guid, }); ManagedUserRoles.Add(role); } private async void RemoveSelectedUser() { if (_notification.ShowQuestion("Are you sure you want to remove the selected user?")) { using (_notification.PushTaskItem("Removing user...")) { await SelectedUser.DeleteCascadeAsync(_manageContext); LoadSelectedOrganization(); } } } private async void AddNewUser() { String email = _notification.ShowTextInput("Enter user email", "email"); if (!String.IsNullOrWhiteSpace(email)) { User user = new User(); user.Email = email; user.Password = "1111"; user.Contact = new Contact() { FirstName = "Twine", LastName = "User", Email = email, }; user.UsersRoles.Add(new UsersRole() { User = user, Role = _manageContext.Roles.SingleOrDefault(x => x.Code == (int)BL.Enumerations.Roles.User) }); try { user.Validate(_manageContext); } catch (Exception ex) { _notification.ShowError(ex.Message); return; } user.Address = new Address(); ManagedOrganization.Users.Add(user); using (_notification.PushTaskItem("Adding new user...")) { await ManagedOrganization.SaveAsync(_manageContext); LoadOrganizations(); SelectedOrganization = Organizations.SingleOrDefault(x => x.Guid == ManagedOrganization.Guid); } } } private void SetUserPlace(Place place) { ManagedUser.Address.AddressString = place.Address.Road; ManagedUser.Address.City = place.Address.City; ManagedUser.Address.Country = place.Address.Country; ManagedUser.Address.CountryCode = place.Address.CountryCode; ManagedUser.Address.Locality = place.Address.CountryCode; ManagedUser.Address.PostalCode = place.Address.PostalCode; ManagedUser.Address.State = place.Address.State; } private void SetOrganizationPlace(Place place) { ManagedOrganization.Address.AddressString = place.Address.Road; ManagedOrganization.Address.City = place.Address.City; ManagedOrganization.Address.Country = place.Address.Country; ManagedOrganization.Address.CountryCode = place.Address.CountryCode; ManagedOrganization.Address.Locality = place.Address.CountryCode; ManagedOrganization.Address.PostalCode = place.Address.PostalCode; ManagedOrganization.Address.State = place.Address.State; } protected override void RaisePropertyChangedAuto([CallerMemberName] string caller = null) { base.RaisePropertyChangedAuto(caller); InvalidateRelayCommands(); } } }