'enum' in Jetfire

This example demonstrates working with the 'Enum' class in Jetfire.

Note: This example can be found in 'JetfireCoreExampleTests' project, which is part of the release download (V1.0.4 or higher).

Jetfire Code
string jetfireCode =
            @"namespace test 
             {
                  public enum FlowerType
                  {
                    Carnation, 
                    Rose, 
                    Daisy 
                  }
                 public workflow FavoriteExample
                 { 
                    // declare and initialize the 'flower' field.
                    FlowerType flower = FlowerType.Carnation; 
                    //
                    // Gets and sets the 'favorite' flower.
                    //
                    public FlowerType FavoriteFlower
                    {
                       get{return this.flower;}
                       set{this.flower = value;}
                    }
                    //
                    // Constructor
                    //
                    public FavoriteExample()
                    {
                    }
                 }
              }";


C# Test Code
#region EnumPropertySet
        /// <summary>
        /// This example demonstrates working with the
        /// 'Enum' class in Jetfire.
        /// 
        /// </summary>
        [TestMethod]
        public void EnumPropertySet()
        {
            LinqStartObjects start = JetfireTest.NewNexusServer(
              "Key",                              // The name of the memory based storage.
              TjServerStorageType.MemoryLinq,
              TjStorageCommand.ClearStorage       // deletes any existing objects from storage
              );
            TjNexus nexus = start.ClientNexus;
            //
            //  Parse source code and create the Jetfire executable code expressions, 
            //  get the workflow class 'FavoriteExample',
            //  then instantiate a new workflow object which sets the favorite flower 
            //  to "Carnation".
            //
            nexus.ParseServer(jetfireCode);
            TjWorkflowClass flowClass = nexus.FindClass<TjWorkflowClass>("test", "FavoriteExample");
            TjWorkflow favouriteExample = flowClass.NewWorkflowServer();  // create a workflow.
            //
            // Get from the property 'FavoriteFlower'.
            //
            TjEnumerator flower = favouriteExample.Get<TjEnumerator>("FavoriteFlower");
            Assert.AreEqual("Carnation", flower.Name);
            //
            //  Get Enumerator for the flower 'Daisy'
            //
            TjEnumClass enumClass = nexus.FindClass<TjEnumClass>("test", "FlowerType");
            TjEnumerator daisy = enumClass.GetMember<TjEnumerator>("Daisy");
            Assert.AreEqual("Daisy", daisy.Name);
            //
            //  Set the 'FavoriteFlower' to 'Daisy'
            //
            favouriteExample.Set("FavoriteFlower", daisy);
            flower = favouriteExample.Get<TjEnumerator>("FavoriteFlower");
            Assert.AreEqual("Daisy", flower.Name);
            
            Assert.AreEqual(0, nexus.ToIncidentArray().Length);
            start.Transport.Dispose();
           

        }
        #endregion

Last edited Jan 23, 2009 at 10:14 PM by JohnHansen, version 3

Comments

No comments yet.