Example #1
0
        public void SendResponse(string responseCode)
        {
            responseType response = new responseType();

            response.requestId = m_request.requestId;
            response.result    = responseCode;
            response.sessionId = m_request.sessionId;

            Console.WriteLine("RESPONSE GETTING SENT " + responseCode + " " + response.requestId.ToString());

            string responseData;

            XmlSerializer serializer = new XmlSerializer(response.GetType());

            using (TextWriter writer = new StringWriter())
            {
                serializer.Serialize(writer, response);
                responseData = writer.ToString();
            }

            m_channel.BeginSendData(
                new System.Net.Mime.ContentType(WireHelpers.Response),
                new ASCIIEncoding().GetBytes(responseData),
                (r) =>
            {
                try
                {
                    m_channel.EndSendData(r);
                }
                catch (Exception)
                {
                    //TODO:Log and Ignore
                }
            }, null);
        }
Example #2
0
        internal static string GetHtmlResponse(responseType response, bool autoCloseTab)
        {
            var imgUrl = string.Empty;

            switch (response)
            {
            case responseType.LabSuccess:
                imgUrl = "https://raw.githubusercontent.com/Azure/azure-devtestlab/master/samples/DevTestLabs/AzureFunctions/LabSuccessfullyUpdated.png";
                break;

            case responseType.VirtualMachineSuccess:
                imgUrl = "https://raw.githubusercontent.com/Azure/azure-devtestlab/master/samples/DevTestLabs/AzureFunctions/VirtualMachineSuccess.png";
                break;

            case responseType.VirtualMachineNotRunning:
                imgUrl = "https://raw.githubusercontent.com/Azure/azure-devtestlab/master/samples/DevTestLabs/AzureFunctions/VirtualMachineNotRunning.png";
                break;

            default:
                throw new ArgumentException("Invalid value passed to internal GetHtmlResponse method");
            }

            if (autoCloseTab)
            {
                return(htmlPageTemplateResponse.Replace("{JAVASCRIPT}", javascriptToCloseBrowserTab).Replace("{IMAGEURL}", imgUrl));
            }
            else
            {
                return(htmlPageTemplateResponse.Replace("{JAVASCRIPT}", "").Replace("{IMAGEURL}", imgUrl));
            }
        }
        /// <summary>
        /// Formira webResponse na osnovu prosledjeno web response-a
        /// </summary>
        /// <param name="response"></param>
        public webResponse(WebResponse response)
        {
            String       __typeString = "null";
            responseType __type       = responseType.nullResponse;

            _response = response;
            if (response != null)
            {
                __typeString = response.GetType().Name;
                __type       = responseType.HttpWebResponse;

                if (!Enum.TryParse <responseType>(__typeString, out __type))
                {
                    __type = responseType.WebResponse;
                }
            }

            type    = __type;
            headers = new List <webHeader>();

            if (response != null)
            {
                foreach (string key in response.Headers.AllKeys)
                {
                    headers.Add(new webHeader(key, response.Headers[key]));
                }

                responseUrl = response.ResponseUri.OriginalString;
                contentType = response.ContentType;

                switch (type)
                {
                case responseType.PackWebResponse:
                    break;

                case responseType.FtpWebResponse:
                    break;

                case responseType.FileWebResponse:
                    FileWebResponse fileRes = response as FileWebResponse;
                    break;

                case responseType.HttpWebResponse:
                    HttpWebResponse httpRes = response as HttpWebResponse;
                    charset    = httpRes.CharacterSet;
                    encoding   = httpRes.ContentEncoding;
                    statusCode = httpRes.StatusCode.ToString();
                    statusDesc = httpRes.StatusDescription;
                    cookies    = new List <Cookie>();
                    foreach (Cookie ck in httpRes.Cookies)
                    {
                        cookies.Add(ck);
                    }
                    method         = httpRes.Method;
                    server         = httpRes.Server;
                    responseDomain = httpRes.ResponseUri.DnsSafeHost;
                    break;
                }
            }
        }
Example #4
0
 public Response(string html = "", string javascript = "", string css = "", string json = "", string selector = "", responseType type = responseType.replace)
 {
     this.html       = html;
     this.javascript = javascript;
     this.css        = css;
     this.selector   = selector;
     this.json       = json;
     this.type       = type;
 }
Example #5
0
        public static string Inject(string selector, responseType injectType, string html, string javascript, string css)
        {
            var response = new Response()
            {
                type       = injectType,
                selector   = selector,
                html       = html,
                javascript = javascript,
                css        = css
            };

            return("{\"d\":" + Serializer.WriteObjectToString(response) + "}");
        }
Example #6
0
        internal void ProcessResponse(responseType response)
        {
            ProcessRequestAsyncResult pendingRequest;

            lock (_pendingRequests)
            {
                _pendingRequests.TryGetValue(response.requestId, out pendingRequest);
            }

            if (pendingRequest != null)
            {
                pendingRequest.ProcessResponse(response);
            }
        }
 public CallResponse(responseType response, object satteliteData = null, string errorData = "no error")
 {
     this.response = response;
     this.satteliteData = satteliteData;
     this.errorData = errorData;
 }
Example #8
0
 public void setType(responseType __type)
 {
     type = __type;
 }