Esempio n. 1
0
        private void StartInstall(IHttpContextProxy httpProxy)
        {
            try
            {
                UpdateInstallStatus(AppInstallStatus.Start);
                var requestData = httpProxy.GetRequestBody <AppInstallerConfig>();
                if (requestData == null)
                {
                    httpProxy.SetResponse(CommonConst._400_BAD_REQUEST);
                    httpProxy.ContentType = CommonConst.CONTENT_TYPE_APPLICATION_JSON;
                    return;
                }
                UpdateInstallStatus(AppInstallStatus.Inprogress);

                WriteCustomConfig(requestData);

                RunInstallScripts();

                InstallModule(requestData, httpProxy);

                UpdateInstallStatus(AppInstallStatus.Finish);
                _routings.LoadRoutes();
                httpProxy.SetResponse(CommonConst._200_OK, GetStatus());
                httpProxy.ContentType = CommonConst.CONTENT_TYPE_APPLICATION_JSON;
            }
            catch (Exception ex)
            {
                httpProxy.SetResponse(CommonConst._500_SERVER_ERROR, ex.Message);
                httpProxy.ContentType = CommonConst.CONTENT_TYPE_APPLICATION_JSON;
                _logger.Error(string.Format("Error in App install {0}", ex.Message), ex);
            }
        }
Esempio n. 2
0
        protected void HandleStaticContent(string requestUriPath)
        {
            if (CommonUtility.IsTextConent(_httpProxy.GetContentType(requestUriPath)))
            {
                var responseString = _contentHandler.GetStringContent(requestUriPath);
                if (!string.IsNullOrEmpty(responseString))
                {
                    _httpProxy.SetResponse(CommonConst._200_OK, responseString);
                }
                else
                {
                    _httpProxy.SetResponse(CommonConst._404_RESOURCE_NOT_FOUND);
                }
            }
            else
            {
                var responseData = _contentHandler.GetContent(requestUriPath);
                if (responseData != null)
                {
                    _httpProxy.SetResponse(CommonConst._200_OK, responseData);
                }
                else
                {
                    _httpProxy.SetResponse(CommonConst._404_RESOURCE_NOT_FOUND, responseData);
                }
            }
            _httpProxy.ContentType = _httpProxy.GetContentType(requestUriPath);

            if (ApplicationConfig.StaticContentCache && !CommonUtility.IsServerSidePage(requestUriPath))
            {
                _httpContext.Response.Cache.SetCacheability(HttpCacheability.Public);
                _httpContext.Response.Cache.SetExpires(DateTime.Now.AddDays(10));
                _httpContext.Response.Cache.SetMaxAge(new TimeSpan(10, 0, 0, 0));
            }
            if (ApplicationMode.Maintenance == ApplicationConfig.GetApplicationMode)
            {
                _httpContext.Response.Headers[string.Format("{0}.{1}", CommonConst.CommonField.HTTP_RESPONE_DEBUG_INFO, CommonConst.CommonValue.TIME_SPAN)]      = (DateTime.Now - _initData.InitDateTime).TotalMilliseconds.ToString();
                _httpContext.Response.Headers[string.Format("{0}.{1}", CommonConst.CommonField.HTTP_RESPONE_DEBUG_INFO, CommonConst.CommonField.TRANSACTION_ID)] = _initData.TransactionId;
            }

            RemoveHeaders();
        }
