Example #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     this.Title = ProjectName;
     Parameter = ProjectParameter.GetSettingsByProjectName(CurrentSession.UserCode, ProjectName, CurrentSession.ShareUserCode);
     if (Parameter == null)
     {
         Response.Redirect("Index.aspx");
     }
     if (!string.IsNullOrEmpty(CurrentSession.ShareUserCode))
     {
         GetTogether.Utility.DirectoryHelper.CopyParameter cp = new GetTogether.Utility.DirectoryHelper.CopyParameter();
         cp.Source = GetPath(CurrentSession.ShareUserCode);
         if (System.IO.Directory.Exists(cp.Source))
         {
             cp.Destination = GetPath(CurrentSession.UserCode);
             if (!System.IO.Directory.Exists(cp.Destination)) System.IO.Directory.CreateDirectory(cp.Destination);
             cp.IsOverwrite = true;
             GetTogether.Utility.DirectoryHelper.Copy(cp);
         }
     }
     if (!string.IsNullOrEmpty(Request["gc"]))
     {
         Codes = WsdlHelper.GetCodes(Parameter.Address);
         Response.ContentType = "text/plain";
         Response.Write(Codes);
         Response.End();
     }
     else
     {
         ProjectHistory ph = Projects.GetProjectHistory(ProjectParameter.GetSettingsPath(CurrentSession.UserCode), ProjectName);
         if (ph == null)
         {
             ph = new ProjectHistory();
         }
         ph.RecentUsed = DateTime.Now;
         string path = GetTogether.Studio.WebService.Projects.GetProjectHistoryFile(ProjectParameter.GetSettingsPath(CurrentSession.UserCode), ProjectName, true);
         GetTogether.Utility.FileHelper.SerializeToFile(ph, path);
     }
 }
