Пример #1
0
//        static public void PerformAction(ActionPage a_page) {
        //this way it may get overriden in Actions.Config, but still does not look like comfortable enough design
        public virtual void PerformAction(ActionPage a_page)
        {
            log4net.ILog log = PtaUtil.getLog4netLogger(typeof(ActionPage).FullName + ".PerformAction(): ");
            try {
                a_page.Action();
            } catch (System.Threading.ThreadAbortException) {
                //this is normal processing of Server.Transfer() and Response.End()
                throw;
            } catch (Exception e) {
                PtaUtil.LogExceptionAndFormParameters(log, e);
                HttpContext.Current.Response.Output.Write(PtaServerConstants.SIMPLE_ERROR_RESPONSE);
            } finally {
                PtaUtil.CloseDataReader(a_page.bboardDR);
            }
        }
 /*
  * Just some code that may be useful in the future
  * //Microsoft.Web.Services3.WebServicesClientProtocol
  * //http://msdn.microsoft.com/en-us/library/microsoft.web.services3.webservicesclientprotocol.aspx
  * //Thread Safety
  * //Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
  * //caching of established/initialized/authenticated webservices does not seem important task by this time
  * static Hashtable webservices = new Hashtable();
  * static ContextWS GetContextWS(String bbHostURL) {
  *  String ws_key = bbHostURL + "/" + typeof(ContextWS).FullName;
  *  ContextWS ctx;
  *  lock (webservices) {
  *      ctx = (ContextWS)webservices[ws_key];
  *      if (ctx == null) {
  *              ctx = new  ContextWS();
  *              webservices.Add(ws_key, ctx);
  *      }
  *  }
  *  return ctx;
  * }
  */
 /// <summary>
 /// Conditionally initializes connection to Blackboard
 /// (this is not of some practical use by this moment as long as there are no series of calls to Blackboard - just register() one)
 /// and performs centrilized exception handling and resources cleanup for calls of Blackboard webservices by PtaProxy.
 /// Caught exceptions are logged and re-thrown.
 /// </summary>
 static public void DoCall(WSCall ws_call)
 {
     log4net.ILog log = PtaUtil.getLog4netLogger(typeof(WSCall).FullName + ".DoCall(): ");
     //try {
     try {
         if (ws_call.NeedsInitialize() && !ws_call.wsWrapper.IsInitialized())
         {
             ws_call.wsWrapper.initialize();
         }
         ws_call.Call();
     } catch (Exception e) {
         PtaUtil.LogExceptionAndFormParameters(log, e);
         throw;
     } finally {
         PtaUtil.CloseDataReader(ws_call.wsWrapper.GetBBoardDR());
     }
 }
        /// <summary>
        /// Standard entry point of IHttpHandler, main processing flow.
        /// </summary>
        public void ProcessRequest(HttpContext context)
        {
            log4net.ILog log = PtaUtil.getLog4netLogger(this.GetType().FullName + ".ProcessRequest(): ");
            try {
                this.context = context;
                String guid = context.Request.Form["ourguid"];
                bboardDR = PtaUtil.GetBBoardDataReaderByGuid(guid);
                onErrorServerTransfer = PtaUtil.GetDBReaderStringField(bboardDR, "OnErrorServerTransfer");
                RequestValidator rv = new RequestValidator(bboardDR);
                rv.Validate(context.Request);
                Redirect();
            } catch (System.Threading.ThreadAbortException) {
                //this is normal processing of Server.Transfer() and Response.End()
                throw;
            } catch (Exception e) {
                PtaUtil.LogExceptionAndFormParameters(log, e);
                //String on_err_st = onErrorServerTransfer;
                //if (on_err_st == null) on_err_st = PtaUtil.GetProxyWebFolder() + "ErrorPages/PtaDefaultErrPage.aspx";
                //context.Server.Transfer(on_err_st, true);
                String back_link = context.Request.Form["tcbaseurl"] + context.Request.Form["returnurl"];
                String err_page  = PtaUtil.GenerateSimpleErrorPage(back_link);
                context.Response.Write(err_page);
                log.Debug("onErrorServerTransfer: " + onErrorServerTransfer);
                if (onErrorServerTransfer != null)
                {
                    context.Server.Transfer(onErrorServerTransfer, true);
                }

                /*                else {
                 *                  back_link = context.Request.Form["tcbaseurl"] + context.Request.Form["returnurl"];
                 *                  context.Response.Write("Your request could not be processed. <br/>");
                 *                  context.Response.Write("Back to Blackboard: " + "<a href=\"" + back_link + "\">" + back_link + "</a><br/>");
                 *              }*/

                //throw;
            } finally {
                PtaUtil.CloseDataReader(drParam);
                PtaUtil.CloseDataReader(drMenuLink);
                PtaUtil.CloseDataReader(bboardDR);
            }
        }
        /// <summary>
        /// Made as static for simplicity of registration XML preview (pta_proxy\Admin\Register.aspx).
        /// </summary>
        static public String GetRegistrationXML(String bbCode)
        {
            log4net.ILog log = PtaUtil.getLog4netLogger(typeof(RegisterToolWSCall).FullName + ".getRegistrationXML: ");
            String       desc;
            //method is static because can be called for preview, i.e. WSCall.wsWrapper.GetBBoardDR() is unavailvable
            SqlDataReader bboardDR = PtaUtil.GetBBoardDataReaderByCode(bbCode);

            try {
                if ("Y".Equals(PtaUtil.GetDBReaderStringField(bboardDR, "IsRegistered")))
                {
                    //??probably some logic on preliminary handling of this can be placed here,
                    //but capability to reregister even with this flag set is necessary
                    //because it is possible proxy to be unregistered at Blackboard but not updated at proxy
                    //(if proxy is not accessibel at the moment of unregistration),
                    //i.e. IsRegistered (as well as ProxyState) can be out of sync with Blackboard
                }
                String proxy_http_url  = WebConfigurationManager.AppSettings["PtaProxyHttpUrl"];
                String proxy_https_url = WebConfigurationManager.AppSettings["PtaProxyHttpsURL"];
                String proxy_s2s_url   = WebConfigurationManager.AppSettings["PtaProxyServerToServerURL"];
                String base_urls       = "";
                if ("Y".Equals(PtaUtil.GetDBReaderStringField(bboardDR, "RegisterHttpsURL")))
                {
                    base_urls += "<base-url type=\"https\">" + proxy_https_url + "</base-url>\n";
                }
                if ("Y".Equals(PtaUtil.GetDBReaderStringField(bboardDR, "RegisterHttpURL")))
                {
                    base_urls += "<base-url type=\"http\">" + proxy_http_url + "</base-url>\n";
                }
                if ("Y".Equals(PtaUtil.GetDBReaderStringField(bboardDR, "RegisterS2SURL")))
                {
                    base_urls += "<base-url type=\"server-to-server\">" + proxy_s2s_url + "</base-url>\n";
                }
                desc = Regex.Replace(REG_XML, "{BASE_URLS}", base_urls);
                if ("Y".Equals(PtaUtil.GetDBReaderStringField(bboardDR, "RegisterActions")))
                {
                    desc = Regex.Replace(desc, "{HTTP_ACTIONS}", HTTP_ACTIONS_XML);
                }
                String proxy_code = PtaUtil.GetDBReaderStringField(bboardDR, "BBoardProxyCode");
                desc = Regex.Replace(desc, "{PROXY_CODE}", proxy_code);


                //String desc = Regex.Replace(REG_XML, "{BASE_HTTP_URL}", proxy_http_url);
                //desc = Regex.Replace(desc, "{BASE_HTTPS_URL}", proxy_https_url);
                desc = Regex.Replace(desc, "{PROXY_WEB_FOLDER}", PtaUtil.GetProxyWebFolder());


                String sql = "SELECT BBLinkPath, BBLinkType, BBLinkName, BBLinkIconPath FROM BBMenuLink WHERE BBoardCode = @BBoardCode AND Enabled = 'Y'";
                log.Info("sql: " + sql);
                SqlConnection con = PtaUtil.GetSqlConnection();
                System.Data.SqlClient.SqlParameter param
                    = new System.Data.SqlClient.SqlParameter("BBoardCode", PtaUtil.GetDBReaderStringField(bboardDR, "BBoardCode"));
                SqlDataReader drMenuLink =
                    Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteReader(con, System.Data.CommandType.Text,
                                                                             sql, param);
                String xml_links = "";
                while (drMenuLink.Read())
                {
                    String xml_part  = MENU_LINK_XML;
                    String link_path = PtaUtil.GetProxyWebFolder() + PtaUtil.PTA_SUBFOLDER + PtaUtil.GetDBReaderStringField(drMenuLink, "BBLinkPath");
                    String link_type = PtaUtil.GetDBReaderStringField(drMenuLink, "BBLinkType");
                    String link_name = PtaUtil.GetDBReaderStringField(drMenuLink, "BBLinkName");
                    String icon_path = PtaUtil.GetDBReaderStringField(drMenuLink, "BBLinkIconPath");
                    xml_part = Regex.Replace(xml_part, "{LINK_PATH}", link_path);
                    xml_part = Regex.Replace(xml_part, "{MENU_LINK_TYPE}", link_type);
                    xml_part = Regex.Replace(xml_part, "{LINK_NAME}", "<name locale:key=\"" + link_name + "\"></name>");
                    if (icon_path != null)
                    {
                        xml_part = Regex.Replace(xml_part, "{LINK_ICON}", "<icon platform=\"blackboard\" style=\"listitem\" >" + icon_path + "</icon>");
                    }
                    else
                    {
                        xml_part = Regex.Replace(xml_part, "{LINK_ICON}", "");
                    }
                    xml_links = xml_links + xml_part;
                }
                desc = Regex.Replace(desc, "{MENU_LINKS}", xml_links);
            } finally {
                PtaUtil.CloseDataReader(bboardDR);
            }
            return(desc);
        }