예제 #1
0
파일: ELinkForm.cs 프로젝트: itadapter/nfx
        private void btnBigID_Click(object sender, EventArgs e)
        {
            ulong id = 182500000000;// ulong.MaxValue;

            var lnk = new ELink(id, null);// new byte[]{ 123, 18});
            tbELink.Text = lnk.Link;
        }
예제 #2
0
파일: ELinkTest.cs 프로젝트: itadapter/nfx
        public void Encode_Decode_All_Range()
        {
            long total = 0;

            ulong step = ulong.MaxValue / 10000;
            ulong inc = 1;
            for(ulong span = 0; span < ulong.MaxValue - step; span +=  inc)
            {
                System.Threading.Tasks.Parallel.For
                (0, 500,
                    (i)=>
                    {
                           ulong id = span + (ulong)i;
                           var lnk = new ELink(id, null);
                           var lnk2 = new ELink( lnk.Link );
                           Assert.AreEqual(lnk.ID, lnk2.ID);
                           System.Threading.Interlocked.Increment(ref total);
                    }
                );

               if (total % 5000 == 0)
                    Console.WriteLine("Processed {0} links = {1:P} Range {2}".Args(total, span / (double)ulong.MaxValue, span));
               if (inc>=step)
                inc = step;
               else
                inc *= 2;
            }
        }
예제 #3
0
파일: ELinkForm.cs 프로젝트: itadapter/nfx
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            var lnk = new ELink((ulong)tbID.Text.AsLong(0), null);
            tbELink.Text = lnk.Link;

            var lnk2 = new ELink( lnk.Link );

            tbResult.Text = lnk2.ID.ToString();
        }
예제 #4
0
파일: ELinkForm.cs 프로젝트: vlapchenko/nfx
        private void button1_Click(object sender, EventArgs e)
        {
            var lnk = new ELink(new GDID((uint)sbEra.Value, 12,(ulong)tbID.Text.AsLong(0)), null);
              tbELink.Text = lnk.Link;

              var lnk2 = new ELink( lnk.Link );

              tbResult.Text = lnk2.GDID.ToString();
        }
예제 #5
0
파일: ELinkTest.cs 프로젝트: itadapter/nfx
        public void Encode_Decode_16_Seeds()
        {
            var lnk = new ELink(4999666333111, null);

            for(int seed = 0; seed < 16; seed++)
            {
                lnk.Encode((byte)seed);
            Console.WriteLine("{0}  {1} -> {2}".Args(seed, lnk.Link, lnk.GDID));
                var lnk2 = new ELink( lnk.Link );
                Assert.AreEqual(lnk.ID, lnk2.ID);
            }
        }
예제 #6
0
        //20160622 DKh
        public static GDIDSymbol AsGDIDSymbol(this object val)
        {
            if (val == null)
            {
                return(new GDIDSymbol());
            }

            if (val is GDIDSymbol)
            {
                return((GDIDSymbol)val);
            }
            if (val is GDID)
            {
                return(new GDIDSymbol((GDID)val, val.ToString()));
            }

            if (val is ELink)
            {
                return(((ELink)val).AsGDIDSymbol);
            }

            if (val is string)
            {
                var sval = ((string)val).Trim();

                GDID gdid;
                if (GDID.TryParse(sval, out gdid))
                {
                    return(new GDIDSymbol(gdid, sval));
                }

                try
                {
                    var elink = new ELink(sval);
                    return(elink.AsGDIDSymbol);
                }
                catch {}
            }

            if (val is ulong)
            {
                return(new GDIDSymbol(new GDID(0, (ulong)val), val.ToString()));
            }
            if (val is byte[])
            {
                var buf = (byte[])val;
                return(new GDIDSymbol(new GDID(buf), buf.ToDumpString(DumpFormat.Hex)));
            }
            return(new GDIDSymbol(new GDID(0, Convert.ToUInt64(val)), val.ToString()));
        }
