Exemplo n.º 1
0
		public static void updateNetworkedData(){
			var data = DataManager.getInstance();
			var postData = new JObject ();

			postData ["token"] = data.getSecret();

			var accessRes = RestCall.POST (URLs.ACCESSLEVEL, postData);
			if ((bool)accessRes ["result"]) {
				Console.WriteLine (accessRes);

				data.setRole ((string)accessRes ["accessLevel"]);
			}

			if (data.isNoAccess () || data.isStandAlone ()) {
				return;
			}
			SENDLOCATION (postData);

			var MapData = RestCall.POST (URLs.MAPDATA, postData);
			if ((bool)MapData ["result"]) {
				Console.WriteLine (MapData);
				updateMapData (MapData);
			}

			var AlertsData = RestCall.POST (URLs.ALERTS, postData);
			if ((bool)MapData ["result"]) {
				Console.WriteLine (AlertsData);
				updateAlertsData (AlertsData);
			}
				
			if (data.isAdmin ()) {
				//user list
				var result = RestCall.POST (URLs.USERLIST, postData);
				Console.WriteLine (result);

				if(!(bool)result["result"]){
					return;
				}
				var userList = (JArray)result ["userList"];
				var addTo = new List<EIMAUser>();

				foreach (JObject item in userList.Children()) {
					
					var user = new EIMAUser ();
					var unparsed = (int)item ["privLevel"];
//					user.username = (string)item ["username"];
					user.username = (string)item ["name"];
					user.unit = (string)item ["unit"];
					user.unitType = (string)item ["unitType"];
					user.status = (string)item ["status"];
					user.organization = (string)item ["organization"];

					if (unparsed == 3)
						user.level = "admin";
					else if (unparsed == 2) {
						user.level = "mapEditor";
					} else if (unparsed == 1) {
						user.level = "user";
					} else if (unparsed == 0) {
						user.level = "noAccess";
					}

					addTo.Add (user);
				}
				addTo.ForEach(Console.WriteLine);

				data.setUsers (addTo);
			}

			Console.WriteLine (data.getD());


		}
