private static object HandleMenuMessage(ValueSet message, Win32API.DisposableDictionary table) { switch ((string)message["Arguments"]) { case "LoadContextMenu": var contextMenuResponse = new ValueSet(); var filePath = (string)message["FilePath"]; var extendedMenu = (bool)message["ExtendedMenu"]; var showOpenMenu = (bool)message["ShowOpenMenu"]; var split = filePath.Split('|').Where(x => !string.IsNullOrWhiteSpace(x)); var cMenuLoad = Win32API.ContextMenu.GetContextMenuForFiles(split.ToArray(), (extendedMenu ? Shell32.CMF.CMF_EXTENDEDVERBS : Shell32.CMF.CMF_NORMAL) | Shell32.CMF.CMF_SYNCCASCADEMENU, FilterMenuItems(showOpenMenu)); table.SetValue("MENU", cMenuLoad); return(cMenuLoad); case "ExecAndCloseContextMenu": var cMenuExec = table.GetValue <Win32API.ContextMenu>("MENU"); if (message.TryGetValue("ItemID", out var menuId)) { switch (message.Get("CommandString", (string)null)) { case "format": var drivePath = cMenuExec.ItemsPath.First(); Win32API.OpenFormatDriveDialog(drivePath); break; default: cMenuExec?.InvokeItem((int)menuId); break; } } // The following line is needed to cleanup resources when menu is closed. // Unfortunately if you uncomment it some menu items will randomly stop working. // Resource cleanup is currently done on app closing, // if we find a solution for the issue above, we should cleanup as soon as a menu is closed. //table.RemoveValue("MENU"); return(null); default: return(null); } }
public void FailToGetUnsetValue() { values = new ValueSet(); Assert.Throws <KeyNotFoundException>(() => values.Get(testShort)); }
public IntegerWorkspace() { var integer = new FixedType <int>("integer", Color.FromKnownColor(KnownColor.Green), new Regex("^[0-9]+$"), s => int.Parse(s)); SystemProcess add; { var input1 = new Parameter <int>("value 1", integer); var input2 = new Parameter <int>("value 2", integer); var output = new Parameter <int>("result", integer); add = new SystemProcess( "Add", "Adds two integers", (ValueSet inputs) => { int value1 = inputs.Get(input1); int value2 = inputs.Get(input2); var outputs = new ValueSet(); outputs.Set(output, value1 + value2); return(new ProcessResult(outputs)); }, new Parameter[] { input1, input2 }, new Parameter[] { output }, null ); Add = async(int in1, int in2) => { var inputs = new ValueSet(); inputs.Set(input1, in1); inputs.Set(input2, in2); var result = await add.Run(inputs); ValueSet outputs = result.Outputs; return(outputs.Get(output)); }; } SystemProcess subtract; { var input1 = new Parameter <int>("value 1", integer); var input2 = new Parameter <int>("value 2", integer); var output = new Parameter <int>("result", integer); subtract = new SystemProcess( "Subtract", "Subtracts one integer from another", (ValueSet inputs) => { int value1 = inputs.Get(input1); int value2 = inputs.Get(input2); var outputs = new ValueSet(); outputs.Set(output, value1 - value2); return(new ProcessResult(outputs)); }, new Parameter[] { input1, input2 }, new Parameter[] { output }, null ); Subtract = async(int in1, int in2) => { var inputs = new ValueSet(); inputs.Set(input1, in1); inputs.Set(input2, in2); var result = await subtract.Run(inputs); ValueSet outputs = result.Outputs; return(outputs.Get(output)); }; } SystemProcess multiply; { var input1 = new Parameter <int>("value 1", integer); var input2 = new Parameter <int>("value 2", integer); var output = new Parameter <int>("result", integer); multiply = new SystemProcess( "Multiply", "Multiplies two integers", (ValueSet inputs) => { int value1 = inputs.Get(input1); int value2 = inputs.Get(input2); var outputs = new ValueSet(); outputs.Set(output, value1 * value2); return(new ProcessResult(outputs)); }, new Parameter[] { input1, input2 }, new Parameter[] { output }, null ); Multiply = async(int in1, int in2) => { var inputs = new ValueSet(); inputs.Set(input1, in1); inputs.Set(input2, in2); var result = await multiply.Run(inputs); ValueSet outputs = result.Outputs; return(outputs.Get(output)); }; } SystemProcess compare; { var input1 = new Parameter <int>("value 1", integer); var input2 = new Parameter <int>("value 2", integer); compare = new SystemProcess( "Compare", "Compare two integers", (ValueSet inputs) => { int value1 = inputs.Get(input1); int value2 = inputs.Get(input2); var comparison = value1.CompareTo(value2); return(new ProcessResult(comparison < 0 ? "less" : comparison > 0 ? "greater" : "equal")); }, new Parameter[] { input1, input2 }, null, new string[] { "less", "greater", "equal" } ); Compare = async(int in1, int in2) => { var inputs = new ValueSet(); inputs.Set(input1, in1); inputs.Set(input2, in2); var result = await compare.Run(inputs); return(result.ReturnPath); }; } RequiredProcess modifyNumber; { var input = new Parameter <int>("value", integer); var output = new Parameter <int>("result", integer); modifyNumber = new RequiredProcess( "Modify number", "Perform some operation(s) on a number", new Parameter[] { input }, new Parameter[] { output }, null ); ModifyNumber = async(int in1) => { var inputs = new ValueSet(); inputs.Set(input, in1); var result = await modifyNumber.Run(inputs); ValueSet outputs = result.Outputs; return(outputs.Get(output)); }; } Types = new DataType[] { integer }; SystemProcesses = new SystemProcess[] { add, subtract, multiply, compare }; RequiredProcesses = new RequiredProcess[] { modifyNumber }; }
// Module defining this command // Optional custom code for this activity /// <summary> /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run. /// </summary> /// <param name="context">The NativeActivityContext for the currently running activity.</param> /// <returns>A populated instance of System.Management.Automation.PowerShell</returns> /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks> protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context) { System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create(); System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName); // Initialize the arguments if (ApplicationName.Expression != null) { targetCommand.AddParameter("ApplicationName", ApplicationName.Get(context)); } if ((ComputerName.Expression != null) && (PSRemotingBehavior.Get(context) != RemotingBehavior.Custom)) { targetCommand.AddParameter("ComputerName", ComputerName.Get(context)); } if (ConnectionURI.Expression != null) { targetCommand.AddParameter("ConnectionURI", ConnectionURI.Get(context)); } if (Dialect.Expression != null) { targetCommand.AddParameter("Dialect", Dialect.Get(context)); } if (FilePath.Expression != null) { targetCommand.AddParameter("FilePath", FilePath.Get(context)); } if (Fragment.Expression != null) { targetCommand.AddParameter("Fragment", Fragment.Get(context)); } if (OptionSet.Expression != null) { targetCommand.AddParameter("OptionSet", OptionSet.Get(context)); } if (Port.Expression != null) { targetCommand.AddParameter("Port", Port.Get(context)); } if (ResourceURI.Expression != null) { targetCommand.AddParameter("ResourceURI", ResourceURI.Get(context)); } if (SelectorSet.Expression != null) { targetCommand.AddParameter("SelectorSet", SelectorSet.Get(context)); } if (SessionOption.Expression != null) { targetCommand.AddParameter("SessionOption", SessionOption.Get(context)); } if (UseSSL.Expression != null) { targetCommand.AddParameter("UseSSL", UseSSL.Get(context)); } if (ValueSet.Expression != null) { targetCommand.AddParameter("ValueSet", ValueSet.Get(context)); } if (Credential.Expression != null) { targetCommand.AddParameter("Credential", Credential.Get(context)); } if (Authentication.Expression != null) { targetCommand.AddParameter("Authentication", Authentication.Get(context)); } if (CertificateThumbprint.Expression != null) { targetCommand.AddParameter("CertificateThumbprint", CertificateThumbprint.Get(context)); } if (GetIsComputerNameSpecified(context) && (PSRemotingBehavior.Get(context) == RemotingBehavior.Custom)) { targetCommand.AddParameter("ComputerName", PSComputerName.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
public bool ContainsKey(string key) { return(GetSync(() => ValueSet.Get(this, key) != null)); }
public object Execute(GetPersonIdByNameQuery query) { var personName = _peopleByName.Get(query.PersonName, () => null); return(personName == null ? null : personName.OwnerId); }