Ejemplo n.º 1
0
 public void RegisterScalarType(Type type)
 {
     if (!ScalarTypes.Contains(type))
     {
         ScalarTypes.Add(type);
     }
 }
Ejemplo n.º 2
0
 public Field(string name, ScalarTypes type, bool isRepeated, object value)
 {
     this.Name       = name;
     this.Type       = type;
     this.IsRepeated = isRepeated;
     this.Value      = value;
 }
Ejemplo n.º 3
0
        internal static void SerializeScalarType(Stream stream, object data, ScalarTypes fieldType, List <Tuple <long, string> > sectionProcessList, ref long offset)
        {
            switch (fieldType)
            {
            case ScalarTypes.Double:
            case ScalarTypes.Float:
                SerializeDouble(stream, (double)data);
                break;

            case ScalarTypes.Bool:
            case ScalarTypes.Int32:
            case ScalarTypes.UInt32:
            case ScalarTypes.Int64:
                SerializeInt64(stream, (long)data);
                break;

            case ScalarTypes.UInt64:
                SerializeUInt64(stream, (ulong)data);
                break;

            case ScalarTypes.String:
            {
                var comeBackPosition          = stream.Position;
                var beginningOfStringPosition = SerializeString(stream, (string)data, ref offset);
                stream.Position = comeBackPosition;
                SerializeInt64(stream, beginningOfStringPosition);
                break;
            }

            case ScalarTypes.Message:
                sectionProcessList.Add(new Tuple <long, string>(stream.Position, (string)data));
                SerializeInt64(stream, 0xDEADBEEF);
                break;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Registers a given SimplType into one of the relevant type registries.
        /// </summary>
        /// <param name="type">Type to register</param>
        /// <returns>True if it succeded, false if it was not registered, exception if an issue occurred or the type would not fit in a category.</returns>
        public static bool RegisterSimplType(SimplType type)
        {
            bool result = false;

            result |= ScalarTypes.TryAdd(type);
            result |= CollectionTypes.TryAdd(type);
            result |= CompositeTypes.TryAdd(type);
            result |= SimplTypes.TryAdd(type);

            return(result);
        }
Ejemplo n.º 5
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.º 6
0
        /// <summary>
        /// Initializes the types.
        /// </summary>
        private void InitializeTypes()
        {
            string[] scalarTypes =
            {
                "bool",
                "int",
                "half",
                "float",
                "double",
                "string", // Actually not a scalar type, but treated similarly.
            };
            foreach (string type in scalarTypes)
            {
                ScalarTypes.Add(new TypeCompletionData(type));
            }

            string[] types =
            {
                "bool1",     "bool2",     "bool3",     "bool4",
                "bool1x1",   "bool1x2",   "bool1x3",   "bool1x4",
                "bool2x1",   "bool2x2",   "bool2x3",   "bool2x4",
                "bool3x1",   "bool3x2",   "bool3x3",   "bool3x4",
                "bool4x1",   "bool4x2",   "bool4x3",   "bool4x4",
                "int1",      "int2",      "int3",      "int4",
                "int1x1",    "int1x2",    "int1x3",    "int1x4",
                "int2x1",    "int2x2",    "int2x3",    "int2x4",
                "int3x1",    "int3x2",    "int3x3",    "int3x4",
                "int4x1",    "int4x2",    "int4x3",    "int4x4",
                "half1",     "half2",     "half3",     "half4",
                "half1x1",   "half1x2",   "half1x3",   "half1x4",
                "half2x1",   "half2x2",   "half2x3",   "half2x4",
                "half3x1",   "half3x2",   "half3x3",   "half3x4",
                "half4x1",   "half4x2",   "half4x3",   "half4x4",
                "float1",    "float2",    "float3",    "float4",
                "float1x1",  "float1x2",  "float1x3",  "float1x4",
                "float2x1",  "float2x2",  "float2x3",  "float2x4",
                "float3x1",  "float3x2",  "float3x3",  "float3x4",
                "float4x1",  "float4x2",  "float4x3",  "float4x4",
                "double1",   "double2",   "double3",   "double4",
                "double1x1", "double1x2", "double1x3", "double1x4",
                "double2x1", "double2x2", "double2x3", "double2x4",
                "double3x1", "double3x2", "double3x3", "double3x4",
                "double4x1", "double4x2", "double4x3", "double4x4",
            };
            foreach (string type in types)
            {
                Types.Add(new TypeCompletionData(type));
            }

            string[] specialTypes =
            {
                "void",
                "sampler","sampler1D",  "sampler2D", "sampler3D", "samplerCUBE", "sampler_state",
                "struct",
            };
            foreach (string type in specialTypes)
            {
                SpecialTypes.Add(new TypeCompletionData(type));
            }

            string[] effectTypes =
            {
                "technique", "pass",
                "asm",
            };
            foreach (string type in effectTypes)
            {
                EffectTypes.Add(new TypeCompletionData(type));
            }
        }
Ejemplo n.º 7
0
        public static void AdvancedConcepts()
        {
            ScalarTypes scalarType       = Helper.FillObject <ScalarTypes>();
            var         scalarTypeEncode = Helper.Encode(scalarType);
            var         scalarTypeDecode = Helper.Decode(scalarTypeEncode, ScalarTypes.Parser);

            Assert.IsTrue(Helper.CompareObjects(scalarType, scalarTypeDecode));

            ComplexTypes complexType = Helper.FillObject <ComplexTypes>();

            complexType.Maps.Add(1, "Suresh");
            complexType.Numbers.Add(10);
            complexType.Details = Any.Pack(Helper.FillObject <Person>());
            var complexTypeEncode = Helper.Encode(complexType);
            var complexTypeDecode = Helper.Decode(complexTypeEncode, ComplexTypes.Parser);

            Assert.IsTrue(Helper.CompareObjects(complexType, complexTypeDecode));

            if (complexTypeDecode.Details.Is(Person.Descriptor))
            {
                complexTypeDecode.Details.TryUnpack(out Person person);
            }
            var oneOfCase = complexTypeDecode.OneofCase;    //returns the name of the field that is set

            NullableTypes nullableType       = Helper.FillObject <NullableTypes>();
            var           nullableTypeEncode = Helper.Encode(nullableType);
            var           nullableTypeDecode = Helper.Decode(nullableTypeEncode, NullableTypes.Parser);

            Assert.IsTrue(Helper.CompareObjects(nullableType, nullableTypeDecode));

            TimeTypes timeType       = Helper.FillObject <TimeTypes>();
            var       timeTypeEncode = Helper.Encode(timeType);
            var       timeTypeDecode = Helper.Decode(timeTypeEncode, TimeTypes.Parser);

            Assert.IsTrue(Helper.CompareObjects(timeType, timeTypeDecode));


            //Write a collections
            List <ScalarTypes> sts = new List <ScalarTypes>();

            sts.Add(Helper.FillObject <ScalarTypes>());
            sts.Add(Helper.FillObject <ScalarTypes>());

            MemoryStream ipStream = new MemoryStream();

            foreach (var st in sts)
            {
                st.WriteDelimitedTo(ipStream);
            }

            using (var file = File.Create("data.bin"))
                file.Write(ipStream.ToArray());
            ipStream.Close();

            List <ScalarTypes> stsDecoded = new List <ScalarTypes>();

            using (var stream = File.OpenRead("data.bin"))
            {
                while (stream.Position < stream.Length)
                {
                    var sto = ScalarTypes.Parser.ParseDelimitedFrom(stream);
                    stsDecoded.Add(sto);
                }
            }
            Assert.IsTrue(Helper.CompareObjects(sts, stsDecoded));
        }
Ejemplo n.º 8
0
        internal static long SerializePrimitiveTypeList(Stream stream, ScalarTypes fieldType, object data, List <Tuple <long, string> > sectionProcessList, ref long offset)
        {
            var beginningOfListPosition = offset;

            stream.Position = offset;

            switch (fieldType)
            {
            case ScalarTypes.Bool:
            case ScalarTypes.Int32:
            case ScalarTypes.UInt32:
            case ScalarTypes.Int64:
            {
                var list = (List <long>)data;
                SerializeInt64(stream, list.Count);

                foreach (var t in list)
                {
                    SerializeInt64(stream, t);
                }

                break;
            }

            case ScalarTypes.UInt64:
            {
                var list = (List <ulong>)data;
                SerializeInt64(stream, list.Count);

                foreach (var t in list)
                {
                    SerializeUInt64(stream, t);
                }

                break;
            }

            case ScalarTypes.Float:
            case ScalarTypes.Double:
            {
                var list = (List <double>)data;
                SerializeInt64(stream, list.Count);

                foreach (var t in list)
                {
                    SerializeDouble(stream, t);
                }

                break;
            }

            case ScalarTypes.String:
            {
                var list = (List <string>)data;

                var count = list.Count;

                SerializeInt64(stream, count);
                var comeBackPosition = stream.Position;

                offset = stream.Position + count * 8;

                var rvaList = new List <long>(count);

                foreach (var t in list)
                {
                    rvaList.Add(offset);
                    offset += SerializeStringBulk(stream, t);
                }

                stream.Position = comeBackPosition;

                foreach (var t in rvaList)
                {
                    SerializeInt64(stream, t);
                }

                break;
            }

            case ScalarTypes.Message:
            {
                var list = (List <string>)data;
                SerializeInt64(stream, list.Count);

                foreach (var t in list)
                {
                    sectionProcessList.Add(new Tuple <long, string>(stream.Position, t));
                    SerializeInt64(stream, 0xDEADBEEF);
                }

                break;
            }
            }

            offset = stream.Position;
            return(beginningOfListPosition);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Check if the type is a supported scalar type.
 /// </summary>
 public static bool IsScalarType(Type type)
 {
     return(type.IsEnum || ScalarTypes.Contains(type));
 }