public void TestObjectTypesWithSpace()
        {
            Assert.AreEqual("{Boolean:b,Int32:i}", typeof(TestClasses.BooleanAndInt).SosTypeDefinition());

            String [] definitions = new String[] {
                "{Boolean:b,Int32:i}",
                "{    Boolean:b,Int32:i}",
                "{    Boolean   :b,Int32:i}",
                "{    Boolean   :    b,Int32:i}",
                "{    Boolean   :    b    ,Int32:i}",
                "{    Boolean   :    b    ,    Int32:i}",
                "{    Boolean   :    b    ,    Int32    :i}",
                "{    Boolean   :    b    ,    Int32    :    i}",
                "{    Boolean   :    b    ,    Int32    :    i     }",
                "{    Boolean   :    b    ,    Int32    :    i     }  ",
            };

            SosObjectDefinition objectDefinition = new SosObjectDefinition(
                "Boolean", "b",
                "Int32", "i");

            for (int i = 0; i < definitions.Length; i++)
            {
                String definition = definitions[i];
                Console.WriteLine(definition);
                Assert.AreEqual(objectDefinition, SosTypes.ParseSosObjectTypeDefinition(definition, 0));
            }
        }
 public void TestFailedObjectDefinitionVerification(Type type, String incorrectTypeDefinitino)
 {
     try
     {
         SosTypes.ParseSosObjectTypeDefinition(incorrectTypeDefinitino, 0).VerifyType(type);
         Assert.Fail("Expected InvalidOperationException");
     }
     catch (InvalidOperationException e)
     {
         Console.WriteLine(e.Message);
     }
 }
        public void TestObjectDefinitionVerification()
        {
            Type[] objectTypes = new Type[] {
                typeof(Object),
            };

            for (int i = 0; i < objectTypes.Length; i++)
            {
                Type objectType = objectTypes[i];

                String typeDefinition = objectType.SosTypeDefinition();
                Console.WriteLine("Verifying " + typeDefinition);
                Assert.AreEqual(objectType,
                                SosTypes.ParseSosObjectTypeDefinition(typeDefinition, 0).GetAndVerifyType(objectType.FullName));
            }
        }
Esempio n. 4
0
        public void UpdateAndVerifyEnumAndObjectTypes(NpcVerifyCriteria criteria)
        {
            if (threadSafe)
            {
                Monitor.Enter(serverEndPoint);
            }
            try
            {
                //
                // The reason for the retry logic is because if the underlying socket is disconnected, it may not
                // fail until after a send and a receive...so the socket should be reconnected and the request should
                // be repeated only once.
                //
                for (UInt32 attempt = 0; ; attempt++)
                {
                    try
                    {
                        Connect();
                        socketLineReader.socket.Send(Encoding.UTF8.GetBytes(":type\n"));

                        enumAndObjectTypes.Clear();

                        while (true)
                        {
                            String typeDefinitionLine = socketLineReader.ReadLine();
                            if (typeDefinitionLine == null)
                            {
                                if (attempt == 0)
                                {
                                    Dispose();
                                    continue; // Retry
                                }
                                throw UnexpectedClose();
                            }
                            if (typeDefinitionLine.Length == 0)
                            {
                                break;                                 // empty line
                            }
                            Int32  spaceIndex     = typeDefinitionLine.IndexOf(' ');
                            String sosTypeName    = typeDefinitionLine.Remove(spaceIndex);
                            String typeDefinition = typeDefinitionLine.Substring(spaceIndex + 1);

                            Type type = GetTypeFromSosTypeName(sosTypeName);
                            if (typeDefinition.StartsWith("Enum"))
                            {
                                SosEnumDefinition enumDefinition = SosTypes.ParseSosEnumTypeDefinition(typeDefinition, 4);
                                enumDefinition.VerifyType(type, (SosVerifyCriteria)criteria);
                            }
                            else
                            {
                                SosObjectDefinition objectDefinition = SosTypes.ParseSosObjectTypeDefinition(typeDefinition, 0);
                                objectDefinition.VerifyType(type);
                            }
                            enumAndObjectTypes.Add(type);
                        }
                        return;
                    }
                    catch (SocketException)
                    {
                        if (socketLineReader != null)
                        {
                            socketLineReader.Dispose();
                            socketLineReader = null;
                        }
                        if (attempt == 0)
                        {
                            continue; // Retry
                        }
                        throw;
                    }
                }
            }
            finally
            {
                if (threadSafe)
                {
                    Monitor.Exit(serverEndPoint);
                }
            }
        }