コード例 #1
0
        static cRootObject TrySerialize(string strInput)
        {
            strInput = RemoveCstyleComments(strInput);
            strInput = ReplaceVariables(strInput);

            cRootObject objScript = Newtonsoft.Json.JsonConvert.DeserializeObject <cRootObject>(strInput);


            /*
             * foreach (System.Collections.Generic.KeyValuePair<string, System.Collections.Generic.Dictionary<string, cProvider>> provider_group in objScript.providers)
             * {
             *  System.Console.WriteLine(provider_group.Key + ":");
             *  foreach (System.Collections.Generic.KeyValuePair<string, cProvider> provider in provider_group.Value)
             *  {
             *      System.Console.WriteLine(provider.Key + ":");
             *      System.Console.WriteLine(provider.Value.label);
             *      System.Console.WriteLine(provider.Value.name);
             *      System.Console.WriteLine(provider.Value.url);
             *  }
             * }
             */

            return(objScript);
        } // End Function TrySerialize
コード例 #2
0
        } // End Function MapProjectPath

        public static void LocalizeSprites()
        {
            string strContent = System.IO.File.ReadAllText(MapProjectPath("~OpenIdSelector/js/openid-de.js"), System.Text.Encoding.UTF8);

            strContent = System.IO.File.ReadAllText(MapProjectPath("~OpenIdSelector/js/openid-en.js"), System.Text.Encoding.UTF8);

            cRootObject localizations = TrySerialize(strContent);

            int cntLarge = localizations.providers["providers_large"].Count;
            int cntSmall = localizations.providers["providers_small"].Count;

            // 100x60
            const int LARGE_PROVIDER_MAX_WIDTH  = 100;
            const int LARGE_PROVIDER_MAX_HEIGHT = 60;

            // 16x16
            const int SMALL_PROVIDER_MAX_WIDTH  = 20;
            const int SMALL_PROVIDER_MAX_HEIGHT = 20;

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(
                System.Math.Max(cntLarge * LARGE_PROVIDER_MAX_WIDTH, cntSmall * SMALL_PROVIDER_MAX_WIDTH)
                , LARGE_PROVIDER_MAX_HEIGHT + SMALL_PROVIDER_MAX_HEIGHT);

            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
            {
                g.Clear(System.Drawing.Color.HotPink);


                int i = 0;
                foreach (System.Collections.Generic.KeyValuePair <string, cProvider> provider in localizations.providers["providers_large"])
                {
                    using (System.Drawing.Image img = System.Drawing.Image.FromFile(MapProjectPath("~OpenIdSelector/images.large/" + provider.Key + ".gif")))
                    {
                        g.DrawImageUnscaled(img, i * LARGE_PROVIDER_MAX_WIDTH + (LARGE_PROVIDER_MAX_WIDTH - img.Width) / 2, (LARGE_PROVIDER_MAX_HEIGHT - img.Height) / 2);
                    } // End Using img

                    using (System.Drawing.Image img = System.Drawing.Image.FromFile(MapProjectPath("~OpenIdSelector/images.small/" + provider.Key + ".ico.png")))
                    {
                        g.DrawImageUnscaled(img, i * SMALL_PROVIDER_MAX_WIDTH + (SMALL_PROVIDER_MAX_WIDTH - img.Width) / 2
                                            , LARGE_PROVIDER_MAX_HEIGHT + (SMALL_PROVIDER_MAX_HEIGHT - img.Height) / 2);
                    } // End Using img

                    System.Console.WriteLine(provider.Key + ":");
                    System.Console.WriteLine(provider.Value.label);
                    System.Console.WriteLine(provider.Value.name);
                    System.Console.WriteLine(provider.Value.url);
                    ++i;
                } // Next provider

                // i = 0;
                foreach (System.Collections.Generic.KeyValuePair <string, cProvider> provider in localizations.providers["providers_small"])
                {
                    using (System.Drawing.Image img = System.Drawing.Image.FromFile(MapProjectPath("~OpenIdSelector/images.small/" + provider.Key + ".ico.png")))
                    {
                        g.DrawImageUnscaled(img, i * SMALL_PROVIDER_MAX_WIDTH + (SMALL_PROVIDER_MAX_WIDTH - img.Width) / 2
                                            , LARGE_PROVIDER_MAX_HEIGHT + (SMALL_PROVIDER_MAX_HEIGHT - img.Height) / 2);
                    } // End Using img

                    System.Console.WriteLine(provider.Key + ":");
                    System.Console.WriteLine(provider.Value.label);
                    System.Console.WriteLine(provider.Value.name);
                    System.Console.WriteLine(provider.Value.url);
                    ++i;
                } // Next provider

                bmp.MakeTransparent(System.Drawing.Color.HotPink);


                string fn = MapProjectPath("~OpenIdSelector/images/openidfile.png");
                bmp.Save(fn, System.Drawing.Imaging.ImageFormat.Png);
            } // End Using g

            System.Console.WriteLine(localizations);
        } // End Sub LocalizeSprites