Example #1
0
        public static void Main(string[] args)
        {
            XmlConfigurator.Configure(new FileInfo("./log.xml"));
            ILog log = LogManager.GetLogger(typeof(QMFExample)) ;
            log.Debug("Starting") ;
            Console myConsole = new qmf.example.Console() ;
            Session session = new Session(myConsole) ;
            session.AddBroker("amqp://localhost") ;

            Dictionary<string, object> options = new Dictionary<string, object>() ;
            options.Add("_class", "ExampleService") ;
            options.Add("_package", "qmf.example.ejb") ;
            ExampleService service = (ExampleService) session.GetObjects(options)[0] ;

            BaseClass baseObject = service.GetBase("Nathan", "A Cool Dude") ;
            System.Console.WriteLine(String.Format( "Base: {0}", baseObject));
            System.Console.WriteLine(String.Format( "Base.name: {0}", baseObject.Name));
            System.Console.WriteLine(String.Format( "Base.description: {0}", baseObject.Description));
            System.Console.WriteLine(String.Format( "Base.stuff: {0}", baseObject.Stuff));

            DerivedClass derivedObject = service.GetDerived("Gillian", "A Cool Dudette", 99) ;
            System.Console.WriteLine(String.Format( "Derived: {0}", derivedObject));
            System.Console.WriteLine(String.Format( "Derived.name: {0}", derivedObject.Name));
            System.Console.WriteLine(String.Format( "Derived.description: {0}", derivedObject.Description));
            System.Console.WriteLine(String.Format( "Derived.stuff: {0}", derivedObject.Stuff));
            System.Console.WriteLine(String.Format( "Derived.count: {0}", derivedObject.Count));

            List<object> many = (List<Object>) service.FindMany() ;
            System.Console.WriteLine("Many: {0}", many) ;
            System.Console.WriteLine("Many.stuff: {0}", ((BaseClass)many[0]).Stuff) ;

            string[] packages = {"qmf.example", "qmf.example.ejb"} ;
            System.Console.WriteLine(XMLUtil.SchemaXML(session, packages)) ;
            session.Close() ;
        }
Example #2
0
		public QMFEvent(Session session, IDecoder dec)
		{
			Session = session ;
			ClassKey = new ClassKey(dec) ;
			Timestamp = dec.ReadInt64() ;
			Severity = (EventSeverity) dec.ReadUint8() ;
			SchemaClass sClass = Session.GetSchema(ClassKey) ;
			Arguments = new Dictionary<string, object>() ;
			
			if (sClass != null) {
				foreach (SchemaArgument arg in sClass.Arguments) {
					Arguments[arg.Name] = Session.DecodeValue(dec, arg.Type) ;	
				}
			}	
		}
Example #3
0
		public static string SchemaXML(Session sess, string packageName) {
			string returnValue = String.Format("<schema package='{0}'>\n", packageName) ;
			foreach (ClassKey key in sess.GetClasses(packageName)) {
				SchemaClass schema = sess.GetSchema(key) ;
				if (schema.Kind == 1) {
					if (schema.SuperType == null)
						returnValue += String.Format("\t<class name='{0}' hash='{1}'>\n", key.ClassName, key.GetHashString()) ;
                    else 
                    	returnValue += String.Format("\t<class name='{0}' hash='{1}' extends='{2}'>\n", key.ClassName, key.GetHashString(), schema.SuperType.GetKeyString()) ;						
					foreach (SchemaProperty prop in schema.Properties) {
						object[] attributes = new object[5] ;
						attributes[0] = prop.Name ;
						attributes[1] = Util.TypeName(prop.Type) ;
						attributes[2] = Util.AccessName(prop.Access) ;
						attributes[3] = prop.Optional ;
						attributes[4] = XMLUtil.CommonAttributes(prop);
						returnValue += String.Format("\t\t<property name='{0}' type='{1}' access='{2}' optional='{3}'{4}/>\n", attributes) ;
					}
					foreach (SchemaMethod meth in schema.Methods) {
						returnValue += String.Format("\t\t<method name='{0}'/>\n", meth.Name) ;	
						foreach (SchemaArgument arg in meth.Arguments) {
							object[] attributes = new object[4] ;					
							attributes[0] = arg.Name ;
							attributes[1] = arg.Direction ;
							attributes[2] = Util.TypeName(arg.Type) ;
							attributes[3] = XMLUtil.CommonAttributes(arg);					
							returnValue += String.Format("\t\t\t<arg name='{0}' dir='{1}' type='{2}'{3}/>\n", attributes) ;
						}
						returnValue += String.Format("\t\t</method>\n") ;
					}
					returnValue += String.Format("\t</class>\n") ;				
				} else {
					returnValue += String.Format("\t<event name='{0}' hash='{1}'>\n", key.ClassName, key.GetHashString()) ;	
					foreach (SchemaArgument arg in schema.Arguments) {
						object[] attributes = new object[4] ;					
						attributes[0] = arg.Name ;
						attributes[1] = Util.TypeName(arg.Type) ;
						attributes[2] = XMLUtil.CommonAttributes(arg);					
						returnValue += String.Format("\t\t\t<arg name='{0}' type='{1}'{2}/>\n", attributes) ;
					}
					returnValue += String.Format("\t</event>\n") ;
				}
			}
			returnValue += String.Format("</schema>\n") ;		
			
			return returnValue ;
		}		
