Ejemplo n.º 1
0
        // GET: Factory
        public async Task <ActionResult> Index()
        {
            ViewBag.Version = Global._sfAdminVersion;
            EmployeeSession empSession = null;

            if (Session["empSession"] != null)
            {
                empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString());
            }
            try
            {
                RestfulAPIHelper apiHelper = new RestfulAPIHelper();
                ViewBag.FactoryList = await apiHelper.callAPIService("GET", Global._factoryInCompanyEndPoint, null);

                ViewBag.CultureInfoList = await apiHelper.callAPIService("GET", Global._cultureInfoEndPoint, null);

                /* Setup Company Name and Company Photo on Page */
                CompanyModel   companyModel = new CompanyModel();
                CompanySession compSession  = await companyModel.GetCompanySessionData();

                ViewBag.CompanyName     = compSession.shortName;
                ViewBag.CompanyPhotoURL = compSession.photoURL;
                ViewBag.CompanyLat      = compSession.lat;
                ViewBag.CompanyLng      = compSession.lng;

                /* Setup Employee Data on Page */
                ViewBag.FirstName      = empSession.firstName;
                ViewBag.LastName       = empSession.lastName;
                ViewBag.Email          = empSession.email;
                ViewBag.PhotoURL       = empSession.photoURL;
                ViewBag.PermissionList = empSession.permissions;

                /* Setup Menu Item Active */
                ViewBag.MenuNavigation = empSession.navigationMenu;
                ViewBag.MenuItem       = "menuFactory";
            }
            catch (Exception ex)
            {
                LoginMsgSession loginMsgSession = new LoginMsgSession();
                if (ex.Message.ToLower() == "invalid session")
                {
                    loginMsgSession.toastLevel = "warning";
                    loginMsgSession.message    = "[[[Please Login]]]";
                }
                else
                {
                    loginMsgSession.toastLevel = "error";
                    loginMsgSession.message    = "[[[Authentication Fail]]].";
                    StringBuilder logMessage = new StringBuilder();
                    logMessage.AppendLine("audit: Authentication Fail.");
                    logMessage.AppendLine("email:" + empSession.email);
                    logMessage.AppendLine("password:"******"loginMsgSession"] = loginMsgSession.Serialize();
                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }
Ejemplo n.º 2
0
        public async Task <int> PostOperationTaskAsync(string name, int companyId, string entity, string entityId, string taskcontent)
        {
            OpsTaskModel     opsTaskModel    = new OpsTaskModel(name, companyId, entity, entityId, taskcontent);
            RestfulAPIHelper apiHelper       = new RestfulAPIHelper();
            string           opsTaskEndPoint = Global._operationTaskEndPoint;
            string           opsTaskPostData = opsTaskModel.GetPostData();
            dynamic          opsTaskObject   = JObject.Parse(await apiHelper.callAPIService("post", opsTaskEndPoint, opsTaskPostData));

            return(opsTaskObject.id);
        }
Ejemplo n.º 3
0
        private async Task <ActionResult> GetAuthenticationToken()
        {
            EmployeeSession empSession = null;

            if (Session["empSession"] != null)
            {
                empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString());
            }
            try
            {
                RestfulAPIHelper apiHelper  = new RestfulAPIHelper();
                string           deviceList = await apiHelper.callAPIService("GET", Global._deviceTypeEndPoint, null); //Just Pick up a light way Authentication API

                /* Set RememberMe Cookie or Destroy Cookie */
                HttpCookie rememberMeCookie = new HttpCookie("rememberMe");

                if (empSession.rememberMe)
                {
                    rememberMeCookie.Values.Add("email", empSession.email);
                    rememberMeCookie.Values.Add("password", empSession.password);
                    rememberMeCookie.Expires = DateTime.Now.AddYears(1);
                }
                else
                {
                    rememberMeCookie.Expires = DateTime.Now.AddYears(-1);
                }
                Response.Cookies.Add(rememberMeCookie);
                Models.Employee employee     = new Models.Employee();
                string[]        redirectPath = employee.getRedirectionPath().Split('/');
                return(RedirectToAction(redirectPath[1], redirectPath[0]));
            }
            catch (Exception ex)
            {
                LoginMsgSession loginMsgSession = new LoginMsgSession();
                if (ex.Message.ToLower() == "invalid session")
                {
                    loginMsgSession.toastLevel = "warning";
                    loginMsgSession.message    = "[[[Please Login]]]";
                }
                else
                {
                    loginMsgSession.toastLevel = "error";
                    loginMsgSession.message    = "[[[Authentication Fail]]].";
                    StringBuilder logMessage = new StringBuilder();
                    logMessage.AppendLine("audit: Authentication Fail.");
                    logMessage.AppendLine("email:" + empSession.email);
                    logMessage.AppendLine("password:"******"loginMsgSession"] = loginMsgSession.Serialize();
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 4
0
        private async Task <string> GetIoTDeviceKey(string iotHubDeviceId)
        {
            RestfulAPIHelper apiHelper = new RestfulAPIHelper();
            string           endPoint  = Global._iotDeviceEndPoint;

            endPoint = endPoint + "/" + iotHubDeviceId;
            string jsonString = await apiHelper.callAPIService("GET", endPoint, null);

            dynamic jsonResult = JObject.Parse(jsonString);

            return(jsonResult.IoTHubDeviceKey);
        }
Ejemplo n.º 5
0
        private async Task <string> GetCertificateThumbprint(string certificateId)
        {
            RestfulAPIHelper apiHelper = new RestfulAPIHelper();
            string           endPoint  = Global._deviceCertificateEndPoint;

            endPoint = endPoint + "/" + certificateId;
            string jsonString = await apiHelper.callAPIService("get", endPoint, null);

            dynamic jsonResult = JObject.Parse(jsonString);

            return(jsonResult.Thumbprint);
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> EditDashboard()
        {
            if (Request.Form["inputCompanyId"] == null)
            {
                return(RedirectToAction("Index", "Company"));
            }
            try
            {
                string           companyId     = Request.Form["inputCompanyId"];
                RestfulAPIHelper apiHelper     = new RestfulAPIHelper();
                string           companyString = await apiHelper.callAPIService("GET", Global._companyEndPoint + "/" + companyId, null);

                dynamic companyObj = JObject.Parse(companyString);

                ViewBag.dashboardList = await apiHelper.callAPIService("GET", Global._externalDashboardEndPoint + "/Company/" + companyId, null);

                ViewBag.CompanyId   = companyId;
                ViewBag.CompanyName = companyObj.Name;
                //ViewBag.CompanyName = companyObj.Name;
                //ViewBag.EmployeeList = await apiHelper.callAPIService("GET", Global._employeeEndPoint + "/Company/" + companyId, null);
                // ViewBag.UserRoleList = await apiHelper.callAPIService("GET", Global._userRoleEndPoint + "/Company/" + companyId, null);

                //ViewBag.FirstName = Session["firstName"].ToString();
                // ViewBag.LastName = Session["lastName"].ToString();
                //ViewBag.Email = Session["email"].ToString();

                /* Setup Menu Item Active */
                ViewBag.MenuItem = "menuCompany";
            }
            catch (Exception ex)
            {
                if (ex.Message.ToLower() == "invalid session")
                {
                    Session["toastLevel"]   = "warning";
                    Session["loginMessage"] = "Please Login";
                }
                else
                {
                    Session["toastLevel"]   = "error";
                    Session["loginMessage"] = "Authentication Fail.";
                    StringBuilder logMessage = new StringBuilder();
                    logMessage.AppendLine("audit: Authentication Fail.");
                    logMessage.AppendLine("email:" + Session["email"]);
                    logMessage.AppendLine("password:"******"password"]);
                    Global._sfAuditLogger.Audit(logMessage);
                }
                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }
Ejemplo n.º 7
0
        private async Task <dynamic> GetIoTHubConnectionString(string iotHubAlias)
        {
            RestfulAPIHelper apiHelper = new RestfulAPIHelper();
            string           endPoint  = Global._iotHubEndPoint;

            endPoint = endPoint + "/" + iotHubAlias;
            string jsonString = await apiHelper.callAPIService("get", endPoint, null);

            dynamic jsonResult = JObject.Parse(jsonString);

            dynamic connectionStrings = new System.Dynamic.ExpandoObject();

            connectionStrings.primary   = jsonResult.P_IoTHubConnectionString;
            connectionStrings.secondary = jsonResult.S_IoTHubConnectionString;

            return(connectionStrings);
        }
Ejemplo n.º 8
0
        private async Task <ActionResult> GetAuthenticationToken()
        {
            try
            {
                RestfulAPIHelper apiHelper = new RestfulAPIHelper();
                ViewBag.FactoryList = await apiHelper.callAPIService("GET", Global._deviceTypeEndPoint, null);      //Just Pick up a light way Authentication API

                /* Set RememberMe Cookie or Destroy Cookie */
                HttpCookie rememberMeCookie = new HttpCookie("rememberMe");
                if ((Session["rememberMe"] != null) && (bool.Parse(Session["rememberMe"].ToString())))
                {
                    rememberMeCookie.Values.Add("email", Session["email"].ToString());
                    rememberMeCookie.Values.Add("password", Session["password"].ToString());
                    rememberMeCookie.Expires = DateTime.Now.AddYears(1);
                }
                else
                {
                    rememberMeCookie.Values.Add("email", Session["email"].ToString());
                    rememberMeCookie.Values.Add("password", Session["password"].ToString());
                    rememberMeCookie.Expires = DateTime.Now.AddYears(-1);
                }
                Response.Cookies.Add(rememberMeCookie);

                return(RedirectToAction("Index", "Company"));
            }
            catch (Exception ex)
            {
                if (ex.Message.ToLower() == "invalid session")
                {
                    Session["toastLevel"]   = "warning";
                    Session["loginMessage"] = "Please Login";
                }
                else
                {
                    Session["toastLevel"]   = "error";
                    Session["loginMessage"] = "Authentication Fail.";
                    StringBuilder logMessage = new StringBuilder();
                    logMessage.AppendLine("audit: Authentication Fail.");
                    logMessage.AppendLine("email:" + Session["email"]);
                    logMessage.AppendLine("password:"******"password"]);
                    Global._sfAuditLogger.Audit(logMessage);
                }
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> EquipmentClass()
        {
            try
            {
                RestfulAPIHelper apiHelper = new RestfulAPIHelper();
                ViewBag.Equipment = await apiHelper.callAPIService("GET", Global._equipmentClassEndPoint, null);

                ViewBag.CompanyList = await apiHelper.callAPIService("GET", Global._companyEndPoint, null);

                /* Setup Company Name and Company Photo on Page */
                ViewBag.CompanyName     = Session["companyName"];
                ViewBag.CompanyPhotoURL = Session["companyPhotoURL"];

                /* Setup Menu Item Active */
                ViewBag.MenuItem = "menuSetup";

                /* Setup Employee Data on Page */
                ViewBag.FirstName = Session["firstName"];
                ViewBag.LastName  = Session["lastName"];
                ViewBag.Email     = Session["email"];
                ViewBag.PhotoURL  = Session["photoURL"];
            }
            catch (Exception ex)
            {
                if (ex.Message.ToLower() == "invalid session")
                {
                    Session["toastLevel"]   = "warning";
                    Session["loginMessage"] = "Please Login";
                }
                else
                {
                    Session["toastLevel"]   = "error";
                    Session["loginMessage"] = "Authentication Fail.";
                    StringBuilder logMessage = new StringBuilder();
                    logMessage.AppendLine("audit: Authentication Fail.");
                    logMessage.AppendLine("email:" + Session["email"]);
                    logMessage.AppendLine("password:"******"password"]);
                    Global._sfAuditLogger.Audit(logMessage);
                }
                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> RunningTask()
        {
            try
            {
                RestfulAPIHelper apiHelper   = new RestfulAPIHelper();
                String           runningTask = await apiHelper.callAPIService("GET", Global._operationTaskSearchEndPoint, null);

                //JObject jsonObj = JObject.Parse(runningTask);
                string temp = runningTask.Replace("\r\n", "");
                ViewBag.RunningTaskList = temp.Replace("\\\\", "\\\\\\\\");
                System.Diagnostics.Debug.Print(runningTask);


                /* Setup Menu Item Active */
                ViewBag.MenuItem = "menuMonitor";

                /* Setup Employee Data on Page */
                ViewBag.FirstName = Session["firstName"];
                ViewBag.LastName  = Session["lastName"];
                ViewBag.Email     = Session["email"];
                ViewBag.PhotoURL  = Session["photoURL"];
            }
            catch (Exception ex)
            {
                if (ex.Message.ToLower() == "invalid session")
                {
                    Session["toastLevel"]   = "warning";
                    Session["loginMessage"] = "Please Login";
                }
                else
                {
                    Session["toastLevel"]   = "error";
                    Session["loginMessage"] = "Authentication Fail.";
                    StringBuilder logMessage = new StringBuilder();
                    logMessage.AppendLine("audit: Authentication Fail.");
                    logMessage.AppendLine("email:" + Session["email"]);
                    logMessage.AppendLine("password:"******"password"]);
                    Global._sfAuditLogger.Audit(logMessage);
                }
                return(RedirectToAction("Index", "Home"));
            }
            return(View());
        }
Ejemplo n.º 11
0
        public async Task Register(string CompanyId)
        {
            string clientOrigin = Context.Headers["Origin"];
            string hubHost      = Context.Headers["Host"];

            if (clientOrigin != null && clientOrigin.Contains("//"))
            {
                clientOrigin = clientOrigin.Substring(clientOrigin.IndexOf("//") + 2);
            }

            if (clientOrigin != null && clientOrigin != hubHost)
            {
                Global._sfAppLogger.Warn("Client Origin: " + clientOrigin);
                Global._sfAppLogger.Warn("Check Allow Domain ...");
                string allowDomain = "";
                try
                {
                    RestfulAPIHelper apiHelper = new RestfulAPIHelper(false, int.Parse(CompanyId));
                    allowDomain = await apiHelper.callAPIService("GET", Global._companyAllowDomainEndPoint, null);

                    allowDomain = allowDomain.Trim('"');
                }
                catch (Exception ex)
                {
                    Global._sfAppLogger.Error("Company Allow Domain API Exception: " + ex.Message + "," + ex.InnerException.Message);
                    return;
                }

                if (allowDomain != "*")
                {
                    if (!allowDomain.Contains(clientOrigin))
                    {
                        Global._sfAppLogger.Warn("Unauthorized. Allow Domain (" + allowDomain + "); Request Domain (" + clientOrigin + ")");
                        return;
                    }
                }
                Global._sfAppLogger.Warn("Authorized. Allow Domain (" + allowDomain + "); Request Domain (" + clientOrigin + ")");
            }
            await Groups.Add(Context.ConnectionId, CompanyId);

            PublishMessageByCompanyId(CompanyId, "{\"topic\":\"welcome\"}");
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> IoTHubReceiver()
        {
            try
            {
                RestfulAPIHelper apiHelper = new RestfulAPIHelper();
                ViewBag.IoTHubList = await apiHelper.callAPIService("GET", Global._iotHubEndPoint, null);

                if (Session["email"] == null)
                {
                    throw new Exception("invalid session");
                }

                ViewBag.FirstName = Session["firstName"].ToString();
                ViewBag.LastName  = Session["lastName"].ToString();
                ViewBag.Email     = Session["email"].ToString();

                /* Setup Menu Item Active */
                ViewBag.MenuItem = "menuMonitor";
            }
            catch (Exception ex)
            {
                if (ex.Message.ToLower() == "invalid session")
                {
                    Session["toastLevel"]   = "warning";
                    Session["loginMessage"] = "Please Login";
                }
                else
                {
                    Session["toastLevel"]   = "error";
                    Session["loginMessage"] = "Authentication Fail.";
                    StringBuilder logMessage = new StringBuilder();
                    logMessage.AppendLine("audit: Authentication Fail.");
                    logMessage.AppendLine("email:" + Session["email"]);
                    logMessage.AppendLine("password:"******"password"]);
                    Global._sfAuditLogger.Audit(logMessage);
                }
                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }
Ejemplo n.º 13
0
        // GET: Company
        public async Task <ActionResult> Index()
        {
            try
            {
                RestfulAPIHelper apiHelper = new RestfulAPIHelper();
                ViewBag.CompanyList = await apiHelper.callAPIService("GET", Global._companyEndPoint, null);

                ViewBag.CultureInfoList = await apiHelper.callAPIService("GET", Global._cultureInfoEndPoint, null);

                ViewBag.FirstName             = Session["firstName"].ToString();
                ViewBag.LastName              = Session["lastName"].ToString();
                ViewBag.Email                 = Session["email"].ToString();
                ViewBag.DocDBConnectionString = Global._sfDocDBConnectionString;
                ViewBag.AdminWebURI           = Global._sfAdminWebURI;

                /* Setup Menu Item Active */
                ViewBag.MenuItem = "menuCompany";
            }
            catch (Exception ex)
            {
                if (ex.Message.ToLower() == "invalid session")
                {
                    Session["toastLevel"]   = "warning";
                    Session["loginMessage"] = "Please Login";
                }
                else
                {
                    Session["toastLevel"]   = "error";
                    Session["loginMessage"] = "Authentication Fail.";
                    StringBuilder logMessage = new StringBuilder();
                    logMessage.AppendLine("audit: Authentication Fail.");
                    logMessage.AppendLine("email:" + Session["email"]);
                    logMessage.AppendLine("password:"******"password"]);
                    Global._sfAuditLogger.Audit(logMessage);
                }
                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }
Ejemplo n.º 14
0
        private async Task initialzation(string certificatePath)
        {
            _restfulAPIHelper = new RestfulAPIHelper(_hwProductKey.email, _hwProductKey.password);

            // Get the Device Model
            string resp = await _restfulAPIHelper.callDeviceAPIService("GET", _hwProductKey.email, null);

            _deviceModels = DeviceModels.CreateDeviceModels(resp);

            verifyAndAppendIoTHubAuthCertificatePath(_deviceModels, _certificatePath);

            // Get the Message Schema of Device
            resp = await _restfulAPIHelper.getDeviceMessageSchemaAPIService(_hwProductKey.email);

            _messageCatalogSchemaList = MessageCatalogSchema.CreateMessageCatalogSchemaList(resp);

            _deviceClient = getAzureIoTDeviceSDKClient(_deviceModels);

            // Get SfTwin Properties Helper
            _sfTwinPropertiesHelper = new SfTwinPropertiesHelper(_deviceClient);

            // Sync System Config of Twin
            await _sfTwinPropertiesHelper.SyncAndUpdateSfTwinPropertiesFromTwin();
        }
Ejemplo n.º 15
0
        public async Task <ActionResult> ReqAction()
        {
            string jsonString = "", postData = "", endPoint = "";

            if (Request.QueryString["action"] != null)
            {
                try
                {
                    RestfulAPIHelper apiHelper      = new RestfulAPIHelper();
                    string           requesterName  = Session["firstName"].ToString() + " " + Session["lastName"].ToString();
                    string           requesterEmail = Session["email"].ToString();
                    switch (Request.QueryString["action"].ToString().ToLower())
                    {
                    case "genextappkey":
                        string uniqueId = Guid.NewGuid().ToString();
                        jsonString = "{\"Key\":\"" + System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(uniqueId)) + "\"}";
                        break;

                    case "getsacredential":
                        var plainTextCredential = System.Text.Encoding.UTF8.GetBytes(Session["email"].ToString() + ":" + Session["password"].ToString());
                        jsonString = "{\"Credential\":\"" + System.Convert.ToBase64String(plainTextCredential) + "\"}";
                        break;

                    case "getcompany":
                        endPoint = Global._companyEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("get", endPoint, null);

                        break;

                    case "deletecompany":
                        endPoint = Global._companyEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            /********** Ops Infra By Andy ***********/
                            int         companyId       = Int32.Parse(Request.QueryString["Id"]);
                            DocDBCmdMsg docDBCmdMsg     = new DocDBCmdMsg("purge", companyId, requesterName, requesterEmail, 0);
                            int         operationTaskId = await PostOperationTaskAsync(docDBCmdMsg.task, companyId, docDBCmdMsg.entity, docDBCmdMsg.entityId, docDBCmdMsg.GetJsonInsensitiveContent());

                            if (operationTaskId > 0)
                            {
                                docDBCmdMsg.taskId = operationTaskId;
                                docDBCmdMsg.SendToServiceBus();
                            }

                            endPoint   = endPoint + "/" + Request.QueryString["Id"];
                            jsonString = await apiHelper.callAPIService("delete", endPoint, null);
                        }

                        break;

                    case "addcompany":
                    {
                        endPoint   = Global._companyEndPoint;
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("post", endPoint, postData);

                        //Get Object ID from API result
                        dynamic jsonResult = JObject.Parse(jsonString);
                        if (jsonResult.id != null)
                        {           //jsonResult = company
                            if (Request.Files.Count > 0)
                            {
                                string entityID = jsonResult.id;
                                endPoint = endPoint + "/" + entityID + "/Image";
                                byte[] byteFile = new byte[Request.Files[0].InputStream.Length];
                                Request.Files[0].InputStream.Read(byteFile, 0, (int)Request.Files[0].InputStream.Length);
                                jsonString = await apiHelper.putUploadFile(endPoint, byteFile, Request.Files[0].FileName);
                            }

                            /********** Ops Infra By Andy ***********/
                            int         companyId       = (int)jsonResult.id;
                            DocDBCmdMsg docDBCmdMsg     = new DocDBCmdMsg("create", companyId, requesterName, requesterEmail, 0);
                            int         operationTaskId = await PostOperationTaskAsync(docDBCmdMsg.task, companyId, docDBCmdMsg.entity, docDBCmdMsg.entityId, docDBCmdMsg.GetJsonInsensitiveContent());

                            if (operationTaskId > 0)
                            {
                                docDBCmdMsg.taskId = operationTaskId;
                                docDBCmdMsg.SendToServiceBus();
                            }
                        }
                        break;
                    }

                    case "updatecompany":
                    {
                        endPoint = Global._companyEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        if (Request.Files.Count > 0)
                        {
                            //admin-api/Company/{id}/Image
                            endPoint = endPoint + "/Image";
                            byte[] byteFile = new byte[Request.Files[0].InputStream.Length];
                            Request.Files[0].InputStream.Read(byteFile, 0, (int)Request.Files[0].InputStream.Length);
                            jsonString = await apiHelper.putUploadFile(endPoint, byteFile, Request.Files[0].FileName);
                        }
                        break;
                    }

                    case "getemployeebycmp":
                    {
                        endPoint = Global._employeeEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/Company/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("get", endPoint, null);

                        break;
                    }

                    case "getuserrolebycmp":
                    {
                        endPoint = Global._userRoleEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/Company/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("get", endPoint, null);

                        break;
                    }

                    case "deleteemployee":
                    {
                        endPoint = Global._employeeEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("delete", endPoint, null);

                        break;
                    }

                    case "addemployee":
                    {
                        endPoint   = Global._employeeEndPoint;
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("post", endPoint, postData);

                        dynamic jsonResult = JObject.Parse(jsonString);

                        if (Request.Files.Count > 0)
                        {
                            //Get Object ID from API result
                            if (jsonResult.id != null)
                            {
                                string entityID = jsonResult.id;
                                endPoint = endPoint + "/" + entityID + "/Image";
                                byte[] byteFile = new byte[Request.Files[0].InputStream.Length];
                                Request.Files[0].InputStream.Read(byteFile, 0, (int)Request.Files[0].InputStream.Length);
                                jsonString = await apiHelper.putUploadFile(endPoint, byteFile, Request.Files[0].FileName);
                            }
                        }

                        if (jsonResult.id != null && Request.Form["UserRoleId"] != null)
                        {
                            endPoint   = endPoint + "/" + jsonResult.id + "/Role";
                            jsonString = await apiHelper.callAPIService("post", endPoint, postData);
                        }

                        break;
                    }

                    case "updateemployee":
                    {
                        endPoint = Global._employeeEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        var RoleEndPoint = endPoint + "/Role";
                        if (Request.Form["UserRoleId"] != null)
                        {
                            jsonString = await apiHelper.callAPIService("put", RoleEndPoint, postData);
                        }
                        else
                        {
                            jsonString = await apiHelper.callAPIService("put", RoleEndPoint, "UserRoleId=");
                        }

                        if (Request.Files.Count > 0)
                        {
                            //admin-api/Company/{id}/Image
                            var    ImageEndPoint = endPoint + "/Image";
                            byte[] byteFile      = new byte[Request.Files[0].InputStream.Length];
                            Request.Files[0].InputStream.Read(byteFile, 0, (int)Request.Files[0].InputStream.Length);
                            jsonString = await apiHelper.putUploadFile(ImageEndPoint, byteFile, Request.Files[0].FileName);
                        }

                        break;
                    }

                    case "resetpassword":
                        endPoint   = Global._employeeEndPoint + "/" + Request.QueryString["Id"] + "/resetpassword";
                        postData   = Request.Form.ToString();
                        jsonString = apiHelper.changePassword("put", endPoint, postData);
                        break;

                    case "getuserrolebyemployeeid":
                        endPoint = Global._employeeEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"] + "/Role";
                        }
                        jsonString = await apiHelper.callAPIService("get", endPoint, null);

                        break;

                    case "getiothub":
                    {
                        endPoint = Global._iotHubInCompanyEndPoint;
                        if (Request.Form["CompanyId"] != null)
                        {
                            endPoint = endPoint + "/" + Request.Form["CompanyId"];
                        }
                        jsonString = await apiHelper.callAPIService("get", endPoint, null);

                        break;
                    }

                    case "deleteiothub":
                    {
                        endPoint = Global._iotHubEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("get", endPoint, null);

                        dynamic jsonResult = JObject.Parse(jsonString);
                        if (jsonResult.IoTHubAlias != null)
                        {
                            string IoTHubAlias = jsonResult.IoTHubAlias;
                            string CompanyId   = Request.Form["CompanyId"];
                            /* Send message to OpsInfra to remove IoTHub Receiver */
                            OpsInfraMessage opsInfraMessage = new OpsInfraMessage("provisioning iothub alias", "IoTHubAlias", IoTHubAlias, "remove iothub alias", 0, Session["firstName"].ToString() + " " + Session["lastName"].ToString(), Session["email"].ToString());
                            OpsTaskModel    opsTask         = new OpsTaskModel("Remove IoTHub Receiver", int.Parse(CompanyId), "IoTHubAlias", IoTHubAlias, opsInfraMessage.GetJsonContent());
                            postData = opsTask.GetPostData();
                            string taskEndPoint = Global._operationTaskEndPoint;
                            jsonString = await apiHelper.callAPIService("POST", taskEndPoint, postData);

                            jsonResult = JObject.Parse(jsonString);
                            if (jsonResult.id != null)
                            {
                                opsInfraMessage.taskId = jsonResult.id;
                                opsInfraMessage.Send();
                            }

                            /* Call Restful API to delete  */
                            jsonString = await apiHelper.callAPIService("delete", endPoint, null);
                        }
                        break;
                    }

                    case "addiothub":
                    {
                        endPoint   = Global._iotHubEndPoint;
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("post", endPoint, postData);

                        /* Send Message to OpsInfra to launch IoTHub Receiver */
                        string          IoTHubAlias     = Request.Form["IoTHubAlias"];
                        string          CompanyId       = Request.Form["CompanyId"];
                        OpsInfraMessage opsInfraMessage = new OpsInfraMessage("provisioning iothub alias", "IoTHubAlias", IoTHubAlias, "create iothub alias", 0, Session["firstName"].ToString() + " " + Session["lastName"].ToString(), Session["email"].ToString());
                        OpsTaskModel    opsTask         = new OpsTaskModel("Launch IoTHub Receiver", int.Parse(CompanyId), "IoTHubAlias", IoTHubAlias, opsInfraMessage.GetJsonContent());
                        postData = opsTask.GetPostData();
                        string taskEndPoint = Global._operationTaskEndPoint;
                        jsonString = await apiHelper.callAPIService("POST", taskEndPoint, postData);

                        dynamic jsonResult = JObject.Parse(jsonString);
                        if (jsonResult.id != null)
                        {
                            opsInfraMessage.taskId = jsonResult.id;
                            opsInfraMessage.Send();
                        }
                        break;
                    }

                    case "updateiothub":
                    {
                        endPoint = Global._iotHubEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        break;
                    }

                    case "addexternaldashboard":
                    {
                        endPoint = Global._externalDashboardEndPoint;
                        //if (Request.QueryString["Id"] != null)
                        // endPoint = endPoint + "/" + Request.QueryString["Id"];
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("post", endPoint, postData);

                        break;
                    }

                    case "updateexternaldashboard":
                    {
                        endPoint = Global._externalDashboardEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }

                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        break;
                    }

                    case "deleteexternaldashboard":
                    {
                        endPoint = Global._externalDashboardEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("delete", endPoint, postData);

                        break;
                    }

                    case "getallexterngetaldashboard":
                    {
                        endPoint   = Global._externalDashboardEndPoint + "/Company/" + Request.QueryString["Id"];
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("get", endPoint, postData);

                        break;
                    }


                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.ToLower() == "invalid session")
                    {
                        Response.StatusCode = 401;
                    }
                    else
                    {
                        StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                        logMessage.AppendLine("EndPoint:" + endPoint);
                        logMessage.AppendLine("Action:" + Request.QueryString["action"].ToString());
                        logMessage.AppendLine("PostData:" + Request.Form.ToString());
                        Global._sfAppLogger.Error(logMessage);
                        Response.StatusCode = 500;
                        jsonString          = ex.Message;
                    }
                }
            }

            return(Content(JsonConvert.SerializeObject(jsonString), "application/json"));
        }
Ejemplo n.º 16
0
        public async Task <ActionResult> ReqAction()
        {
            string jsonString = "", postData = "", endPoint = "";

            if (Request.QueryString["action"] != null)
            {
                try
                {
                    RestfulAPIHelper apiHelper = new RestfulAPIHelper();
                    switch (Request.QueryString["action"].ToString().ToLower())
                    {
                    case "changepassword":
                        endPoint   = Global._employeeEndPoint + "/" + Request.QueryString["Id"] + "/changepassword";
                        postData   = Request.Form.ToString();
                        jsonString = apiHelper.changePassword("put", endPoint, postData);
                        break;

                    case "updateemployee":
                    {
                        endPoint = Global._employeeEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            postData   = Request.Form.ToString();
                            endPoint   = endPoint + "/" + Request.QueryString["Id"];
                            jsonString = await apiHelper.callAPIService("put", endPoint, postData);
                        }

                        if (Request.Files.Count > 0)
                        {
                            //admin-api/Company/{id}/Image
                            var    ImageEndPoint = endPoint + "/Image";
                            byte[] byteFile      = new byte[Request.Files[0].InputStream.Length];
                            Request.Files[0].InputStream.Read(byteFile, 0, (int)Request.Files[0].InputStream.Length);
                            jsonString = await apiHelper.putUploadFile(ImageEndPoint, byteFile, Request.Files[0].FileName);
                        }

                        break;
                    }


                    default:

                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.ToLower() == "invalid session")
                    {
                        Response.StatusCode = 401;
                    }
                    else
                    {
                        StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                        logMessage.AppendLine("EndPoint:" + endPoint);
                        logMessage.AppendLine("Action:" + Request.QueryString["action"].ToString());
                        logMessage.AppendLine("PostData:" + Request.Form.ToString());
                        Global._sfAppLogger.Error(logMessage);
                        Response.StatusCode = 500;
                        jsonString          = ex.Message;
                    }
                }
            }

            return(Content(JsonConvert.SerializeObject(jsonString), "application/json"));
        }
Ejemplo n.º 17
0
        public async Task <ActionResult> LoginBySA()
        {
            EmployeeSession empSession = new EmployeeSession();

            try
            {
                string   inputCredential       = Request.Form["inputCredential"];
                var      inputCredentialByte   = System.Convert.FromBase64String(inputCredential);
                string   inputCredentialString = System.Text.Encoding.UTF8.GetString(inputCredentialByte);
                string[] credential            = inputCredentialString.Split(':');

                empSession.email      = credential[0];
                empSession.password   = credential[1];
                empSession.companyId  = int.Parse(Request.Form["inputCompanyId"]);
                empSession.adminFlag  = true;
                Session["empSession"] = empSession.Serialize();
                Session["loginBySA"]  = true;

                /* Set Company Entity */
                RestfulAPIHelper apiHelper     = new RestfulAPIHelper();
                string           CompanyEntiry = await apiHelper.callAPIService("GET", Global._companyEndPoint, null);

                dynamic companyObj = JObject.Parse(CompanyEntiry);

                CompanySession compSession = new CompanySession();
                if (companyObj.ShortName != null)
                {
                    compSession.shortName = companyObj.ShortName;
                }
                else
                {
                    compSession.shortName = companyObj.Name;
                }

                compSession.name       = companyObj.Name;
                compSession.photoURL   = companyObj.LogoURL;
                compSession.id         = companyObj.Id;
                compSession.lat        = companyObj.Latitude;
                compSession.lng        = companyObj.Longitude;
                Session["compSession"] = compSession.Serialize();

                /* Get User Authentication */
                return(await GetAuthenticationToken());
            }
            catch (Exception ex)
            {
                LoginMsgSession loginMsgSession = new LoginMsgSession();
                if (ex.Message.ToLower() == "invalid session")
                {
                    loginMsgSession.toastLevel = "warning";
                    loginMsgSession.message    = "[[[Please Login]]]";
                }
                else
                {
                    loginMsgSession.toastLevel = "error";
                    loginMsgSession.message    = "[[[Authentication Fail]]].";
                    StringBuilder logMessage = new StringBuilder();
                    logMessage.AppendLine("audit: Authentication Fail.");
                    logMessage.AppendLine("email:" + empSession.email);
                    logMessage.AppendLine("password:"******"loginMsgSession"] = loginMsgSession.Serialize();
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 18
0
        public async Task <ActionResult> ReqAction()
        {
            string jsonString = "", postData = "", endPoint = "";

            if (Request.QueryString["action"] != null)
            {
                try
                {
                    RestfulAPIHelper apiHelper = new RestfulAPIHelper();
                    switch (Request.QueryString["action"].ToString().ToLower())
                    {
                    case "addwidgetclass":
                        endPoint   = Global._widgetClassEndPoint;
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("post", endPoint, postData);

                        break;

                    case "updatewidgetclass":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._widgetClassEndPoint + "/" + Request.QueryString["Id"];
                        }
                        postData = Request.Form.ToString();
                        System.Diagnostics.Debug.Print("endPoint" + endPoint);
                        System.Diagnostics.Debug.Print("postData" + postData);
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        break;

                    case "getequipmentwidgetclass":
                        jsonString = await apiHelper.callAPIService("GET", Global._widgetClassEndPoint + "?level=equipment", null);

                        break;

                    case "getcompanywidgetclass":
                        jsonString = await apiHelper.callAPIService("GET", Global._widgetClassEndPoint + "?level=company", null);

                        break;

                    case "getfactorywidgetclass":
                        jsonString = await apiHelper.callAPIService("GET", Global._widgetClassEndPoint + "?level=factory", null);

                        break;

                    case "addequipclass":
                        endPoint   = Global._equipmentClassEndPoint;
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("post", endPoint, postData);

                        break;

                    case "deleteequipclass":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._equipmentClassEndPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("delete", endPoint, null);

                        break;

                    case "updateequipclass":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._equipmentClassEndPoint + "/" + Request.QueryString["Id"];
                        }
                        postData = Request.Form.ToString();
                        System.Diagnostics.Debug.Print("endPoint" + endPoint);
                        System.Diagnostics.Debug.Print("postData" + postData);
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        break;

                    case "getequipmentclass":
                        jsonString = await apiHelper.callAPIService("GET", Global._equipmentClassEndPoint, null);

                        break;

                    case "getdeviceclass":
                        jsonString = await apiHelper.callAPIService("GET", Global._deviceClassEndPoint, null);

                        break;

                    case "deletedeviceclass":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._deviceClassEndPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("delete", endPoint, null);

                        break;

                    case "adddeviceclass":
                        endPoint   = Global._deviceClassEndPoint;
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("post", endPoint, postData);

                        break;

                    case "updatedeviceclass":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._deviceClassEndPoint + "/" + Request.QueryString["Id"];
                        }
                        postData = Request.Form.ToString();
                        //System.Diagnostics.Debug.Print("endPoint" + endPoint);
                        //System.Diagnostics.Debug.Print("postData" + postData);
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        break;

                    //Device Configuration
                    case "getdeviceconfig":
                        jsonString = await apiHelper.callAPIService("GET", Global._deviceConfigEndPoint, null);

                        break;

                    case "updatedeviceconfig":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._deviceConfigEndPoint + "/" + Request.QueryString["Id"];
                        }
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        break;

                    case "adddeviceconfig":
                        endPoint   = Global._deviceConfigEndPoint;
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("post", endPoint, postData);

                        break;

                    case "deletedeviceconfig":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._deviceConfigEndPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("delete", endPoint, null);

                        break;

                    //MandatoryMsg
                    case "getmandatorymsg":
                        jsonString = await apiHelper.callAPIService("GET", Global._mandatoryMsgEndPoint, null);

                        break;

                    case "addmandatorymsg":
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("post", Global._mandatoryMsgEndPoint, postData);

                        break;

                    case "updatemandatorymsg":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._mandatoryMsgEndPoint + "/" + Request.QueryString["Id"];
                        }
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        break;

                    case "deletemandatorymsg":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._mandatoryMsgEndPoint + "/" + Request.QueryString["Id"];
                        }
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("delete", endPoint, null);

                        break;

                    //PermissionCatalog
                    case "getpermissioncatalog":
                        jsonString = await apiHelper.callAPIService("GET", Global._permissionCatalogEndPoint, null);

                        break;

                    case "addpermissioncatalog":
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("post", Global._permissionCatalogEndPoint, postData);

                        break;

                    case "updatepermissioncatalog":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._permissionCatalogEndPoint + "/" + Request.QueryString["Id"];
                        }
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        break;

                    case "deletepermissioncatalog":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._permissionCatalogEndPoint + "/" + Request.QueryString["Id"];
                        }
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("delete", endPoint, null);

                        break;

                    default:

                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.ToLower() == "invalid session")
                    {
                        Response.StatusCode = 401;
                    }
                    else
                    {
                        StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                        logMessage.AppendLine("EndPoint:" + endPoint);
                        logMessage.AppendLine("Action:" + Request.QueryString["action"].ToString());
                        logMessage.AppendLine("PostData:" + Request.Form.ToString());
                        Global._sfAppLogger.Error(logMessage);
                        Response.StatusCode = 500;
                        jsonString          = ex.Message;
                    }
                }
            }

            return(Content(JsonConvert.SerializeObject(jsonString), "application/json"));
        }
