예제 #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());
        }
예제 #2
0
        public ActionResult Index()
        {
            if (Session["loginMsgSession"] != null)
            {
                LoginMsgSession logMsgSession = LoginMsgSession.LoadByJsonString(Session["loginMsgSession"].ToString());
                ViewBag.LoginMessage = logMsgSession.message;
                ViewBag.ToastLevel   = logMsgSession.toastLevel;
            }

            ViewBag.Version = Global._sfAdminVersion;

            /* Read Cookie */
            if (Request.Cookies["rememberMe"] != null)
            {
                NameValueCollection qscoll = HttpUtility.ParseQueryString(Request.Cookies["rememberMe"].Value);
                ViewBag.CookieEmail      = qscoll["email"];
                ViewBag.CookiePassword   = qscoll["password"];
                ViewBag.CookieRememberMe = "checked";
            }
            var jsonString = "";
            var cookie     = Request.Cookies["i18n.langtag"];

            if (cookie != null)
            {
                jsonString = cookie.Value;
            }
            else
            {
                jsonString = "";
            }
            return(View("Login"));
        }
예제 #3
0
        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"));
        }
예제 #4
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"));
            }
        }
        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());
        }
예제 #7
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());
        }
예제 #8
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"));
            }
        }