Example #4
0
 		// This constructor is used by a session make object call to 
 		// create a blank object from a schema.
 		public QMFObject(Session session, SchemaClass schema, bool hasProperties, bool hasStats , bool isManaged) {
			Session = session ;
			Schema = schema ;
			Managed = isManaged ; 
			
			if (hasProperties) {
				foreach (SchemaProperty prop in Schema.GetAllProperties()) {
					object propValue = null ; 
					if (!prop.Optional) {
						propValue = Util.DefaultValue(prop.Type) ;
					}
					this.SetProperty(prop.Name, propValue) ;			
				}
			}	
			
			if (hasStats) {
				foreach (SchemaStatistic stat in Schema.Statistics)  {			
					SetStatistic(stat.Name, Util.DefaultValue(stat.Type)) ;
				}
			}															
 		}
Example #5
0
 public DerivedClass(Session session, SchemaClass schema, Decoder dec, bool hasProperties, bool hasStats , bool isManaged)
     : base(session, schema, dec, hasProperties, hasStats, isManaged)
 {
 }
Example #6
0
 		// This constructor is used by the session to create an object based on a data 
 		// stream by the agent.
		public QMFObject(Session session, SchemaClass schema, IDecoder dec, bool hasProperties, bool hasStats , bool isManaged)
		{
			Session = session ;
			Schema = schema ;
			Managed = isManaged ;
			
			if (Managed) {
			    // FIXME DateTime or Uint64??
				CurrentTime = new DateTime(dec.ReadDatetime()) ;
				CreateTime = new DateTime(dec.ReadDatetime()) ;				
				DeleteTime = new DateTime(dec.ReadDatetime()) ;				
				ObjectID = new ObjectID(dec) ;
			}
			
			if (hasProperties) {
				List<string> excluded = ProcessPresenceMasks(dec, Schema) ;
				
				foreach (SchemaProperty prop in Schema.GetAllProperties()) {
					if (excluded.Contains(prop.Name)) {
					    log.Debug(String.Format("Setting Property Default {0}", prop.Name)) ;					    					
						safeAddProperty(prop.Name, null) ;	
					} else {
						//log.Debug(String.Format("Setting Property {0}", prop.Name)) ;
						safeAddProperty(prop.Name, session.DecodeValue(dec, prop.Type)) ;
					}
				}
			}
			
			if (hasStats) {
				foreach (SchemaStatistic stat in Schema.GetAllStatistics())  {
					//log.Debug(String.Format("Setting Statistic {0}", stat.Name)) ;				
					Statistics.Add(stat.Name, session.DecodeValue(dec, stat.Type)) ;
				}
			}
			
		}
Example #7
0
 public BaseClass(Session session, SchemaClass schema, bool hasProperties, bool hasStats , bool isManaged)
     : base(session, schema, hasProperties, hasStats, isManaged)
 {
 }
Example #8
0
		public static string SchemaXML(Session sess, string[] packageNames) {
			string returnValue = "<schemas>\n" ;
			foreach (string package in packageNames) {
				returnValue += XMLUtil.SchemaXML(sess, package) ;
				returnValue += "\n" ;
			}
			returnValue += "</schemas>\n" ;
			return returnValue ;
		}
Example #9
0
 public ExampleService(Session session, SchemaClass schema, Decoder dec, bool hasProperties, bool hasStats , bool isManaged)
     : base(session, schema, dec, hasProperties, hasStats, isManaged)
 {
 }