Ejemplo n.º 19
0
        public async Task <ActionResult> ReqAction()
        {
            string jsonString = "", postData = "", endPoint = "";
            int    companyId;

            if (Request.QueryString["mAction"] != null)
            {
                try
                {
                    RestfulAPIHelper apiHelper = new RestfulAPIHelper();
                    switch (Request.QueryString["mAction"].ToString().ToLower())
                    {
                    case "iothubreceiver":
                    {
                        companyId = int.Parse(Request.QueryString["companyId"].ToString());
                        string subAction   = Request.QueryString["sAction"].ToString();
                        string IoTHubAlias = Request.Form["iotHubAlias"].ToString();

                        endPoint = Global._operationTaskEndPoint;

                        if (subAction.ToLower() == "launch iothub receiver")
                        {
                            OpsInfraMessage opsInfraMessage = new OpsInfraMessage("provisioning iothub alias", "IoTHubAlias", IoTHubAlias, "create iothub alias", 0, Session["firstName"].ToString() + " " + Session["lastName"].ToString(), Session["email"].ToString());
                            OpsTaskModel    opsTask         = new OpsTaskModel(subAction, companyId, "IoTHubAlias", IoTHubAlias, opsInfraMessage.GetJsonContent());
                            postData   = opsTask.GetPostData();
                            jsonString = await apiHelper.callAPIService("POST", endPoint, postData);

                            dynamic jsonResult = JObject.Parse(jsonString);
                            if (jsonResult.id != null)
                            {
                                opsInfraMessage.taskId = jsonResult.id;
                                opsInfraMessage.Send();
                            }
                        }
                        else if (subAction.ToLower() == "restart iothub receiver")
                        {
                            IoTHubEventProcessTopic iotHubTopic = new IoTHubEventProcessTopic("Restart", IoTHubAlias, 0, Session["firstName"].ToString() + " " + Session["lastName"].ToString(), Session["email"].ToString());
                            OpsTaskModel            opsTask     = new OpsTaskModel(subAction, companyId, "IoTHubAlias", IoTHubAlias, iotHubTopic.GetJsonContent());
                            postData   = opsTask.GetPostData();
                            jsonString = await apiHelper.callAPIService("POST", endPoint, postData);

                            dynamic jsonResult = JObject.Parse(jsonString);
                            if (jsonResult.id != null)
                            {
                                iotHubTopic.taskId = jsonResult.id;
                                iotHubTopic.Send();
                            }
                        }
                        break;
                    }

                    case "getrunningtask":
                    {
                        endPoint = Global._operationTaskSearchEndPoint;
                        string q = "?";
                        if (Request.QueryString["taskstatus"] != null)
                        {
                            endPoint = endPoint + q + "taskstatus=" + Request.QueryString["taskstatus"];
                            q        = "&";
                        }
                        if (Request.QueryString["hours"] != null)
                        {
                            endPoint = endPoint + q + "hours=" + Request.QueryString["hours"];
                        }
                        jsonString = await apiHelper.callAPIService("GET", endPoint, postData);

                        break;
                    }

                    case "getusagelogsumbyday":
                    {
                        endPoint = Global._usageLogSumByDayEndPoint;
                        string q = "?";
                        if (Request.QueryString["day"] != null)
                        {
                            endPoint = endPoint + q + "days=" + Request.QueryString["day"];
                            q        = "&";
                        }

                        endPoint   = endPoint + q + "order=desc";
                        jsonString = await apiHelper.callAPIService("GET", endPoint, postData);

                        break;
                    }

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.ToLower() == "invalid session")
                    {
                        Response.StatusCode = 401;
                    }
                    else
                    {
                        StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                        logMessage.AppendLine("EndPoint:" + endPoint);
                        logMessage.AppendLine("Action:" + Request.QueryString["action"].ToString());
                        logMessage.AppendLine("PostData:" + Request.Form.ToString());
                        Global._sfAppLogger.Error(logMessage);
                        Response.StatusCode = 500;
                        jsonString          = ex.Message;
                    }
                }
            }
            return(Content(JsonConvert.SerializeObject(jsonString), "application/json"));
        }