예제 #7
0
        public object Shorten(string initialUrl)
        {
            if (initialUrl.IsNullOrWhiteSpace())
                return new Index { Message = MESSAGE_EMPTY_URL };

            var id = SiteContext.NextId();
            var urlMap = new UrlMap { Id = id, URL = initialUrl };
            SiteContext.DataStore.Upsert(urlMap);

            var el = new ELink((ulong)id, null);
            var host = WorkContext.Request.UserHostName;
            var shortenUrl = SHORTEN_URL_FORMAT.Args(host, el.Link);

            return new Index { InitialUrl = initialUrl, Message = shortenUrl, IsHyperlink = true };
        }
예제 #8
0
        public static GDID AsGDID(this object val)
        {
            if (val == null)
            {
                return(GDID.Zero);
            }

            if (val is GDID)
            {
                return((GDID)val);
            }

            if (val is ELink)
            {
                return(((ELink)val).GDID);
            }

            if (val is string)
            {
                var sval = ((string)val).Trim();

                GDID gdid;
                if (GDID.TryParse(sval, out gdid))
                {
                    return(gdid);
                }

                //20160109 DKH also interpret string via ELink
                try
                {
                    var elink = new ELink(sval);
                    return(elink.GDID);
                }
                catch {}
            }

            if (val is ulong)
            {
                return(new GDID(0, (ulong)val));
            }
            if (val is byte[])
            {
                return(new GDID((byte[])val));
            }
            return(new GDID(0, Convert.ToUInt64(val)));
        }
예제 #9
0
        protected override MethodInfo FindMatchingAction(WorkContext work, string action, out object[] args)
        {
            if (action.IndexOf('-') > 3) // pattern: xxx-...
            {
                try
                {
                    var el = new ELink(action);
                    args = new object[] {el.ID};
                    return mi_Resolve;
                }
                catch
                {
                }
            }

            args = null;
            return null;
        }
예제 #10
0
파일: ELinkTest.cs 프로젝트: itadapter/nfx
        public void Encode_Decode_MetaOdd()
        {
            var lnk = new ELink(1, new byte[]{0x01, 0xfe, 0xda, 0x5, 0x07});
            lnk.Encode(1);

            var lnk2 = new ELink( lnk.Link );
            Assert.AreEqual(lnk.ID, lnk2.ID);
            Assert.AreEqual(0x01, lnk2.Metadata[0]);
            Assert.AreEqual(0xfe, lnk2.Metadata[1]);
            Assert.AreEqual(0xda, lnk2.Metadata[2]);
            Assert.AreEqual(0x05, lnk2.Metadata[3]);
            Assert.AreEqual(0x07, lnk2.Metadata[4]);
        }
예제 #11
0
파일: ELinkTest.cs 프로젝트: itadapter/nfx
        public void GDID_EncodeDecode_4()
        {
            //CHAGVU-ANHTUGIFNU-TVWETOUF-JOJKJU
            var src = new ELink( new GDID(27, 15, 200100999666333000), new byte[] {(byte)'a',(byte)'b',(byte)'c'} );
            Console.WriteLine("{0} -> {1} + 'abc'".Args(src.Link, src.GDID));
            var lnk = new ELink( src.Link );

            var gdid = lnk.GDID;
            Assert.AreEqual(27, gdid.Era);
            Assert.AreEqual(15, gdid.Authority);
            Assert.AreEqual(200100999666333000, gdid.Counter);
            Assert.IsNotNull( lnk.Metadata);
            Assert.AreEqual(3, lnk.Metadata.Length);

            Assert.AreEqual((byte)'a', lnk.Metadata[0]);
            Assert.AreEqual((byte)'b', lnk.Metadata[1]);
            Assert.AreEqual((byte)'c', lnk.Metadata[2]);
        }
