Exemplo n.º 1
0
        public void TestMethod5()
        {
            Guid guid = new Guid("{d3902802-2842-4d50-bc5b-134c27efe5ff}");

            Console.WriteLine(guid);

            byte[] guidBytes = guid.ToByteArray();
            byte[] sifted    = new byte[guidBytes.Length + 1];
            Buffer.BlockCopy(guidBytes, 0, sifted, 0, guidBytes.Length);

            BigInteger bigInteger = new BigInteger(sifted);

            Assert.AreEqual(BigInteger.One, bigInteger.Sign);

            string encoded = BaseConvert.ToBaseString(bigInteger, BaseConvert.Base62);

            Assert.IsNotNull(encoded);
            Console.WriteLine(encoded);

            BigInteger result = BaseConvert.FromBaseString(encoded, BaseConvert.Base62);

            Assert.IsNotNull(result);

            byte[] actualBytes = result.ToByteArray();
            byte[] bytes       = new byte[16];

            int count = Math.Min(bytes.Length, actualBytes.Length);

            Buffer.BlockCopy(actualBytes, 0, bytes, 0, count);

            Guid actual = new Guid(bytes);

            Assert.AreEqual(guid, actual);
            Console.WriteLine(actual);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Encodes the given Guid as an encoded string.
        /// </summary>
        /// <param name="guid">The Guid to encode</param>
        /// <returns>The encoded string.</returns>
        public static string Encode(Guid guid)
        {
            byte[] guidBytes = guid.ToByteArray();
            // add extra byte to make number positive
            byte[] sifted = new byte[guidBytes.Length + 1];
            Buffer.BlockCopy(guidBytes, 0, sifted, 0, guidBytes.Length);

            return(BaseConvert.ToBaseString(sifted, BaseConvert.Base62));;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Convert a hexadecimal id into a base-62 encoded id.
        /// </summary>
        /// <param name="hex">A hexadecimal id.</param>
        /// <returns>A base-62 encoded id.</returns>
        private static string ToBase62(string hex)
        {
            string uri = BaseConvert.Convert(hex, 16, 62);

            /* Prepend zeroes until base-62 string length is 22. */
            while (uri.Length < 22)
            {
                uri.Insert(0, "0");
            }

            return(uri);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Convert a base-62 encoded id into a hexadecimal id.
        /// </summary>
        /// <param name="base62">A base-62 encoded id.</param>
        /// <returns>A hexadecimal id.</returns>
        private static string ToHex(string base62)
        {
            string hex = BaseConvert.Convert(base62, 62, 16);

            /* Prepend zeroes until hexadecimal string length is 32. */
            while (hex.Length < 32)
            {
                hex.Insert(0, "0");
            }

            return(hex);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Decodes the given encoded string to a Guid.
        /// </summary>
        /// <param name="value">The encoded string of a Guid.</param>
        /// <returns>A Guid that was represented by the encoded string.</returns>
        public static Guid Decode(string value)
        {
            BigInteger result = BaseConvert.FromBaseString(value, BaseConvert.Base62);

            byte[] resultBytes = result.ToByteArray();
            byte[] bytes       = new byte[16];

            // size to guid
            int count = Math.Min(bytes.Length, resultBytes.Length);

            Buffer.BlockCopy(resultBytes, 0, bytes, 0, count);

            return(new Guid(bytes));
        }
Exemplo n.º 6
0
        public void TestFrom10Unsigned()
        {
            int[] bases = { 2, 8, 10, 16 };

            foreach (var b in bases)
            {
                for (int j = 0; j < 100; j++)
                {
                    string s = Convert.ToString(j, b);

                    string myConversion = BaseConvert.From10Unsigned(j, b);
                    Assert.AreEqual(myConversion, s);
                }
            }
            Assert.ThrowsException <ArgumentException>(() => BaseConvert.From10Unsigned(-1000, 2));
            Assert.ThrowsException <ArgumentException>(() => BaseConvert.From10Unsigned(-1000, -2));
            Assert.ThrowsException <ArgumentException>(() => BaseConvert.From10Unsigned(1000, -2));
            Assert.ThrowsException <ArgumentException>(() => BaseConvert.From10Unsigned(1000, 1));
            Assert.ThrowsException <ArgumentException>(() => BaseConvert.From10Unsigned(0, 1));
            Assert.ThrowsException <ArgumentException>(() => BaseConvert.From10Unsigned(1, 0));
        }
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";
            string jsonstate;
            string json;

            using (var reader = new System.IO.StreamReader(Request.InputStream))
            {
                json = reader.ReadToEnd();
            }

            Response.Write(json);
            if (json != null)
            {
                ViewBag.jsonstate = " Não esta nula a variavel Json<br> ";
            }
            BaseConvert dadojson = (BaseConvert)JsonConvert.DeserializeObject(json);


            Connection conexao = new Connection();

            MySqlCommand command = new MySqlCommand("INSERT INTO usuario (nick)" + "VALUES('" + dadojson.nickname + "')", conexao.objConexao
                                                    );

            conexao.abrir();
            command.ExecuteNonQuery();
            if (conexao.VerificaConexao())
            {
                ViewBag.conex = "   Conectado    ";
            }
            else
            {
                ViewBag.conex = "   Não Conectado    ";
            }


            return(View());
        }
Exemplo n.º 8
0
 public void SetStrategy(BaseConvert strategy)
 {
     this.strategy = strategy;
 }
Exemplo n.º 9
0
        public static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Need the input file.");
                Console.Read();
                return;
            }

            var inFile   = args[0];
            var outFile  = inFile + ".json";
            var outFile2 = inFile + ".txt";

            if (!File.Exists(inFile))
            {
                Console.WriteLine("File not found.");
                Console.Read();
                return;
            }

            var isDone = false;

            try
            {
                // OBS:
                // It's better to convert using same class model
                // as the one used in AikaEmu.GameServer.

                var fileName = Path.GetFileNameWithoutExtension(inFile);
                if (fileName == null)
                {
                    return;
                }

                BaseConvert convert = null;
                switch (fileName)
                {
                case "ItemList":
                    convert = new ItemList();
                    break;

                case "npcpos":
                    convert = new NpcPos();
                    break;

                case "MobPos":
                    convert = new MobPos();
                    break;

                case "ExpList":
                    convert = new ExpList();
                    break;

                case "PranExpList":
                    convert = new PranExpList();
                    break;

                case "MN":
                    convert = new Mn();
                    break;

                case "GearCore":
                    convert = new GearCore();
                    break;

                case "ConvertCore":
                    convert = new ConvertCore();
                    break;

                case "Title":
                    convert = new Title();
                    break;

                case "Recipe":
                    convert = new Recipe();
                    break;

                case "RecipeRate":
                    convert = new RecipeRate();
                    break;

                case "ItemEffect":
                    convert = new ItemEffect();
                    break;

                case "ReinforceA":
                case "ReinforceW":
                    convert = new ReinforceA();
                    ((ReinforceA)convert).IsReinforceW = fileName == "ReinforceW";
                    break;

                case "Reinforce2":
                case "Reinforce3":
                    convert = new Reinforce2();
                    break;

                case "MakeItems":
                    convert = new MakeItems();
                    break;

                case "SetItem":
                    convert = new SetItem();
                    break;

                case "SkillData":
                    convert = new SkillData();
                    break;

                case "Quest":
                    convert = new Quest();
                    break;

                case "Map":
                    convert = new Map();
                    break;

                case "ObjPos":
                    convert = new ObjPos();
                    break;

                case "SPosition":
                    convert = new SPosition();
                    break;

                case "Dialog":
                    convert = new Dialog();
                    break;

                case "StatusPoint":
                    convert = new StatusPoint();
                    break;
                }

                if (convert != null)
                {
                    convert.SetupFile(inFile, outFile, outFile2);
                    convert.Convert();
                    convert.Save();
                    isDone = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.Read();
                throw;
            }
            finally
            {
                if (isDone)
                {
                    Console.WriteLine("Input: " + Path.GetFileName(inFile));
                    Console.WriteLine("Output: " + Path.GetFileName(outFile));
                    Console.WriteLine("OutputSql: " + Path.GetFileName(outFile2));
                    Console.WriteLine("Converted with success.");
                }
                else
                {
                    Console.WriteLine("Error in conversion.");
                }
            }

            Console.Read();
        }
Exemplo n.º 10
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Sets a strategy. </summary>
        ///
        /// <remarks>   Viki, 8/1/2018. </remarks>
        ///
        /// <param name="convert">  The convert. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void SetStrategy(BaseConvert convert)
        {
            this.convert = convert;
        }