Ejemplo n.º 20
0
        public async Task <ActionResult> ReqAction()
        {
            string jsonString = "";

            if (Request.QueryString["action"] != null)
            {
                string endPoint = Global._superAdminEndPoint;
                try
                {
                    RestfulAPIHelper apiHelper = new RestfulAPIHelper();
                    switch (Request.QueryString["action"].ToString().ToLower())
                    {
                    case "getsuperadmin":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("get", endPoint, null);

                        break;

                    case "deletesuperadmin":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("delete", endPoint, null);

                        break;

                    case "addsuperadmin":
                    {
                        string postData = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("post", endPoint, postData);

                        break;
                    }

                    case "updatesuperadmin":
                    {
                        //admin-api/SuperAdmin/{id}/
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        string postData = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        break;
                    }

                    case "changepassword":
                    {
                        endPoint = Global._superAdminEndPoint + "/" + Request.QueryString["Id"] + "/changepassword";
                        string postData = Request.Form.ToString();
                        jsonString = apiHelper.changePassword("put", endPoint, postData);
                        break;
                    }

                    default:

                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.ToLower() == "invalid session")
                    {
                        Response.StatusCode = 401;
                    }
                    else
                    {
                        StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                        logMessage.AppendLine("EndPoint:" + endPoint);
                        logMessage.AppendLine("Action:" + Request.QueryString["action"].ToString());
                        logMessage.AppendLine("PostData:" + Request.Form.ToString());
                        Global._sfAppLogger.Error(logMessage);
                        Response.StatusCode = 500;
                        jsonString          = ex.Message;
                    }
                }
            }

            return(Content(JsonConvert.SerializeObject(jsonString), "application/json"));
        }