Esempio n. 3
0
        private bool HandleAPI(IHttpContextProxy httpProxy, string requestResource)
        {
            switch (requestResource)
            {
            case CHECK_STATUS_API:
                httpProxy.SetResponse(CommonConst._200_OK, GetStatus());
                httpProxy.ContentType = CommonConst.CONTENT_TYPE_APPLICATION_JSON;
                return(true);

            case PREREQUISITE_STATUS_API:
                httpProxy.SetResponse(CommonConst._200_OK, CheckAccess());
                httpProxy.ContentType = CommonConst.CONTENT_TYPE_APPLICATION_JSON;
                return(true);

            case INSTALL_START_API:
                StartInstall(httpProxy);
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        private void HandleResource(string requestResource, IHttpContextProxy httpProxy)
        {
            if (string.IsNullOrEmpty(requestResource) || requestResource == "/")
            {
                requestResource = defaultResourceName;
            }
            string filePath = string.Format("{0}/../wwwroot/appinstall/{1}", ApplicationConfig.AppBinPath, requestResource);

            if (File.Exists(filePath))
            {
                var fileData = File.ReadAllBytes(filePath);
                httpProxy.SetResponse(CommonConst._200_OK, fileData);
            }
            else
            {
                _logger.Error(string.Format("File not found : {0}", filePath));
                httpProxy.SetResponse(CommonConst._404_RESOURCE_NOT_FOUND);
            }

            httpProxy.ContentType = httpProxy.GetMimeType(requestResource);
        }
Esempio n. 5
0
        public void Exec(RoutingModel route, IHttpContextProxy httpProxy)
        {
            ILogger           loggerController  = Logger.GetLogger(route.ExecuteType, httpProxy.TransactionId);
            RouteEventHandler routeEventHandler = new RouteEventHandler();

            try
            {
                loggerController.Info(string.Format("{0}:: Route: [{1}]", "RouteExecuter.Exec", route.ToString()));
                IActionExecuter actionExecuter = new ActionExecuter(loggerController);
                ParamContainer  paramContainer = ActionExecuterHelper.CreateParamContainer(route, httpProxy, loggerController, actionExecuter);
                WriteStartTransaction(loggerController, httpProxy, route);
                (paramContainer.GetKey(CommonConst.CommonValue.PARAM_SESSION_PROVIDER) as ISessionProvider).SetValue(CommonConst.CommonField.UPDATED_DATE_TIME, CommonUtility.GetUnixTimestamp(DateTime.Now));
                // Execute before Events
                routeEventHandler.ExecBeforeEvent(actionExecuter, route, paramContainer);

                var objResult = actionExecuter.Exec(route, paramContainer);
                httpProxy.ContentType = route.ContentType;

                // Add response in param
                paramContainer.AddKey(CommonConst.CommonValue.PARAM_API_RESPONSE, () => { return(objResult); });

                if (objResult == null)
                {
                    httpProxy.SetResponse(CommonConst._500_SERVER_ERROR);
                }
                else if (objResult is byte[])
                {
                    WriteEndTransaction(loggerController, "*** Binary Data ***");
                    httpProxy.SetResponse(CommonConst._200_OK, (byte[])objResult);
                }
                else if (objResult is string)
                {
                    WriteEndTransaction(loggerController, (objResult as string));
                    httpProxy.SetResponse(CommonConst._200_OK, objResult as string);
                }
                else
                {
                    var responseData = (objResult as JObject).ToString();
                    WriteEndTransaction(loggerController, responseData);
                    httpProxy.SetResponse(CommonConst._200_OK, responseData);
                }

                // Execute after Events
                routeEventHandler.ExecAfterEvent(actionExecuter, route, paramContainer, objResult);

                //    List<string> userGroups = _httpProxy.GetSessionUserGroups();
                //    if (route.auth_users.Count == 0 || userGroups.Intersect(route.auth_users).Any())
                //    {
                //        var objResult = routeExecuter.Exec(route, helper);
                //        if (objResult == null)
                //        {
                //            SetInternalServerError();
                //            return null;
                //        }
                //        else if (objResult is byte[])
                //        {
                //            return (byte[])objResult;
                //        }
                //        else
                //        {
                //            return Encoding.UTF8.GetBytes((objResult as JObject).ToString());
                //        }
                //    }
                //    else
                //    {
                //        SetUnauthorized();
                //        return Encoding.UTF8.GetBytes((ZApp.Common.HttpUtility.GetFullResponse((int)ResponseCodes.Unauthorized, ResponseCodes.Unauthorized.ToString(), null)).ToString());
                //    }
            }
            catch (UnauthorizedAccessException ex)
            {
                loggerController.Error(string.Format("Error While executing Route : {0}, Error : {1}", route.ToString(), ex.Message), ex);
                httpProxy.SetResponse(CommonConst._401_UNAUTHORIZED);
            }
            catch (Exception ex)
            {
                httpProxy.SetResponse(CommonConst._500_SERVER_ERROR);
                loggerController.Error(string.Format("Error While executing Route : {0}, Error : {1}", route.ToString(), ex.Message), ex);
            }
        }