Exemplo n.º 2
0
		public UserInfoPage (EIMAUser user)
		{
			var data = DataManager.getInstance ();
			var name = new TableSection ("Name");
			var cell1 = new TextCell {
				Text = user.name,
				TextColor = Color.White,
			};
			name.Add (cell1);

			var username = new TableSection ("Username");
			var cell2 = new TextCell {
				Text = user.username,
				TextColor = Color.White,
			};
			username.Add (cell2);

			var unit = new TableSection ("Unit");
			var cell3 = new TextCell {
				Text = user.unit,
				TextColor = Color.White,
			};
			unit.Add (cell3);

			var unitType = new TableSection ("Unit Type");
			var cell4 = new TextCell {
				Text = user.unitType,
				TextColor = Color.White,
			};
			unitType.Add (cell4);

			var organization = new TableSection ("Organization");
			var cell5 = new TextCell {
				Text = user.organization,
				TextColor = Color.White,
			};
			organization.Add (cell5);

			var status = new TableSection ("Status");
			var cell6 = new TextCell {
				Text = user.status,
				TextColor = Color.White,
			};
			status.Add (cell6);

			var level = new TableSection ("Privilege Level");
			var cell7 = new TextCell {
				Text = user.level,
				TextColor = Color.White,
			};
			level.Add (cell7);


			TableRoot root = new TableRoot ();
			root.Add (name);
			root.Add (username);
			root.Add (unit);
			root.Add (unitType);
			root.Add (organization);
			root.Add (status);
			root.Add (level);
			TableView tableView = new TableView (root);

			var command1 = new Command (async o => await Application.Current.MainPage.Navigation.PopModalAsync ());
			var command2 = new Command (async o => {
				var action = await Application.Current.MainPage.DisplayActionSheet (
					"Enter New Privilege Level",
					"Cancel",
					null,
					"No Access",
					"Standard User",
					"Map Editor",
					"Admin"
				);

				if (action == "No Access") { 
					user.level = "noAccess";
					Users.userList.Add (user);
					await Application.Current.MainPage.DisplayAlert ("", "The user is now a No Access User", "OK");
				} else if (action == "Standard User") { 
					user.level = "user";
					Users.userList.Add (user);
					await Application.Current.MainPage.DisplayAlert ("", "The user is now a Standard User", "OK");
				}	else if (action == "Map Editor") { 
					user.level = "mapEditor";
					Users.userList.Add (user);
					await Application.Current.MainPage.DisplayAlert ("", "The user is now a Map Editor", "OK");
				} else if (action == "Admin") { 
					user.level = "admin";
					Users.userList.Add (user);
					await Application.Current.MainPage.DisplayAlert ("", "The user is now an Admin", "OK");
				}

				var postData = new JObject ();

				postData ["token"] = data.getSecret();
				postData ["privLevel"] = user.level;
				postData ["username"] = user.username;
				Console.WriteLine(postData);
				Console.WriteLine(RestCall.POST (URLs.EDITPRIV, postData));
			});


			var changePrivilege = new Button {
				Text = "Change Privilege",
				VerticalOptions = LayoutOptions.Start,
				Command = command2,
			};

			var backButton = new Button {
				Text = "Back",
				VerticalOptions = LayoutOptions.Start,
				Command = command1,
			};

			var label = new Label {
				Text = "Enter your message:",
				FontSize = 20
			};

			var entry = new Entry {
				Placeholder = "Message"
			};

			var sendCommands = new Command (async o => {
				var postData = new JObject ();

				postData ["token"] = data.getSecret();
				postData ["message"] = entry.Text;
				postData ["username"] = user.username;

				Console.WriteLine(RestCall.POST (URLs.SENDMESSAGE, postData));
				await Application.Current.MainPage.Navigation.PopModalAsync ();
			});

			var sendButton = new Button {
				Text = "Send",

				// insert code to send message

				Command = sendCommands
			};

				
			var cancelButton = new Button {
				Text = "Cancel",
				Command = new Command (async o => await Application.Current.MainPage.Navigation.PopModalAsync ()),
			};

			var stackLayout1 = new StackLayout ();
			stackLayout1.Children.Add (label);
			stackLayout1.Children.Add (entry);
			var stackLayout2 = new StackLayout ();
			stackLayout2.Children.Add (sendButton);
			stackLayout2.Children.Add (cancelButton);
			stackLayout2.HorizontalOptions = LayoutOptions.Center;
			stackLayout2.Orientation = StackOrientation.Horizontal;
			stackLayout1.Children.Add (stackLayout2);
			stackLayout1.VerticalOptions = LayoutOptions.Center;

			ContentPage contentpage = new ContentPage ();
			contentpage.Content = stackLayout1;

			var command3 = new Command (async o => await Application.Current.MainPage.Navigation.PushModalAsync (contentpage));
			var messageButton = new Button {
				Text = "Send Message",
				VerticalOptions = LayoutOptions.Start,
				Command = command3,
			};

			var stackLayout3 = new StackLayout ();
			stackLayout3.Children.Add (tableView);
			var stackLayout4 = new StackLayout ();
			stackLayout4.Children.Add (changePrivilege);
			stackLayout4.Children.Add (messageButton);
			stackLayout4.Children.Add (backButton);
			stackLayout4.HorizontalOptions = LayoutOptions.Center;
			stackLayout4.Orientation = StackOrientation.Horizontal;
			stackLayout3.Children.Add (stackLayout4);
			Content = stackLayout3;

		}
Exemplo n.º 3
0
		//Get Users
		public List<EIMAUser> getUsers(){
			var toRet = new List<EIMAUser> ();
			JArray users = (JArray)dataStore ["incident"] ["userList"];

			foreach (JObject item in users.Children()) {
				var toAdd = new EIMAUser ();

				toAdd.level = (string)item ["level"];
				toAdd.username = (string)item ["username"];
				toAdd.name = (string)item ["name"];
				toAdd.unit = (string)item ["unit"];
				toAdd.unitType = (string)item ["unitType"];
				toAdd.status = (string)item ["status"];
				toAdd.organization = (string)item ["organization"];

				toRet.Add (toAdd);
			}
			return toRet;
		}