Ejemplo n.º 1
0
        // 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 Sytem.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 (Name.Expression != null)
            {
                targetCommand.AddParameter("Name", Name.Get(context));
            }

            if (FullyQualifiedName.Expression != null)
            {
                targetCommand.AddParameter("FullyQualifiedName", FullyQualifiedName.Get(context));
            }

            if (All.Expression != null)
            {
                targetCommand.AddParameter("All", All.Get(context));
            }

            if (ListAvailable.Expression != null)
            {
                targetCommand.AddParameter("ListAvailable", ListAvailable.Get(context));
            }

            if (Refresh.Expression != null)
            {
                targetCommand.AddParameter("Refresh", Refresh.Get(context));
            }

            if (PSSession.Expression != null)
            {
                targetCommand.AddParameter("PSSession", PSSession.Get(context));
            }

            if (CimSession.Expression != null)
            {
                targetCommand.AddParameter("CimSession", CimSession.Get(context));
            }

            if (CimResourceUri.Expression != null)
            {
                targetCommand.AddParameter("CimResourceUri", CimResourceUri.Get(context));
            }

            if (CimNamespace.Expression != null)
            {
                targetCommand.AddParameter("CimNamespace", CimNamespace.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
Ejemplo n.º 2
0
        protected override void EndProcessing()
        {
            base.EndProcessing();

            if (ListAvailable.ToBool())
            {
                if (Extended.ToBool())
                {
                    FontFamily.PseudoMonoSpaced = true;
                    WriteObject(FontFamily.Monospaced.Where(f => f.FontType != FontType.PostScript && f.Name.Length <= 32), true);
                }
                else
                {
                    WriteObject(FontFamily.Console, true);
                }
            }
            else if (string.IsNullOrEmpty(Name))
            {
                ConsoleFont info = new ConsoleFont
                {
                    cbSize = Marshal.SizeOf <ConsoleFont>()
                };

                // First determine whether there's already a TrueType font.
                if (GetCurrentConsoleFontEx(ConsoleOutputHandle, true, ref info))
                {
                    var ff = FontFamily.All.FirstOrDefault(f => f.Name == info.FontName);

                    if (null != ff)
                    {
                        var result = new PSObject(ff);
                        result.Properties.Add(new PSNoteProperty("Size", info.FontWidth + "x" + info.FontSize));
                        result.Properties.Add(new PSNoteProperty("Weight", info.FontWeight));

                        WriteObject(result);
                    }
                    else
                    {
                        WriteObject(info);
                    }
                }
                else
                {
                    var er = Marshal.GetLastWin32Error();
                    throw new System.ComponentModel.Win32Exception(er, "Error getting the console font");
                }
            }
            else
            {
                var pattern = WildcardPattern.Get(Name, WildcardOptions.Compiled & WildcardOptions.CultureInvariant & WildcardOptions.IgnoreCase);
                WriteObject(FontFamily.All.Where(f => pattern.IsMatch(f.Name)), true);
            }
        }
Ejemplo n.º 3
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (ListAvailable.SelectedIndex != -1)
     {
         int I = ListAvailable.SelectedIndex;
         ListSelect.Items.Add(ListAvailable.SelectedItem.ToString());
         ListAvailable.Items.RemoveAt(I);
         ListAvailable.Focus();
         if (ListAvailable.Items.Count > 0)
         {
             if (I < ListAvailable.Items.Count)
             {
                 ListAvailable.SetSelected(I, true);
             }
             else
             {
                 ListAvailable.SetSelected(0, true);
             }
         }
     }
 }
Ejemplo n.º 4
0
        public ListViewAssociation(bool simple = true)
        {
            if (simple)
            {
                listViewFilter = new ListBoxFilter <T> {
                    List          = new List <T> (),
                    MinHeight     = 200,
                    MinWidth      = 300,
                    SelectionMode = selectionMode,
                };
            }
            else
            {
                listViewFilter = new ListView <T> {
                    List          = new List <T> (),
                    MinHeight     = 200,
                    MinWidth      = 600,
                    SelectionMode = selectionMode,
                };
            }

            add.Clicked += delegate {
                var dialogo = new Dialog {
                    Title = string.Format(Application.TranslationCatalog.GetString("Add {0}"), Title),
                };

                if (simple)
                {
                    listViewFilter = new ListBoxFilter <T> {
                        List          = new List <T> (),
                        MinHeight     = 200,
                        MinWidth      = 300,
                        SelectionMode = selectionMode,
                    };
                }
                else
                {
                    var listViewSelector = new ListView <T> {
                        List          = new List <T> (),
                        MinHeight     = 200,
                        MinWidth      = 600,
                        SelectionMode = selectionMode,
                    };
                    listViewSelector.RemoveColumnAt(columnsRemoved);
                    listViewFilter = listViewSelector;
                }

                dialogo.Buttons.Add(Command.Cancel, Command.Add);

                listViewFilter.List = ListAvailable.Except(List).ToList();

                var box = new HBox();
                box.PackStart((Widget)listViewFilter, true, true);
                dialogo.Content = box;
                if (dialogo.Run() == Command.Add)
                {
                    //TODO permitir multiseleccion para poder agregar de a mas de un elemento a la vez
                    if (listViewFilter.SelectedItems.Count == 0)
                    {
                        MessageDialog.ShowWarning(Application.TranslationCatalog.GetString("Must select a item."));
                    }
                    else
                    {
                        foreach (var item in listViewFilter.SelectedItems)
                        {
                            if (OnSimilarity(List, item))
                            {
                                MessageDialog.ShowWarning(Application.TranslationCatalog.GetString("A validation rule prevents adding this item."));
                            }
                            else
                            {
                                if (AddItem != null)
                                {
                                    OnAddItem(item);
                                }
                                else
                                {
                                    listView.Add(item);
                                }
                            }
                        }
                        OnChanged();
                    }
                }

                box.Remove((Widget)listViewFilter);
                dialogo.Close();
            };

            remove.Clicked += delegate {
                //TODO ver como resolver que se puedan remover multiples items a la vez
                var row = listView.SelectedRow;
                if (row == -1)
                {
                    MessageDialog.ShowMessage(string.Format(Application.TranslationCatalog.GetString("Select a {0} to remove"), TypeName()));
                }
                else
                {
                    if (OnPreventRemove(listView.SelectedItem))
                    {
                        MessageDialog.ShowWarning(Application.TranslationCatalog.GetString("A validation rule prevents you from deleting the selected item"));
                    }
                    else
                    {
                        OnRemoveItem(listView.SelectedItem);
                        listView.Remove();
                        OnChanged();
                    }
                }
            };

            actions.PackStart(add);
            actions.PackStart(remove);
            PackStart(listView, true, true);
            PackEnd(actions, false, true);
        }