private void HandleLoadedScenario(Scenarios.Action a)
        {
            bool isLoop = a.repetitions > 1 || a.repetitions < 0;

            if (isLoop) //Start of loop
            {
                Scenarios.RepeatStartMarker startMark = new Sate.Scenarios.RepeatStartMarker(a.repetitions);
                this.reclistBox.Items.Add(startMark);
            }

            if (a.action == Scenarios.DobAction.Sequence)
            {
                for (int i = 0; i < a.sequence.Length; i++)
                {
                    HandleLoadedScenario(a.sequence[i]);
                }
            }
            else
            {
                this.reclistBox.Items.Add(a);
            }

            if (isLoop) //End of loop
            {
                Scenarios.RepeatStopMarker stopMark = new Sate.Scenarios.RepeatStopMarker();
                this.reclistBox.Items.Add(stopMark);
            }


            if (a.xmlObject != null)
            {
                try
                {
                    a.objInfo.Obj = Safir.Dob.Typesystem.Serialization.ToObject(a.xmlObject);
                    //long typeId = a.objInfo.Obj.GetTypeId();
                    //string className = Safir.Dob.Typesystem.Operations.GetName(typeId);
                    //System.Type dobType = MainForm.Instance.DotsGenerated.GetType(className);
                    //System.Reflection.ConstructorInfo constr =
                    //    dobType.GetConstructor(new System.Type[] { typeof(Safir.Dob.Typesystem.Object) });
                    //System.Reflection.ConstructorInfo constr = dobType.GetConstructor(System.Type.EmptyTypes);
                    //a.obj = (Safir.Dob.Typesystem.Object)constr.Invoke(new object[] { a.obj });
                    //      a.numberOfInstances = Safir.Dob.Typesystem.Operations.GetMaxNumberOfInstances(typeId);
                }
                catch (Safir.Dob.Typesystem.IllegalValueException e)
                {
                    MessageBox.Show("Failed to load serialized object:\n\n" + a.xmlObject, "Serialization Error: " + e.Message);
                }
            }
        }
        private void repeatmenuItem_Click(object sender, System.EventArgs e)
        {
            if (this.reclistBox.SelectedIndices.Count > 0)
            {
                RepeatForm rf = new RepeatForm(10);
                rf.ShowDialog();
                int start = this.reclistBox.SelectedIndices[0];
                int stop  = this.reclistBox.SelectedIndices[this.reclistBox.SelectedIndices.Count - 1];

                Scenarios.RepeatStartMarker startMark = new Sate.Scenarios.RepeatStartMarker(rf.Repetitions);
                Scenarios.RepeatStopMarker  stopMark  = new Sate.Scenarios.RepeatStopMarker();

                this.reclistBox.Items.Insert(start, startMark);
                this.reclistBox.Items.Insert(stop + 2, stopMark);

                BuildScenario();
            }
        }