Raven.Studio.Models.PatchModel.GetValues C# (CSharp) Method

GetValues() public method

public GetValues ( ) : object>.Dictionary
return object>.Dictionary
		public Dictionary<string, object> GetValues()
		{
			var values = new Dictionary<string, object>();

			foreach (var patchValue in Values)
			{
				if(values.ContainsKey(patchValue.Key))
				{
					MessageBox.Show("You Can not have more then one value for each key. (The key " + patchValue.Key + " apprears more then once");
					return null;
				}
				int integer;
				if(int.TryParse(patchValue.Value, out integer))
				{
					values.Add(patchValue.Key, integer);
					continue;
				}

				long longNum;
				if(long.TryParse(patchValue.Value, out longNum))
				{
					values.Add(patchValue.Key, longNum);
					continue;
				}

				decimal decimalNum;
				if (decimal.TryParse(patchValue.Value, out decimalNum))
				{
					values.Add(patchValue.Key, decimalNum);
					continue;
				}

				bool boolean;
				if (bool.TryParse(patchValue.Value, out boolean))
				{
					values.Add(patchValue.Key, boolean);
					continue;
				}

				values.Add(patchValue.Key, patchValue.Value);
			}

			return values;
		}
	}

Usage Example

Ejemplo n.º 1
0
        public override void Execute(object parameter)
        {
            patchModel.ClearQueryError();

            AskUser.ConfirmationAsync("Patch Documents", "Are you sure you want to apply this patch to all selected documents?")
            .ContinueWhenTrueInTheUIThread(() =>
            {
                var values = patchModel.GetValues();
                if (values == null)
                {
                    return;
                }
                var request = new ScriptedPatchRequest {
                    Script = patchModel.Script.CurrentSnapshot.Text, Values = values
                };
                var selectedItems = patchModel.QueryResults.ItemSelection.GetSelectedItems();
                var commands      = new ICommandData[selectedItems.Count()];
                var counter       = 0;

                foreach (var item in selectedItems)
                {
                    commands[counter] = new ScriptedPatchCommandData
                    {
                        Patch = request,
                        Key   = item.Item.Id
                    };

                    counter++;
                }

                ApplicationModel.Database.Value.AsyncDatabaseCommands
                .BatchAsync(commands)
                .ContinueOnUIThread(t => { if (t.IsFaulted)
                                           {
                                               patchModel.HandlePatchError(t.Exception);
                                           }
                                    })
                .ContinueOnSuccessInTheUIThread(() => ApplicationModel.Database.Value
                                                .AsyncDatabaseCommands
                                                .GetAsync(patchModel.SelectedItem)
                                                .ContinueOnSuccessInTheUIThread(doc =>
                {
                    if (doc != null)
                    {
                        patchModel.OriginalDoc.SetText(doc.ToJson().ToString());
                        patchModel.NewDoc.SetText("");
                        patchModel.ShowAfterPrompt = true;
                    }
                    else
                    {
                        patchModel.OriginalDoc.SetText("");
                        patchModel.NewDoc.SetText("");
                        patchModel.ShowAfterPrompt          = true;
                        patchModel.ShowBeforeAndAfterPrompt = true;
                    }
                }));
            });
        }
All Usage Examples Of Raven.Studio.Models.PatchModel::GetValues