예제 #12
0
파일: ELinkTest.cs 프로젝트: itadapter/nfx
        public void GDID_EncodeDecode_3()
        {
            var src = new ELink( new GDID(567333, 3, 167898777), new byte[] {1,2,3,4,5} );
            Console.WriteLine("ELink with GDID and 5 bytes metadata: "+src.Link);
            var lnk = new ELink( src.Link );

            var gdid = lnk.GDID;
            Assert.AreEqual(567333, gdid.Era);
            Assert.AreEqual(3, gdid.Authority);
            Assert.AreEqual(167898777, gdid.Counter);
            Assert.IsNotNull( lnk.Metadata);
            Assert.AreEqual(5, lnk.Metadata.Length);

            Assert.AreEqual(1, lnk.Metadata[0]);
            Assert.AreEqual(2, lnk.Metadata[1]);
            Assert.AreEqual(3, lnk.Metadata[2]);
            Assert.AreEqual(4, lnk.Metadata[3]);
            Assert.AreEqual(5, lnk.Metadata[4]);
        }
예제 #13
0
파일: ELinkTest.cs 프로젝트: itadapter/nfx
        public void GDID_EncodeDecode_2()
        {
            var lnk = new ELink( new GDID(0, 3, 1678), new byte[] {1,2,3,4,5} );

            var gdid = lnk.GDID;
            Assert.AreEqual(0, gdid.Era);
            Assert.AreEqual(3, gdid.Authority);
            Assert.AreEqual(1678, gdid.Counter);
            Assert.IsNotNull( lnk.Metadata);
            Assert.AreEqual(5, lnk.Metadata.Length);

            Assert.AreEqual(1, lnk.Metadata[0]);
            Assert.AreEqual(2, lnk.Metadata[1]);
            Assert.AreEqual(3, lnk.Metadata[2]);
            Assert.AreEqual(4, lnk.Metadata[3]);
            Assert.AreEqual(5, lnk.Metadata[4]);
        }
예제 #14
0
파일: ELinkTest.cs 프로젝트: itadapter/nfx
        public void GDID_EncodeDecode_1()
        {
            var lnk = new ELink( new GDID(0, 7, 10678159678), null );
            Console.WriteLine("ELink {0} with GDID and no extra metadata: {1}".Args(lnk.ID, lnk.Link));

            var gdid = lnk.GDID;
            Assert.AreEqual(0, gdid.Era);
            Assert.AreEqual(7, gdid.Authority);
            Assert.AreEqual(10678159678, gdid.Counter);

                lnk = new ELink( new GDID(230, 0xf, 67123456), null );
                Console.WriteLine("ELink {0} with GDID and no extra metadata: {1}".Args(lnk.ID, lnk.Link));

                gdid = lnk.GDID;
                Assert.AreEqual(230, gdid.Era);
                Assert.AreEqual(15, gdid.Authority);
                Assert.AreEqual(67123456, gdid.Counter);

            lnk = new ELink( new GDID(0, 2, 123000), null );
            Console.WriteLine("ELink {0} with GDID and no extra metadata: {1}".Args(lnk.ID, lnk.Link));

            gdid = lnk.GDID;
            Assert.AreEqual(2, gdid.Authority);
            Assert.AreEqual(123000, gdid.Counter);
        }
예제 #15
0
파일: ELinkTest.cs 프로젝트: itadapter/nfx
 public void Encode_Min()
 {
     var lnk = new ELink(0, null);
     lnk.Encode(1);
     Assert.AreEqual("AIAIAJ-AJ", lnk.Link);
 }
예제 #16
0
        public void GDIDSymbol()
        {
            var link1 = new ELink(new GDID(5,1,2));
               var link2 = new ELink(new GDID(0,1,2));

               Assert.AreEqual( new GDIDSymbol(new GDID(5, 1, 2), "5:1:2"),  "5:1:2".AsGDIDSymbol());
               Assert.AreEqual( new GDIDSymbol(new GDID(5, 1, 2), "5:1:2"),  "5:1:2".AsType(typeof(GDIDSymbol)));
               Assert.AreEqual( link1.AsGDIDSymbol, link1.Link.AsType(typeof(GDIDSymbol), false));

               Assert.AreEqual( new GDIDSymbol(new GDID(0, 1, 2), "0:1:2"),  "0:1:2".AsGDIDSymbol());
               Assert.AreEqual( new GDIDSymbol(new GDID(0, 1, 2), "0:1:2"),  "0:1:2".AsType(typeof(GDIDSymbol)));
               Assert.AreEqual( link2.AsGDIDSymbol, link2.Link.AsType(typeof(GDIDSymbol), false));

               string ns = null;
               Assert.IsNull( ns.AsNullableGDIDSymbol());
               Assert.IsNull( ns.AsNullableGDIDSymbol(new GDIDSymbol(new GDID(7, 8, 9), "AAA")));
               Assert.AreEqual( new GDIDSymbol(new GDID(7,8,9), "AAA"), "wdef8we9f9u8".AsNullableGDIDSymbol(new GDIDSymbol(new GDID(7, 8, 9), "AAA")));
        }