Ejemplo n.º 21
0
        public async Task <ActionResult> RunningTask()
        {
            ViewBag.Version = Global._sfAdminVersion;
            EmployeeSession empSession = null;

            if (Session["empSession"] != null)
            {
                empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString());
            }
            try
            {
                RestfulAPIHelper apiHelper   = new RestfulAPIHelper();
                String           runningTask = await apiHelper.callAPIService("GET", Global._operationTaskSearchEndPoint, null);

                //JObject jsonObj = JObject.Parse(runningTask);
                runningTask             = runningTask.Replace("\r\n", "");
                ViewBag.RunningTaskList = runningTask.Replace("\\\\", "\\\\\\\\");
                System.Diagnostics.Debug.Print(runningTask);
                //ViewBag.RunningTaskList = await apiHelper.callAPIService("GET", Global._operationTaskEndPoint, null);
                /* Setup Company Name and Company Photo on Page */
                CompanyModel   companyModel = new CompanyModel();
                CompanySession compSession  = await companyModel.GetCompanySessionData();

                ViewBag.CompanyId       = compSession.id;
                ViewBag.CompanyName     = compSession.shortName;
                ViewBag.CompanyPhotoURL = compSession.photoURL;

                /* Setup Employee Data on Page */
                ViewBag.FirstName      = empSession.firstName;
                ViewBag.LastName       = empSession.lastName;
                ViewBag.Email          = empSession.email;
                ViewBag.PhotoURL       = empSession.photoURL;
                ViewBag.PermissionList = empSession.permissions;

                /* Setup Menu Item Active */
                ViewBag.MenuNavigation = empSession.navigationMenu;
                ViewBag.MenuItem       = "menuMonitor";
            }
            catch (Exception ex)
            {
                LoginMsgSession loginMsgSession = new LoginMsgSession();
                if (ex.Message.ToLower() == "invalid session")
                {
                    loginMsgSession.toastLevel = "warning";
                    loginMsgSession.message    = "[[[Please Login]]]";
                }
                else
                {
                    loginMsgSession.toastLevel = "error";
                    loginMsgSession.message    = "[[[Authentication Fail]]].";
                    StringBuilder logMessage = new StringBuilder();
                    logMessage.AppendLine("audit: Authentication Fail.");
                    logMessage.AppendLine("email:" + empSession.email);
                    logMessage.AppendLine("password:"******"loginMsgSession"] = loginMsgSession.Serialize();
                return(RedirectToAction("Index", "Home"));
            }
            return(View());
        }
