// Case 1658: 1.2.3_ImportImage_SimpleInstance_large file
        public void Run_Import_SimpleInstance_LargeFile_Case1658()
        {
            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");

                string instanceID = null;

                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);
                    }
                }

                XMLParameter epGetInstanceInfo = new XMLParameter();
                for (int i = 0; i < ids.ExpectedValues.Count; i++)
                {
                    if (ids.ExpectedValues.GetParameter(i).Step == "getInstanceInfo")
                    {
                        epGetInstanceInfo.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                    }
                }

                try
                {
                    if (isCreatePatient)
                    {
                        CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                        r.CheckPoints.Add(pCreate);

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

                    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 simple instance return sample:
                     * <trophy type="result" version="1.0">
                     * <status code="0" message="ok" />
                     * <instance><parameter key="internal_id" value="1f678090-2c54-4128-8d13-833645ac7483" /></instance>
                     * </trophy>
                     * ****************************************/

                    if (rslImport.IsErrorOccured)
                    {
                        pImport.Result = TestResult.Fail;
                        pImport.Outputs.AddParameter("Import simple instance fail", "Import", rslImport.Message);
                        pImport.Outputs.AddParameter("Import simple instance returns error code", "Import", rslImport.Code.ToString());
                    }
                    else
                    {
                        // Check the return contiains instance id
                        instanceID = rslImport.MultiResults[0].GetParameterValueByName("internal_id"); // image internal_id
                        if (instanceID == null || instanceID == string.Empty)
                        {
                            pImport.Result = TestResult.Fail;
                            pImport.Outputs.AddParameter("Import simple instance returns wrong instance internal id", "Import", rslImport.ResultContent);
                        }
                        else
                        {
                            pImport.Result = TestResult.Pass;
                            pImport.Outputs.AddParameter("import simple instance returns OK", "Import", rslImport.ResultContent);
                        }
                    }

                    #region Call getInstanceInfo to check expected key and value
                    SimpleInstanceService simpleInstanceSvc = new SimpleInstanceService();

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

                    XMLResult rtGetInstanceInfo = simpleInstanceSvc.getInstanceInfo(instanceID);
                    if (rtGetInstanceInfo.IsErrorOccured)
                    {
                        cpGetInstanceInfo.Result = TestResult.Fail;
                        cpGetInstanceInfo.Outputs.AddParameter("Get Instance Info return error", "getInstanceInfo", rtGetInstanceInfo.ResultContent);
                    }
                    else
                    {
                        cpGetInstanceInfo.Outputs.AddParameter("Get Instance Info return success", "getInstanceInfo", rtGetInstanceInfo.Message);

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

                        if (cpGetInstanceInfo.Result != TestResult.Fail)
                        {
                            cpGetInstanceInfo.Result = TestResult.Pass;
                            cpGetInstanceInfo.Outputs.AddParameter("Get Instance Info return all correct info", "GetInstanceInfo", rtGetInstanceInfo.ResultContent);
                        }
                    }
                    #endregion

                    System.Threading.Thread.Sleep(10000);

                    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();
        }
        //Case 161: 1.3.2_CreateSimpleInstance_N1_WithAllParameters
        public void Run_SimpleInstance_CreateSimpleInstance_Case161()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            string instanceUID = string.Empty;
            bool isCreatePatient = false;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Create simple instance");
                CheckPoint pCreate = new CheckPoint("Create patient", "Test create");
                r.CheckPoints.Add(pCreate);
                PatientService ps = new PatientService();
                //ImageService ims = new ImageService();
                SimpleInstanceService sis = new SimpleInstanceService();
                XMLParameter pa = new XMLParameter("patient");
                XMLParameter sia = new XMLParameter("instance");

                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 == "simple")
                    {
                        sia.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }

                }
                if (isCreatePatient)
                {
                    XMLResult result = ps.createPatient(pa);
                    if (!result.IsErrorOccured)
                    {
                        patientUID = result.SingleResult;

                        pCreate.Outputs.AddParameter("create", "Create patient UID", patientUID);
                        pCreate.Result = TestResult.Pass;
                    }
                }

                CheckPoint pInstance = new CheckPoint("Simple instance create", "Test image");
                r.CheckPoints.Add(pInstance);
                if (patientUID != string.Empty)
                {
                    sia.AddParameter("patient_internal_id", patientUID);
                    XMLResult instanceRsl = sis.createSimpleInstance(sia);
                    if (instanceRsl.IsErrorOccured)
                    {

                        pInstance.Outputs.AddParameter("create", "Create SimpleInstance error", instanceRsl.Message);
                        pInstance.Result = TestResult.Fail;
                    }
                    else
                    {
                        instanceUID = instanceRsl.SingleResult;
                        pInstance.Outputs.AddParameter("create", "Create SimpleInstance Id", instanceUID);
                        pInstance.Result = TestResult.Pass;
                    }
                }

                ps.deletePatient(patientUID);

                SaveRound(r);
            }

            Output();
        }
        public void Run_Acquisition_New_CS1600_8_Case1680()
        {
            int runCount = 0;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                string acquireType = string.Empty;
                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");

                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);

                System.Threading.Thread.Sleep(1000);

                string acq_session_id = "";
                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", "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 image_internal_id_from_acqResult = "";
                    //string ps_internal_id_from_acqResult = "";
                    //string image_internal_id_from_mapfile = "";
                    //string ps_internal_id_from_mapfile = "";
                    string video_internal_id_from_acqResult = "";
                    string video_internal_id_from_mapfile = "";
                    string retInstanceType = "";

                    //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 ERROR", "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);
                        //timeout added
                        if (!rslgetAcqResult.IsErrorOccured && rslgetAcqResult.Code == 0)
                        {
                            pCheckMessage.Outputs.AddParameter("Show the content after getAcquisitionResult", "Output getAcquisitionResult", rslgetAcqResult.ResultContent);
                            ParseXMLContent rslacqResult = new ParseXMLContent(rslgetAcqResult.ResultContent);
                            video_internal_id_from_acqResult = rslacqResult.getStringWithPathAndType("trophy/object_info", "video", "value");
                            break;
                        }
                        timeout++;
                        System.Threading.Thread.Sleep(1000);
                    } while (timeout < 120);
                    if (timeout >= 120)
                    {
                        pCheckMessage.Result = TestResult.Fail;
                        pCheckMessage.Outputs.AddParameter("Try too many times", "Check getAcquisitionResult", "TIMEOUT of getAcquisitionResult");
                        break;
                    }

                    //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 = "";

                    if (mapping_content != null)
                    {
                        ParseXMLContent pc = new ParseXMLContent(mapping_content);
                        pc.getValueFromPath("path_mapping/instance");
                        string type = pc.getValueByKey("type");

                        int indexKey = type.IndexOf(";");
                        if (indexKey != -1)
                            type = type.Substring(0, indexKey);

                        bool gotType = false;
                        foreach (KeyValuePair<string, string> kvp in expectVal)
                        {
                            if (kvp.Key == "type" && kvp.Value == type)
                            {
                                gotType = true;
                                retInstanceType = type;
                            }
                        }
                        if (!gotType)
                        {
                            pCheckMessage.Result = TestResult.Fail;
                            pCheckMessage.Outputs.AddParameter("Type Check ERROR", "Check Command ", "The socket message content with WRONG type");
                            SaveRound(r);
                            continue;
                        }

                        string original_path = pc.getValueByKey("original_path");

                        //check the acquired image has been put into correct position.
                        target_path = pc.getValueByKey("target_path");
                        string temp_target_path = target_path;
                        int indexPath = temp_target_path.IndexOf(";");
                        if (indexPath != -1)
                            temp_target_path = temp_target_path.Substring(0, indexPath);
                        //now the Processing data file not provide correct after send command
                        bool dicomfileexist = Utility.isFileExisted(temp_target_path);
                        if (!dicomfileexist)
                        {
                            pCheckMessage.Result = TestResult.Fail;
                            pCheckMessage.Outputs.AddParameter("Dicom File Check ERROR", "Check Command", "The acquired image not in cache place");
                            SaveRound(r);
                            continue;
                        }

                        //image_internal_id_from_mapfile = pc.getWithPathAndTypeFromMappingFile("path_mapping", "Image", "instance_internal_id");
                        //ps_internal_id_from_mapfile = pc.getWithPathAndTypeFromMappingFile("path_mapping", "Image", "ps_internal_id");
                        video_internal_id_from_mapfile = pc.getWithPathAndTypeFromMappingFile("path_mapping", "Video", "instance_internal_id");
                    }
                    if (video_internal_id_from_acqResult != video_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;
                    }

                    //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", "Output acquisition SDK content", acq_out);
                    pCheckMessage.Result = TestResult.Pass;
                    pCheckMessage.Outputs.AddParameter("Message and Interface result", "Check Command", "All ID is matched");

                    CheckPoint pCheckGetImage = new CheckPoint("Check NOTIFICATION", "Acquisition complete Message");
                    r.CheckPoints.Add(pCheckGetImage);
                    apps.sendGenericNotification(stopMessageType, stopMessageContent);
                    System.Threading.Thread.Sleep(1000);

                    //check getImageInfo
                    int getn = rn.getNotificationNumber();
                    if (getn == 2)
                    {

                        //XMLParameter getImage = new XMLParameter("image");
                        int indexImage = video_internal_id_from_acqResult.IndexOf(";");
                        if (indexImage != -1)
                            video_internal_id_from_acqResult = video_internal_id_from_acqResult.Substring(0, indexImage);
                        //getImage.AddParameter("internal_id", video_internal_id_from_acqResult);
                        //ImageService imagesrv = new ImageService();
                        SimpleInstanceService simplesrv = new SimpleInstanceService();
                        XMLResult getVideoRsl = simplesrv.getInstanceInfo(video_internal_id_from_acqResult);
                        //match items
                        pCheckGetImage.Outputs.AddParameter("Get Video Info result", "Get Return XML", getVideoRsl.ResultContent);
                        int matchValueCount = 0;
                        ParseXMLContent rslVideoResult = new ParseXMLContent(getVideoRsl.ResultContent);
                        if (target_path.Contains(rslVideoResult.getResultWithKey("trophy/instance", "file_name")))
                        {
                            matchValueCount++;
                        }
                        if ((rslVideoResult.getResultWithKey("trophy/instance", "patient_internal_id")).Contains(patient_uid + ";"))
                        {
                            matchValueCount++;
                        }
                        if ((rslVideoResult.getResultWithKey("trophy/instance", "instance_type")).Contains(retInstanceType.ToLower()))
                        {
                            matchValueCount++;
                        }
                        if ((rslVideoResult.getResultWithKey("trophy/instance", "object_type")).Contains("SimpleInstance;"))
                        {
                            matchValueCount++;
                        }
                        if (matchValueCount == 4)
                        {
                            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");
                    }

                }
                SaveRound(r);
            }
            Output();
        }