Beispiel #1
0
        async private void Save2Button_Click(object sender, RoutedEventArgs e)         //Should be synchronous after refactoring
        {
            int count = 0;

            foreach (dynamic group in Storage.latestData.groups)
            {
                count++;
            }
            if (count >= 16)
            {
                MessageBox.Show("Group table is full. Only 16 groups can be stored at a time.", "Too Many Groups", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            groupName = "";
            GroupNameWindow nameWindow = new GroupNameWindow();

            nameWindow.Owner = this;
            nameWindow.ShowDialog();

            if (groupName != "")
            {
                foreach (dynamic group in Storage.latestData.groups)
                {
                    if (group.Value.name == groupName)
                    {
                        MessageBox.Show("Group name already in use.", "Name Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }

                dynamic newGroup = GroupCreation(groupName);

                HttpClient    client  = new HttpClient();
                string        address = AddressBuild.GroupsRoot();
                StringContent content = new StringContent(JsonParser.Serialize(newGroup));
                Task <HttpResponseMessage> postData = client.PostAsync(address, content);
                HttpResponseMessage        response = await postData;

                string responseString = await response.Content.ReadAsStringAsync();

                if (responseString.Contains("success"))                   //Extremely ugly hack. Use JsonParser after refactoring.
                {
                    responseString = responseString.Remove(0, responseString.IndexOf("groups/") + 7);
                    responseString = responseString.Remove(responseString.IndexOf("\""), responseString.Length - responseString.IndexOf("\""));

                    //Add group to latestData
                    JsonParser.Create(Storage.latestData, new string[] { "groups", responseString }, newGroup);

                    //Append list of groups
                    this.GroupCombo.Items.Add(new ComboItem(groupName, responseString));
                    this.GroupCombo.SelectedIndex = this.GroupCombo.Items.Count - 1;
                }
            }
        }
Beispiel #2
0
        async private void Name2Button_Click(object sender, RoutedEventArgs e)
        {
            ComboItem temp = (ComboItem)GroupCombo.SelectedItem;

            groupName = "";
            GroupNameWindow nameWindow = new GroupNameWindow();

            nameWindow.Owner = this;
            nameWindow.ShowDialog();

            if (groupName != "")
            {
                foreach (dynamic group in Storage.latestData.groups)
                {
                    if (group.Value.name == groupName)
                    {
                        if (temp.nameStore != groupName)
                        {
                            MessageBox.Show("Group name already in use.", "Name Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        return;
                    }
                }

                dynamic groupData = new ExpandoObject();
                groupData.name = groupName;

                HttpClient    client  = new HttpClient();
                string        address = AddressBuild.GroupUriSpecify(temp.idStore);
                StringContent content = new StringContent(JsonParser.Serialize(groupData));
                Task <HttpResponseMessage> postData = client.PutAsync(address, content);
                HttpResponseMessage        response = await postData;

                string responseString = await response.Content.ReadAsStringAsync();

                if (responseString.Contains("success"))                   //Extremely ugly hack. Use JsonParser after refactoring.
                //Edit group in latestData
                {
                    JsonParser.Modify(Storage.latestData, new string[] { "groups", temp.idStore, "name" }, groupName);

                    //Edit list entry
                    int tempIndex = this.GroupCombo.SelectedIndex;
                    this.GroupCombo.Items[tempIndex] = new ComboItem(groupName, temp.idStore);
                    this.GroupCombo.SelectedIndex    = tempIndex;
                }
            }
        }
Beispiel #3
0
		async private void Name2Button_Click(object sender, RoutedEventArgs e)
		{
			ComboItem temp = (ComboItem)GroupCombo.SelectedItem;
			groupName = "";
			GroupNameWindow nameWindow = new GroupNameWindow();
			nameWindow.Owner = this;
			nameWindow.ShowDialog();

			if (groupName != "") {
				foreach (dynamic group in Storage.latestData.groups) {
					if (group.Value.name == groupName) {
						if (temp.nameStore != groupName) {
							MessageBox.Show("Group name already in use.", "Name Error", MessageBoxButton.OK, MessageBoxImage.Error);
						}
						return;
					}
				}

				dynamic groupData = new ExpandoObject();
				groupData.name = groupName;

				HttpClient client = new HttpClient();
				string address = AddressBuild.GroupUriSpecify(temp.idStore);
				StringContent content = new StringContent(JsonParser.Serialize(groupData));
				Task<HttpResponseMessage> postData = client.PutAsync(address, content);
				HttpResponseMessage response = await postData;

				string responseString = await response.Content.ReadAsStringAsync();
				if (responseString.Contains("success")) { //Extremely ugly hack. Use JsonParser after refactoring.
					//Edit group in latestData
					JsonParser.Modify(Storage.latestData, new string[] { "groups", temp.idStore, "name" }, groupName);

					//Edit list entry
					int tempIndex = this.GroupCombo.SelectedIndex;
					this.GroupCombo.Items[tempIndex] = new ComboItem(groupName, temp.idStore);
					this.GroupCombo.SelectedIndex = tempIndex;
				}
			}
		}
Beispiel #4
0
		async private void Save2Button_Click(object sender, RoutedEventArgs e) //Should be synchronous after refactoring
		{
			int count = 0;
			foreach (dynamic group in Storage.latestData.groups) {
				count++;
			}
			if (count >= 16) {
				MessageBox.Show("Group table is full. Only 16 groups can be stored at a time.", "Too Many Groups", MessageBoxButton.OK, MessageBoxImage.Error);
				return;
			}

			groupName = "";
			GroupNameWindow nameWindow = new GroupNameWindow();
			nameWindow.Owner = this;
			nameWindow.ShowDialog();

			if (groupName != "") {
				foreach (dynamic group in Storage.latestData.groups) {
					if (group.Value.name == groupName) {
						MessageBox.Show("Group name already in use.", "Name Error", MessageBoxButton.OK, MessageBoxImage.Error);
						return;
					}
				}

				dynamic newGroup = GroupCreation(groupName);

				HttpClient client = new HttpClient();
				string address = AddressBuild.GroupsRoot();
				StringContent content = new StringContent(JsonParser.Serialize(newGroup));
				Task<HttpResponseMessage> postData = client.PostAsync(address, content);
				HttpResponseMessage response = await postData;

				string responseString = await response.Content.ReadAsStringAsync();
				if (responseString.Contains("success")) { //Extremely ugly hack. Use JsonParser after refactoring.
					responseString = responseString.Remove(0, responseString.IndexOf("groups/") + 7);
					responseString = responseString.Remove(responseString.IndexOf("\""), responseString.Length - responseString.IndexOf("\""));

					//Add group to latestData
					JsonParser.Create(Storage.latestData, new string[] { "groups", responseString }, newGroup);

					//Append list of groups
					this.GroupCombo.Items.Add(new ComboItem(groupName, responseString));
					this.GroupCombo.SelectedIndex = this.GroupCombo.Items.Count - 1;
				}
			}
		}