public void RecordSessionOfVM()
 {
     try
     {
         _service = ecb.getConnection().Service;
         _sic = ecb.getConnection().ServiceContent;
         ArrayList supportedVersions = VersionUtil.getSupportedVersions(ecb.get_option("url"));
         ManagedObjectReference vmmor = ecb.getServiceUtil().GetDecendentMoRef(null, "VirtualMachine", ecb.get_option("vmname"));
         if (vmmor == null)
         {
             Console.WriteLine("Unable to find VirtualMachine named : " + ecb.get_option("vmname") + " in Inventory");
         }
         if (VersionUtil.isApiVersionSupported(supportedVersions, "2.5"))
         {
             Boolean flag = VersionUtil.isApiVersionSupported(supportedVersions, "4.0");
             if (flag)
             {
                 if (ecb.get_option("snapshotname") == null || ecb.get_option("description") == null)
                 {
                     Console.WriteLine("snapshotname and description arguments are " +
                                       "mandatory for recording session feature");
                     return;
                 }
                 VirtualMachineFlagInfo flagInfo = new VirtualMachineFlagInfo();
                 flagInfo.recordReplayEnabled = true;
                 flagInfo.recordReplayEnabledSpecified = true;
                 VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
                 configSpec.flags = flagInfo;
                 _service.ReconfigVM_TaskAsync(vmmor, configSpec);
                 _service.StartRecording_TaskAsync(vmmor, ecb.get_option("snapshotname"), ecb.get_option("description"));
                 _service.StopRecording_TaskAsync(vmmor);
                 Console.WriteLine("Session recorded successfully");
             }
             else
             {
                 VirtualMachineSnapshotTree[] tree = (VirtualMachineSnapshotTree[])getObjectProperty(vmmor,
                                                      "snapshot.rootSnapshotList");
                 if (tree != null && tree.Length != 0)
                 {
                     ManagedObjectReference taskMor = _service.RemoveAllSnapshots_Task(vmmor, true, false);
                     object[] result = ecb.getServiceUtil().WaitForValues(taskMor, new string[] { "info.state", "info.result" },
                                       new string[] { "state" }, // info has a property - state for state of the task
                                       new object[][] { new object[] { TaskInfoState.success, TaskInfoState.error } }
                                       );
                     if (result[0].Equals(TaskInfoState.success))
                     {
                         Console.WriteLine("Removed all the snapshot successfully");
                     }
                 }
                 else
                 {
                     Console.WriteLine("No snapshot found for this virtual machine");
                 }
             }
         }
         else
         {
             VirtualMachineSnapshotTree[] tree = (VirtualMachineSnapshotTree[])getObjectProperty(vmmor,
                                                  "snapshot.rootSnapshotList");
             if (tree != null && tree.Length != 0)
             {
                 ManagedObjectReference taskMor = _service.RemoveAllSnapshots_Task(vmmor, true, false);
                 object[] result = ecb.getServiceUtil().WaitForValues(taskMor, new string[] { "info.state", "info.result" },
                                   new string[] { "state" }, // info has a property - state for state of the task
                                   new object[][] { new object[] { TaskInfoState.success, TaskInfoState.error } }
                                  );
                 if (result[0].Equals(TaskInfoState.success))
                 {
                     Console.WriteLine("Removed all the snapshot successfully");
                 }
             }
             else
             {
                 Console.WriteLine("No snapshot found for this virtual machine");
             }
         }
     }
     catch (Exception e)
     {
         ecb.log.LogLine("RecordSession : Failed Connect");
         throw e;
     }
     finally
     {
         ecb.log.LogLine("Ended RecordSession");
         ecb.log.Close();
     }
 }
 public void RecordSessionOfVM()
 {
     try
     {
         _service = ecb.getConnection().Service;
         _sic     = ecb.getConnection().ServiceContent;
         ArrayList supportedVersions  = VersionUtil.getSupportedVersions(ecb.get_option("url"));
         ManagedObjectReference vmmor = ecb.getServiceUtil().GetDecendentMoRef(null, "VirtualMachine", ecb.get_option("vmname"));
         if (vmmor == null)
         {
             Console.WriteLine("Unable to find VirtualMachine named : " + ecb.get_option("vmname") + " in Inventory");
         }
         if (VersionUtil.isApiVersionSupported(supportedVersions, "2.5"))
         {
             Boolean flag = VersionUtil.isApiVersionSupported(supportedVersions, "4.0");
             if (flag)
             {
                 if (ecb.get_option("snapshotname") == null || ecb.get_option("description") == null)
                 {
                     Console.WriteLine("snapshotname and description arguments are " +
                                       "mandatory for recording session feature");
                     return;
                 }
                 VirtualMachineFlagInfo flagInfo = new VirtualMachineFlagInfo();
                 flagInfo.recordReplayEnabled          = true;
                 flagInfo.recordReplayEnabledSpecified = true;
                 VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
                 configSpec.flags = flagInfo;
                 _service.ReconfigVM_TaskAsync(vmmor, configSpec);
                 _service.StartRecording_TaskAsync(vmmor, ecb.get_option("snapshotname"), ecb.get_option("description"));
                 _service.StopRecording_TaskAsync(vmmor);
                 Console.WriteLine("Session recorded successfully");
             }
             else
             {
                 VirtualMachineSnapshotTree[] tree = (VirtualMachineSnapshotTree[])getObjectProperty(vmmor,
                                                                                                     "snapshot.rootSnapshotList");
                 if (tree != null && tree.Length != 0)
                 {
                     ManagedObjectReference taskMor = _service.RemoveAllSnapshots_Task(vmmor, true, false);
                     object[] result = ecb.getServiceUtil().WaitForValues(taskMor, new string[] { "info.state", "info.result" },
                                                                          new string[] { "state" }, // info has a property - state for state of the task
                                                                          new object[][] { new object[] { TaskInfoState.success, TaskInfoState.error } }
                                                                          );
                     if (result[0].Equals(TaskInfoState.success))
                     {
                         Console.WriteLine("Removed all the snapshot successfully");
                     }
                 }
                 else
                 {
                     Console.WriteLine("No snapshot found for this virtual machine");
                 }
             }
         }
         else
         {
             VirtualMachineSnapshotTree[] tree = (VirtualMachineSnapshotTree[])getObjectProperty(vmmor,
                                                                                                 "snapshot.rootSnapshotList");
             if (tree != null && tree.Length != 0)
             {
                 ManagedObjectReference taskMor = _service.RemoveAllSnapshots_Task(vmmor, true, false);
                 object[] result = ecb.getServiceUtil().WaitForValues(taskMor, new string[] { "info.state", "info.result" },
                                                                      new string[] { "state" }, // info has a property - state for state of the task
                                                                      new object[][] { new object[] { TaskInfoState.success, TaskInfoState.error } }
                                                                      );
                 if (result[0].Equals(TaskInfoState.success))
                 {
                     Console.WriteLine("Removed all the snapshot successfully");
                 }
             }
             else
             {
                 Console.WriteLine("No snapshot found for this virtual machine");
             }
         }
     }
     catch (Exception e)
     {
         ecb.log.LogLine("RecordSession : Failed Connect");
         throw e;
     }
     finally
     {
         ecb.log.LogLine("Ended RecordSession");
         ecb.log.Close();
     }
 }