Example #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            switch (type)
            {
                case 0:
                    #region Get Methods
                    WebService_Components_Methods c = (WebService_Components_Methods)Page.LoadControl("~/WebService/Components/Methods.ascx");
                    try
                    {
                        c.Methods = CurrentWsdl.Methods;
                        c.Parameter = this.Parameter;
                    }
                    catch (Exception ex)
                    {
                        c.Error = ex.ToString();
                    }
                    this.Page.Controls.Add(c);
                    break;
                    #endregion
                case 1:
                    #region Get Method Information
                    GetMethodInformationMain();
                    break;
                    #endregion
                case 2:
                    #region Invoke Method
                    string retXml = string.Empty;
                    DateTime startDt = DateTime.Now;
                    try
                    {
                        System.Reflection.MethodInfo mi = CurrentWsdl.GetMethodByName(MethodName);
                        MethodSetting methodSetting = new MethodSetting();
                        methodSetting.RqtMode = MethodSetting.RequestMode.Object;
                        if (GetTogether.Utility.NumberHelper.ToInt(Request["WMP_SOAP_" + MethodName], 0) == 1)
                        {
                            methodSetting.RqtMode = MethodSetting.RequestMode.SOAP;
                        }
                        string historyPath = GetInvokeHistoryPath();
                        if (!System.IO.Directory.Exists(historyPath)) System.IO.Directory.CreateDirectory(historyPath);
                        System.IO.File.WriteAllText(GetInvokeHistoryParameterFile("[Request-Mode]"),
                            GetTogether.Utility.SerializationHelper.SerializeToXml(methodSetting));
                        if (methodSetting.RqtMode == MethodSetting.RequestMode.Object)
                        {
                            List<object> parameters = new List<object>();
                            StringBuilder sbParam = new StringBuilder();
                            List<object> referenceObjects = new List<object>();
                            foreach (System.Reflection.ParameterInfo pi in mi.GetParameters())
                            {
                                string rqtValue = Request.Form["WMP_" + pi.Name];
                                sbParam.AppendLine(rqtValue);
                                object p = WsdlHelper.ConvertParameter(CurrentWsdl, pi, rqtValue);
                                if (pi.ParameterType.IsByRef)
                                {
                                    referenceObjects.Add(p);
                                }
                                parameters.Add(p);
                                if (!System.IO.Directory.Exists(historyPath)) System.IO.Directory.CreateDirectory(historyPath);
                                System.IO.File.WriteAllText(GetInvokeHistoryParameterFile(pi.Name), WsdlHelper.ParameterToString(p));
                            }
                            foreach (FieldInfo fi in CurrentWsdl.GetHeaders(mi))
                            {
                                string rqtValue = Request.Form["WMP_" + fi.Name];
                                sbParam.AppendLine(rqtValue);
                                object p = WsdlHelper.ConvertParameter(CurrentWsdl, fi, rqtValue);
                                if (fi.FieldType.IsByRef)
                                {
                                    referenceObjects.Add(p);
                                }
                                GetTogether.Mapping.ObjectHelper.SetValue(CurrentWsdl.ServiceObject, fi.Name, p);
                                fi.SetValue(CurrentWsdl.ServiceObject, p);
                                //parameters.Add(p);
                                if (!System.IO.Directory.Exists(historyPath)) System.IO.Directory.CreateDirectory(historyPath);
                                System.IO.File.WriteAllText(GetInvokeHistoryParameterFile(fi.Name), WsdlHelper.ParameterToString(p));
                            }
                            object ret = CurrentWsdl.Invoke(MethodName, parameters.Count > 0 ? parameters.ToArray() : null);
                            if (ret == null)
                                retXml = "";
                            else
                            {
                                if (Parameter.AddressType == AddressType.WebService)
                                    retXml = GetTogether.Utility.SerializationHelper.SerializeToXml(ret);
                                else
                                    retXml = (string)ret;
                            }
                            if (referenceObjects.Count > 0)
                            {
                                retXml += "\r\n---------------------------";
                                retXml += "\r\nBy Reference Object(s)";
                                retXml += "\r\n---------------------------";

                                foreach (object obj in referenceObjects)
                                {
                                    retXml += "\r\n" + GetTogether.Utility.SerializationHelper.SerializeToXml(obj);
                                }
                            }
                        }
                        else
                        {
                            string requestXml = Request["WMP_SOAP_Request_" + MethodName];
                            retXml = RequestHelper.SendWebRequest(Parameter, mi, requestXml);
                            System.IO.File.WriteAllText(GetInvokeHistoryParameterFile("[SOAP-Request]"), requestXml);
                        }
                    }
                    catch (Exception ex)
                    {
                        retXml = ex.ToString();
                    }
                    string forwardUrl = @"<div style='display:none;' id='dv-forward-{3}'>
        <textarea style='width:500px;height:80px;margin:5px;' class='txt'>http://{0}/{1}/WebService/Edit.aspx?pn={2}&method={3}&history={4}&share-usercode={5}</textarea></div>";
                    string forwardHtml = string.Format(forwardUrl, Request.Url.Host, Request.Url.AbsolutePath.Split('/')[1], System.Web.HttpUtility.UrlEncode(ProjectName), MethodName, System.Web.HttpUtility.UrlEncode(HistoryName), CurrentSession.UserCode);
                    string duration = DateTime.Now.Subtract(startDt).TotalSeconds.ToString();
                    StringBuilder sbOpenInNewWindow = new StringBuilder();
                    if (!string.IsNullOrEmpty(retXml))
                    {
                        sbOpenInNewWindow.Append("&nbsp;&nbsp;<span class='mm-split'>|</span>&nbsp;&nbsp;");
                        sbOpenInNewWindow.Append("Open in New Window : ");
                        string opTemp = "<a href='javascript:;;' onclick=\"$('#type-{0}').val('{1}');$('#form-{0}')[0].submit();\">{2}</a>";
                        sbOpenInNewWindow.AppendFormat(opTemp, MethodName, "text/xml", "XML");
                        sbOpenInNewWindow.Append(" , ");
                        sbOpenInNewWindow.AppendFormat(opTemp, MethodName, "text/plain", "TEXT");
                        sbOpenInNewWindow.Append(" , ");
                        sbOpenInNewWindow.AppendFormat(opTemp, MethodName, "text/html", "HTML");
                    }

                    string info = string.Format("<div class='header-2' style='padding-left:2px;'>Duration:{0}&nbsp;&nbsp;<span class='mm-split'>|</span>&nbsp;&nbsp;Content Length:{2} {1}</div><div class='line-sub'></div>", duration, sbOpenInNewWindow.ToString(), retXml.Length);
                    string html = string.Empty;
                    if (!string.IsNullOrEmpty(retXml))
                        html = string.Format("<form id='form-{1}' method='post' target='_blank' action='../Viewer.aspx'><input name='type-{1}' id='type-{1}' type='hidden' /><textarea rows='10' name='result-{1}' style='width:99.8%;'>{0}</textarea></form>", retXml, MethodName);
                    else
                        html = "<div class='header-2' style='padding-left:2px;'>Method was invoked successfully.</div><div class='line-sub'></div>";
                    Response.Write(info + html + forwardHtml);
                    break;
                    #endregion
                case 3:
                    #region Get Invoke History
                    try
                    {
                        Dictionary<string, object> parameters = new Dictionary<string, object>();
                        System.Reflection.MethodInfo mi = CurrentWsdl.GetMethodByName(MethodName);
                        FieldInfo[] headers = CurrentWsdl.GetHeaders(mi);
                        foreach (System.Reflection.FieldInfo fi in headers)
                        {
                            string hFile = GetInvokeHistoryParameterFile(fi.Name);
                            if (System.IO.File.Exists(hFile))
                            {
                                string hValue = System.IO.File.ReadAllText(hFile, System.Text.Encoding.UTF8);
                                parameters.Add(fi.Name, WsdlHelper.ConvertParameter(CurrentWsdl, fi, hValue));
                            }
                        }
                        foreach (System.Reflection.ParameterInfo pi in mi.GetParameters())
                        {
                            string hFile = GetInvokeHistoryParameterFile(pi.Name);
                            if (System.IO.File.Exists(hFile))
                            {
                                string hValue = System.IO.File.ReadAllText(hFile, System.Text.Encoding.UTF8);
                                parameters.Add(pi.Name, WsdlHelper.ConvertParameter(CurrentWsdl, pi, hValue));
                            }
                        }

                        if (mi.GetParameters().Length != parameters.Count - headers.Length)
                            GetMethodInformationMain();
                        else
                            Response.Write(GetMethodInformation(MethodName, parameters, mi.ReturnType, GetMethodSetting()));
                    }
                    catch (Exception ex)
                    {
                        string exError = string.Format("<textarea rows='5' style='width:99.8%;height:100px;'>{0}</textarea>", ex.ToString());
                        string header = string.Format("<div class='header-2' style='padding-left:2px;'>{0}{1}</div><div class='line-sub'></div>", MethodName, string.Format(refreshMethod, MethodName, Parameter.Address));
                        Response.Write(string.Format(containerDiv, MethodName, header + exError));
                    }
                    break;
                    #endregion
                case 4:
                    #region Delete Invoke History
                    try
                    {
                        string path = GetInvokeHistoryPath();
                        if (System.IO.Directory.Exists(path))
                        {
                            string pathDeleted = System.IO.Path.Combine(GetTogether.Studio.WebService.ProjectParameter.GetSettingsPath(CurrentSession.UserCode), "Deleted Invoke History\\" + MethodName + "\\" + HistoryName);
                            if (!System.IO.Directory.Exists(pathDeleted))
                                System.IO.Directory.CreateDirectory(pathDeleted);
                            GetTogether.Utility.DirectoryHelper.CopyParameter cp = new GetTogether.Utility.DirectoryHelper.CopyParameter();
                            cp.Destination = pathDeleted;
                            cp.Source = path;
                            cp.IsOverwrite = true;
                            GetTogether.Utility.DirectoryHelper.Copy(cp);
                            System.IO.Directory.Delete(path, true);
                        }
                        JsonSuccess();
                    }
                    catch (Exception ex)
                    {
                        JsonError(ex.ToString());
                    }
                    break;
                    #endregion
                case 5:
                    #region Format Xml
                    Response.Write(GetTogether.Utility.Xml.XmlHelper.FormatXml(Request["xml"]));
                    break;
                    #endregion
                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }