Ejemplo n.º 1
0
 public void RegisterScalarType(Type type)
 {
     if (!ScalarTypes.Contains(type))
     {
         ScalarTypes.Add(type);
     }
 }
Ejemplo n.º 2
0
        protected override void EndProcessing()
        {
            object SendObj  = null;
            bool   isScalar = false;
            List <System.Management.Automation.TableControlColumn> TableColl = null;

            base.EndProcessing();
            if (FullList.Count == 0)
            {
                return; //nothing to do.
            }
            ////////////////////////////////////////////////////////////////
            // Generate objects for call

            if (ScalarTypes.Contains(FullList[0].TypeNames[0]))
            {
                isScalar = true;
                SendObj  = new DataTable();
                ((DataTable)SendObj).Columns.Add(FullList[0].TypeNames[0], FullList[0].BaseObject.GetType());
                foreach (PSObject Item in FullList)
                {
                    ((DataTable)SendObj).Rows.Add(Item);
                }
            }
            else if (HasObjectSpecialForammting(FullList[0], out SendObj, out TableColl))
            {
                foreach (PSObject Item in FullList)
                {
                    SessionState.PSVariable.Set("MyOutGridViewDataItem", Item);
                    object[] values = new object[((DataTable)SendObj).Columns.Count];
                    for (int i = 0; i < TableColl.Count; i++)
                    {
                        if (TableColl[i].DisplayEntry.ValueType == DisplayEntryValueType.Property)
                        {
                            if (Item.Properties[TableColl[i].DisplayEntry.Value] != null)
                            {
                                values[i] = Item.Properties[TableColl[i].DisplayEntry.Value].Value;
                            }
                        }
                        else
                        {
                            Collection <PSObject> results = base.InvokeCommand.InvokeScript("$MyOutGridViewDataItem | foreach-object -process { " + TableColl[i].DisplayEntry.Value + " }");
                            if (results.Count > 0)
                            {
                                values[i] = results.First();
                            }
                        }
                    }

                    ((DataTable)SendObj).Rows.Add(values);
                }
            }
            else
            {
                SendObj = new ArrayList();
                ((ArrayList)SendObj).AddRange(FullList);  // XxX Verify - Might be FUllList.BaseObject
            }

            ////////////////////////////////////////////////////////////////

            // Display List
            SynchronizedInvoke.InvokeIfRequired(PSHostCallBack.ParentControl, () => PSHostCallBack.ParentControl.FinishedGridView(SendObj, FullList.Count,
                                                                                                                                  this.Wait || this.OutputMode != OutputModeOption.None, this.OutputMode == OutputModeOption.Multiple, !isScalar));


            if (!this.Wait && this.OutputMode == OutputModeOption.None)
            {
                return; // Done do not wait for output...
            }
            List <int> selectedItems = null;

            if (PSHostCallBack.ParentControl.WaitForResult(out selectedItems))
            {
                if (selectedItems != null && selectedItems.Count > 0 && this.OutputMode != OutputModeOption.None)
                {
                    Trace.TraceInformation("Out-GridView() Complete Count: {0}", selectedItems.Count);
                    foreach (int Row in selectedItems)
                    {
                        if (Row >= 0 && Row < FullList.Count)
                        {
                            base.WriteObject(FullList[Row]);
                        }
                    }
                }
            }

            // Cleanup
            base.StopProcessing();
            SynchronizedInvoke.InvokeIfRequired(PSHostCallBack.ParentControl, () => PSHostCallBack.ParentControl.EndGridView());
            FullList = null;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Check if the type is a supported scalar type.
 /// </summary>
 public static bool IsScalarType(Type type)
 {
     return(type.IsEnum || ScalarTypes.Contains(type));
 }