Ejemplo n.º 22
0
        public async Task <ActionResult> FactoryDashboard()
        {
            ViewBag.Version         = Global._sfAdminVersion;
            ViewBag.WidgetOutput    = "<H2>Nothing Found.</H2>";
            ViewBag.GoogleMapAPIKey = Global._sfGoogleMapAPIKey;
            ViewBag.BaiduMapAPIKey  = Global._sfBaiduMapAPIKey;

            CompanyModel   companyModel = new CompanyModel();
            CompanySession compSession  = await companyModel.GetCompanySessionData();

            EmployeeSession empSession = null;

            if (Session["empSession"] != null)
            {
                empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString());
            }

            ViewBag.PermissionList = empSession.permissions;


            if (Request.QueryString["factoryId"] != null || Request.Form["factoryId"] != null)
            {
                string factoryId = Request.QueryString["factoryId"] != null ? Request.QueryString["factoryId"] : Request.Form["factoryId"];
                try
                {
                    RestfulAPIHelper apiHelper     = new RestfulAPIHelper();
                    string           factoryString = await apiHelper.callAPIService("GET", Global._factoryEndPoint + "/" + factoryId, null);

                    ViewBag.Factory = factoryString;
                    dynamic factoryObj = JObject.Parse(factoryString);

                    string EquipmentString = await apiHelper.callAPIService("GET", Global._equipmentInFactoryEndPoint + "/" + factoryId, null);

                    dynamic EquipmentObjs = JsonConvert.DeserializeObject(EquipmentString);

                    String WidgetCatalog = await apiHelper.callAPIService("GET", Global._widgetCatalogInCompanyEndPoint + "?level=factory", null);

                    ViewBag.WidgetCatalogList = WidgetCatalog.Replace("\r\n", "").Replace("\\\\", "\\\\\\\\");


                    /* Construct an New JSON String which contain all equipment under the Factory;  */
                    /* Using ExpandoObject to add couple new element into JSON object, which will be use on JavaScript */

                    List <ExpandoObject> Equipments = new List <ExpandoObject>();
                    foreach (var equipmentObj in EquipmentObjs)
                    {
                        ExpandoObject newEquipmentObj = JsonConvert.DeserializeObject <ExpandoObject>(JsonConvert.SerializeObject(equipmentObj), new ExpandoObjectConverter());
                        AddExpandoObjectProperty(newEquipmentObj, "msgTimestamp", "");
                        AddExpandoObjectProperty(newEquipmentObj, "alarmMsgTimestamp", "");
                        Equipments.Add(newEquipmentObj);
                    }

                    ViewBag.EquipmentList = JsonConvert.SerializeObject(Equipments);
                    /* End JSON Construct */

                    string AlarmMessageString = "[]";
                    try
                    {
                        string endPoint = Global._alarmMessageInFactoryEndPoint + "/" + factoryId + "?hours=24&top=100&order=asc";
                        AlarmMessageString = await apiHelper.callAPIService("GET", endPoint, null);

                        dynamic alarmObjs = JsonConvert.DeserializeObject(AlarmMessageString);
                        ViewBag.AlarmMessageCount = alarmObjs.Count;
                        //AlarmMessageString = AlarmMessageString.Replace("\\\"", "");
                    }
                    catch (Exception ex)
                    {
                        ViewBag.AlarmMessageCount = 0;
                        StringBuilder logMessage = new StringBuilder();
                        logMessage.AppendLine("Error on retrieve AlarmMessage from DocDB");
                        logMessage.AppendLine("Exeption:" + ex.Message);
                        Global._sfAppLogger.Error(logMessage);
                    }

                    //ViewBag.AlarmMessageList = AlarmMessageString;

                    /* Get Factory Widget */
                    string factoryDashboardJson = await apiHelper.callAPIService("GET", Global._factoryDashboard + "/" + factoryId, null);

                    try
                    {
                        dynamic factoryDashboardObj = JsonConvert.DeserializeObject(factoryDashboardJson);

                        int DashboardId = (int)factoryDashboardObj[0].Id;

                        if (DashboardId > 0)
                        {
                            string widgetJson = await apiHelper.callAPIService("GET", Global._widgetInDashboardEndPoint + "/" + DashboardId, null);

                            if (!string.IsNullOrEmpty(widgetJson))
                            {
                                DashboardModel dashboardModel = new DashboardModel();
                                dashboardModel.GenerateFactoryWidgetHTMLContent(factoryObj, widgetJson, compSession, EquipmentString);
                                ViewBag.WidgetOutput          = dashboardModel.GetWidgetHTMLContent();
                                ViewBag.WidgetUpdateFunctions = dashboardModel.GetWidgetJavaScriptFunction();
                                ViewBag.DashboardId           = DashboardId;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        ;
                    }


                    /* Setup Company Name and Company Photo on Page */
                    ViewBag.CompanyId       = compSession.id;
                    ViewBag.CompanyName     = compSession.shortName;
                    ViewBag.CompanyPhotoURL = compSession.photoURL;

                    /* Setup Menu Item Active */
                    ViewBag.MenuNavigation = "";
                    ViewBag.MenuItem       = "";
                }
                catch (Exception ex)
                {
                    // EmployeeSession empSession = null;
                    //if (Session["empSession"] != null)
                    //  empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString());
                    LoginMsgSession loginMsgSession = new LoginMsgSession();
                    if (ex.Message.ToLower() == "invalid session")
                    {
                        loginMsgSession.toastLevel = "warning";
                        loginMsgSession.message    = "[[[Please Login]]]";
                    }
                    else
                    {
                        loginMsgSession.toastLevel = "error";
                        loginMsgSession.message    = "[[[Authentication Fail]]].";
                        StringBuilder logMessage = new StringBuilder();
                        logMessage.AppendLine("audit: Authentication Fail.");
                        logMessage.AppendLine("email:" + empSession.email);
                        logMessage.AppendLine("password:"******"loginMsgSession"] = loginMsgSession.Serialize();
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View());
        }
Ejemplo n.º 23
0
        public async Task <ActionResult> EquipmentClassDashboard()
        {
            ViewBag.Version = Global._sfAdminVersion;
            int    EquipmentClassId = 0, DashboardId = 0;
            string endPoint = "", EquipmentId = "";

            ViewBag.WidgetOutput          = "<H2>Nothing Found.</H2>";
            ViewBag.WidgetUpdateFunctions = "";
            EmployeeSession empSession = null;

            if (Session["empSession"] != null)
            {
                empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString());
            }
            ViewBag.PermissionList = empSession.permissions;

            if (Request.QueryString["equipmentId"] != null || Request.Form["equipmentId"] != null)
            {
                try
                {
                    RestfulAPIHelper apiHelper = new RestfulAPIHelper();
                    if (Request.QueryString["equipmentId"] != null)
                    {
                        EquipmentId = Request.QueryString["equipmentId"].ToString();
                    }
                    else
                    {
                        EquipmentId = Request.Form["equipmentId"].ToString();
                    }
                    endPoint = Global._equipmentEndPoint + "/" + EquipmentId;
                    string equipmentString = await apiHelper.callAPIService("GET", endPoint, null);

                    endPoint = Global._dashboardInCompanyEndPoint + "?type=equipmentclass";
                    string equipmentClassDashboardJson = await apiHelper.callAPIService("GET", endPoint, null);

                    try
                    {
                        dynamic equipmentObj = JObject.Parse(equipmentString);
                        EquipmentClassId    = equipmentObj.EquipmentClassId;
                        ViewBag.EquipmentId = (string)equipmentObj.EquipmentId;

                        dynamic dashboardObjs = JsonConvert.DeserializeObject(equipmentClassDashboardJson);
                        foreach (var dashboard in dashboardObjs)
                        {
                            if (dashboard.EquipmentClassId == EquipmentClassId)
                            {
                                DashboardId = dashboard.Id;
                                break;
                            }
                        }
                        if (DashboardId > 0)
                        {
                            ViewBag.WidgetCatalogList = await apiHelper.callAPIService("GET", Global._widgetCatalogInCompanyEndPoint + "?level=equipment", null);

                            ViewBag.DashboardId = DashboardId;
                            endPoint            = Global._widgetInDashboardEndPoint + "/" + DashboardId;
                            string widgetJson = await apiHelper.callAPIService("GET", endPoint, null);

                            if (!string.IsNullOrEmpty(widgetJson))
                            {
                                DashboardModel dashboardModel = new DashboardModel();
                                dashboardModel.GenerateWidgetHTMLContent(equipmentString, widgetJson);
                                ViewBag.WidgetOutput               = dashboardModel.GetWidgetHTMLContent();
                                ViewBag.WidgetUpdateFunctions      = dashboardModel.GetWidgetJavaScriptFunction();
                                ViewBag.AlarmWidgetUpdateFunctions = dashboardModel.GetAlarmWidgetJavaScriptFunction();
                            }
                        }
                    }
                    catch (Exception)
                    {
                        ;
                    }
                    ViewBag.CompanyId = empSession.companyId;
                }
                catch (Exception ex)
                {
                    LoginMsgSession loginMsgSession = new LoginMsgSession();
                    if (ex.Message.ToLower() == "invalid session")
                    {
                        loginMsgSession.toastLevel = "warning";
                        loginMsgSession.message    = "[[[Please Login]]]";
                    }
                    else
                    {
                        loginMsgSession.toastLevel = "error";
                        loginMsgSession.message    = "[[[Authentication Fail]]].";
                        StringBuilder logMessage = new StringBuilder();
                        logMessage.AppendLine("audit: Authentication Fail.");
                        logMessage.AppendLine("email:" + empSession.email);
                        logMessage.AppendLine("password:"******"loginMsgSession"] = loginMsgSession.Serialize();
                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View());
        }
Ejemplo n.º 24
0
        public async Task <ActionResult> ReqAction()
        {
            string jsonString = "", postData = "", endPoint = "";

            if (Request.QueryString["action"] != null)
            {
                try
                {
                    EmployeeSession empSession = null;
                    if (Session["empSession"] != null)
                    {
                        empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString());
                    }
                    RestfulAPIHelper apiHelper      = new RestfulAPIHelper();
                    string           requesterName  = empSession.firstName + " " + empSession.lastName;
                    string           requesterEmail = empSession.email;
                    int companyId = empSession.companyId;
                    switch (Request.QueryString["action"].ToString().ToLower())
                    {
                    case "getiotdevice":
                    {
                        endPoint   = Global._iotDeviceInCompanyEndPoint;
                        jsonString = await apiHelper.callAPIService("GET", endPoint, null);

                        break;
                    }

                    case "getiotdevicebyfactory":
                    {
                        string factoryId = Request.QueryString["factoryId"];
                        if (factoryId != null)
                        {
                            if (factoryId.ToLower() == "all")
                            {
                                endPoint = Global._iotDeviceInCompanyEndPoint;
                            }
                            else
                            {
                                endPoint = Global._iotDeviceInFactoryEndPoint + "/" + factoryId;
                            }
                        }
                        jsonString = await apiHelper.callAPIService("GET", endPoint, null);

                        break;
                    }

                    case "addiotdevice":
                    {
                        //add
                        endPoint   = Global._iotDeviceEndPoint;
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("POST", endPoint, postData);

                        System.Diagnostics.Debug.Print(endPoint);
                        System.Diagnostics.Debug.Print(postData);

                        /********** Send OpsInfra command message ***********/
                        string iotHubAlias    = Request.Form["IoTHubAlias"];
                        string iotHubDeviceId = Request.Form["IoTHubDeviceId"];
                        string authType       = Request.Form["AuthenticationType"];
                        string ceritficateId  = Request.Form["DeviceCertificateId"];

                        IoTDeviceCmdMsg deviceCmdMsg = new IoTDeviceCmdMsg("create iothub register", iotHubDeviceId, authType, requesterName, requesterEmail, 0);
                        await deviceCmdMsg.Init(iotHubAlias, ceritficateId);

                        int operationTaskId = await PostOperationTaskAsync(deviceCmdMsg.task, companyId, deviceCmdMsg.entity, deviceCmdMsg.entityId, deviceCmdMsg.GetJsonInsensitiveContent());

                        if (operationTaskId > 0)
                        {
                            deviceCmdMsg.taskId = operationTaskId;
                            deviceCmdMsg.SendToServiceBus();
                        }
                        break;
                    }

                    case "updateiotdevice":
                    {
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._iotDeviceEndPoint + "/" + Request.QueryString["Id"];
                        }
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("GET", endPoint, null);

                        dynamic oldIoTDeviceObj = JObject.Parse(jsonString);
                        jsonString = await apiHelper.callAPIService("PUT", endPoint, postData);

                        /********** Send OpsInfra command message ***********/
                        dynamic newIoTDeviceObj        = new JObject();
                        string  newIoTHubDeviceId      = Request.Form["IoTHubDeviceId"];
                        string  newAuthenticationType  = Request.Form["AuthenticationType"];
                        string  newIoTHubAlias         = Request.Form["IoTHubAlias"];
                        string  newDeviceCertificateId = Request.Form["DeviceCertificateId"];

                        string oldIoTHubDeviceId      = oldIoTDeviceObj.IoTHubDeviceId;
                        string oldAuthenticationType  = oldIoTDeviceObj.AuthenticationType;
                        string oldIoTHubAlias         = oldIoTDeviceObj.IoTHubAlias;
                        string oldDeviceCertificateId = oldIoTDeviceObj.DeviceCertificateId;

                        IoTDeviceCmdMsg deviceCmdMsg = new IoTDeviceCmdMsg("update iothub register", newIoTHubDeviceId, newAuthenticationType, requesterName, requesterEmail, 0);
                        if (oldIoTHubAlias == newIoTHubAlias)
                        {
                            await deviceCmdMsg.Init(newIoTHubAlias, newDeviceCertificateId);
                        }
                        else
                        {
                            await deviceCmdMsg.Init(newIoTHubAlias, newDeviceCertificateId, oldIoTHubAlias);
                        }

                        int operationTaskId = await PostOperationTaskAsync(deviceCmdMsg.task, companyId, deviceCmdMsg.entity, deviceCmdMsg.entityId, deviceCmdMsg.GetJsonInsensitiveContent());

                        if (operationTaskId > 0)
                        {
                            deviceCmdMsg.taskId = operationTaskId;
                            deviceCmdMsg.SendToServiceBus();
                        }

                        break;
                    }

                    case "resetpassword":
                    {
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._iotDeviceEndPoint + "/" + Request.QueryString["Id"] + "/" + "ResetPassword";
                        }
                        postData   = Request.Form.ToString();
                        jsonString = apiHelper.changePassword("PUT", endPoint, postData);
                        break;
                    }

                    case "deleteiotdevice":
                    {
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._iotDeviceEndPoint + "/" + Request.QueryString["Id"];
                        }

                        /********** Send OpsInfra command message ***********/
                        dynamic existingIoTDeviceObj = JObject.Parse(await apiHelper.callAPIService("GET", endPoint, null));
                        string  iotHubAlias          = existingIoTDeviceObj.IoTHubAlias;
                        string  iotHubDeviceId       = existingIoTDeviceObj.IoTHubDeviceId;
                        string  authType             = existingIoTDeviceObj.AuthenticationType;

                        IoTDeviceCmdMsg deviceCmdMsg = new IoTDeviceCmdMsg("remove iothub register", iotHubDeviceId, authType, requesterName, requesterEmail, 0);
                        await deviceCmdMsg.Init(iotHubAlias);

                        int operationTaskId = await PostOperationTaskAsync(deviceCmdMsg.task, companyId, deviceCmdMsg.entity, deviceCmdMsg.entityId, deviceCmdMsg.GetJsonInsensitiveContent());

                        if (operationTaskId > 0)
                        {
                            deviceCmdMsg.taskId = operationTaskId;
                            deviceCmdMsg.SendToServiceBus();
                        }

                        //Delete data in DB
                        jsonString = await apiHelper.callAPIService("DELETE", endPoint, null);

                        break;
                    }

                    //attach message
                    case "getattachedmessagebydeviceid":
                    {
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._iotDeviceEndPoint + "/" + Request.QueryString["Id"] + "/Message";
                        }
                        jsonString = await apiHelper.callAPIService("GET", endPoint, null);

                        break;
                    }

                    case "updateattachedmessage":
                    {
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._iotDeviceEndPoint + "/" + Request.QueryString["Id"] + "/Message";
                        }
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("PUT", endPoint, postData);

                        break;
                    }

                    case "getdeviceconfiguration":
                    {
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._iotDeviceEndPoint + "/" + Request.QueryString["Id"] + "/Configuration";
                        }
                        jsonString = await apiHelper.callAPIService("GET", endPoint, null);

                        break;
                    }

                    case "updatedeviceconfiguration":
                    {
                        string iotHubDeviceId = Request.QueryString["Id"];
                        if (iotHubDeviceId != null)
                        {
                            endPoint = Global._iotDeviceEndPoint + "/" + iotHubDeviceId + "/DesiredProperty";
                        }
                        postData   = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("PUT", endPoint, postData);

                        System.Diagnostics.Debug.Print(endPoint);
                        System.Diagnostics.Debug.Print(postData);


                        /********** Send OpsInfra command message ***********/
                        string deviceConfiguration       = Request.Form["devicetwinsdesired"];
                        IoTDeviceManagementCmdMsg cmdMsg = new IoTDeviceManagementCmdMsg("update device desired property", iotHubDeviceId, requesterName, requesterEmail, 0, deviceConfiguration);
                        await cmdMsg.Init();

                        int operationTaskId = await PostOperationTaskAsync(cmdMsg.task, companyId, cmdMsg.entity, cmdMsg.entityId, cmdMsg.GetJsonInsensitiveContent());

                        if (operationTaskId > 0)
                        {
                            cmdMsg.taskId = operationTaskId;
                            cmdMsg.SendToServiceBus();
                        }
                        break;
                    }

                    case "downloadmessagetemplate":
                    {
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = Global._iotDeviceEndPoint + "/" + Request.QueryString["Id"] + "/MessageTemplate";
                        }

                        HttpResponseMessage response = new HttpResponseMessage();
                        jsonString = await apiHelper.callAPIService("GET", endPoint, null);

                        break;
                    }

                    default:

                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.ToLower() == "invalid session")
                    {
                        Response.StatusCode = 401;
                    }
                    else
                    {
                        StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                        logMessage.AppendLine("EndPoint:" + endPoint);
                        logMessage.AppendLine("Action:" + Request.QueryString["action"].ToString());
                        logMessage.AppendLine("PostData:" + Request.Form.ToString());
                        System.Diagnostics.Debug.Print("EndPoint:" + endPoint);
                        System.Diagnostics.Debug.Print("Action:" + Request.QueryString["action"].ToString());
                        System.Diagnostics.Debug.Print("PostData:" + Request.Form.ToString());
                        System.Diagnostics.Debug.Print("Message:" + ex.Message);
                        Global._sfAppLogger.Error(logMessage);
                        Response.StatusCode = 500;
                        jsonString          = ex.Message;
                    }
                }
            }
            return(Content(JsonConvert.SerializeObject(jsonString), "application/json"));
        }
