コード例 #1
0
        private void ReadHttpPage(TheRequestData pRequest, Guid MyAppGuid, string tMagixc, Action <TheRequestData> pSinkProcessResponse) //TheRelayAppInfo MyApp,
        {
            TheRelayAppInfo MyApp = TheThingRegistry.GetThingObjectByMID(MyBaseEngine.GetEngineName(), MyAppGuid) as TheRelayAppInfo;    // MyRelayApps.MyMirrorCache.GetEntryByFunc(s => s.cdeMID.Equals(MyAppGuid));

            if (MyApp == null)
            {
                if (pRequest.cdeN.Equals(TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.DeviceID))
                {
                    TSM tTSM = new TSM(MyBaseEngine.GetEngineName(), "WEBRELAY_REQUEST")
                    {
                        PLB = pRequest.PostData
                    };
                    pRequest.PostData       = null;
                    pRequest.ResponseBuffer = null;
                    if (!string.IsNullOrEmpty(pRequest.CookieString))
                    {
                        pRequest.CookieString += ";";
                    }
                    else
                    {
                        pRequest.CookieString = "";
                    }
                    pRequest.CookieString += tMagixc;
                    if (string.IsNullOrEmpty(TheBaseAssets.MyServiceHostInfo.RootDir))
                    {
                        pRequest.RequestUriString = pRequest.RequestUri.ToString();
                    }
                    else
                    {
                        pRequest.RequestUriString = pRequest.RequestUri.Scheme + "://" + pRequest.RequestUri.Host + ":" + pRequest.RequestUri.Port + pRequest.cdeRealPage;
                        if (!string.IsNullOrEmpty(pRequest.RequestUri.Query))
                        {
                            pRequest.RequestUriString += "?" + pRequest.RequestUri.Query;
                        }
                    }
                    TheBaseAssets.MySYSLOG.WriteToLog(400, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM(MyBaseEngine.GetEngineName(), string.Format("Requesting Page:{0}", pRequest.RequestUriString), eMsgLevel.l6_Debug));

                    tTSM.PLS = TheCommonUtils.SerializeObjectToJSONString(pRequest);
                    tTSM.SID = pRequest.SessionState.GetSID();
                    TheCommCore.PublishCentral(tTSM); //  .PublishToNode(MyApp.HostUrl, pRequest.SessionState.SScopeID, tTSM);
                }
                return;
            }
            if (TheCommonUtils.IsUrlLocalhost(MyApp.GetBaseThing().Address))
            {
                TheCommonUtils.GetAnyFile(pRequest);
                if (tMagixc != null)
                {
                    pRequest.CookieString = tMagixc;
                }
                pSinkProcessResponse(pRequest);
            }
            else
            {
                int    relPathIndex = pRequest.RequestUri.AbsolutePath.IndexOf('/', 1);
                string relPath      = relPathIndex == -1 ? "" : pRequest.RequestUri.AbsolutePath.Substring(relPathIndex + 1) + pRequest.RequestUri.Query;
                var    tUri         = pRequest.RequestUri.AbsolutePath.StartsWith("/CDEWRA") ? new Uri(MyApp.GetBaseThing().Address + MyApp.HomePage + relPath) : new Uri(MyApp.GetBaseThing().Address.TrimEnd('/') + pRequest.RequestUri.AbsolutePath + pRequest.RequestUri.Query);
                if (!string.IsNullOrEmpty(tMagixc))
                {
                    if (!string.IsNullOrEmpty(pRequest.CookieString))
                    {
                        pRequest.CookieString += ";";
                    }
                    else
                    {
                        pRequest.CookieString = "";
                    }
                    pRequest.CookieString += tMagixc;
                }
                pRequest.RequestUri       = tUri;
                pRequest.ErrorDescription = "";
                pRequest.RequestCookies   = pRequest.SessionState.StateCookies;
                if (!string.IsNullOrEmpty(MyApp.SUID) && !string.IsNullOrEmpty(MyApp.SPWD))
                {
                    pRequest.UID = MyApp.SUID;
                    pRequest.PWD = MyApp.SPWD;
                }
                if (MyApp.IsHTTP10)
                {
                    pRequest.HttpVersion = 1.0;
                }
                if (string.IsNullOrEmpty(MyApp.CloudUrl))
                {
                    MyApp.CloudUrl = TheBaseAssets.MyServiceHostInfo.GetPrimaryStationURL(false);
                }
                pRequest.Header = null;
                if (pRequest.PostData != null && pRequest.PostData.Length > 0)      //MONO Relay might not work right!
                {
                    TheREST MyRest = new TheREST();
                    MyRest.PostRESTAsync(pRequest, pSinkProcessResponse, pSinkProcessResponse);
                }
                else
                {
                    TheREST.GetRESTAsync(pRequest, pSinkProcessResponse, pSinkProcessResponse);
                }
                TheBaseAssets.MySYSLOG.WriteToLog(400, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM(MyBaseEngine.GetEngineName(), string.Format("Requesting Page:{0} Sent", pRequest.RequestUri), eMsgLevel.l3_ImportantMessage));
            }
        }
コード例 #2
0
 private void CmdCallHttpIntercepter_Click(object sender, EventArgs e)
 {
     nsCDEngine.ViewModels.TheRequestData p = new nsCDEngine.ViewModels.TheRequestData();
     p.cdeRealPage = "/HelloHTTPInterceptor?TARGET=MyPlugin";
     TheCommonUtils.GetAnyFile(p);
 }