Ejemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                context.Response.ContentType = "application/json";
                context.Response.Charset     = Encoding.UTF8.WebName;
                context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                //context.Response.Cache.SetExpires( );
                //context.Response.Cache.SetLastModified( );
                context.Response.StatusCode = (int)HttpStatusCode.OK;


                if (context.Request.HttpMethod.Equals("GET"))
                {
                    var scId          = TryParseString(context, "ScId", true);
                    var accessTokenId = Int32.Parse(scId);
                    var accessToken   = m_valisSystem.ValidateAccessToken(accessTokenId);
                    ProcessGetRequestWrapped(accessToken, context);
                }
                else if (context.Request.HttpMethod.Equals("POST"))
                {
                    var scId          = TryParseString(context, "ScId", true);
                    var accessTokenId = Int32.Parse(scId);
                    var accessToken   = m_valisSystem.ValidateAccessToken(accessTokenId);
                    ProcessPostRequestWrapped(accessToken, context);
                }
                else
                {
                    #region HTTP Error 405 Method not allowed
                    SendException(context, null, HttpStatusCode.MethodNotAllowed);
                    #endregion
                }


                context.Response.Flush();
                context.ApplicationInstance.CompleteRequest();
            }
            catch (ArgumentException ex)
            {
                #region HTTP Error 400 Bad Request
                SendException(context, ex, HttpStatusCode.BadRequest);
                #endregion
            }
            catch (ThreadAbortException)
            {
                //catching the ThreadAbortExceptions from HttpResponse.End() calls...
            }
            catch (Exception ex)
            {
                #region HTTP Error 500 Internal Server Error
                SendException(context, ex, HttpStatusCode.InternalServerError);
                #endregion
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                /*validate accesstoken:*/
                var scId          = TryParseString(context, "ScId", true);
                var accessTokenId = Int32.Parse(scId);
                var accessToken   = m_valisSystem.ValidateAccessToken(accessTokenId);

                /*grab call parameters:*/
                var surveyId      = TryParseInt32(context, "surveyId");
                var viewId        = TryParseGuid(context, "viewId");
                var textsLanguage = TryParseInt16(context, "textsLanguage", false, BuiltinLanguages.PrimaryLanguage);

                /*load requested survey from system:*/
                VLSurveyManager surveyManager = VLSurveyManager.GetAnInstance(accessToken);
                var             survey        = surveyManager.ExportAllResponsesAsXls(surveyId);
                if (survey == null)
                {
                    throw new VLException(SR.GetString(SR.There_is_no_item_with_id, "Survey", surveyId));
                }

                if (survey.AllResponsesXlsxExportIsValid)
                {
                    /*send xlsl report:*/
                    SendFile(context.Request, context.Response, survey);
                }
            }
            catch (ArgumentException ex)
            {
                #region HTTP Error 400 Bad Request
                SendException(context, ex, HttpStatusCode.BadRequest);
                #endregion
            }
            catch (ThreadAbortException)
            {
                //catching the ThreadAbortExceptions from HttpResponse.End() calls...
            }
            catch (Exception ex)
            {
                #region HTTP Error 500 Internal Server Error
                SendException(context, ex, HttpStatusCode.InternalServerError);
                #endregion
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            m_context = context;

            try
            {
                var command  = Request.QueryString["a"];
                var type     = Request.QueryString["type"];
                var _scId    = TryParseString(context, "scId", true);
                var surveyId = TryParseInt32(context, "survey", false, null);

                var accessTokenId = Int32.Parse(_scId);
                var accessToken   = m_valisSystem.ValidateAccessToken(accessTokenId);

                Logger.InfoFormat("command={0}, type={1}, scId={2}, surveyId={3}", command, type, _scId, surveyId);
                ProcessRequestImplementation(accessToken, surveyId, command);
            }
            catch (Exception ex)
            {
                Logger.Error(context.Request.RawUrl, ex);
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                /*validate accesstoken:*/
                var scId          = TryParseString(context, "ScId", true);
                var accessTokenId = Int32.Parse(scId);
                var accessToken   = m_valisSystem.ValidateAccessToken(accessTokenId);

                /*grab call parameters:*/
                var surveyId      = TryParseInt32(context, "surveyId");
                var viewId        = TryParseGuid(context, "viewId");
                var textsLanguage = TryParseInt16(context, "textsLanguage", false, BuiltinLanguages.PrimaryLanguage);

                /*load requested view from system:*/
                VLSurveyManager surveyManager = VLSurveyManager.GetAnInstance(accessToken);
                var             view          = surveyManager.GetViewById(viewId);
                if (view == null)
                {
                    throw new VLException(SR.GetString(SR.There_is_no_item_with_id, "View", viewId));
                }

                if (checkPhantomJs == false)
                {
                    /*check to see if does exist phantomjs.exe*/
                    var      _fileName = Path.Combine(ValisSystem.Core.PhantomJs.Path, "phantomjs.exe");
                    FileInfo fileInfo  = new FileInfo(_fileName);
                    if (fileInfo.Exists == false)
                    {
                        throw new VLException(string.Format("phantomjs.exe does not exist! (path = {0})", _fileName));
                    }
                    /*check to see if does exist rasterize.js*/
                    _fileName = Path.Combine(ValisSystem.Core.PhantomJs.Path, "rasterize.js");
                    fileInfo  = new FileInfo(_fileName);
                    if (fileInfo.Exists == false)
                    {
                        throw new VLException(string.Format("rasterize.js does not exist! (path = {0})", _fileName));
                    }

                    checkPhantomJs = true;
                }


                /*check for the existance of the file:*/
                if (view.PdfReportIsValid)
                {
                    FileInfo fileInfo = new FileInfo(GetFilePath(view));
                    if (fileInfo.Exists == false)
                    {
                        view.PdfReportIsValid = false;
                    }
                }
                /*prepare pdf report if it is not ready:*/
                if (!view.PdfReportIsValid)
                {
                    if (string.IsNullOrWhiteSpace(view.PdfReportName) == false && string.IsNullOrWhiteSpace(view.PdfReportPath) == false)
                    {
                        /*erase previous report*/
                        try
                        {
                            FileInfo fileInfo = new FileInfo(GetFilePath(view));
                            if (fileInfo.Exists)
                            {
                                fileInfo.Delete();
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(HttpContext.Current.Request.RawUrl, ex);
                        }
                        finally
                        {
                            view.PdfReportPath = null;
                            view.PdfReportName = null;
                        }
                    }

                    view.PdfReportCreationDt = DateTime.Now;
                    var pdfReportPath = Path.Combine(Path.Combine(view.Client.ToString(CultureInfo.InvariantCulture), view.Survey.ToString(CultureInfo.InvariantCulture)), "reports");
                    var pdfReportName = "report" + view.PdfReportCreationDt.Value.ToString("yyyyMMddHHmmss") + ".pdf";

                    view.PdfReportPath = pdfReportPath;
                    view.PdfReportName = pdfReportName;
                    var filename = GetFilePath(view);

                    var arguments = string.Format("rasterize.js \"http://{0}/clay/mysurveys/analysis/report.aspx?surveyid={1}\" \"{2}\" A4", ValisSystem.Core.ReportEngine.Host, surveyId, filename);
                    ExecutePhantomJs(arguments);

                    view.PdfReportIsValid = true;
                    view = surveyManager.UpdateView(view);
                }


                /*send pdf report:*/
                SendFile(context.Request, context.Response, view);
            }
            catch (ArgumentException ex)
            {
                #region HTTP Error 400 Bad Request
                SendException(context, ex, HttpStatusCode.BadRequest);
                #endregion
            }
            catch (ThreadAbortException)
            {
                //catching the ThreadAbortExceptions from HttpResponse.End() calls...
            }
            catch (Exception ex)
            {
                #region HTTP Error 500 Internal Server Error
                SendException(context, ex, HttpStatusCode.InternalServerError);
                #endregion
            }
        }
Ejemplo n.º 5
0
        public void ConnectivityTest02()
        {
            ValisSystem vsystem = new ValisSystem();

            Assert.IsNull(vsystem.LogOnUser(null, null));
            Assert.IsNull(vsystem.LogOnUser("sysadmin", string.Empty));
            Assert.IsNull(vsystem.LogOnUser(string.Empty, "tolk!3n"));
            Assert.IsNull(vsystem.LogOnUser("qeqeqeqwe", "qweqqe"));

            //WE CHECK THE builtin sysadmin ACCOUNT:
            var sysAdmin = vsystem.LogOnUser("sysadmin", "tolk!3n");

            Assert.IsNotNull(sysAdmin);
            Assert.IsTrue(sysAdmin.Principal == 2);
            Assert.IsTrue(sysAdmin.PrincipalType == PrincipalType.SystemUser);
            Assert.IsTrue(sysAdmin.IsBuiltIn);
            Assert.IsTrue(sysAdmin.DefaultLanguage == BuiltinLanguages.Invariant.LanguageId);
            //ValidateAccessToken
            var sysAdmin2 = vsystem.ValidateAccessToken(sysAdmin.AccessTokenId);

            Assert.IsNotNull(sysAdmin2);
            Assert.AreEqual <VLAccessToken>(sysAdmin, sysAdmin2);

            vsystem.LogOffUser(sysAdmin);
            sysAdmin2 = vsystem.ValidateAccessToken(sysAdmin.AccessTokenId);
            Assert.IsNull(sysAdmin2);


            //WE CHECK THE builtin developer ACCOUNT:
            var dev = vsystem.LogOnUser("developer", "tolk!3n");

            Assert.IsNotNull(dev);
            Assert.IsTrue(dev.Principal == 3);
            Assert.IsTrue(dev.IsBuiltIn);
            Assert.IsTrue(dev.DefaultLanguage == BuiltinLanguages.Greek.LanguageId);
            //ValidateAccessToken
            var dev2 = vsystem.ValidateAccessToken(dev.AccessTokenId);

            Assert.IsNotNull(dev2);
            Assert.AreEqual <VLAccessToken>(dev, dev2);

            vsystem.LogOffUser(dev);
            dev2 = vsystem.ValidateAccessToken(dev.AccessTokenId);
            Assert.IsNull(dev2);


            //WE CHECK the builtin administrator ACCOUNT:
            var admin = vsystem.LogOnUser("admin", "tolk!3n");

            Assert.IsNotNull(admin);
            Assert.IsTrue(admin.Principal == 4);
            Assert.IsTrue(admin.IsBuiltIn);
            Assert.IsTrue(admin.DefaultLanguage == BuiltinLanguages.Greek.LanguageId);
            //ValidateAccessToken
            var admin2 = vsystem.ValidateAccessToken(admin.AccessTokenId);

            Assert.IsNotNull(admin2);
            Assert.AreEqual <VLAccessToken>(admin, admin2);

            vsystem.LogOffUser(admin);
            admin2 = vsystem.ValidateAccessToken(admin.AccessTokenId);
            Assert.IsNull(admin2);
        }