Ejemplo n.º 25
0
        public async Task <ActionResult> ReqAction()
        {
            string jsonString = "";

            if (Request.QueryString["action"] != null)
            {
                string          endPoint   = Global._messageEndPoint;
                EmployeeSession empSession = null;
                if (Session["empSession"] != null)
                {
                    empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString());
                }
                try
                {
                    RestfulAPIHelper apiHelper = new RestfulAPIHelper();
                    switch (Request.QueryString["action"].ToString().ToLower())
                    {
                    case "getmessagecatalog":
                        endPoint = Global._messageInCompanyEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("get", endPoint, null);

                        break;

                    case "deletemessagecatalog":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("delete", endPoint, null);

                        break;

                    case "addmessagecatalog":
                    {
                        string postData = Request.Form.ToString();
                        postData   = postData + "&CompanyId=" + empSession.companyId;
                        jsonString = await apiHelper.callAPIService("post", endPoint, postData);

                        break;
                    }

                    case "updatemessagecatalog":
                    {
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        string postData = Request.Form.ToString();
                        postData   = postData + "&CompanyId=" + empSession.companyId;
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        break;
                    }

                    //Message Element
                    case "getmessageelementbyid":
                    {
                        endPoint = Global._messageElementEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/MessageCatalog/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("get", endPoint, null);

                        break;
                    }

                    case "getchildmessagebyid":
                    {
                        endPoint = Global._messageEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("get", endPoint, null);

                        break;
                    }

                    case "addmessageelement":
                    {
                        string postData = Request.Form.ToString();
                        endPoint   = Global._messageElementEndPoint;
                        jsonString = await apiHelper.callAPIService("post", endPoint, postData);

                        break;
                    }

                    case "deletemessageelement":
                    {
                        endPoint = Global._messageElementEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        string postData = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("delete", endPoint, postData);

                        break;
                    }

                    case "updatemessageelement":
                    {
                        endPoint = Global._messageElementEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        string postData = Request.Form.ToString();
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        break;
                    }


                    default:

                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.ToLower() == "invalid session")
                    {
                        Response.StatusCode = 401;
                    }
                    else
                    {
                        StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                        logMessage.AppendLine("EndPoint:" + endPoint);
                        logMessage.AppendLine("Action:" + Request.QueryString["action"].ToString());
                        logMessage.AppendLine("PostData:" + Request.Form.ToString());
                        Global._sfAppLogger.Error(logMessage);
                        Response.StatusCode = 500;
                        jsonString          = ex.Message;
                    }
                }
            }

            return(Content(JsonConvert.SerializeObject(jsonString), "application/json"));
        }
