//Case 230: 1.3.8_ListFMSPresentationState_Normal
        public void Run_FMS_ListFMSPresentationState_Normal_Case230()
        {
            /** Using service: AcquisitionService,FMSService
            * Using interface:
            *   AcquisitionService::startAcquisition
            *   AcquisitionService::getAcquisitionResult
            *	  FMSService::listFMSPresentationState
            *	  FMSService::deleteFMS
            **/
            int runCount = 0;
            string acquireType = string.Empty;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Acquisition");
                AcquisitionService acqs = new AcquisitionService();
                FMSService fmss = new FMSService();

                XMLParameter acq = new XMLParameter("acq_info");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "acquire")
                    {
                        acq.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "acquireType")
                    {
                        acquireType = ids.InputParameters.GetParameter(i).Key;
                    }
                }

                CheckPoint pAcquire = new CheckPoint("Acquire Image", "Acquisition FMS");
                r.CheckPoints.Add(pAcquire);
                System.Diagnostics.Debug.Print("Acquire start");

                XMLResult rslAcqRVG = acqs.startAcquisition(acq);
                System.Threading.Thread.Sleep(1200);

                switch (acquireType)
                {
                    case "FMS":
                        System.Diagnostics.Debug.Print("FMS Acquire");
                        Utility.AcqFMS(22, 120);
                        break;
                    default:
                        System.Diagnostics.Debug.Print("NOT FMS/PANO/CEPH/CR Acquire");
                        break;
                }

                if (rslAcqRVG.IsErrorOccured)
                {
                    System.Diagnostics.Debug.Print("Acquire fail:");
                    pAcquire.Result = TestResult.Fail;
                    pAcquire.Outputs.AddParameter("Acquire image error", "startAcquisition", rslAcqRVG.Message);
                }
                else
                {
                    pAcquire.Outputs.AddParameter("Acquire session ID", "startAcquisition", rslAcqRVG.SingleResult);
                    int DORVGcount = 0;
                    XMLResult getAcqRVG = new XMLResult();
                    do
                    {
                        System.Threading.Thread.Sleep(3000);
                        System.Diagnostics.Debug.Print("get acquire in do");
                        DORVGcount++;
                        getAcqRVG = acqs.getAcquisitionResult(rslAcqRVG.SingleResult);
                        if (!getAcqRVG.IsErrorOccured)
                        {
                            ParseXMLContent parser = new ParseXMLContent(getAcqRVG.ResultContent); // To parse the return XML

                            string fmsID = parser.getStringWithPathAndType("trophy/object_info", "fms", "value");
                            string[] fmsIDs = fmsID.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                            int fmsCount = fmsIDs.Length;

                            string imageID = parser.getStringWithPathAndType("trophy/object_info", "image", "value");
                            string[] imageIDs = imageID.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                            int imageCount = imageIDs.Length;

                            string psID = parser.getStringWithPathAndType("trophy/object_info", "presentation_state", "value");
                            string[] psIDs = psID.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                            int psCount = psIDs.Length;

                            if (fmsCount == 1 && imageCount >= 1 && psCount >= 1 && imageCount == psCount)
                            {
                                string FMSInternalID = fmsIDs[0];
                                XMLResult rslListPs = fmss.listFMSPresentationState(FMSInternalID);
                                int matchItem = 0;
                                for (int p = 0; p < rslListPs.MultiResults[0].Parameters.Count; p++)
                                {
                                    if (psID.Contains(rslListPs.MultiResults[0].Parameters[p].ParameterValue))
                                        matchItem++;
                                }
                                if (matchItem == psCount)
                                {
                                    pAcquire.Outputs.AddParameter("List FMS presentationstate", "FMS Service", "Get PS from listFMSPresentationState and match");
                                }
                                else
                                {
                                    pAcquire.Outputs.AddParameter("List FMS presentationstate", "FMS Service", "Get PS from listFMSPresentationState but not match");
                                }

                                XMLResult delFmsRls = fmss.deleteFMS("true", FMSInternalID);
                                if (delFmsRls.IsErrorOccured)
                                {
                                    pAcquire.Result = TestResult.Fail;
                                    pAcquire.Outputs.AddParameter("Delete FMS Result", "FMS Service", delFmsRls.Message);
                                    pAcquire.Outputs.AddParameter("Delete FMS", "FMS Service", "Delete FMS Error");
                                    break;
                                }
                                pAcquire.Outputs.AddParameter("Delete FMS Result", "FMS Service", delFmsRls.ResultContent);

                                pAcquire.Result = TestResult.Pass;
                                pAcquire.Outputs.AddParameter("Delete FMS and images", "FMS Service", "All images and fms has been deleted");
                            }
                            else
                            {
                                pAcquire.Result = TestResult.Fail;
                                pAcquire.Outputs.AddParameter("getAcquisitionResult", "FMS Service", "No Image or PS id return");
                            }
                            break;
                        }

                        if (getAcqRVG.Code != 0 && getAcqRVG.Code != 499)
                        {
                            pAcquire.Result = TestResult.Fail;
                            pAcquire.Outputs.AddParameter("Get acquire image error", "getAcquisitionResult", getAcqRVG.Message);
                            break;
                        }
                        if (getAcqRVG.IsErrorOccured && getAcqRVG.Code != 499)
                            continue;
                        System.Diagnostics.Debug.Print("get acquireResult:" + DORVGcount);
                        if (DORVGcount > 60)
                        {
                            pAcquire.Result = TestResult.Fail;
                            pAcquire.Outputs.AddParameter("Get acquire image error", "getAcquisitionResult", "Acquire great with 3 minutes, timeout!");
                            break;
                        }
                    } while (true);
                }
                SaveRound(r);
            }
            Output();
        }
        //Case 160: 1.3.8_FindFMS_Normal
        public void Run_FMS_FindFMS_Normal_Case160()
        {
            int runCount = 0;
            string findPSid = string.Empty;
            string expectFmsId = string.Empty;

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                Round r = this.NewRound(runCount.ToString(), "Acquisition");

                CheckPoint pFMS = new CheckPoint("Find PS in FMS", "Find FMS");
                r.CheckPoints.Add(pFMS);

                FMSService fmss = new FMSService();

                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "presentationstate")
                    {
                        findPSid = ids.InputParameters.GetParameter(i).Value;
                    }
                }

                for (int i = 0; i < ids.ExpectedValues.Count; i++)
                {
                    if (ids.ExpectedValues.GetParameter(i).Step == "fms")
                    {
                        expectFmsId = ids.ExpectedValues.GetParameter(i).Value;
                    }
                }

                XMLResult rslFindFms = fmss.findFMS(findPSid);

                if (rslFindFms.IsErrorOccured)
                {
                    pFMS.Result = TestResult.Fail;
                    pFMS.Outputs.AddParameter("Find FMS Result", "FMS Service", rslFindFms.Message);
                    pFMS.Outputs.AddParameter("Find FMS", "FMS Service", "Find FMS Return Error");
                    break;
                }
                else
                {
                    try
                    {

                        if (rslFindFms.MultiResults[0].Parameters[0].ParameterName == "internal_id"
                          && rslFindFms.MultiResults[0].Parameters[0].ParameterValue == expectFmsId)
                        {
                            pFMS.Result = TestResult.Pass;
                            pFMS.Outputs.AddParameter("Find FMS Result", "FMS Service", "Find the correct fms id");
                        }
                        else
                        {
                            pFMS.Result = TestResult.Fail;
                            pFMS.Outputs.AddParameter("Find FMS Result", "FMS Service", "Can't find the correct fms");
                        }
                    }
                    catch
                    {
                        pFMS.Result = TestResult.Fail;
                        pFMS.Outputs.AddParameter("Find FMS Result", "FMS Service", "Can't find the correct fms");
                    }
                }

                SaveRound(r);
            }
            Output();
        }
        //Case 158: 1.3.8_GetFMSIndexedInfo_Normal
        public void Run_FMS_GetFMSIndexedInfo_Normal_Case158()
        {
            int runCount = 0;
            string acquireType = string.Empty;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Acquisition");
                AcquisitionService acqs = new AcquisitionService();
                FMSService fmss = new FMSService();
                ImageService igs = new ImageService();
                PresentationStateService pss = new PresentationStateService();

                XMLParameter acq = new XMLParameter("acq_info");
                XMLParameter FmsInfo = new XMLParameter("fms");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "acquire")
                    {
                        acq.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "acquireType")
                    {
                        acquireType = ids.InputParameters.GetParameter(i).Key;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "FMSInfo")
                    {
                        FmsInfo.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                }

                CheckPoint pAcquire = new CheckPoint("Acquire Image", "Acquisition FMS");
                r.CheckPoints.Add(pAcquire);
                System.Diagnostics.Debug.Print("Acquire start");

                XMLResult rslAcqRVG = acqs.startAcquisition(acq);
                System.Threading.Thread.Sleep(3000);

                switch (acquireType)
                {
                    case "FMS":
                        System.Diagnostics.Debug.Print("FMS Acquire");
                        Utility.AcqFMS(22, 60);
                        break;
                    default:
                        System.Diagnostics.Debug.Print("NOT FMS/PANO/CEPH/CR Acquire");
                        break;
                }

                if (rslAcqRVG.IsErrorOccured)
                {
                    System.Diagnostics.Debug.Print("Acquire fail:");
                    pAcquire.Result = TestResult.Fail;
                    pAcquire.Outputs.AddParameter("Acquire image error", "startAcquisition", rslAcqRVG.Message);
                }
                else
                {
                    pAcquire.Outputs.AddParameter("Acquire session ID", "startAcquisition", rslAcqRVG.SingleResult);
                    int DORVGcount = 0;
                    XMLResult getAcqRVG = new XMLResult();
                    do
                    {
                        System.Threading.Thread.Sleep(3000);
                        System.Diagnostics.Debug.Print("get acquire in do");
                        DORVGcount++;
                        getAcqRVG = acqs.getAcquisitionResult(rslAcqRVG.SingleResult);
                        if (!getAcqRVG.IsErrorOccured)
                        {
                            ParseXMLContent parser = new ParseXMLContent(getAcqRVG.ResultContent); // To parse the return XML

                            string fmsID = parser.getStringWithPathAndType("trophy/object_info", "fms", "value");
                            string[] fmsIDs = fmsID.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                            int fmsCount = fmsIDs.Length;

                            string imageID = parser.getStringWithPathAndType("trophy/object_info", "image", "value");
                            string[] imageIDs = imageID.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                            int imageCount = imageIDs.Length;

                            string psID = parser.getStringWithPathAndType("trophy/object_info", "presentation_state", "value");
                            string[] psIDs = psID.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                            int psCount = psIDs.Length;

                            if (fmsCount == 1 && imageCount >= 1 && psCount >= 1 && imageCount == psCount)
                            {
                                pAcquire.Result = TestResult.Pass;
                                pAcquire.Outputs.AddParameter("getAcquisitionResult", "Acquisition", getAcqRVG.ResultContent);

                                string FMSInternalID = fmsIDs[0];

                                CheckPoint pFMS = new CheckPoint("Set FMS Info", "FMS Service");
                                r.CheckPoints.Add(pFMS);
                                XMLResult rslSetFmsInfo = fmss.setFMSInfo(FmsInfo, FMSInternalID);
                                if (rslSetFmsInfo.IsErrorOccured)
                                {
                                    pFMS.Result = TestResult.Fail;
                                    pFMS.Outputs.AddParameter("Set FMS Result", "FMS Service", rslSetFmsInfo.ResultContent);
                                }

                                XMLResult rslGetFmsInfo = fmss.getFMSInfo(FMSInternalID);
                                if (rslGetFmsInfo.IsErrorOccured)
                                {
                                    pFMS.Result = TestResult.Fail;
                                    pFMS.Outputs.AddParameter("Get FMS Info Fail", "FMS Service", rslGetFmsInfo.ResultContent);
                                }
                                else
                                {
                                    pFMS.Result = TestResult.Pass;

                                    pFMS.Outputs.AddParameter("Get FMS Info Result", "FMS Service", rslGetFmsInfo.ResultContent);
                                    int matchGetItem = 0;
                                    for (int setI = 0; setI < FmsInfo.Length; setI++)
                                    {
                                        for (int getI = 0; getI < rslGetFmsInfo.MultiResults[0].Parameters.Count; getI++)
                                        {
                                            if (rslGetFmsInfo.MultiResults[0].Parameters[getI].ParameterName == FmsInfo.Parameters[setI].ParameterName
                                              && rslGetFmsInfo.MultiResults[0].Parameters[getI].ParameterValue == FmsInfo.Parameters[setI].ParameterValue)
                                                matchGetItem++;
                                        }
                                    }
                                    if (matchGetItem == FmsInfo.Length)
                                    {
                                        pFMS.Result = TestResult.Pass;
                                        pFMS.Outputs.AddParameter("Get FMS Info Result Match Setting", "FMS Service", "Success");
                                    }
                                    else
                                    {
                                        pFMS.Result = TestResult.Fail;
                                        pFMS.Outputs.AddParameter("Get FMS Info Result Not Match Setting", "FMS Service", "Failure");
                                    }

                                }

                                XMLResult delFmsRls = fmss.deleteFMS("true", FMSInternalID);
                                if (delFmsRls.IsErrorOccured)
                                {
                                    pFMS.Result = TestResult.Fail;
                                    pFMS.Outputs.AddParameter("Delete FMS Result", "FMS Service", delFmsRls.Message);
                                    pFMS.Outputs.AddParameter("Delete FMS", "FMS Service", "Delete FMS Error");
                                    break;
                                }
                                pFMS.Outputs.AddParameter("Delete FMS Result", "FMS Service", delFmsRls.ResultContent);
                                pFMS.Outputs.AddParameter("Delete FMS and images", "FMS Service", "All images and fms has been deleted");
                            }
                            else
                            {
                                pAcquire.Result = TestResult.Fail;
                                pAcquire.Outputs.AddParameter("getAcquisitionResult", "FMS Service", "No Image or PS id return");
                            }
                            break;
                        }

                        if (getAcqRVG.Code != 0 && getAcqRVG.Code != 499)
                        {
                            pAcquire.Result = TestResult.Fail;
                            pAcquire.Outputs.AddParameter("Get acquire image error", "getAcquisitionResult", getAcqRVG.Message);
                            break;
                        }
                        if (getAcqRVG.IsErrorOccured && getAcqRVG.Code != 499)
                            continue;
                        System.Diagnostics.Debug.Print("get acquireResult:" + DORVGcount);
                        if (DORVGcount > 60)
                        {
                            pAcquire.Result = TestResult.Fail;
                            pAcquire.Outputs.AddParameter("Get acquire image error", "getAcquisitionResult", "Acquire great with 3 minutes, timeout!");
                            break;
                        }
                    } while (true);
                }
                SaveRound(r);
            }
            Output();
        }
        //Case 159: 1.3.8_1.3.8_DeleteFMS_Normal
        public void Run_FMS_DeleteFMS_Normal_Case159()
        {
            int runCount = 0;
            string acquireType = string.Empty;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Acquisition");
                AcquisitionService acqs = new AcquisitionService();
                FMSService fmss = new FMSService();
                ImageService igs = new ImageService();
                PresentationStateService pss = new PresentationStateService();

                XMLParameter acq = new XMLParameter("acq_info");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "acquire")
                    {
                        acq.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "acquireType")
                    {
                        acquireType = ids.InputParameters.GetParameter(i).Key;
                    }
                }

                CheckPoint pAcquire = new CheckPoint("Acquire Image", "Acquisition FMS");
                r.CheckPoints.Add(pAcquire);
                System.Diagnostics.Debug.Print("Acquire start");

                XMLResult rslAcqRVG = acqs.startAcquisition(acq);
                System.Threading.Thread.Sleep(3000);

                switch (acquireType)
                {
                    case "FMS":
                        System.Diagnostics.Debug.Print("FMS Acquire");
                        Utility.AcqFMS(15, 300); //can not set too long, otherwise there may be overtaken images
                        break;
                    default:
                        System.Diagnostics.Debug.Print("NOT FMS/PANO/CEPH/CR Acquire");
                        break;
                }

                if (rslAcqRVG.IsErrorOccured)
                {
                    System.Diagnostics.Debug.Print("Acquire fail:");
                    pAcquire.Result = TestResult.Fail;
                    pAcquire.Outputs.AddParameter("Acquire image error", "startAcquisition", rslAcqRVG.Message);
                }
                else
                {
                    pAcquire.Outputs.AddParameter("Acquire session ID", "startAcquisition", rslAcqRVG.SingleResult);
                    int DORVGcount = 0;
                    XMLResult getAcqRVG = new XMLResult();
                    do
                    {
                        System.Threading.Thread.Sleep(3000);
                        System.Diagnostics.Debug.Print("get acquire in do");
                        DORVGcount++;
                        getAcqRVG = acqs.getAcquisitionResult(rslAcqRVG.SingleResult);
                        if (!getAcqRVG.IsErrorOccured)
                        {
                            ParseXMLContent parser = new ParseXMLContent(getAcqRVG.ResultContent); // To parse the return XML

                            string fmsID = parser.getStringWithPathAndType("trophy/object_info", "fms", "value");
                            string[] fmsIDs = fmsID.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                            int fmsCount = fmsIDs.Length;

                            string imageID = parser.getStringWithPathAndType("trophy/object_info", "image", "value");
                            string[] imageIDs = imageID.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                            int imageCount = imageIDs.Length;

                            string psID = parser.getStringWithPathAndType("trophy/object_info", "presentation_state", "value");
                            string[] psIDs = psID.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                            int psCount = psIDs.Length;

                            if (fmsCount == 1 && imageCount >= 1 && psCount >= 1 && imageCount == psCount)
                            {
                                string FMSInternalID = fmsIDs[0];
                                XMLResult delFmsRls = fmss.deleteFMS("true", FMSInternalID);
                                if (delFmsRls.IsErrorOccured)
                                {
                                    pAcquire.Result = TestResult.Fail;
                                    pAcquire.Outputs.AddParameter("Delete FMS Result", "Acquisition", delFmsRls.ResultContent);
                                    pAcquire.Outputs.AddParameter("Delete FMS", "Acquisition", "Delete FMS Error");
                                    break;
                                }
                                pAcquire.Outputs.AddParameter("Delete FMS Result", "Acquisition", delFmsRls.ResultContent);

                                XMLResult getFmsRls = fmss.getFMSDescription(FMSInternalID);
                                if (!getFmsRls.IsErrorOccured)
                                {
                                    pAcquire.Result = TestResult.Fail;
                                    pAcquire.Outputs.AddParameter("Get FMS", "Acquisition", getFmsRls.ResultContent);
                                    pAcquire.Outputs.AddParameter("Get FMS", "Acquisition", "FMS does not delete");
                                    break;
                                }
                                pAcquire.Outputs.AddParameter("Get FMS", "Acquisition", getFmsRls.ResultContent);

                                bool isImageExisted = false;
                                for (int i = 1; i <= imageIDs.Length; i++)
                                {
                                    XMLResult getImageRls = igs.getImageDescription(imageIDs[i - 1]);
                                    if (!getImageRls.IsErrorOccured)
                                    {
                                        isImageExisted = true;
                                        break;
                                    }
                                    pAcquire.Outputs.AddParameter("Get FMS Images: " + i, "Acquisition", getImageRls.ResultContent);
                                }
                                if (isImageExisted)
                                {
                                    pAcquire.Result = TestResult.Fail;
                                    pAcquire.Outputs.AddParameter("Get FMS Images", "Acquisition", "Images is not deleted from FMS");
                                    break;
                                }

                                pAcquire.Result = TestResult.Pass;
                                pAcquire.Outputs.AddParameter("Delete FMS and images", "Acquisition", "Fms and imahes have been deleted");
                            }
                            else
                            {
                                pAcquire.Result = TestResult.Fail;
                                pAcquire.Outputs.AddParameter("getAcquisitionResult", "Acquisition", "No Image or PS id return");
                            }
                            break;
                        }
                        if (getAcqRVG.IsErrorOccured && getAcqRVG.Code != 499)
                            continue;
                        if (getAcqRVG.Code != 0 && getAcqRVG.Code != 499)
                        {
                            pAcquire.Result = TestResult.Fail;
                            pAcquire.Outputs.AddParameter("Get acquire image error", "getAcquisitionResult", getAcqRVG.Message);
                        }
                        System.Diagnostics.Debug.Print("get acquireResult:" + DORVGcount);
                        if (DORVGcount > 60)
                        {
                            pAcquire.Result = TestResult.Fail;
                            pAcquire.Outputs.AddParameter("Get acquire image error", "getAcquisitionResult", "Acquire great with 3 minutes, timeout!");
                            break;
                        }
                    } while (true);
                }
                SaveRound(r);
            }
            Output();
        }
        // Case 1560:  1.1.04.03 SetImage_N03_Call setImage for archived image in FMS
        public void Run_Image_SetInfo_ImageInFMS_Case1560()
        {
            int runCount = 0;

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), ids.Description);

                try
                {
                    #region Parameter initialize
                    string patientInternalId = string.Empty;
                    string fmsFullPath = string.Empty;
                    string objectFileFullPath = string.Empty;
                    string archivedPath = string.Empty;

                    XMLParameter pSetImageInfo = new XMLParameter("image");
                    for (int i = 0; i < ids.InputParameters.Count; i++)
                    {
                        if (ids.InputParameters.GetParameter(i).Step == "importFMS")
                        {
                            if (ids.InputParameters.GetParameter(i).Key == "patient_internal_id")
                            {
                                patientInternalId = ids.InputParameters.GetParameter(i).Value;
                            }
                            else if (ids.InputParameters.GetParameter(i).Key == "objectFileFullPath")
                            {
                                fmsFullPath = ids.InputParameters.GetParameter(i).Value;
                            }
                        }
                        else if (ids.InputParameters.GetParameter(i).Step == "importImage")
                        {

                            if (ids.InputParameters.GetParameter(i).Key == "objectFileFullPath")
                            {
                                objectFileFullPath = ids.InputParameters.GetParameter(i).Value;
                            }
                            else if (ids.InputParameters.GetParameter(i).Key == "archivePath")
                            {
                                archivedPath = ids.InputParameters.GetParameter(i).Value;
                            }
                        }
                        else if (ids.InputParameters.GetParameter(i).Step == "setImageInfo")
                        {
                            pSetImageInfo.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }
                    }
                    #endregion

                    ImportService importService = new ImportService();
                    FMSService fmsSvc = new FMSService();
                    ImageService imageService = new ImageService();

                    #region Step 1-1: Call ImportService.importObject to import FMS
                    string fmsID = string.Empty;

                    CheckPoint cpImportFMS = new CheckPoint("Import Image", "Call ImportService.importObject to import a FMS");
                    r.CheckPoints.Add(cpImportFMS);

                    XMLResult rtImportFMS = importService.importObject(patientInternalId, null, fmsFullPath, null, true, "false");
                    if (rtImportFMS.IsErrorOccured)
                    {
                        cpImportFMS.Result = TestResult.Fail;
                        cpImportFMS.Outputs.AddParameter("Import image returns error", "Import image", rtImportFMS.Message);

                        SaveRound(r);
                        continue; // There is error when create image, end current run
                    }
                    else
                    {
                        cpImportFMS.Result = TestResult.Pass;
                        cpImportFMS.Outputs.AddParameter("Import image returns success", "Import image", rtImportFMS.Message);

                        foreach (XMLParameter p in rtImportFMS.MultiResults)
                        {
                            if (p.Name == "fms")
                            {
                                fmsID = p.Parameters[0].ParameterValue;
                                break;
                            }
                        }
                    }
                    #endregion

                    #region Step 1-2: Call ImportService.importObject to import a image
                    string imageInternalID = string.Empty;
                    string currentPSID = string.Empty;

                    CheckPoint cpImportImage = new CheckPoint("Import Image", "Call ImportService.importObject to import an archived  image");
                    r.CheckPoints.Add(cpImportImage);

                    XMLResult rtImportImage = importService.importObject(patientInternalId, null, objectFileFullPath, archivedPath, true, "false");
                    if (rtImportImage.IsErrorOccured)
                    {
                        cpImportImage.Result = TestResult.Fail;
                        cpImportImage.Outputs.AddParameter("Import image returns error", "Import image", rtImportImage.Message);

                        SaveRound(r);
                        continue; // There is error when create image, end current run
                    }
                    else
                    {
                        cpImportImage.Result = TestResult.Pass;
                        cpImportImage.Outputs.AddParameter("Import image returns success", "Import image", rtImportImage.Message);

                        imageInternalID = rtImportImage.MultiResults[0].Parameters[0].ParameterValue;
                        currentPSID = rtImportImage.MultiResults[1].Parameters[0].ParameterValue;
                    }
                    #endregion

                    #region Step 1-3: Add image into FMS
                    CheckPoint cpSetFMS = new CheckPoint("Set FMS", " Call setFMSDescription to add the archived image into it");
                    r.CheckPoints.Add(cpImportFMS);

                    XMLParameterCollection pSetFMSDescription = new XMLParameterCollection();

                    XMLParameter pFMSDes = new XMLParameter("fms");
                    pFMSDes.AddParameter("xml_description", "");

                    XMLParameter pFMSPS = new XMLParameter("presentationstate");
                    foreach (XMLParameter p in rtImportFMS.MultiResults) //Add original PS
                    {
                        if (p.Name == "presentationstate")
                        {
                            pFMSPS.AddParameter("internal_id", p.Parameters[0].ParameterValue);
                        }
                    }
                    pFMSPS.AddParameter("internal_id", currentPSID);

                    pSetFMSDescription.Add(pFMSDes);
                    pSetFMSDescription.Add(pFMSPS);

                    XMLResult rtSetFMS = fmsSvc.setFMSDescription(pSetFMSDescription, fmsID);

                    if (rtSetFMS.IsErrorOccured)
                    {
                        cpSetFMS.Result = TestResult.Fail;
                        cpSetFMS.Outputs.AddParameter("Set FMS", "setFMSDescription return error: ", rtSetFMS.ResultContent);
                    }
                    else
                    {
                        cpSetFMS.Result = TestResult.Pass;
                    }
                    #endregion

                    #region Step 2-1: Check the getImageDescription return is correct after import image
                    CheckPoint cpGetImageDescriptionAfterImport = new CheckPoint("Check getImageDescription return", "Check getImageDescription return is corerct or not after import image");
                    r.CheckPoints.Add(cpGetImageDescriptionAfterImport);

                    XMLResult rtGetImageDescriptionAfterImport = imageService.getImageDescription(imageInternalID);
                    string imagePathAfterImport = rtGetImageDescriptionAfterImport.MultiResults[0].GetParameterValueByName("path");
                    string archivedPathAfterImport = rtGetImageDescriptionAfterImport.MultiResults[0].GetParameterValueByName("archive_path");
                    string archiveTagAfterImport = rtGetImageDescriptionAfterImport.MultiResults[0].GetParameterValueByName("tags");

                    if (imagePathAfterImport == string.Empty && archivedPathAfterImport == archivedPath && string.IsNullOrEmpty(archiveTagAfterImport))
                    {
                        cpGetImageDescriptionAfterImport.Result = TestResult.Pass;
                        cpGetImageDescriptionAfterImport.Outputs.AddParameter("getImageDescription", "Check getImageDescription return", "The getImageDescription return is correct after import image");
                    }
                    else
                    {
                        cpGetImageDescriptionAfterImport.Result = TestResult.Fail;
                        cpGetImageDescriptionAfterImport.Outputs.AddParameter("getImageDescription", "Check getImageDescription return", "The getImageDescription return is not correct after import image. Actually get: " + rtGetImageDescriptionAfterImport.ResultContent);
                    }
                    #endregion

                    #region Step 2-2: Check the info is correct in getImageInfo return after import image
                    CheckPoint cpGetImageInfoAfterImport = new CheckPoint("Check getImageInfo return", "Check getImageInfo return is corerct or not import the image");
                    r.CheckPoints.Add(cpGetImageInfoAfterImport);

                    XMLParameter pGetImageInfoAfterImport = new XMLParameter("image");
                    pGetImageInfoAfterImport.AddParameter("internal_id", imageInternalID);
                    XMLResult rtGetImageInfo = imageService.getImageInfo(pGetImageInfoAfterImport);

                    imagePathAfterImport = rtGetImageInfo.DicomArrayResult.GetParameterValueByName("path");
                    archivedPathAfterImport = rtGetImageInfo.DicomArrayResult.GetParameterValueByName("archive_path");
                    archiveTagAfterImport = rtGetImageInfo.DicomArrayResult.GetParameterValueByName("tags");

                    if (string.IsNullOrEmpty(imagePathAfterImport)) //&& archivedPathAfterImport == archivedPath && archiveTagAfterImport == "archived", will be supported in new service
                    {
                        cpGetImageInfoAfterImport.Result = TestResult.Pass;
                        cpGetImageInfoAfterImport.Outputs.AddParameter("getImageInfo", "Check getImageInfo return", "The getImageInfo return is correct after import image");
                    }
                    else
                    {
                        cpGetImageInfoAfterImport.Result = TestResult.Fail;
                        cpGetImageInfoAfterImport.Outputs.AddParameter("getImageInfo", "Check getImageInfo return", "The getImageInfo return is not correct after import image. Actually get: " + rtGetImageInfo.ResultContent);
                    }
                    #endregion

                    #region Step 3: Call ImageService.SetImageInfo to save the archived image as normal image
                    CheckPoint cpSetImageInfo = new CheckPoint("Set Image Info", "Call ImageService.SetImageInfo to save the archived image as normal image");
                    r.CheckPoints.Add(cpSetImageInfo);

                    XMLResult rtSetImageInfo = imageService.setImageInfo(pSetImageInfo, imageInternalID);

                    if (rtSetImageInfo.IsErrorOccured)
                    {
                        cpSetImageInfo.Result = TestResult.Fail;
                        cpSetImageInfo.Outputs.AddParameter("SetImageInfo returns error", "SetImageInfo", rtSetImageInfo.Message);
                    }
                    else
                    {
                        cpSetImageInfo.Result = TestResult.Pass;
                        cpSetImageInfo.Outputs.AddParameter("SetImageInfo returns success", "SetImageInfo", rtSetImageInfo.Message);

                        // Wait the file is transferred to server DB
                        System.Threading.Thread.Sleep(3000);

                        // Below to check the info is correct after setImageInfo. Check points includes:
                        //1. The Image ID and PS ID are not changed
                        //2. GetImageDescription return correct image path and archive path, correct archive flag
                        //3. GetImageInfo return correct image path, correct archive flag
                        //4. Use the image path to check the image file is in server DB
                        //5. The original archived image is not deleted

                        //#region Step 3: Check the image is set, not newly created
                        ////PatientService patientSvc = new PatientService();
                        ////patientSvc.listObjects();
                        ////NewPatientService newPatientSvc = new NewPatientService();
                        ////newPatientSvc.listObjects();
                        //#endregion

                        #region Step 4: Check the ps is set, not newly created after set image
                        CheckPoint cpPSID = new CheckPoint("Check PS ID", "Check the PS ID is not changed after call setImageInfo");
                        r.CheckPoints.Add(cpPSID);

                        XMLParameter pListPS = new XMLParameter("filter");
                        pListPS.AddParameter("current", "true");
                        string currentPSIDAfterSet = imageService.listPresentationState(pListPS, imageInternalID).SingleResult; // may need change

                        if (currentPSIDAfterSet == currentPSID)
                        {
                            cpPSID.Result = TestResult.Pass;
                            cpPSID.Outputs.AddParameter("listPresentationState", "Check PS ID", "The PS ID is not changed");
                        }
                        else
                        {
                            cpPSID.Result = TestResult.Fail;
                            cpPSID.Outputs.AddParameter("listPresentationState", "Check PS ID", "The PS ID is changed. Expect: " + currentPSID + "; Actually new PS ID: " + currentPSIDAfterSet);
                        }
                        #endregion

                        string imagePathAfterSet = string.Empty;
                        string archivePathAfterSet = string.Empty;
                        string archiveTagAfterSet = string.Empty;

                        #region Step 5: Check the getImageDescription return is correct after set image
                        CheckPoint cpGetImageDescriptionAfterSet = new CheckPoint("Check getImageDescription return", "Check getImageDescription return is corerct or not after call setImageInfo");
                        r.CheckPoints.Add(cpGetImageDescriptionAfterSet);

                        XMLResult rtGetImageDescriptionAfterSet = imageService.getImageDescription(imageInternalID);
                        imagePathAfterSet = rtGetImageDescriptionAfterSet.MultiResults[0].GetParameterValueByName("path");
                        archivePathAfterSet = rtGetImageDescriptionAfterSet.MultiResults[0].GetParameterValueByName("archive_path");
                        archiveTagAfterSet = rtGetImageDescriptionAfterSet.MultiResults[0].GetParameterValueByName("tags");

                        if (imagePathAfterSet.Contains(imageInternalID) && string.IsNullOrEmpty(archivePathAfterSet) && string.IsNullOrEmpty(archiveTagAfterSet)) // imagePathAfterSet sampe: C:/Documents and Settings/All Users/Application Data/TW/PAS/pas_data/patient/03/8af0a7e63310cc65013310d46d0e0003/1956bc28-ca5e-4720-a857-d4de18fc1479/02962f27-e4be-4d59-b112-9663a2f2572b.dcm"
                        {
                            cpGetImageDescriptionAfterSet.Result = TestResult.Pass;
                            cpGetImageDescriptionAfterSet.Outputs.AddParameter("getImageDescription", "Check getImageDescription return", "The getImageDescription return is correct after set image");
                        }
                        else
                        {
                            cpGetImageDescriptionAfterSet.Result = TestResult.Fail;
                            cpGetImageDescriptionAfterSet.Outputs.AddParameter("getImageDescription", "Check getImageDescription return", "The getImageDescription return is not correct after set image. Actually get: " + rtGetImageDescriptionAfterSet.ResultContent);
                        }
                        #endregion

                        #region Step 6: Check the getImageinfo return is correct after set image
                        CheckPoint cpGetImageInfoAfterSet = new CheckPoint("Check getImageInfo return", "Check getImageInfo return is corerct or not after call setImageInfo");
                        r.CheckPoints.Add(cpGetImageInfoAfterSet);

                        XMLParameter pGetImageInfoAfterSet = new XMLParameter("image");
                        pGetImageInfoAfterSet.AddParameter("internal_id", imageInternalID);
                        XMLResult rtGetImageInfoAfterSet = imageService.getImageInfo(pGetImageInfoAfterSet);

                        imagePathAfterSet = rtGetImageInfoAfterSet.DicomArrayResult.GetParameterValueByName("path");
                        archivePathAfterSet = rtGetImageInfoAfterSet.DicomArrayResult.GetParameterValueByName("archive_path");
                        archiveTagAfterSet = rtGetImageInfoAfterSet.DicomArrayResult.GetParameterValueByName("tags");

                        if (imagePathAfterSet.Contains(imageInternalID) && string.IsNullOrEmpty(archivePathAfterSet) && string.IsNullOrEmpty(archiveTagAfterSet))
                        {
                            cpGetImageInfoAfterSet.Result = TestResult.Pass;
                            cpGetImageInfoAfterSet.Outputs.AddParameter("getImageInfo", "Check getImageInfo return", "The getImageInfo return is correct after set image");
                        }
                        else
                        {
                            cpGetImageInfoAfterSet.Result = TestResult.Fail;
                            cpGetImageInfoAfterSet.Outputs.AddParameter("getImageInfo", "Check getImageInfo return", "The getImageInfo return is not correct after set image. Actually get: " + rtGetImageInfoAfterSet.ResultContent);
                        }
                        #endregion

                        #region Step 7: Check the file exist in server DB
                        CheckPoint cpImageInDB = new CheckPoint("Check file in DB", "Check the file exist in server DB after call setImageInfo");
                        r.CheckPoints.Add(cpImageInDB);

                        if (Utility.IsImageExistInServerDB(imagePathAfterSet))
                        {
                            cpImageInDB.Result = TestResult.Pass;
                            cpImageInDB.Outputs.AddParameter("Check the file exist in server DB after call setImageInfo", "Check file in DB", "File exist");
                        }
                        else
                        {
                            cpImageInDB.Result = TestResult.Fail;
                            cpImageInDB.Outputs.AddParameter("Check the file exist in server DB after call setImageInfo", "Check file in DB", "File NOT exist");
                        }
                        #endregion

                        #region Step 8: Check the original archived image is not deleted
                        CheckPoint cpOriginalArchivedImage = new CheckPoint("Check original archived file", "Check the original archived image is not deleted after call setImageInfo");
                        r.CheckPoints.Add(cpOriginalArchivedImage);

                        if (System.IO.File.Exists(archivedPath))
                        {
                            cpOriginalArchivedImage.Result = TestResult.Pass;
                            cpOriginalArchivedImage.Outputs.AddParameter("Check the original archived image is not deleted after call setImageInfo", "Check original archived file", "File exist");
                        }
                        else
                        {
                            cpOriginalArchivedImage.Result = TestResult.Fail;
                            cpOriginalArchivedImage.Outputs.AddParameter("Check the original archived image is not deleted after call setImageInfo", "Check original archived file", "File NOT exist");
                        }
                        #endregion
                    }
                    #endregion

                    #region Step 9: Call ImageService.deleteImage to delete the created image
                    CheckPoint cp_DeleteImage = new CheckPoint("Delete Image", "Call imageService.deleteImage to delete the image");
                    r.CheckPoints.Add(cp_DeleteImage);

                    XMLResult rt_DeleteImage = imageService.deleteImage(imageInternalID, new XMLParameter("preferences"));
                    if (rt_DeleteImage.IsErrorOccured)
                    {
                        cp_DeleteImage.Result = TestResult.Fail;
                        cp_DeleteImage.Outputs.AddParameter("delete image", "Delete image returns error", rt_DeleteImage.Message);
                    }
                    else
                    {
                        cp_DeleteImage.Result = TestResult.Pass;
                        cp_DeleteImage.Outputs.AddParameter("delete image", "Delete image returns success", rt_DeleteImage.Message);
                    }
                    #endregion

                    #region Step 10: Call FMSService.deleteFMS to delete the FMS
                    CheckPoint cp_DeleteFMS = new CheckPoint("Delete FMS", "Call fmsService.deleteFMS to delete the FMS");
                    r.CheckPoints.Add(cp_DeleteFMS);

                    XMLResult rt_DeleteFMS = fmsSvc.deleteFMS("true", fmsID);
                    if (rt_DeleteFMS.IsErrorOccured)
                    {
                        cp_DeleteFMS.Result = TestResult.Fail;
                        cp_DeleteFMS.Outputs.AddParameter("delete fms", "Delete fms returns error", rt_DeleteFMS.Message);
                    }
                    else
                    {
                        cp_DeleteFMS.Result = TestResult.Pass;
                        cp_DeleteFMS.Outputs.AddParameter("delete fms", "Delete fms returns success", rt_DeleteFMS.Message);
                    }
                    #endregion

                    SaveRound(r);
                }
                catch (Exception ex)
                {
                    CheckPoint cp = new CheckPoint();
                    r.CheckPoints.Add(cp);
                    cp.Result = TestResult.Fail;
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message", ex.Message);
                    SaveRound(r);
                }
            }

            Output();
        }
        //Case 1598: 1.1.06.21_ImportDir_MainDirectory_N01
        public void Run_Import_ImportDir_MainDirectory_Case1598()
        {
            int runCount = 0;
            NotificationSim.ReceiveNotification rn = new ReceiveNotification();
            System.Collections.Generic.List<string> topics = new System.Collections.Generic.List<string>();
            topics.Add("topic.postImportCompleted");
            string stopTopic = "teststop";
            string stopContent = "teststop";
            rn.startListon(topics, stopTopic, stopContent);

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "ImportMainDir");
                CheckPoint pimp = new CheckPoint("ImportDir", "Import Additional Dir");
                r.CheckPoints.Add(pimp);

                //create patient for import
                PatientService ps = new PatientService();
                XMLParameter cInputPatient = new XMLParameter("patient");
                cInputPatient.AddParameter("first_name", "test");
                cInputPatient.AddParameter("last_name", "importmaindir");
                XMLResult rslCreate = ps.createPatient(cInputPatient);

                if (rslCreate.IsErrorOccured)
                {
                    pimp.Result = TestResult.Fail;
                    pimp.Outputs.AddParameter("Import Main Dir", "Create Patient Fail", rslCreate.Message);
                    SaveRound(r);
                    continue;
                }
                string patientid = rslCreate.SingleResult;
                try
                {
                    string kdis6dir = ids.InputParameters.GetParameter("kdis6_dir").Value;

                    int retrynum = int.Parse(ids.InputParameters.GetParameter("retrynum").Value);
                    string flag = "import";
                    ImportService imps = new ImportService();
                    XMLResult rslimport = imps.importDir(patientid, kdis6dir, flag);

                    if (rslimport.Code != 800)
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "Import Fail", rslimport.Message);
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }

                    int n = 0;
                    while (rn.getRecievedNumber() == 0)
                    {
                        n++;
                        if (n < retrynum)
                        {
                            System.Threading.Thread.Sleep(5000);
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (n == retrynum)
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "Notification Fail", "No notification recieved after retry " + n.ToString() + " times.");
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }

                    ApplicationService app = new ApplicationService();
                    app.sendGenericNotification(stopTopic, stopContent);
                    System.Threading.Thread.Sleep(1000);
                    System.Collections.Generic.List<string> mmm = rn.getNotificationContent();
                    System.Collections.Generic.List<string> imageids = PAS.AutoTest.TestUtility.Utility.parsePostImportResult("Image", mmm[0]);
                    System.Collections.Generic.List<string> fmsids = PAS.AutoTest.TestUtility.Utility.parsePostImportResult("FMS", mmm[0]);
                    System.Collections.Generic.List<string> analysisids = PAS.AutoTest.TestUtility.Utility.parsePostImportResult("Analysis", mmm[0]);

                    int expectedimgcount = int.Parse(ids.ExpectedValues.GetParameter("imgnum").Value);
                    int expectedfmscount = int.Parse(ids.ExpectedValues.GetParameter("fmsnum").Value);
                    int expectedanalysiscount = int.Parse(ids.ExpectedValues.GetParameter("analysisnum").Value);

                    //check counts
                    if (imageids.Count != expectedimgcount)
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "Image Count is not correct", "Actual:" + imageids.Count.ToString() + ",Expected:" + expectedimgcount.ToString());
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }

                    if (fmsids.Count != expectedfmscount)
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "FMS Count is not correct", "Actual:" + fmsids.Count.ToString() + ",Expected:" + expectedfmscount.ToString());
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }

                    if (analysisids.Count != expectedanalysiscount)
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "Analysis Count is not correct", "Actual:" + analysisids.Count.ToString() + ",Expected:" + expectedanalysiscount.ToString());
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }

                    //get image info
                    ImageService imgs = new ImageService();
                    foreach (string imgid in imageids)
                    {
                        XMLParameter cInputImage = new XMLParameter("image");
                        cInputImage.AddParameter("internal_id", imgid);
                        XMLResult rslget = imgs.getImageInfo(cInputImage);
                        if (rslget.IsErrorOccured)
                        {
                            pimp.Result = TestResult.Fail;
                            pimp.Outputs.AddParameter("Import Main Dir", "GetImage Fail", rslget.Message);
                            SaveRound(r);
                            ps.deletePatient(patientid);
                            goto error;
                        }
                    }
                    //get FMS info
                    FMSService fmss = new FMSService();
                    foreach (string fmsid in fmsids)
                    {
                        XMLResult rslget = fmss.getFMSInfo(fmsid);
                        if (rslget.IsErrorOccured)
                        {
                            pimp.Result = TestResult.Fail;
                            pimp.Outputs.AddParameter("Import Main Dir", "GetFMS Fail", rslget.Message);
                            SaveRound(r);
                            ps.deletePatient(patientid);
                            goto error;
                        }
                        rslget = fmss.getFMSDescription(fmsid);
                        if (rslget.IsErrorOccured)
                        {
                            pimp.Result = TestResult.Fail;
                            pimp.Outputs.AddParameter("Import Main Dir", "GetFMS Fail", rslget.Message);
                            SaveRound(r);
                            ps.deletePatient(patientid);
                            goto error;
                        }
                    }
                    //get Analysis info
                    AnalysisService anas = new AnalysisService();
                    foreach (string analysisid in analysisids)
                    {
                        XMLResult rslget = anas.getAnalysisInfo(analysisid);
                        if (rslget.IsErrorOccured)
                        {
                            pimp.Result = TestResult.Fail;
                            pimp.Outputs.AddParameter("Import Main Dir", "GetAnalysis Fail", rslget.Message);
                            SaveRound(r);
                            ps.deletePatient(patientid);
                            goto error;
                        }
                        rslget = anas.getAnalysisDescription(analysisid);
                        if (rslget.IsErrorOccured)
                        {
                            pimp.Result = TestResult.Fail;
                            pimp.Outputs.AddParameter("Import Main Dir", "GetAnalysis Fail", rslget.Message);
                            SaveRound(r);
                            ps.deletePatient(patientid);
                            goto error;
                        }
                    }

                    //check list object
                    NewPatientService nps = new NewPatientService();
                    PatientListObjectsRequestType request = new PatientListObjectsRequestType();
                    request.currentSpecified = true;
                    request.current = true;
                    request.patientInternalId = patientid;
                    request.type = PatientListObjectsType.all;
                    PatientListObjectsResponseType response = nps.listObjects(request);
                    //to refresh code 800 to 0
                    response = nps.listObjects(request);

                    if (!nps.LastReturnXMLValidateResult.isValid)
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "list object fail", "Response is not complied with schema");
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }

                    if (response.status.code != 0)
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "list object fail,message: ", response.status.message);
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }

                    int expectedcurrentps = int.Parse(ids.ExpectedValues.GetParameter("curpsnum").Value);
                    int expectedcurrentfms = int.Parse(ids.ExpectedValues.GetParameter("curfmsnum").Value);
                    int expectedcurrentanalysis = int.Parse(ids.ExpectedValues.GetParameter("curanalysisnum").Value);
                    if (response.presentationStates.Length != expectedcurrentps)
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "list object fail,current image count not correct: ", "actural:" + response.presentationStates.Length.ToString() + " expect:" + expectedcurrentps.ToString());
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }
                    //get PS
                    PresentationStateService pss = new PresentationStateService();
                    foreach (PresentationStateType pst in response.presentationStates)
                    {
                        XMLResult rslget = pss.getPresentationState(pst.uid);
                        if (rslget.IsErrorOccured)
                        {
                            pimp.Result = TestResult.Fail;
                            pimp.Outputs.AddParameter("Import Main Dir", "get PS fail: ", rslget.Message);
                            SaveRound(r);
                            ps.deletePatient(patientid);
                            goto error;
                        }

                    }

                    if (response.analysiss != null)
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "list object fail,current analysis count not correct: ", "Expect no analysis will be returned");
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }

                    if (response.fmss.Length != expectedcurrentfms)
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "list object fail,current fms count not correct: ", "actural:" + response.fmss.Length.ToString() + " expect:" + expectedcurrentfms.ToString());
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }

                    //list noncurrent objects

                    request.currentSpecified = true;
                    request.current = false;
                    request.patientInternalId = patientid;
                    request.type = PatientListObjectsType.all;

                    response = nps.listObjects(request);

                    int expectednoncurrentps = int.Parse(ids.ExpectedValues.GetParameter("noncurpsnum").Value);
                    int expectednoncurrentfms = int.Parse(ids.ExpectedValues.GetParameter("noncurfmsnum").Value);
                    int expectednoncurrentanalysis = int.Parse(ids.ExpectedValues.GetParameter("noncuranalysisnum").Value);
                    if (response.presentationStates.Length != expectednoncurrentps)
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "list object fail, non current ps count not correct: ", "actual:" + response.presentationStates.Length.ToString() + " expect:" + expectednoncurrentanalysis.ToString());
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }
                    //get PS
                    foreach (PresentationStateType pst in response.presentationStates)
                    {
                        XMLResult rslget = pss.getPresentationState(pst.uid);
                        if (rslget.IsErrorOccured)
                        {
                            pimp.Result = TestResult.Fail;
                            pimp.Outputs.AddParameter("Import Main Dir", "get PS fail: ", rslget.Message);
                            SaveRound(r);
                            ps.deletePatient(patientid);
                            goto error;
                        }

                    }

                    //check 3d object

                    if (response.volumes.Length != int.Parse(ids.ExpectedValues.GetParameter("expect3dnum").Value))
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "Import 3d objects fail: ", "Count is " + response.volumes.Length.ToString() + ",expect:" + ids.ExpectedValues.GetParameter("expect3dnum").Value);
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }

                    if (response.analysiss.Length != expectednoncurrentanalysis)
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "list object fail,non current analysis count not correct: ", "actual:" + response.analysiss.Length.ToString() + " expect:" + expectednoncurrentanalysis.ToString());
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }

                    if (response.fmss.Length != expectednoncurrentfms)
                    {
                        pimp.Result = TestResult.Fail;
                        pimp.Outputs.AddParameter("Import Main Dir", "list object fail,non current fms count not correct: ", "actual:" + response.fmss.Length.ToString() + " expect:" + expectednoncurrentfms.ToString());
                        SaveRound(r);
                        ps.deletePatient(patientid);
                        continue;
                    }

                    //Finally the test success
                    pimp.Result = TestResult.Pass;
                    pimp.Outputs.AddParameter("Import Main Dir", "Success", "OK");
                    SaveRound(r);
                    ps.deletePatient(patientid);
                }
                catch (Exception e)
                {
                    ps.deletePatient(patientid);
                    pimp.Result = TestResult.Fail;
                    pimp.Outputs.AddParameter("Import Main Dir", "Fail", "Exception caught,message:" + e.Message);
                    SaveRound(r);
                }

            }
            error:
            Output();
        }
        // Case 1496: 1.2.3_ImportImage_FMS
        public void Run_Import_FMS_Case1496()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = true;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import image");
                CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                r.CheckPoints.Add(pCreate);

                PatientService ps = new PatientService();
                ImportService ims = new ImportService();
                XMLParameter pa = new XMLParameter("patient");
                XMLParameter ia = new XMLParameter("import");

                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "import")
                    {
                        ia.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                }

                string ep_nodeNum = string.Empty;
                string ep_totalSubImageNum = string.Empty;
                string ep_successImageNum = string.Empty;
                for (int i = 0; i < ids.ExpectedValues.Count; i++)
                {
                    if (ids.ExpectedValues.GetParameter(i).Step == "import")
                    {
                        if (ids.ExpectedValues.GetParameter(i).Key == "node")
                        {
                            ep_nodeNum = ids.ExpectedValues.GetParameter(i).Value;
                        }
                        else if (ids.ExpectedValues.GetParameter(i).Key == "total")
                        {
                            ep_totalSubImageNum = ids.ExpectedValues.GetParameter(i).Value;
                        }
                        else if (ids.ExpectedValues.GetParameter(i).Key == "success")
                        {
                            ep_successImageNum = ids.ExpectedValues.GetParameter(i).Value;
                        }
                    }
                }

                XMLParameter epGetFMSInfo = new XMLParameter();
                //XMLParameter epGetFMSDescription = new XMLParameter();

                for (int i = 0; i < ids.ExpectedValues.Count; i++)
                {
                    if (ids.ExpectedValues.GetParameter(i).Step == "getFMSInfo")
                    {
                        epGetFMSInfo.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                    }
                    //else if (ids.ExpectedValues.GetParameter(i).Step == "getFMSDescription")
                    //{
                    //    epGetFMSDescription.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                    //}
                }

                try
                {
                    if (isCreatePatient)
                    {
                        XMLResult result = ps.createPatient(pa);
                        if (!result.IsErrorOccured)
                        {
                            patientUID = result.SingleResult;
                            pCreate.Outputs.AddParameter("Create patient UID", "Create Patient", patientUID);
                            pCreate.Result = TestResult.Pass;
                        }
                        else
                        {
                            pCreate.Outputs.AddParameter("Create patient UID", "Create Patient Fail", result.ResultContent);
                            pCreate.Result = TestResult.Fail;
                        }
                    }

                    CheckPoint pImport = new CheckPoint("Import Image", "Test import");
                    r.CheckPoints.Add(pImport);

                    string filePath = string.Empty;
                    string archivePath = string.Empty;
                    bool move = false;
                    for (int c = 0; c < ia.Length; c++)
                    {
                        if (ia.GetParameterName(c) == "path")
                            filePath = ia.GetParameterValue(c);
                        if (ia.GetParameterName(c) == "archivePath")
                            archivePath = ia.GetParameterValue(c);
                        if (ia.GetParameterName(c) == "move")
                        {
                            if (ia.GetParameterValue(c) == "true")
                                move = true;
                        }
                    }

                    XMLResult rslImport = ims.importObject(patientUID, "", filePath, archivePath, move, "false");

                    /*********************** import FMS return sample:
                       <trophy type="result" version="1.0">
                          <status code="0" message="ok" />
                        - <fms>
                          <parameter key="internal_id" value="637e9a0d-73dc-447e-bf7d-607b6a088468" />
                          </fms>
                        - <image>
                          <parameter key="internal_id" value="c8e90079-1f6f-4d6c-92d2-4cd91e63c3bc" />
                          </image>
                        - <presentationstate>
                          <parameter key="internal_id" value="2ff59bd5-d1c3-4a3b-a514-9871abded236" />
                          </presentationstate>
                        - <image>
                          <parameter key="internal_id" value="9057d7c5-8e1a-4aee-95ce-a4a9e98dc42e" />
                          </image>
                        - <presentationstate>
                          <parameter key="internal_id" value="99179d8d-9855-4bb4-b1c0-c47c7e364d95" />
                          </presentationstate>
                          </trophy>
                     * **********************/

                    if (rslImport.IsErrorOccured)
                    {
                        pImport.Result = TestResult.Fail;
                        pImport.Outputs.AddParameter("Import FMS fail", "Import", rslImport.Message);
                        pImport.Outputs.AddParameter("Import FMS returns error code", "Import", rslImport.Code.ToString());
                    }
                    else
                    {
                        if (rslImport.MultiResults.Count.ToString() != ep_nodeNum)
                        {
                            pImport.Result = TestResult.Fail;
                            pImport.Outputs.AddParameter("Import FMS returns wrong node", "Import", rslImport.ResultContent);
                        }
                        else
                        {
                            pImport.Result = TestResult.Pass;

                            for (int i = 0; i < rslImport.MultiResults.Count - 1; i++)
                            {
                                string internalID = rslImport.MultiResults[i].GetParameterValueByName("internal_id");
                                if (internalID == null || internalID == string.Empty)
                                {
                                    pImport.Result = TestResult.Fail;
                                    pImport.Outputs.AddParameter("Import image returns wrong FMS, image or PS info", "Import", rslImport.ResultContent);
                                    break;
                                }
                            }

                            if (pImport.Result == TestResult.Pass)
                            {
                                string totalSubImages = rslImport.MultiResults[rslImport.MultiResults.Count - 1].GetParameterValueByName("total");
                                string successSubImages = rslImport.MultiResults[rslImport.MultiResults.Count - 1].GetParameterValueByName("success");

                                if (totalSubImages != ep_totalSubImageNum || successSubImages != ep_successImageNum)
                                {
                                    pImport.Result = TestResult.Fail;
                                    pImport.Outputs.AddParameter("Import FMS returns wrong info for [other] when import sub images", "Import", rslImport.ResultContent);
                                }
                                else
                                {
                                    pImport.Result = TestResult.Pass;
                                    pImport.Outputs.AddParameter("import FMS returns OK", "Import", rslImport.ResultContent);
                                }
                            }
                        }
                    }

                    #region Call GetFMSInfo to check the return value
                    FMSService fmsSvc = new FMSService();

                    string fmsID = string.Empty; // Try to get from the import return
                    fmsID = rslImport.MultiResults[0].GetParameterValueByName("internal_id");

                    CheckPoint cpGetFMSInfo = new CheckPoint("GetFMSInfo", "Call GetFMSInfo to check the return value");
                    r.CheckPoints.Add(cpGetFMSInfo);

                    XMLResult rtGetFMSInfo = fmsSvc.getFMSInfo(fmsID);
                    if (rtGetFMSInfo.IsErrorOccured)
                    {
                        cpGetFMSInfo.Result = TestResult.Fail;
                        cpGetFMSInfo.Outputs.AddParameter("Get FMS Info returns error", "getFMSInfo", rtGetFMSInfo.ResultContent);
                    }
                    else
                    {
                        cpGetFMSInfo.Outputs.AddParameter("Get FMS Info returns success", "getFMSInfo", rtGetFMSInfo.Message);

                        //Check the return info contain the expected key and value: parameter key="XXX" value="XXX"
                        foreach (XMLParameterNode node in epGetFMSInfo.Parameters)
                        {
                            if (!rtGetFMSInfo.ResultContent.Contains("parameter key=\"" + node.ParameterName + "\" value=\"" + node.ParameterValue + "\""))
                            {
                                cpGetFMSInfo.Result = TestResult.Fail;
                                cpGetFMSInfo.Outputs.AddParameter("Get FMS Info returns wrong key-value info for: " + node.ParameterName, "GetFMSInfo", rtGetFMSInfo.ResultContent);
                                continue;
                            }
                            else
                            {
                                cpGetFMSInfo.Outputs.AddParameter("Get FMS Info returns correct key-value info for: " + node.ParameterName, "GetFMSInfo", "ok");
                            }
                        }

                        if (cpGetFMSInfo.Result != TestResult.Fail)
                        {
                            cpGetFMSInfo.Result = TestResult.Pass;
                            cpGetFMSInfo.Outputs.AddParameter("Get FMS Info return all correct info", "GetFMSInfo", rtGetFMSInfo.ResultContent);
                        }
                    }
                    #endregion

                    if (isDeletePatient)
                    {
                        CheckPoint cpDelete = new CheckPoint("Delete Patient", "Test delete patient");
                        r.CheckPoints.Add(cpDelete);
                        XMLResult rltDelete = ps.deletePatient(patientUID);
                        if (rltDelete.IsErrorOccured)
                        {
                            cpDelete.Outputs.AddParameter("Delete created patient returns error", "Delete Patient", rltDelete.Message);
                            cpDelete.Result = TestResult.Fail;
                        }
                        else
                        {
                            cpDelete.Outputs.AddParameter("Delete created patient returns OK", "Delete Patient", rltDelete.Message);
                            cpDelete.Result = TestResult.Pass;
                        }
                    }

                    SaveRound(r);
                }
                catch (Exception ex)
                {
                    CheckPoint cp = new CheckPoint();
                    r.CheckPoints.Add(cp);
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message", ex.Message);
                    cp.Result = TestResult.Fail;
                    SaveRound(r);
                }
            }
            Output();
        }
        public void Run_Acquisition_New_FMS_2_Case1670()
        {
            int runCount = 0;
            string acquireType = string.Empty;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Acquisition");

                ApplicationService apps = new ApplicationService();
                //start 2D simulator and register 2D simulator to CSDM with same port number
                Start2DSimulator s2d = new Start2DSimulator(10000);
                System.Threading.Thread.Sleep(20);
                apps.registerApplication("2DViewer", "localhost", 10000, true);

                //get acquire information and expect information
                XMLParameter acq = new XMLParameter("acq_info");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "acquire")
                    {
                        acq.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "acquireType")
                    {
                        acquireType = ids.InputParameters.GetParameter(i).Key;
                    }
                }
                Dictionary<string, string> expectVal = new Dictionary<string, string>();
                for (int j = 0; j < ids.ExpectedValues.Count; j++)
                {
                    if (ids.InputParameters.GetParameter(j).Step == "acquire")
                    {
                        expectVal.Add(ids.ExpectedValues.GetParameter(j).Key, ids.ExpectedValues.GetParameter(j).Value);
                    }
                }

                CheckPoint pAcquire = new CheckPoint("Acquire Image", "Acquisition RVG");
                r.CheckPoints.Add(pAcquire);
                System.Diagnostics.Debug.Print("Acquire start");

                //start stomp message listener
                string stopMessageType = "teststop";
                string stopMessageContent = "teststop";

                string hostadd = PAS.AutoTest.TestUtility.Utility.GetCSDMConfig(PAS.AutoTest.TestUtility.CSDMConfigSection.remote, "host");
                string portnoti = PAS.AutoTest.TestUtility.Utility.GetCSDMConfig(PAS.AutoTest.TestUtility.CSDMConfigSection.remote, "notificationPort");
                NotificationSim.ReceiveNotification rn = new NotificationSim.ReceiveNotification(hostadd, int.Parse(portnoti));

                System.Collections.Generic.List<string> rms = new System.Collections.Generic.List<string>();
                rms.Add("topic.acquisitionCompleted");
                rn.startListon(rms, stopMessageType, stopMessageContent);

                AcquisitionService acqs = new AcquisitionService();
                XMLResult rslAcqRVG = acqs.startAcquisition(acq);

                switch (acquireType)
                {
                    case "FMS":
                        System.Diagnostics.Debug.Print("FMS Acquire");
                        //Utility.AcqFMS(40, 300);
                        System.Threading.Thread tx = new System.Threading.Thread(Utility.AcquireFMSOne);
                        tx.Start();
                        break;
                    default:
                        System.Diagnostics.Debug.Print("NOT FMS/PANO/CEPH/CR Acquire");
                        break;
                }

                string acq_session_id = "";
                //System.Threading.Thread.Sleep(50);
                if (rslAcqRVG.IsErrorOccured)
                {
                    System.Diagnostics.Debug.Print("Acquire fail:");
                    pAcquire.Result = TestResult.Fail;
                    pAcquire.Outputs.AddParameter("Acquire image error", "startAcquisition", rslAcqRVG.Message);
                    continue;
                }
                else
                {
                    acq_session_id = rslAcqRVG.SingleResult;
                    pAcquire.Result = TestResult.Pass;
                    pAcquire.Outputs.AddParameter("Acquire image success", "startAcquisition", rslAcqRVG.ResultContent);

                    //start an advanced simulator to receive the specified command
                    int port = 10000;
                    string sRet = "";
                    TwoDSim.AdvanceSimulator asi = new TwoDSim.AdvanceSimulator(port);
                    asi.StartSimulater("0,OK;open_acquired_objects");
                    sRet = asi.StopSimulator(120000);

                    CheckPoint pCheckMessage = new CheckPoint("Check Command", "Acquisition SOCKET Message");
                    r.CheckPoints.Add(pCheckMessage);
                    if (sRet == "")
                    {
                        pCheckMessage.Result = TestResult.Fail;
                        pCheckMessage.Outputs.AddParameter("NO COMMAND ERROR", "Check Command", "TIMEOUT: The socket message doesn't received");
                        SaveRound(r);
                        continue;
                    }
                    else
                    {
                        pCheckMessage.Outputs.AddParameter("open_acquired_objects COMMAND parameter", "Record Command", sRet);
                    }

                    ParseMessageContent cn = new ParseMessageContent(sRet);

                    //get patient internal id from command message
                    string patient_uid = cn.getValueFromKey("-patient_internal_id");
                    bool gotPatientId = false;
                    foreach (KeyValuePair<string, string> kvp in expectVal)
                    {
                        if (kvp.Key == "patient_internal_id" && kvp.Value == patient_uid)
                        {
                            gotPatientId = true;
                        }
                    }
                    if (!gotPatientId)
                    {
                        pCheckMessage.Result = TestResult.Fail;
                        pCheckMessage.Outputs.AddParameter("Patient ID Check ERROR", "Check Command", "The socket message content with WRONG patient ID");
                        SaveRound(r);
                        continue;
                    }

                    string fms_internal_id_from_acqResult = "";
                    string fms_internal_id_from_mapfile = "";
                    string image_internal_id_from_acqResult = "";
                    string ps_internal_id_from_acqResult = "";
                    string image_internal_id_from_mapfile = "";
                    string ps_internal_id_from_mapfile = "";

                    //get acquisition session id from command message
                    string session_uid_from_command = cn.getValueFromKey("-session_id");
                    if (acq_session_id != session_uid_from_command)
                    {
                        pCheckMessage.Result = TestResult.Fail;
                        pCheckMessage.Outputs.AddParameter("Session ID Check EROR", "Check Command", "The session id from command not equals the id from startAcquisition!");
                        SaveRound(r);
                        continue;
                    }

                    int timeout = 0;
                    do
                    {
                        XMLResult rslgetAcqResult = acqs.getAcquisitionResult(session_uid_from_command);

                        if (!rslgetAcqResult.IsErrorOccured && rslgetAcqResult.Code == 0)
                        {
                            pCheckMessage.Outputs.AddParameter("Show the content after getAcquisitionResult", "Output getAcquisitionResult", rslgetAcqResult.ResultContent);
                            ParseXMLContent rslForFMS = new ParseXMLContent(rslgetAcqResult.ResultContent);
                            fms_internal_id_from_acqResult = rslForFMS.getStringWithPathAndType("trophy/object_info", "fms", "value");
                            image_internal_id_from_acqResult = rslForFMS.getStringWithPathAndType("trophy/object_info", "image", "value");
                            ps_internal_id_from_acqResult = rslForFMS.getStringWithPathAndType("trophy/object_info", "presentation_state", "value");
                            break;
                        }
                        timeout++;
                        System.Threading.Thread.Sleep(1000);
                    } while (timeout < 300);
                    if (timeout >= 300)
                    {
                        pCheckMessage.Result = TestResult.Fail;
                        pCheckMessage.Outputs.AddParameter("Try too many times", "Check getAcquisitionResult", "TIMEOUT of getAcquisitionResult");
                        break;
                    }

                    string fmsfilepath = "";
                    string original_path = "";
                    //parser the mapping xml content from command message
                    string mapping_xml = cn.getValueFromKey("-mapping_xml");
                    string mapping_content = base64tools.DecodeString4base(mapping_xml);
                    pCheckMessage.Outputs.AddParameter("Show the decode mapping file content", "Output mappingfile", mapping_content);
                    string target_path = "";
                    string keep_target_path = "";
                    if (mapping_content != null)
                    {
                        ParseXMLContent pc = new ParseXMLContent(mapping_content);
                        pc.getValueFromPath("path_mapping/instance");
                        string type = pc.getValueByKey("type");
                        bool gotType = false;
                        foreach (KeyValuePair<string, string> kvp in expectVal)
                        {
                            if (kvp.Key == "type" && type.Contains(kvp.Value))
                            {
                                gotType = true;
                            }
                        }
                        if (!gotType)
                        {
                            pCheckMessage.Result = TestResult.Fail;
                            pCheckMessage.Outputs.AddParameter("Type Check ERROR", "Check Command", "The socket message content with WRONG type");
                            SaveRound(r);
                            continue;
                        }

                        original_path = pc.getValueByKey("original_path");

                        //check the acquired image has been put into correct position.
                        target_path = pc.getValueByKey("target_path");
                        keep_target_path = target_path;
                        int needCheckFile = 0;
                        int checkedFile = 0;
                        do
                        {
                            string sub_target_path = target_path;
                            int indexKey = sub_target_path.IndexOf(";");
                            if (indexKey != -1)
                            {
                                sub_target_path = sub_target_path.Substring(0, indexKey);
                                target_path = target_path.Substring(indexKey + 1);

                                //temp in here to skip the processing file check.
                                if (sub_target_path.Contains(".xml"))
                                {
                                    continue;
                                }

                                needCheckFile++;
                                bool dicomfileexist = Utility.isFileExisted(sub_target_path);
                                if (sub_target_path.Contains(".fms"))
                                    fmsfilepath = sub_target_path;

                                if (!dicomfileexist)
                                {
                                    pCheckMessage.Result = TestResult.Fail;
                                    pCheckMessage.Outputs.AddParameter("Dicom File {" + sub_target_path + "} Check ERROR", "Check Command", "The acquired image not in cache place");
                                    SaveRound(r);
                                    continue;
                                }
                                checkedFile++;
                            }
                        } while (target_path != "");

                        if (needCheckFile != checkedFile)
                        {
                            pCheckMessage.Result = TestResult.Fail;
                            pCheckMessage.Outputs.AddParameter("Files Check ERROR", "Check Command", "No all files contained in Message are exist");
                            SaveRound(r);
                            continue;
                        }

                        //get all image uid from mapping file
                        image_internal_id_from_mapfile = pc.getWithPathAndTypeFromMappingFile("path_mapping", "Image", "instance_internal_id");
                        //get all ps uid from mapping file
                        ps_internal_id_from_mapfile = pc.getWithPathAndTypeFromMappingFile("path_mapping", "Image", "ps_internal_id");
                        //get FMS uid from mapping file
                        fms_internal_id_from_mapfile = pc.getWithPathAndTypeFromMappingFile("path_mapping", "FMS", "instance_internal_id");

                        string processdatafilecontent = pc.getWithPathAndTypeFromMappingFile("path_mapping", "ProcessingDataFile", "content");
                        int countForProcessing = 0;
                        do
                        {
                            string sub_processdatafilecontent = processdatafilecontent;
                            int indexKey3 = sub_processdatafilecontent.IndexOf(";");
                            if (indexKey3 != -1)
                            {

                                sub_processdatafilecontent = sub_processdatafilecontent.Substring(0, indexKey3);
                                processdatafilecontent = processdatafilecontent.Substring(indexKey3 + 1);
                                if (sub_processdatafilecontent != "")
                                {
                                    countForProcessing++;
                                    string processingXMLcontent = base64tools.DecodeString4base(sub_processdatafilecontent);
                                    pCheckMessage.Outputs.AddParameter("Processing Data File from SDK", "Processing Content " + countForProcessing, processingXMLcontent);
                                }
                            }
                        } while (processdatafilecontent != "");

                    }
                    if (image_internal_id_from_acqResult != image_internal_id_from_mapfile)
                    {
                        pCheckMessage.Result = TestResult.Fail;
                        pCheckMessage.Outputs.AddParameter("Message and Interface result", "Check Command", "The image id from command not equals the id from getAcquisitionResult!");
                        SaveRound(r);
                        continue;
                    }
                    if (ps_internal_id_from_acqResult != ps_internal_id_from_mapfile)
                    {
                        pCheckMessage.Result = TestResult.Fail;
                        pCheckMessage.Outputs.AddParameter("Message and Interface result", "Check Command", "The presentation id from command not equals the id from getAcquisitionResult!");
                        SaveRound(r);
                        continue;
                    }
                    if (fms_internal_id_from_acqResult != fms_internal_id_from_mapfile)
                    {
                        pCheckMessage.Result = TestResult.Fail;
                        pCheckMessage.Outputs.AddParameter("Message and Interface result", "Check Command", "The FMS id from command not equals the id from getAcquisitionResult!");
                        SaveRound(r);
                        continue;
                    }

                    //parser the trophy xml content from command message
                    string acq_out_xml = cn.getValueFromKey("-acq_out_xml");
                    string acq_out = base64tools.DecodeString4base(acq_out_xml);
                    pCheckMessage.Outputs.AddParameter("XML From SDK", "Check Command", acq_out);

                    //Check the FMS contain the correct image that compare with mapping files
                    ParseXMLContent pc1 = new ParseXMLContent(fmsfilepath, "File");
                    string psIDInFMS = pc1.getStringFromPath("FMS_DATA/ItemData/Identifier");
                    int checkPSIDInResult = 0;
                    int psInFMSContent = 0;
                    do
                    {
                        string sub_psID = psIDInFMS;
                        int indexKey = sub_psID.IndexOf(";");
                        if (indexKey != -1)
                        {
                            psInFMSContent++;
                            sub_psID = sub_psID.Substring(0, indexKey);
                            psIDInFMS = psIDInFMS.Substring(indexKey + 1);
                        }
                        if (ps_internal_id_from_acqResult.Contains(sub_psID))
                        {
                            checkPSIDInResult++;
                        }

                    } while (psIDInFMS != "");
                    if (checkPSIDInResult == psInFMSContent)
                    {
                        pCheckMessage.Outputs.AddParameter("Message and Interface result", "Check Command", "All IMAGEs in FMS are matched with mapping file");
                    }
                    else
                    {
                        pCheckMessage.Outputs.AddParameter("Message and Interface result", "Check Command", "NOT All IMAGEs in FMS are matched with mapping file");
                    }
                    //Check the FMS contain the correct image end

                    System.Threading.Thread.Sleep(5000);
                    CheckPoint pCheckGetImage = new CheckPoint("Check NOTIFICATION", "Acquisition complete Message");
                    r.CheckPoints.Add(pCheckGetImage);
                    apps.sendGenericNotification(stopMessageType, stopMessageContent);
                    System.Threading.Thread.Sleep(1000);
                    //check getFMSInfo
                    int getn = rn.getRecievedNumber();
                    if (getn == 2)
                    {
                        FMSService fmss = new FMSService();
                        int indexKey = fms_internal_id_from_mapfile.IndexOf(";");
                        if (indexKey != -1)
                        {
                            fms_internal_id_from_mapfile = fms_internal_id_from_mapfile.Substring(0, indexKey);
                        }

                        //check get FMS description with content
                        XMLResult fmsDesRsl = fmss.getFMSDescription(fms_internal_id_from_mapfile);
                        string psids = "";
                        if (fmsDesRsl.IsErrorOccured || fmsDesRsl.Code != 0)
                        {
                            pCheckGetImage.Result = TestResult.Fail;
                            pCheckGetImage.Outputs.AddParameter("Get FMS Info result", "Get Return XML", fmsDesRsl.ResultContent);
                            continue;
                        }
                        else
                        {
                            ParseXMLContent pc2 = new ParseXMLContent(fmsDesRsl.ResultContent);
                            pc2.getValueFromPath("trophy/presentationstate");
                            psids = pc2.getValueByKey("internal_id");
                        }
                        int checkPSIDInFMSDes = 0;
                        int psInGetFMSDes = 0;
                        do
                        {
                            string sub_psID = psids;
                            int indKey = sub_psID.IndexOf(";");
                            if (indKey != -1)
                            {
                                psInGetFMSDes++;
                                sub_psID = sub_psID.Substring(0, indKey);
                                psids = psids.Substring(indKey + 1);
                            }
                            if (ps_internal_id_from_acqResult.Contains(sub_psID))
                            {
                                checkPSIDInFMSDes++;
                            }

                        } while (psids != "");

                        if (checkPSIDInFMSDes == psInGetFMSDes)
                        {
                            pCheckGetImage.Outputs.AddParameter("Check the presentation ids again with getAcquisitionResult", "Check the presentation ids", "ALL IDs is equal with aspect");
                        }
                        else
                        {
                            pCheckGetImage.Result = TestResult.Fail;
                            pCheckGetImage.Outputs.AddParameter("Check the presentation ids again with getAcquisitionResult", "Check the presentation ids", "Some IDs is not equal with aspect");
                            continue;
                        }

                        //got the first image to check
                        XMLParameter getImage = new XMLParameter("image");
                        int indexImage = image_internal_id_from_acqResult.IndexOf(";");
                        if (indexImage != -1)
                            image_internal_id_from_acqResult = image_internal_id_from_acqResult.Substring(0, indexImage);
                        getImage.AddParameter("internal_id", image_internal_id_from_acqResult);
                        ImageService imagesrv = new ImageService();
                        XMLResult getImageRsl = imagesrv.getImageInfo(getImage);
                        //match items
                        pCheckGetImage.Outputs.AddParameter("Get Image Info result", "Get Return XML", getImageRsl.ResultContent);
                        int matchValueCount = 0;
                        for (int i = 0; i < getImageRsl.DicomArrayResult.Length; i++)
                        {
                            if (getImageRsl.DicomArrayResult.Parameters[i].ParameterName == "internal_id"
                                && getImageRsl.DicomArrayResult.Parameters[i].ParameterValue == image_internal_id_from_acqResult)
                            {
                                matchValueCount++;
                            }

                            if (getImageRsl.DicomArrayResult.Parameters[i].ParameterName == "patient_internal_id"
                                && getImageRsl.DicomArrayResult.Parameters[i].ParameterValue == patient_uid)
                            {
                                matchValueCount++;
                            }
                            keep_target_path = keep_target_path.Replace('\\', '/');
                            if (getImageRsl.DicomArrayResult.Parameters[i].ParameterName == "path"
                                && keep_target_path.Contains(getImageRsl.DicomArrayResult.Parameters[i].ParameterValue))
                            {
                                matchValueCount++;
                            }
                        }
                        if (matchValueCount == 3)
                        {
                            pCheckGetImage.Result = TestResult.Pass;
                            pCheckGetImage.Outputs.AddParameter("Get Image Info result", "Check Return XML", "All ID is matched");
                        }
                        else
                        {
                            pCheckGetImage.Result = TestResult.Fail;
                            pCheckGetImage.Outputs.AddParameter("Get Image Info result", "Check Return XML", "Some ID is not matched");
                        }

                    }
                    else
                    {
                        pCheckGetImage.Result = TestResult.Fail;
                        pCheckGetImage.Outputs.AddParameter("Notification not received", "Check Return", "No acquisition complete Message be received");
                    }

                    pCheckMessage.Result = TestResult.Pass;
                }
                SaveRound(r);
            }
            Output();
        }