Esempio n. 1
0
    //static lm_scorm fake_root = new lm_scorm();
    //static ProjectInfo fake_project = new ProjectInfo();
    void Application_BeginRequest(object sender, EventArgs e) {
      HttpApplication app = (HttpApplication)sender;
      string query;
      ConfigNewEA cfg = null;

      if ((query = app.Request["ExerciseUrl"]) != null) {
        cfg = new LMComLib.ConfigNewEA() {
          ExerciseUrl = query,
          CourseLang = LowUtils.EnumParse<Langs>(app.Request["CourseLang"]),
          Lang = "en-gb",
          courseId = LowUtils.EnumParse<CourseIds>(app.Request["courseId"]),
          isGrammar = app.Request["isGrammar"] == "true"
        };
      }
      //else if ((queryObj = app.Request["ExerciseUrl"]) != null) {
      //  cfg = new ConfigNewEA() { ExerciseUrl = queryObj, Lang = "de-de", CourseLang = Langs.en_gb };
      //}
      if (cfg != null) {
        urlInfo.setCulture(cfg.Lang);
        cfg.LMS = LMSType.LMCom;
        cfg.DebugMode = false;
        cfg.IsExternalDict = true;
        cfg.IsExternalGrammar = true;
        cfg.IsListenTalk = true;
        var oldToNew = app.Request["oldeaDataType"];
        CourseMeta.oldeaDataType dt = string.IsNullOrEmpty(oldToNew) ? CourseMeta.oldeaDataType.lmdata : LowUtils.EnumParse<CourseMeta.oldeaDataType>(oldToNew);
        //XXX1
        LMComLib.TradosLib.oldToNewTransform = null;
        LMComLib.TradosLib.readLMDataFile = null;
        var fn = OldToNew.exFile.urlToFile("/" + cfg.ExerciseUrl, CourseMeta.oldeaDataType.lmdata);
        if (File.Exists(fn)) {
          var fileEx = new OldToNew.exFile(fn);
          var newExist = fileEx.getMeta().isByHand();
          switch (dt) {
            case CourseMeta.oldeaDataType.lmdata: 
              break;
            case CourseMeta.oldeaDataType.lmdataNew:
              if (newExist) {
                app.Response.ClearContent();
                app.Response.WriteFile(fileEx.fileName(CourseMeta.oldeaDataType.lmdataNew));
                app.Response.End();
              } else {
                LMComLib.TradosLib.oldToNewTransform = root => {
                  OldToNew.handler.oldToNewTransform(root, fileEx);
                  app.Response.ClearContent();
                  app.Response.Write(root.ToString());
                  app.Response.End();
                };
              }
              break;
            case CourseMeta.oldeaDataType.xmlNew:
              if (newExist) {
                LMScormLibDOM.oldToNewSound.transformedXml = File.ReadAllText(fileEx.fileName(CourseMeta.oldeaDataType.lmdataNew), Encoding.UTF8);
                LMComLib.TradosLib.readLMDataFile = () => LMScormLibDOM.oldToNewSound.transformedXml;
              } else
                LMComLib.TradosLib.oldToNewTransform = root => OldToNew.handler.oldToNewTransform(root, fileEx);
              break;
          }
        }
        //LMComLib.TradosLib.oldToNewTransform = dt == CourseMeta.oldeaDataType.lmdata ? (Action<XElement>)null : root => {
        //  OldToNew.handler.oldToNewTransform(root, fileEx);
        //  if (dt == CourseMeta.oldeaDataType.lmdataNew) {
        //    app.Response.ClearContent();
        //    app.Response.Write(root.ToString());
        //    app.Response.End();
        //  }
        //};
        //cfg.oldToNewTransform = dt == CourseMeta.oldeaDataType.lmdata ? null : (Func<string, string>)(fn => OldToNew.handler.onReadNewEAFile(dt, fn));
        cfg.SoundPlayer = SoundPlayerType.HTML5;
        //Lang = "cs-cz",
        //CourseLang = Langs.en_gb,
        //ExerciseUrl = null
        HttpContext.Current.Items[ConfigLow.c_configKey] = cfg;
        EaUrlInfo.HackEaUrlInfo(cfg.ExerciseUrl);
        return;
      }
      //AppData.AppDataLib.processCrawler(((HttpApplication)sender).Context);
      //AppData.AppDataLib.returnImg(((HttpApplication)sender).Context);
      try {
        if (Machines.isCrawlerEx(app.Context)) {
          app.Context.Response.Write("<h1>Online výuka jazyku ZDARMA</h1>");
          app.Context.Response.Write(@"
<p>Váš internet browser byl rozpoznán jako Crawler se jménem <b>" + app.Context.Request.UserAgent + @"</b>, což bezpečnostní pravidla aplikace neumožňují.</p>
<p>Pošlete nám prosím na adresu [email protected] jméno crawlera (označené tučně), chybu okamžitě odstraníme. </p>
<p>Děkujeme za pochopení</p> <p>váš LANGMaster team.</p>");
          app.Context.Response.Flush();
          app.Context.Response.End();
        }
        EaUrlInfo eaInfo = new EaUrlInfo(app.Request.Url.AbsolutePath, app.Request.Url.Query);
        if (!Machines.isLMCom) urlInfo.normalizeCulture();
        Logging.Trace(TraceLevel.Verbose, TraceCategory.All, "Handlers.cs/Application_BeginRequest url={0}", eaInfo.oldUrl);
        //LocalizeLMData.adjustThreadCulture();
        app.Context.Trace.Write("Application_BeginRequest: " + eaInfo.oldUrl);
        switch (eaInfo.redirectType) {
          case RedirectType.Rewrite:
            app.Context.RewritePath(eaInfo.RewriteUrl, false);
            doCache(app.Context.Response.Cache, eaInfo.clientCache);
            break;
          case RedirectType.Redirect:
            app.Context.Response.Redirect(eaInfo.RewriteUrl, false);
            break;
          case RedirectType.Execute:
            //app.Server.Execute(eaInfo.RewriteUrl, false);
            app.Context.RewritePath(eaInfo.RewriteUrl, false);
            //doCache(app.Context.Response.Cache, eaInfo.clientCache);
            break;
          case RedirectType.WriteFile:
            app.Context.Response.Clear();
            app.Context.Response.WriteFile(eaInfo.RewriteUrl);
            doCache(app.Context.Response.Cache, eaInfo.clientCache);
            app.Context.Response.End();
            break;
        }
      } catch (System.Threading.ThreadAbortException exp) {
        throw;
      } catch (Exception exp) {
        Logging.Trace(TraceLevel.Error, TraceCategory.All, "Handlers.cs/Application_BeginRequest error={0}", exp.Message);
        throw;
      }
    }
Esempio n. 2
0
 public static EaUrlInfo HackEaUrlInfo(string url) {
   EaUrlInfo res = new EaUrlInfo();
   res.oldUrl = null; // ("~/" + url + ".htm").ToLowerInvariant();
   res.CourseNode = null; // SiteMap.Provider.FindSiteMapNode(res2.oldUrl);
   //string fn = HostingEnvironment.MapPath(res2.oldUrl);
   HttpContext.Current.Items[c_EaUrlInfo] = res;
   //string fn = @"q:\LMNet2\WebApps\EduAuthorNew\" + url.Replace('/', '\\') + ".htm";
   res.fileName = HostingEnvironment.MapPath("~/" + url + ".htm");
   //throw new Exception(fn);
   if (!htmFilter.Any(f => url.IndexOf(f) >= 0)) res.fileName += ".aspx.lmdata";
   //res2.root = LMDataReader.ReadFromFile(@"q:\LMNet2\WebApps\EduAuthorNew\" + url.Replace('/', '\\') + ".htm.aspx.old");
   res.root = LMDataReader.ReadFromFile(res.fileName);
   res.root.SiteNode = SiteMap.Provider.FindSiteMapNode("~/" + url + ".htm");
   res.type = pageType.course;
   return res;
 } EaUrlInfo() { }