Ejemplo n.º 26
0
        public async Task <ActionResult> ReqAction()
        {
            string jsonString = "", endPoint = "", factoryId = "", equipmentId = "", dataRange = "24", top = "100";

            try
            {
                RestfulAPIHelper apiHelper = new RestfulAPIHelper();
                if (Request.QueryString["action"] != null)
                {
                    switch (Request.QueryString["action"].ToLower())
                    {
                    case "getcompanyalarm":
                    {
                        if (Request.QueryString["dataRange"] != null)
                        {
                            dataRange = Request.QueryString["dataRange"];
                        }
                        endPoint   = Global._alarmMessageInCompanyEndPoint + "?hours=" + dataRange + "&top=" + top + "&order=desc";
                        jsonString = await apiHelper.callAPIService("GET", endPoint, null);

                        break;
                    }

                    case "getfactoryalarm":
                    {
                        factoryId = Request.QueryString["Id"];
                        if (Request.QueryString["dataRange"] != null)
                        {
                            dataRange = Request.QueryString["dataRange"];
                        }
                        endPoint   = Global._alarmMessageInFactoryEndPoint + "/" + factoryId + "?hours=" + dataRange + "&top=" + top + "&order=desc";
                        jsonString = await apiHelper.callAPIService("GET", endPoint, null);

                        break;
                    }

                    case "getequipmentalarm":
                    {
                        equipmentId = Request.QueryString["Id"];
                        if (Request.QueryString["dataRange"] != null)
                        {
                            dataRange = Request.QueryString["dataRange"];
                        }
                        endPoint   = Global._alarmMessageInEquipmentEndPoint + "/" + equipmentId + "?hours=" + dataRange + "&top=" + top + "&order=desc";
                        jsonString = await apiHelper.callAPIService("GET", endPoint, null);

                        break;
                    }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.ToLower() == "invalid session")
                {
                    Response.StatusCode = 401;
                }
                else
                {
                    StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                    logMessage.AppendLine("EndPoint:" + endPoint);
                    logMessage.AppendLine("Action:" + Request.QueryString["action"].ToString());
                    logMessage.AppendLine("PostData:" + Request.Form.ToString());
                    System.Diagnostics.Debug.Print("EndPoint:" + endPoint);
                    System.Diagnostics.Debug.Print("Action:" + Request.QueryString["action"].ToString());
                    System.Diagnostics.Debug.Print("PostData:" + Request.Form.ToString());
                    System.Diagnostics.Debug.Print("Message:" + ex.Message);
                    Global._sfAppLogger.Error(logMessage);
                    Response.StatusCode = 500;
                    jsonString          = ex.Message;
                }
            }
            return(Content(JsonConvert.SerializeObject(jsonString), "application/json"));
        }
Ejemplo n.º 27
0
        public async Task <ActionResult> ReqAction()
        {
            ViewBag.Version = Global._sfAdminVersion;
            string jsonString = "";

            if (Request.QueryString["action"] != null)
            {
                string endPoint = Global._factoryEndPoint;
                try
                {
                    RestfulAPIHelper apiHelper  = new RestfulAPIHelper();
                    EmployeeSession  empSession = null;
                    if (Session["empSession"] != null)
                    {
                        empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString());
                    }
                    switch (Request.QueryString["action"].ToString().ToLower())
                    {
                    case "getfactory":
                        endPoint = Global._factoryInCompanyEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("get", endPoint, null);

                        break;

                    case "deletefactory":
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("delete", endPoint, null);

                        Global._sfAppLogger.Info("Delete Factory Completed; Factory ID:" + Request.QueryString["Id"] + ";Login Email:" + empSession.email);
                        break;

                    case "addfactory":
                    {
                        string postData = Request.Form.ToString();
                        postData   = postData + "&CompanyId=" + empSession.companyId;
                        jsonString = await apiHelper.callAPIService("post", endPoint, postData);

                        if (Request.Files.Count > 0)
                        {
                            //Get Object ID from API result
                            dynamic jsonResult = JObject.Parse(jsonString);
                            if (jsonResult.id != null)
                            {
                                string entityID = jsonResult.id;
                                endPoint = endPoint + "/" + entityID + "/Image";
                                byte[] byteFile = new byte[Request.Files[0].InputStream.Length];
                                Request.Files[0].InputStream.Read(byteFile, 0, (int)Request.Files[0].InputStream.Length);
                                jsonString = await apiHelper.putUploadFile(endPoint, byteFile, Request.Files[0].FileName);
                            }
                        }
                        Global._sfAppLogger.Info("Add Factory Completed; API Return:" + jsonString + ";Login Email:" + empSession.email);
                        break;
                    }

                    case "updatefactory":
                    {
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        string postData = Request.Form.ToString();
                        postData   = postData + "&CompanyId=" + empSession.companyId;
                        jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                        if (Request.Files.Count > 0)
                        {
                            //admin-api/Factory/{id}/Image
                            endPoint = endPoint + "/Image";

                            byte[] byteFile = new byte[Request.Files[0].InputStream.Length];
                            Request.Files[0].InputStream.Read(byteFile, 0, (int)Request.Files[0].InputStream.Length);
                            jsonString = await apiHelper.putUploadFile(endPoint, byteFile, Request.Files[0].FileName);
                        }
                        Global._sfAppLogger.Info("Update Factory Completed; Factory ID:" + Request.QueryString["Id"] + "; post Data:" + postData + ";Login Email:" + empSession.email);
                        break;
                    }

                    default:

                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.ToLower() == "invalid session")
                    {
                        Response.StatusCode = 401;
                    }
                    else
                    {
                        StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                        logMessage.AppendLine("EndPoint:" + endPoint);
                        logMessage.AppendLine("Action:" + Request.QueryString["action"].ToString());
                        logMessage.AppendLine("PostData:" + Request.Form.ToString());
                        Global._sfAppLogger.Error(logMessage);
                        Response.StatusCode = 500;
                        jsonString          = ex.Message;
                    }
                }
            }

            return(Content(JsonConvert.SerializeObject(jsonString), "application/json"));
        }
