protected override void Create(){
     m_csi1 = new CSI(this);
     Plot1 = AddPlot(new PlotAttributes("CSI", 0, Color.Blue, Color.Empty, 0, 0, true));
 }
 void CSI.IConsole.ReadLineAsync(CSI.Interpreter.InputHandler callback)
 {
     CSI.Interpreter.InputHandler inputHandler = this.inputHandler;
     this.inputHandler = callback;  // Register new callback
     if (inputHandler != null)
     {
         inputHandler(null);  // Cancel previous handler
     }
 }
 protected override void Create(){
     m_csi1 = new CSI(this);
     Plot1 = AddPlot(new PlotAttributes("CSI", 0, Color.Blue, Color.Empty, 0, 0, true));
 }
        public ActionResult CSIPersonalRecordsResults(CSI csi)
        {
            CheckLoginState();

            var    arraylist = new ArrayList();
            string name      = csi.FirstName;
            string sur       = csi.Surname;
            string id        = csi.IDNumber;
            string seaType   = csi.seaType;
            string eqType    = csi.eqType;
            string refe      = csi.Reference;

            var url     = "";
            var client  = new RestClient();
            var request = new RestRequest();

            DateTime time = DateTime.Now;

            string date_add = DateTime.Today.ToShortDateString();
            string time_add = time.ToString("T");
            string page     = "CSI Person " + eqType + "By " + seaType;
            string action   = "Name:" + name + "; Surname:" + sur;
            string user_id;

            try
            {
                user_id = Session["ID"].ToString();
            }
            catch (Exception e)
            {
                return(RedirectToAction("Index", "Home"));
            }

            string us = Session["Name"].ToString();

            string dbConnectionString = ConfigurationManager.ConnectionStrings["MySqlConnection"].ConnectionString;//string.Format("server={0};uid={1};pwd={2};database={3};", serverIp, username, password, databaseName);

            var conn = new MySql.Data.MySqlClient.MySqlConnection(dbConnectionString);

            string query_uid = "INSERT INTO logs (date,time,page,action,user_id,user) VALUES('" + date_add + "','" + time_add + "','" + page + "','" + action + "','" + user_id + "','" + us + "')";

            TempData["user"] = Session["Name"].ToString();
            TempData["date"] = DateTime.Today.ToShortDateString();
            TempData["ref"]  = refe;
            conn.Open();

            var cmd2 = new MySqlCommand(query_uid, conn);

            var reader2 = cmd2.ExecuteReader();

            conn.Close();
            string authtoken = GetLoginToken("*****@*****.**", "P@ssw0rd!");

            if (!tokenValid(authtoken))
            {
                //exit with a warning
            }
            //request headers
            request.RequestFormat = DataFormat.Json;
            request.AddHeader("Content-Type", "application/json");

            IRestResponse response = client.Execute <RootObject>(request);
            dynamic       rootObject;
            JObject       o;
            JToken        token;

            try
            {
                switch (seaType + "|" + eqType)
                {
                case "idnumber|trace":
                    url     = "https://uatrest.searchworks.co.za/individual/csipersontrace/idnumber/";
                    client  = new RestClient(url);
                    request = new RestRequest(Method.POST);
                    var apiIdTrace = new
                    {
                        SessionToken = authtoken,
                        Reference    = us, //search reference: probably store in logs
                        IDNumber     = id,
                    };
                    request.Parameters.Clear();
                    request.AddParameter("application/json", JsonConvert.SerializeObject(apiIdTrace), ParameterType.RequestBody);
                    request.AddParameter("Authorization", "Bearer " + authtoken, ParameterType.HttpHeader);
                    //ApiResponse is a class to model the data we want from the API response
                    //make the API request and get a response
                    response   = client.Execute <RootObject>(request);
                    rootObject = JObject.Parse(response.Content);
                    //JObject o = JObject.Parse(response.Content);
                    o     = JObject.Parse(response.Content);//Newtonsoft.Json.Linq.JObject search!!!!
                    token = JToken.Parse(response.Content);
                    TempData["SearchType"]      = seaType;
                    TempData["ResponseMessage"] = rootObject.ResponseMessage;
                    TempData["PDFCopyURL"]      = rootObject.PDFCopyURL;
                    TempData["FirstName"]       = rootObject.ResponseObject.PersonInformation.FirstName;
                    TempData["Title"]           = rootObject.ResponseObject.PersonInformation.Title;
                    TempData["Surname"]         = rootObject.ResponseObject.PersonInformation.Surname;
                    TempData["Fullname"]        = rootObject.ResponseObject.PersonInformation.Fullname;
                    TempData["IDNumber"]        = rootObject.ResponseObject.PersonInformation.IDNumber;
                    TempData["DateOfBirth"]     = rootObject.ResponseObject.PersonInformation.DateOfBirth;
                    TempData["MaritalStatus"]   = rootObject.ResponseObject.PersonInformation.MaritalStatus;
                    TempData["Gender"]          = rootObject.ResponseObject.PersonInformation.Gender;
                    TempData["Age"]             = rootObject.ResponseObject.PersonInformation.Age;
                    TempData["Quality"]         = rootObject.ResponseObject.PersonInformation.Quality;
                    TempData.Keep();
                    return(View());

                case "name|trace":

                    Debug.WriteLine("name|trace");

                    url = "https://uatrest.searchworks.co.za/individual/csipersonrecords/personverification/name/";

                    client  = new RestClient(url);
                    request = new RestRequest(Method.POST);
                    var apinameTrace = new
                    {
                        sessionToken = authtoken,
                        reference    = us, //search reference: probably store in logs
                        firstName    = name,
                        surname      = sur
                    };
                    //add parameters and token to request
                    request.Parameters.Clear();
                    request.AddParameter("application/json", JsonConvert.SerializeObject(apinameTrace), ParameterType.RequestBody);
                    request.AddParameter("Authorization", "Bearer " + authtoken, ParameterType.HttpHeader);
                    //ApiResponse is a class to model the data we want from the API response
                    //make the API request and get a response
                    response   = client.Execute <RootObject>(request);
                    rootObject = JObject.Parse(response.Content);
                    o          = JObject.Parse(response.Content);//Newtonsoft.Json.Linq.JObject search!!!!
                    token      = JToken.Parse(response.Content);
                    System.Diagnostics.Debug.WriteLine(JObject.Parse(response.Content));
                    TempData["SearchType"]      = seaType;
                    TempData["ResponseMessage"] = rootObject.ResponseMessage;
                    TempData["PDFCopyURL"]      = rootObject.PDFCopyURL;
                    TempData["FirstName"]       = rootObject.ResponseObject[0].PersonInformation.FirstName;
                    TempData["Title"]           = rootObject.ResponseObject[0].PersonInformation.Title;
                    TempData["Surname"]         = rootObject.ResponseObject[0].PersonInformation.Surname;
                    TempData["Fullname"]        = rootObject.ResponseObject[0].PersonInformation.Fullname;
                    TempData["IDNumber"]        = rootObject.ResponseObject[0].PersonInformation.IDNumber;
                    TempData["DateOfBirth"]     = rootObject.ResponseObject[0].PersonInformation.DateOfBirth;
                    TempData["MaritalStatus"]   = rootObject.ResponseObject[0].PersonInformation.MaritalStatus;
                    TempData["Gender"]          = rootObject.ResponseObject[0].PersonInformation.Gender;
                    TempData["Age"]             = rootObject.ResponseObject[0].PersonInformation.Age;
                    TempData["Quality"]         = rootObject.ResponseObject[0].PersonInformation.Quality;
                    TempData.Keep();
                    //ViewData["FirstName1"] = (Array)o.SelectToken("ResponseObject");
                    //extract list of companies returned

                    //PersonInformation lst = getIndividualList(response);
                    return(View());

                case "nameandidnumber|trace":
                    Debug.WriteLine("nameandidnumber|trace");
                    url     = "https://uatrest.searchworks.co.za/individual/csipersonrecords/personverification/nameidnumber/";
                    client  = new RestClient(url);
                    request = new RestRequest(Method.POST);

                    var apinameidTrace = new
                    {
                        sessionToken = authtoken,
                        reference    = us, //search reference: probably store in logs
                        idNumber     = id,
                        firstName    = name,
                        surname      = sur
                    };
                    //add parameters and token to request
                    request.Parameters.Clear();
                    request.AddParameter("application/json", JsonConvert.SerializeObject(apinameidTrace), ParameterType.RequestBody);
                    request.AddParameter("Authorization", "Bearer " + authtoken, ParameterType.HttpHeader);
                    //ApiResponse is a class to model the data we want from the API response
                    //make the API request and get a response
                    response   = client.Execute <RootObject>(request);
                    rootObject = JObject.Parse(response.Content);
                    o          = JObject.Parse(response.Content);//Newtonsoft.Json.Linq.JObject search!!!!
                    token      = JToken.Parse(response.Content);
                    System.Diagnostics.Debug.WriteLine(response.Content);
                    TempData["SearchType"]      = seaType;
                    TempData["ResponseMessage"] = rootObject.ResponseMessage;
                    TempData["PDFCopyURL"]      = rootObject.PDFCopyURL;
                    TempData["FirstName"]       = rootObject.ResponseObject[0].PersonInformation.FirstName;
                    TempData["Title"]           = rootObject.ResponseObject[0].PersonInformation.Title;
                    TempData["Surname"]         = rootObject.ResponseObject[0].PersonInformation.Surname;
                    TempData["Fullname"]        = rootObject.ResponseObject[0].PersonInformation.Fullname;
                    TempData["IDNumber"]        = rootObject.ResponseObject[0].PersonInformation.IDNumber;
                    TempData["DateOfBirth"]     = rootObject.ResponseObject[0].PersonInformation.DateOfBirth;
                    TempData["MaritalStatus"]   = rootObject.ResponseObject[0].PersonInformation.MaritalStatus;
                    TempData["Gender"]          = rootObject.ResponseObject[0].PersonInformation.Gender;
                    TempData["Age"]             = rootObject.ResponseObject[0].PersonInformation.Age;
                    TempData["Quality"]         = rootObject.ResponseObject[0].PersonInformation.Quality;
                    TempData.Keep();

                    return(View());

                case "idnumber|verification":
                    //company search API call
                    url = "https://uatrest.searchworks.co.za/individual/csipersonrecords/personverification/idnumber/";
                    //create RestSharp client and POST request object
                    client  = new RestClient(url);
                    request = new RestRequest(Method.POST);
                    //object containing input parameter data for company() API method
                    var apiIdVeri = new
                    {
                        sessionToken = authtoken,
                        reference    = us, //search reference: probably store in logs
                        idNumber     = id,
                    };
                    //add parameters and token to request
                    request.Parameters.Clear();
                    request.AddParameter("application/json", JsonConvert.SerializeObject(apiIdVeri), ParameterType.RequestBody);
                    request.AddParameter("Authorization", "Bearer " + authtoken, ParameterType.HttpHeader);
                    //ApiResponse is a class to model the data we want from the API response
                    //make the API request and get a response
                    response   = client.Execute <RootObject>(request);
                    rootObject = JObject.Parse(response.Content);
                    //JObject o = JObject.Parse(response.Content);
                    o     = JObject.Parse(response.Content);//Newtonsoft.Json.Linq.JObject search!!!!
                    token = JToken.Parse(response.Content);
                    System.Diagnostics.Debug.WriteLine(response.Content);
                    TempData["SearchType"]      = seaType;
                    TempData["ResponseMessage"] = rootObject.ResponseMessage;
                    TempData["PDFCopyURL"]      = rootObject.PDFCopyURL;
                    TempData["FirstName"]       = rootObject.ResponseObject[0].PersonInformation.FirstName;
                    TempData["Title"]           = rootObject.ResponseObject[0].PersonInformation.Title;
                    TempData["Surname"]         = rootObject.ResponseObject[0].PersonInformation.Surname;
                    TempData["Fullname"]        = rootObject.ResponseObject[0].PersonInformation.Fullname;
                    TempData["IDNumber"]        = rootObject.ResponseObject[0].PersonInformation.IDNumber;
                    TempData["DateOfBirth"]     = rootObject.ResponseObject[0].PersonInformation.DateOfBirth;
                    TempData["MaritalStatus"]   = rootObject.ResponseObject[0].PersonInformation.MaritalStatus;
                    TempData["Gender"]          = rootObject.ResponseObject[0].PersonInformation.Gender;
                    TempData["Age"]             = rootObject.ResponseObject[0].PersonInformation.Age;
                    TempData["Quality"]         = rootObject.ResponseObject[0].PersonInformation.Quality;
                    TempData.Keep();

                    return(View());

                case "name|verification":
                    Debug.WriteLine("name|verification");

                    url = "https://uatrest.searchworks.co.za/individual/csipersonrecords/personverification/name/";

                    client  = new RestClient(url);
                    request = new RestRequest(Method.POST);
                    var apinameVeri = new
                    {
                        sessionToken = authtoken,
                        reference    = us, //search reference: probably store in logs
                        firstName    = name,
                        surname      = sur
                    };
                    //add parameters and token to request
                    request.Parameters.Clear();
                    request.AddParameter("application/json", JsonConvert.SerializeObject(apinameVeri), ParameterType.RequestBody);
                    request.AddParameter("Authorization", "Bearer " + authtoken, ParameterType.HttpHeader);
                    //ApiResponse is a class to model the data we want from the API response
                    //make the API request and get a response
                    response   = client.Execute <RootObject>(request);
                    rootObject = JObject.Parse(response.Content);
                    o          = JObject.Parse(response.Content);//Newtonsoft.Json.Linq.JObject search!!!!
                    token      = JToken.Parse(response.Content);
                    System.Diagnostics.Debug.WriteLine(response.Content);
                    TempData["SearchType"]      = seaType;
                    TempData["ResponseMessage"] = rootObject.ResponseMessage;
                    TempData["PDFCopyURL"]      = rootObject.PDFCopyURL;
                    TempData["FirstName"]       = rootObject.ResponseObject[0].PersonInformation.FirstName;
                    TempData["Title"]           = rootObject.ResponseObject[0].PersonInformation.Title;
                    TempData["Surname"]         = rootObject.ResponseObject[0].PersonInformation.Surname;
                    TempData["Fullname"]        = rootObject.ResponseObject[0].PersonInformation.Fullname;
                    TempData["IDNumber"]        = rootObject.ResponseObject[0].PersonInformation.IDNumber;
                    TempData["DateOfBirth"]     = rootObject.ResponseObject[0].PersonInformation.DateOfBirth;
                    TempData["MaritalStatus"]   = rootObject.ResponseObject[0].PersonInformation.MaritalStatus;
                    TempData["Gender"]          = rootObject.ResponseObject[0].PersonInformation.Gender;
                    TempData["Age"]             = rootObject.ResponseObject[0].PersonInformation.Age;
                    TempData["Quality"]         = rootObject.ResponseObject[0].PersonInformation.Quality;
                    TempData.Keep();

                    return(View());

                case "nameandidnumber|verification":
                    Debug.WriteLine("nameandidnumber|verification");
                    url     = "https://uatrest.searchworks.co.za/individual/csipersonrecords/personverification/nameidnumber/";
                    client  = new RestClient(url);
                    request = new RestRequest(Method.POST);

                    var apinameidVeri = new
                    {
                        sessionToken = authtoken,
                        reference    = us, //search reference: probably store in logs
                        idNumber     = id,
                        firstName    = name,
                        surname      = sur
                    };
                    //add parameters and token to request
                    request.Parameters.Clear();
                    request.AddParameter("application/json", JsonConvert.SerializeObject(apinameidVeri), ParameterType.RequestBody);
                    request.AddParameter("Authorization", "Bearer " + authtoken, ParameterType.HttpHeader);
                    //ApiResponse is a class to model the data we want from the API response
                    //make the API request and get a response
                    response   = client.Execute <RootObject>(request);
                    rootObject = JObject.Parse(response.Content);
                    o          = JObject.Parse(response.Content);//Newtonsoft.Json.Linq.JObject search!!!!
                    token      = JToken.Parse(response.Content);
                    System.Diagnostics.Debug.WriteLine(response.Content);
                    TempData["SearchType"]      = seaType;
                    TempData["ResponseMessage"] = rootObject.ResponseMessage;
                    TempData["PDFCopyURL"]      = rootObject.PDFCopyURL;
                    TempData["FirstName"]       = rootObject.ResponseObject[0].PersonInformation.FirstName;
                    TempData["Title"]           = rootObject.ResponseObject[0].PersonInformation.Title;
                    TempData["Surname"]         = rootObject.ResponseObject[0].PersonInformation.Surname;
                    TempData["Fullname"]        = rootObject.ResponseObject[0].PersonInformation.Fullname;
                    TempData["IDNumber"]        = rootObject.ResponseObject[0].PersonInformation.IDNumber;
                    TempData["DateOfBirth"]     = rootObject.ResponseObject[0].PersonInformation.DateOfBirth;
                    TempData["MaritalStatus"]   = rootObject.ResponseObject[0].PersonInformation.MaritalStatus;
                    TempData["Gender"]          = rootObject.ResponseObject[0].PersonInformation.Gender;
                    TempData["Age"]             = rootObject.ResponseObject[0].PersonInformation.Age;
                    TempData["Quality"]         = rootObject.ResponseObject[0].PersonInformation.Quality;
                    TempData.Keep();
                    return(View());
                }
            }
            catch (Exception e)
            {
                TempData["msg"] = "An error occured, please check the entered values.";
            }

            return(View());
        }