Exemple #1
0
        public override async Task <string> InsertURLAsync(string url)
        {
            using (var db = new LiteDB.LiteDatabase(DB_FileName))
            {
                var collection = db.GetCollection <URLObject>();

                url = url.ToLower();

                var existingResult = collection.FindOne(a => a.URL == url);

                if (existingResult != null)
                {
                    return(existingResult.Key);
                }

                var urlObject = new URLObject
                {
                    URL = url,
                    Key = KeyGenerator.Generate()
                };

                collection.Insert(urlObject);

                return(urlObject.Key);
            }
        }
Exemple #2
0
        public override async Task <string> InsertURLAsync(string url)
        {
            var collection = _db.GetCollection <URLObject>(nameof(URLObject));

            var result = await(await collection.FindAsync(a => a.URL == url)).FirstOrDefaultAsync();

            if (result != null)
            {
                return(result.Key);
            }

            var urlObject = new URLObject
            {
                URL = url,
                Key = KeyGenerator.Generate()
            };

            await collection.InsertOneAsync(urlObject);

            return(urlObject.Key);
        }
Exemple #3
0
    public void Init(LitJson.JsonData jsonData)
    {
        this.Success = jsonData["res"].ToString().ToInt() == 0 ? true : false;
        if (this.Success)
        {
            string strType = jsonData["type"].ToString();
            if (strType == UpdateType.resource.ToString())
            {
                this.UType = UpdateType.resource;
            }
            else if (strType == UpdateType.client.ToString())
            {
                this.UType = UpdateType.client;
            }
            else if (strType == UpdateType.platform.ToString())
            {
                this.UType = UpdateType.platform;
            }
            else if (strType == UpdateType.none.ToString())
            {
                this.UType = UpdateType.none;
            }
            this.ServerVersion = new VersionVO(jsonData["version"].ToString().Trim());

            urlObjectList.Clear();
            int count = jsonData["urlarray"].Count;
            LitJson.JsonData jsonElement = jsonData["urlarray"];
            for (int index = 0; index < count; ++index)
            {
                URLObject url = new URLObject();
                url.url    = jsonElement[index]["url"].ToString();
                url.length = (uint)jsonElement[index]["length"].ToString().ToInt();
                urlObjectList.Add(url);
                TotalLength += url.length;
            }
        }
    }