Ejemplo n.º 28
0
        public async Task <ActionResult> ReqAction()
        {
            ViewBag.Version = Global._sfAdminVersion;
            string jsonString = "", postData = "", endPoint = "";

            try
            {
                RestfulAPIHelper apiHelper = new RestfulAPIHelper();
                if (Request.QueryString["action"] != null)
                {
                    switch (Request.QueryString["action"].ToLower())
                    {
                    case "getequipment":
                    {
                        endPoint   = Global._equipmentInCompanyEndPoint;
                        jsonString = await apiHelper.callAPIService("GET", endPoint, null);

                        break;
                    }

                    case "getequipbyfactory":
                    {
                        string factoryId = Request.QueryString["factoryId"];
                        if (factoryId != null)
                        {
                            if (factoryId.ToLower() == "all")
                            {
                                endPoint = Global._equipmentInCompanyEndPoint;
                            }
                            else
                            {
                                endPoint = Global._equipmentInFactoryEndPoint + "/" + factoryId;
                            }
                        }
                        jsonString = await apiHelper.callAPIService("GET", endPoint, null);

                        break;
                    }

                    case "addequipment":
                    {
                        endPoint = Global._equipmentEndPoint;
                        postData = Request.Form.ToString();

                        var queryString = HttpUtility.ParseQueryString(postData);
                        if (queryString["Location"] != null && queryString["Location"] == "Factory")
                        {
                            string factoryEndPoint = Global._factoryEndPoint + "/" + queryString["FactoryId"];
                            string factoryString   = await apiHelper.callAPIService("get", factoryEndPoint, null);

                            dynamic factoryResult = JObject.Parse(factoryString);
                            postData = postData + "&Latitude=" + factoryResult.Latitude;
                            postData = postData + "&Longitude=" + factoryResult.Longitude;
                        }

                        jsonString = await apiHelper.callAPIService("post", endPoint, postData);

                        dynamic jsonResult = JObject.Parse(jsonString);
                        if (Request.Files.Count > 0)
                        {
                            if (jsonResult.id != null)
                            {
                                string entityID = jsonResult.id;
                                endPoint = endPoint + "/" + entityID + "/Image";
                                byte[] byteFile = new byte[Request.Files[0].InputStream.Length];
                                Request.Files[0].InputStream.Read(byteFile, 0, (int)Request.Files[0].InputStream.Length);
                                jsonString = await apiHelper.putUploadFile(endPoint, byteFile, Request.Files[0].FileName);
                            }
                            if (Request.Files.Count > 0)
                            {
                                //admin-api/Company/{id}/Image
                                var    ImageEndPoint = endPoint + "/Image";
                                byte[] byteFile      = new byte[Request.Files[0].InputStream.Length];
                                Request.Files[0].InputStream.Read(byteFile, 0, (int)Request.Files[0].InputStream.Length);
                                jsonString = await apiHelper.putUploadFile(ImageEndPoint, byteFile, Request.Files[0].FileName);
                            }
                        }
                        break;
                    }

                    case "deleteequipment":
                    {
                        endPoint = Global._equipmentEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"];
                        }
                        jsonString = await apiHelper.callAPIService("delete", endPoint, postData);

                        break;
                    }

                    case "updateequipment":
                    {
                        endPoint = Global._equipmentEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            postData = Request.Form.ToString();

                            var queryString = HttpUtility.ParseQueryString(postData);
                            if (queryString["Location"] != null && queryString["Location"] == "Factory")
                            {
                                string factoryEndPoint = Global._factoryEndPoint + "/" + queryString["FactoryId"];
                                string factoryString   = await apiHelper.callAPIService("get", factoryEndPoint, null);

                                dynamic factoryResult = JObject.Parse(factoryString);
                                postData = postData + "&Latitude=" + factoryResult.Latitude;
                                postData = postData + "&Longitude=" + factoryResult.Longitude;
                            }

                            endPoint   = endPoint + "/" + Request.QueryString["Id"];
                            jsonString = await apiHelper.callAPIService("put", endPoint, postData);

                            if (Request.Files.Count > 0)
                            {
                                //admin-api/Company/{id}/Image
                                var    ImageEndPoint = endPoint + "/Image";
                                byte[] byteFile      = new byte[Request.Files[0].InputStream.Length];
                                Request.Files[0].InputStream.Read(byteFile, 0, (int)Request.Files[0].InputStream.Length);
                                jsonString = await apiHelper.putUploadFile(ImageEndPoint, byteFile, Request.Files[0].FileName);
                            }
                            // Update Meta-Data
                            string   metaDataPost = "";
                            string[] phrases      = postData.Split('&');
                            foreach (var input in phrases)
                            {
                                if (input.StartsWith("metaDatas"))
                                {
                                    metaDataPost = metaDataPost + input + "&";
                                }
                            }

                            if (!string.IsNullOrEmpty(metaDataPost))
                            {
                                var MetaDataEndPoint = endPoint + "/MetaData";
                                jsonString = await apiHelper.callAPIService("put", MetaDataEndPoint, metaDataPost);
                            }
                        }
                        break;
                    }

                    case "getmetadata":
                    {
                        endPoint = Global._equipmentEndPoint;
                        if (Request.QueryString["Id"] != null)
                        {
                            endPoint = endPoint + "/" + Request.QueryString["Id"] + "/MetaData";
                        }
                        jsonString = await apiHelper.callAPIService("GET", endPoint, null);

                        break;
                    }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.ToLower() == "invalid session")
                {
                    Response.StatusCode = 401;
                }
                else
                {
                    StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                    logMessage.AppendLine("EndPoint:" + endPoint);
                    logMessage.AppendLine("Action:" + Request.QueryString["action"].ToString());
                    logMessage.AppendLine("PostData:" + Request.Form.ToString());
                    System.Diagnostics.Debug.Print("EndPoint:" + endPoint);
                    System.Diagnostics.Debug.Print("Action:" + Request.QueryString["action"].ToString());
                    System.Diagnostics.Debug.Print("PostData:" + Request.Form.ToString());
                    System.Diagnostics.Debug.Print("Message:" + ex.Message);
                    Global._sfAppLogger.Error(logMessage);
                    Response.StatusCode = 500;
                    jsonString          = ex.Message;
                }
            }
            return(Content(JsonConvert.SerializeObject(jsonString), "application/json"));
        }