예제 #17
0
        public void GDIDSymbol()
        {
            object obj = new GDIDSymbol(new GDID(3,4,5), "ABC");

            Assert.AreEqual(obj, obj.AsGDIDSymbol());
            Assert.AreEqual(obj, obj.AsGDIDSymbol(new GDIDSymbol(new GDID(23,14,15), "ABC")));

            var link = new ELink(new GDID(4,12,8721));

            Assert.AreEqual(link.AsGDIDSymbol, link.Link.AsGDIDSymbol());
            Assert.AreEqual(link.AsGDIDSymbol, "3rewtfef:4:5".AsGDIDSymbol(link.AsGDIDSymbol()));

            try
            {
              "3rewtfef:4:5".AsGDIDSymbol(link.AsGDIDSymbol, handling: ConvertErrorHandling.Throw);
              Assert.Fail("No excepetion");
            }
            catch
            {
              Assert.Pass();
            }
        }
예제 #18
0
파일: ELinkForm.cs 프로젝트: itadapter/nfx
        private void btnDecode_Click(object sender, EventArgs e)
        {
            var lnk2 = new ELink( tbELink.Text );

            tbResult.Text = lnk2.GDID.ToString();
        }
예제 #19
0
파일: ELinkTest.cs 프로젝트: itadapter/nfx
        public void Encode_Decode_Max()
        {
            var lnk = new ELink(ulong.MaxValue, null);
            lnk.Encode(1);

            var lnk2 = new ELink( lnk.Link );
            Assert.AreEqual(lnk.ID, lnk2.ID);
        }
예제 #20
0
파일: ELinkTest.cs 프로젝트: itadapter/nfx
        public void Encode_Decode_Min()
        {
            var lnk = new ELink(0, null);
            lnk.Encode(1);

            var lnk2 = new ELink( lnk.Link );
            Assert.AreEqual(lnk.ID, lnk2.ID);
        }
예제 #21
0
파일: ELinkTest.cs 프로젝트: itadapter/nfx
 public void Encode_Max()
 {
     var lnk = new ELink(ulong.MaxValue, null);
     lnk.Encode(1);
     Assert.AreEqual("CHBRHM-VIVIVIVI-VIVIVIVI", lnk.Link);
 }
예제 #22
0
        public void GDID()
        {
            var link1 = new ELink(new GDID(5,1,2));
               var link2 = new ELink(new GDID(0,1,2));

               Assert.AreEqual( new GDID(5, 1, 2),  "5:1:2".AsGDID());
               Assert.AreEqual( new GDID(5, 1, 2),  "5:1:2".AsType(typeof(GDID)));
               Assert.AreEqual( new GDID(5, 1, 2),  link1.Link.AsType(typeof(GDID), false));

               Assert.AreEqual( new GDID(0, 1, 2),  "0:1:2".AsGDID());
               Assert.AreEqual( new GDID(0, 1, 2),  "0:1:2".AsType(typeof(GDID)));
               Assert.AreEqual( new GDID(0, 1, 2),  link2.Link.AsType(typeof(GDID), false));

               string ns = null;
               Assert.IsNull( ns.AsNullableGDID());
               Assert.IsNull( ns.AsNullableGDID(new GDID(7, 8, 9)));
               Assert.AreEqual( new GDID(7,8,9), "dewsdfwefwerf".AsNullableGDID(new GDID(7, 8, 9)));
        }