// 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()); }
public async Task <ActionResult> ShowProfile() { EmployeeSession empSession = null; if (Session["empSession"] != null) { empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString()); } try { /* 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.CompanyID = compSession.id; /* 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; ViewBag.Id = empSession.id; ViewBag.EmployeeNumber = empSession.employeeNumber; ViewBag.AdminFlag = empSession.adminFlag; ViewBag.Lang = empSession.Lang; KeyValuePair <string, i18n.LanguageTag>[] langx = LanguageHelpers.GetAppLanguages().OrderBy(x => x.Key).ToArray(); ViewBag.langs = JsonConvert.SerializeObject(langx); } 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(PartialView("Profile")); }
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")); } }
public ActionResult SetLanguage(string langtag, string returnUrl) { if (langtag == null) { langtag = "en"; } // If valid 'langtag' passed. i18n.LanguageTag lt = i18n.LanguageTag.GetCachedInstance(langtag); EmployeeSession empSession = null; if (Session["empSession"] != null) { empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString()); empSession.Lang = langtag; Session["empSession"] = empSession.Serialize(); } if (lt.IsValid()) { // Set persistent cookie in the client to remember the language choice. Response.Cookies.Add(new HttpCookie("i18n.langtag") { Value = lt.ToString(), HttpOnly = true, Expires = DateTime.UtcNow.AddYears(1) }); } // Owise...delete any 'language' cookie in the client. else { var cookie = Response.Cookies["i18n.langtag"]; if (cookie != null) { cookie.Value = null; cookie.Expires = DateTime.UtcNow.AddMonths(-1); } } // Update PAL setting so that new language is reflected in any URL patched in the // response (Late URL Localization). System.Web.HttpContext.Current.SetPrincipalAppLanguageForRequest(lt); // Patch in the new langtag into any return URL. if (returnUrl.IsSet()) { returnUrl = LocalizedApplication.Current.UrlLocalizerForApp.SetLangTagInUrlPath(HttpContext, returnUrl, UriKind.RelativeOrAbsolute, lt == null ? null : lt.ToString()).ToString(); } // Redirect user agent as approp. return(Json(new { status = "success", NewURL = returnUrl })); }
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")); }
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")); }
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")); }
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()); }
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()); }
public async Task <ActionResult> ReqAction() { string jsonString = "", postData = "", endPoint = ""; if (Request.QueryString["mAction"] != null) { try { EmployeeSession empSession = null; if (Session["empSession"] != null) { empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString()); } RestfulAPIHelper apiHelper = new RestfulAPIHelper(); switch (Request.QueryString["mAction"].ToString().ToLower()) { case "iothubreceiver": { 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, empSession.firstName + " " + empSession.lastName, empSession.email); OpsTaskModel opsTask = new OpsTaskModel(subAction, empSession.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, empSession.firstName + " " + empSession.lastName, empSession.email); OpsTaskModel opsTask = new OpsTaskModel(subAction, empSession.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; endPoint = endPoint + "?"; if (Request.QueryString["taskstatus"] != null) { endPoint = endPoint + "&taskstatus=" + Request.QueryString["taskstatus"]; } if (Request.QueryString["hours"] != null) { endPoint = endPoint + "&hours=" + Request.QueryString["hours"]; } jsonString = await apiHelper.callAPIService("GET", endPoint, postData); break; } case "getusagelog": { endPoint = Global._usageLogEndPoint; endPoint = endPoint + "?"; if (Request.QueryString["days"] != null) { endPoint = endPoint + "&days=" + Request.QueryString["days"]; } if (Request.QueryString["order"] != null) { endPoint = endPoint + "&order=" + Request.QueryString["order"]; } 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")); }
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()); }