Exemple #1
0
        internal Server(string strDnsAddress, string strCacheDir, string strSecureToken, bool blEnabled)
#endif
        {
            m_blEnabled = blEnabled;
            string strEdition, strConfigEdition;

            m_strSecureToken = strSecureToken;

            // --- create the connection to the server ---

#if !DAPPLE
            m_oCommand = new Geosoft.Dap.Command(strDnsAddress, true, Geosoft.Dap.Command.Version.GEOSOFT_XML_1_1);

            m_strCacheRoot = string.Empty;
            GXNet.CSYS.IGetDirectory(GXNet.Constant.SYS_DIR_USER, ref m_strCacheRoot);
#else
            m_oCommand     = new Geosoft.Dap.Command(strDnsAddress, false, Geosoft.Dap.Command.Version.GEOSOFT_XML_1_1, WorldWind.Net.WebDownload.DownloadTimeout);
            m_strCacheRoot = strCacheDir;
#endif

            m_strUrl = strDnsAddress;

#if !DAPPLE
            // --- ensure this server is trusted ---

            GXNet.CDAP.SetAuthorization(m_strUrl, Geosoft.GXNet.Constant.GUI_AUTH_TRUST);
#endif
            try
            {
                m_oCatalogs = new CatalogCollection(this);

                if (m_blEnabled)
                {
                    ConfigureServer();

                    // --- If the edition change we need to reload the configuration ---
                    m_oCommand.GetCatalogEdition(out strConfigEdition, out strEdition);
                    if (m_strCacheVersion != strConfigEdition)
                    {
                        UpdateConfiguration();
                    }
                }
            }
            catch
            {
                // we want to support showing servers as offline in the tree (otherwise we may loose them with offline mode)
                m_eStatus = ServerStatus.OffLine;
            }
        }
