コード例 #1
0
        /// <summary>
        /// Sets the given model for the LayerControl in the ASP.NET session.
        /// </summary>
        /// <remarks>If a custom model is used, then this method can be used to set the model in the session that will be used instead.</remarks>
        /// <param name="model">The model to be set in the ASP.NET session.</param>
        public static void SetModelInSession(LayerControlModel model)
        {
            HttpContext context = HttpContext.Current;
            string      key     = string.Format("{0}_LayerModel", context.Session.SessionID);

            context.Session[key] = model;
        }
コード例 #2
0
 /// <summary>
 /// Creates the default model for the LayerControl provided by MapXtreme and sets the object in the ASP.NET session.
 /// </summary>
 /// <remarks>This method tries to extract the model for the LayerControl from the ASP.NET session. If the medel is not found it will create the default one and places it there.
 /// This is a safe method, and always returns the model. TThis method can be used when the model may not exist in the session.</remarks>
 /// <returns>LayerControlModel from session.</returns>
 public static LayerControlModel SetDefaultModelInSession()
 {
     HttpContext context = HttpContext.Current;
     LayerControlModel model = GetModelFromSession();
     if (model == null) {
         model = new LayerControlModel();
         SetModelInSession(model);
     }
     return model;
 }
コード例 #3
0
        /// <summary>
        /// Creates the default model for the LayerControl provided by MapXtreme and sets the object in the ASP.NET session.
        /// </summary>
        /// <remarks>This method tries to extract the model for the LayerControl from the ASP.NET session. If the medel is not found it will create the default one and places it there.
        /// This is a safe method, and always returns the model. TThis method can be used when the model may not exist in the session.</remarks>
        /// <returns>LayerControlModel from session.</returns>
        public static LayerControlModel SetDefaultModelInSession()
        {
            HttpContext       context = HttpContext.Current;
            LayerControlModel model   = GetModelFromSession();

            if (model == null)
            {
                model = new LayerControlModel();
                SetModelInSession(model);
            }
            return(model);
        }
コード例 #4
0
        /// <summary>
        /// Gets the model for the LayerControl from the ASP.NET session.
        /// </summary>
        /// <remarks>This method will return null if the model is not found.</remarks>
        /// <returns>LayerControl model</returns>
        public static LayerControlModel GetModelFromSession()
        {
            HttpContext       context = HttpContext.Current;
            string            key     = string.Format("{0}_LayerModel", context.Session.SessionID);
            LayerControlModel model   = null;

            if (context.Session[key] != null)
            {
                model = context.Session[key] as LayerControlModel;
            }
            return(model);
        }
コード例 #5
0
        /// <summary>
        /// Processes requests for the LayerControl.
        /// </summary>
        /// <param name="context">HttpContext</param>
        /// <remarks>This method parses the URL. Gets the model for the LayerControl from the session and then uses that to get the XML. Then the HTML is generated
        /// by using XSLT transform and returnes back as response.
        /// </remarks>
        public void ProcessRequest(HttpContext context)
        {
            string _command      = context.Request["Command"];
            string _uniqueID     = context.Request["UniqueID"];
            string _mapAlias     = context.Request["MapAlias"];
            string _mapControlID = context.Request["MapControlID"];
            // Get Xslt file name
            string _xsltFile = context.Request["XsltFile"];

            // Get the resource path name passed as data and properly encode it.
            byte[] buffer        = new byte[context.Request.InputStream.Length];
            int    read          = context.Request.InputStream.Read(buffer, 0, (int)context.Request.InputStream.Length);
            string _resourcePath = System.Text.UTF8Encoding.UTF8.GetString(buffer);
            string _imgPath      = _resourcePath;
            // Form the full path for xslt file
            string            _xsltPath  = context.Server.MapPath(_resourcePath) + "\\" + _xsltFile;
            LayerControlModel layerModel = LayerControlModel.SetDefaultModelInSession();

            switch (_command)
            {
            case "GetHTML":
                XmlDocument treeDoc = layerModel.GetLayerXML(_mapAlias, _uniqueID, _imgPath);

                // load the xslt file into reader
                System.IO.TextReader tr = new System.IO.StreamReader(_xsltPath);
                MemoryStream         ms = new MemoryStream();
                StreamWriter         sw = new StreamWriter(ms);
                // Now replace the tags in the xslt file with actual strings from resources
                string line = "";
                while ((line = tr.ReadLine()) != null)
                {
                    Regex           regexp = new Regex("(Treeview2_([0-9]+))");
                    MatchCollection mc     = regexp.Matches(line);
                    for (int i = mc.Count - 1; i >= 0; i--)
                    {
                        Match   m       = mc[i];
                        Group   g       = m.Groups[0];
                        Capture c       = m.Groups[0].Captures[0];
                        string  resName = line.Substring(c.Index, c.Length);
                        if (resName.Equals("Treeview2_3"))
                        {
                            line = line.Replace(resName, Resources.ResourceFolder);
                        }
                        else
                        {
                            string resString = L10NUtils.Resources.GetString(resName);
                            line = line.Replace(resName, resString);
                        }
                    }
                    sw.WriteLine(line);
                }

                sw.Flush();
                ms.Position = 0;

                // Use that TextReader as the Source for the XmlTextReader
                System.Xml.XmlReader xr = new System.Xml.XmlTextReader(ms);
                // Create a new XslTransform class
                System.Xml.Xsl.XslTransform treeView = new System.Xml.Xsl.XslTransform();
                // Load the XmlReader StyleSheet into the XslTransform class
                treeView.Load(xr, null, null);

                StringWriter sw2 = new StringWriter();

                XPathNavigator nav = treeDoc.CreateNavigator();

                // Do the transform and write to response
                treeView.Transform(nav, null, sw2, null);
                context.Response.Write(sw2.ToString());
                tr.Close();
                sw.Close();
                ms.Close();
                sw2.Close();

                /*
                 * XmlDocument treeDoc = layerModel.GetLayerXML(_mapAlias,  _uniqueID, _imgPath);
                 *
                 * XslTransform treeView = new XslTransform();
                 * treeView.Load(_xsltPath);
                 *
                 * StringWriter sw = new StringWriter();
                 *
                 * XPathNavigator nav = treeDoc.CreateNavigator();
                 *
                 * // Do the transform and write to response
                 * treeView.Transform(nav, null,  sw,  null);
                 * context.Response.Write(sw.ToString());
                 */
                break;
            }
        }
コード例 #6
0
 /// <summary>
 /// Sets the given model for the LayerControl in the ASP.NET session.
 /// </summary>
 /// <remarks>If a custom model is used, then this method can be used to set the model in the session that will be used instead.</remarks>
 /// <param name="model">The model to be set in the ASP.NET session.</param>
 public static void SetModelInSession(LayerControlModel model)
 {
     HttpContext context = HttpContext.Current;
     string key = string.Format("{0}_LayerModel", context.Session.SessionID);
     context.Session[key] = model;
 }