Ejemplo n.º 1
0
        public async Task <(string url, bool permanent, bool preserveMethod)> TryGetUrlAsync(string idcode)
        {
            if (idcode.Length >= 3 && Int64.TryParse(idcode, out long discard))
            {
                var partkey = "";
                var rowkey  = "";
                var chars   = idcode.ToCharArray();
                for (int i = 0; i < idcode.Length; i++)
                {
                    if (i <= 1)
                    {
                        partkey += idcode[i];
                    }
                    else
                    {
                        rowkey += idcode[i];
                    }
                }
                CloudTable table = await TableExecutor <TableEntity> .CreateTableAsync("shorturls", _cloudStorage);

                var result = await TableExecutor <ShorterData> .PointQueryAsync(table, partkey, rowkey);

                if (result != null)
                {
                    return(result.Url, result.Permanent, result.PreserveMethod);
                }
            }
            return(String.Empty, false, true);
        }
Ejemplo n.º 2
0
        public async Task <bool> Init()
        {
            var table = await TableExecutor <TableEntity> .CreateTableAsync("shorturls", _cloudStorage);

            for (int i = 0; i < 99; i++)
            {
                var partkey = i.ToString("00");
                var index   = await TableExecutor <IndexEntity> .PointQueryAsync(table, partkey, "index");

                if (index == null)
                {
                    index = new IndexEntity(partkey, "index", 0L);
                    await TableExecutor <IndexEntity> .InsertOrMergeEntityAsync(table, index);
                }
                TableIndex.AddOrUpdate(partkey, index.Index, (k, v) => v = index.Index);
            }
            return(true);
        }