Exemplo n.º 1
0
        /// <summary>
        /// Get bitmap from SVG XML
        /// </summary>
        /// <param name="svgXml"></param>
        /// <param name="bitmapWidth">Desired width in pixels</param>
        /// <returns></returns>

        public static Bitmap GetBitmapFromSvgXml(
            string svgXml,
            int bitmapWidth)
        {
            RectangleF bb = new RectangleF();

            if (Lex.IsUndefined(svgXml) || bitmapWidth <= 0)
            {
                return(new Bitmap(1, 1));
            }

            try
            {
                SvgDocument doc = AdjustSvgDocumentToFitContent(svgXml, bitmapWidth, SvgUnitType.Pixel);

                if (doc == null)
                {
                    return(new Bitmap(1, 1));
                }

                int bitmapHeight = 1;
                if (doc.Width > 0)
                {
                    bitmapHeight = (int)((doc.Height / doc.Width) * bitmapWidth);
                }

                Bitmap bmp = doc.Draw(bitmapWidth, bitmapHeight);                 // create bitmap

                //Bitmap bmp = doc.Draw(); // create bitmap

                if (DebugMx.True && ClientState.IsDeveloper)                 // debug - dump xml and bitmap
                {
                    try
                    {
                        FileUtil.WriteFile(@"c:\downloads\SvgUtilTestXml.html", svgXml);
                        bmp.Save(@"c:\downloads\SvgUtilTestBmp.bmp");
                    }
                    catch (Exception ex) { ex = ex; }
                }

                return(bmp);
            }

            catch (Exception ex)
            {
                DebugLog.Message(ex);
                throw new Exception(ex.Message, ex);
            }

            //SvgAspectRatio aspectRatio = doc.AspectRatio; // aspect of the viewport.
            //RectangleF docBounds = doc.Bounds; // bounds of the svg element
            //SvgUnit docLeft = doc.X; // left position
            //SvgUnit docTop = doc.Y; // top position
            //SvgUnit docHeight = doc.Height; // height
            //SvgUnit docWidth = doc.Width; // width

            //string matchString = "<rect x='.0' y='.0' width='242.0' height='242.0' fill='rgba(0,0,0,0.00)' stroke='none'/>";
            //xml = Lex.Replace(xml, matchString, "");

            //float xRat = (dr.Width / vb.Width); // * (br.Width / vb.Width);
            //float yRat = (dr.Height / vb.Height); // * (br.Height / vb.Height);
            //RectangleF cr = new RectangleF(br.X * xRat, br.Y * yRat, br.Width * xRat, br.Height * yRat);
            //Bitmap bmp2 = bmp.Clone(cr, bmp.PixelFormat); // extract rectangle
        }
Exemplo n.º 2
0
        /// <summary>
        /// Check if the current version of the client is up to date and where it is
        /// </summary>
        /// <param name="localIniPath"></param>
        /// <param name="localIniFile"></param>
        /// <param name="clientDeploymentDir"></param>
        /// <param name="remoteIniPath"></param>
        /// <param name="remoteIniFile"></param>
        /// <param name="logActivity"></param>
        /// <returns></returns>

        public static bool ClientVersionIsUpToDate(
            out string localIniPath,
            out IniFile localIniFile,
            out string clientDeploymentDir,
            out string remoteIniPath,
            out IniFile remoteIniFile,
            bool logActivity)
        {
            StreamReader sr          = null;
            string       localBinDir = null;

            localIniPath        = "";
            localIniFile        = null;
            clientDeploymentDir = "";
            remoteIniPath       = "";
            remoteIniFile       = null;

            try
            {
                if (logActivity)
                {
                    DebugLog.Message("Getting local & remote deployment Ids...");
                }

                localIniPath = DefaultMobiusClientFolder + @"\MobiusClient.ini";                 // ini file on client
                if (!File.Exists(localIniPath))
                {
                    localIniPath = Application.StartupPath + @"\MobiusClient.ini";                     // ini file on client
                    if (!File.Exists(localIniPath))
                    {
                        return(true);
                    }
                }

                localIniFile = new IniFile(localIniPath, "Mobius");

                string localDeploymentId = localIniFile.Read("DeploymentId", "UnknownLocalDeployment");
                if (logActivity)
                {
                    DebugLog.Message("LocalDeploymentId: " + localDeploymentId);
                }

                clientDeploymentDir = localIniFile.Read("ClientDeploymentDir", DefaultMobiusClientFolder);
                if (logActivity)
                {
                    DebugLog.Message("ClientDeploymentDir: " + clientDeploymentDir);
                }

                string remoteBinDir = localIniFile.Read("ServerBinDir");                 // bin directory on server where things are
                if (Lex.IsNullOrEmpty(remoteBinDir))
                {
                    throw new Exception("ServerBinDir not defined in " + localIniPath);
                }

                remoteIniPath = remoteBinDir + @"\MobiusClient.ini"; // ini file on server

                try                                                  // be sure we can read remote inifile & trap any error
                {
                    sr = new StreamReader(remoteIniPath);
                    sr.Close();
                    remoteIniFile = new IniFile(remoteIniPath, "Mobius");
                    if (remoteIniFile == null)
                    {
                        throw new Exception("Null IniFile Object");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Can't open remote inifile: " + remoteIniPath + ", " + ex.Message);
                }

                string remoteDeploymentId = remoteIniFile.Read("DeploymentId", "UnknownRemoteDeployment");
                bool   deploymentIdsMatch = (localDeploymentId == remoteDeploymentId);               // local & remote deployment ids the same?

                if (logActivity)
                {
                    DebugLog.Message("RemoteDeploymentId: " + remoteDeploymentId);
                }

                // Get current client deployment dir

                string clientExePath = clientDeploymentDir + @"\MobiusClient.exe";                 // make sure executable is there
                if (!File.Exists(clientExePath))
                {
                    return(false);
                }

                if (!deploymentIdsMatch)
                {
                    return(false);           // local & remote deployment ids the same?
                }
                return(true);                // up to date
            }

            catch (Exception ex)
            {
                if (logActivity)
                {
                    string msg =
                        "Client version check failed\r\n" +
                        ex.Message + "\r\n" +
                        ex.StackTrace;
                    DebugLog.Message(msg);

                    MessageBox.Show(msg);
                }

                return(true);                // say true if error
            }
        }