Exemple #2
0
        /// <summary>
        ///     <para>Initializes an instance of the <see cref="Server"/> class.</para>
        /// </summary>
        /// <param name="oServerNode">
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <para>The argument <paramref name="oServerNode"/> is <langword name="null"/>.</para>
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     <para>The argument <paramref name="oServerNode"/> is out of range.</para>
        /// </exception>
        internal Server(XmlNode oServerNode, string strSecureToken)
        {
            string  strEdition, strConfigEdition;
            XmlNode oAttr;

            m_strSecureToken = strSecureToken;

            m_strCacheRoot = string.Empty;
            GXNet.CSYS.IGetDirectory(GXNet.Constant.SYS_DIR_USER, ref m_strCacheRoot);

            if (oServerNode == null)
            {
                throw new ArgumentNullException("oServerNode");
            }
            if (oServerNode.Name != Constant.Xml.Tag.Server)
            {
                throw new ArgumentOutOfRangeException("oServerNode");
            }

            oAttr = oServerNode.Attributes.GetNamedItem(Constant.Xml.Attr.Name);
            if (oAttr == null)
            {
                throw new ApplicationException("Missing name attribute in server node");
            }
            m_strName = oAttr.Value;

            oAttr = oServerNode.Attributes.GetNamedItem(Constant.Xml.Attr.Url);
            if (oAttr == null)
            {
                throw new ApplicationException("Missing url attribute in server node");
            }
            m_strUrl = oAttr.Value;

            oAttr = oServerNode.Attributes.GetNamedItem(Constant.Xml.Attr.Status);
            if (oAttr == null)
            {
                throw new ApplicationException("Missing status attribute in server node");
            }
            m_eStatus = ParseStatus(oAttr.Value);

            oAttr = oServerNode.Attributes.GetNamedItem(Constant.Xml.Attr.Major_Version);
            if (oAttr == null)
            {
                throw new ApplicationException("Missing major version attribute in server node");
            }
            m_iMajorVersion = Int32.Parse(oAttr.Value);

            oAttr = oServerNode.Attributes.GetNamedItem(Constant.Xml.Attr.Minor_Version);
            if (oAttr == null)
            {
                throw new ApplicationException("Missing minor version attribute in server node");
            }
            m_iMinorVersion = Int32.Parse(oAttr.Value);

            oAttr = oServerNode.Attributes.GetNamedItem(Constant.Xml.Attr.CacheVersion);
            if (oAttr == null)
            {
                throw new ApplicationException("Missing cache version attribute in server node");
            }
            m_strCacheVersion = oAttr.Value;

            if (m_eStatus != ServerStatus.Disabled)
            {
                m_oCommand = new Geosoft.Dap.Command(m_strUrl, true, Geosoft.Dap.Command.Version.GEOSOFT_XML_1_1);

                // --- this is a 6.2 server, get decreased configuration parameters ---

                if (m_iMajorVersion < 6 || (m_iMajorVersion == 6 && m_iMinorVersion < 3))
                {
                    m_oCommand.ChangeVersion(Command.Version.GEOSOFT_XML_1_0);
                }

                // --- ensure this server is trusted ---

                GXNet.CDAP.SetAuthorization(m_strUrl, Geosoft.GXNet.Constant.GUI_AUTH_TRUST);

                try
                {
                    m_oCatalogs = new CatalogCollection(this);

                    ConfigureServer();

                    // --- If the edition change we need to reload the configuration ---
                    m_oCommand.GetCatalogEdition(out strConfigEdition, out strEdition);
                    if (m_strCacheVersion != strConfigEdition)
                    {
                        UpdateConfiguration();
                    }
                }
                catch
                {
                    // we want to support showing servers as offline in the tree (otherwise we may loose them with offline mode)
                    m_eStatus = ServerStatus.OffLine;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Download an image for a layer.
        /// </summary>
        /// <param name="strCacheFilename">The filename to save the layer to.</param>
        /// <param name="oTile">The tile of this layer to download.</param>
        private void DownloadDapImage(string strCacheFilename, TileInfo oTile)
        {
            Format oFormat = new Format();
            oFormat.Type = "image/png";
            oFormat.Transparent = true;

            Resolution oRes = new Resolution();
            oRes.Height = TileInfo.TileSizePixels;
            oRes.Width = TileInfo.TileSizePixels;

            ArrayList oArr = new ArrayList();
            oArr.Add(m_strLayer);

            Command oCommand = new Command(m_strServer, false, Command.Version.GEOSOFT_XML_1_1, false, DapSecureToken.Instance);
            XmlDocument result = oCommand.GetImage(oFormat, oTile.Bounds, oRes, oArr);

            // --- Save the resulting image ---

            XmlNodeList hNodeList = result.SelectNodes("/" + Geosoft.Dap.Xml.Common.Constant.Tag.GEO_XML_TAG + "/" + Geosoft.Dap.Xml.Common.Constant.Tag.RESPONSE_TAG + "/" + Geosoft.Dap.Xml.Common.Constant.Tag.IMAGE_TAG + "/" + Geosoft.Dap.Xml.Common.Constant.Tag.PICTURE_TAG);
            if (hNodeList.Count == 0)
            {
                hNodeList = result.SelectNodes("/" + Geosoft.Dap.Xml.Common.Constant.Tag.GEO_XML_TAG + "/" + Geosoft.Dap.Xml.Common.Constant.Tag.RESPONSE_TAG + "/" + Geosoft.Dap.Xml.Common.Constant.Tag.TILE_TAG);
            }
            FileStream fs = new FileStream(strCacheFilename, System.IO.FileMode.Create);
            BinaryWriter bs = new BinaryWriter(fs);

            foreach (XmlNode hNode in hNodeList)
            {
                XmlNode hN1 = hNode.FirstChild;
                string jpegImage = hN1.Value;

                if (jpegImage != null)
                {
                    byte[] jpegRawImage = Convert.FromBase64String(jpegImage);

                    bs.Write(jpegRawImage);
                }
            }
            bs.Flush();
            bs.Close();
            fs.Close();
        }