Esempio n. 1
0
        private async Task <bool> DoActualLoad(string rsrc, CancellationToken cancelToken)
        {
            RaiseLoading();

            Debug_n("Loading repository data from source...", rsrc);

            if (!_credentials.UserName.IsBlank() &&
                _credentials.Password.IsBlank())
            {
                return(Warn_n("LoginCfgFile does not include a password.",
                              "Please supply a password to login."));
            }

            //if (!_credentials.IsCompleteInfo)
            //    return Error_n("LoginCfgFile may not have been parsed.",
            //                   "_credentials.IsCompleteInfo == FALSE");

            if (!_client.LocalizeSessionFile(_credentials))
            {
                return(false);
            }

            if (!_client.IsLoggedIn)
            {
                if (_client.HasSavedSession)
                {
                    await _client.LoadSession(cancelToken);
                }
            }

            if (!_client.IsLoggedIn)
            {
                if (!await _client.Login(_credentials, cancelToken))
                {
                    return(false);
                }
            }


            var dtos = await _client.Get <List <TNodeDto> >(rsrc, cancelToken, null,
                                                            "Successfully loaded repository data ({0} fetched).",
                                                            x => "{0:record}".f(x.Count));

            if (dtos == null)
            {
                return(false);
            }

            _list = dtos.Select(x => FromDto(x)).ToList();

            if (_list.Count == 1 && _list[0] == null)
            {
                _list.Clear();
            }

            StartTrackingChanges();

            RaiseLoaded();
            return(true);
        }
Esempio n. 2
0
 internal async Task<bool> Load(ID7Client client, CancellationToken token)
 {
     if (IsLoaded) return true;
     Terms = await client.Get<List<D7Term>>(URL.Json_TaxoTerms, token);
     if (Terms == null) return false;
     return IsLoaded = true;
 }
Esempio n. 3
0
        internal async Task <bool> Load(ID7Client client, CancellationToken token)
        {
            if (IsLoaded)
            {
                return(true);
            }
            Terms = await client.Get <List <D7Term> >(URL.Json_TaxoTerms, token);

            if (Terms == null)
            {
                return(false);
            }
            return(IsLoaded = true);
        }
Esempio n. 4
0
        protected virtual async Task <bool> ReadFromServer(DateTime date, CancellationToken token)
        {
            var url = _resourceURL.Slash(date.ToArg());

            if (!_client.IsLoggedIn)
            {
                return(Error_n("D7Client is not logged in.", ""));
            }

            //Debug_n("Reading from server...", url);
            List <TIn> d7r = null;

            try
            {
                d7r = await _client.Get <List <TIn> >(url, token);
            }
            catch (Exception ex) { return(LogError("_client.Get", ex)); }
            if (d7r == null)
            {
                return(false);
            }

            if (d7r.Count == 0)
            {
                Warn_n(RecCount(d7r), url);
            }
            else
            {
                Info_n(RecCount(d7r), url);
            }

            if (SameAsLast(d7r, date))
            {
                return(true);
            }

            var hSet = new HashSet <TOut>();

            foreach (var dto in d7r)
            {
                try
                {
                    ForEachD7Dto(dto, date, hSet);
                }
                catch (Exception ex) { return(LogError($"‹{GetType().Name}›.ForEachD7Dto", ex)); }
            }

            RaiseLoadedFromServer(date);
            return(true);
        }
Esempio n. 5
0
        private async Task <bool> Query(ID7Client client, string subUrl, CancellationToken tkn)
        {
            Debug_n($"Querying repository of ‹{ClsTyp}›...", subUrl);

            List <TNodeDto> dtos;

            try
            {
                dtos = await client.Get <List <TNodeDto> >(subUrl, tkn);
            }
            catch (Exception ex)
            {
                return(Error_n("Query error:", ex.Details(false, false)));
            }

            if (dtos == null)
            {
                return(false);
            }

            var tmp = dtos.Select(x => FromDto(x));

            if (!AreKeysUnique(tmp))
            {
                return(Warn_n($"‹{ClsTyp}› Keys are not unique.", GetKey.ToString()));
            }

            _list = tmp.ToList();
            if (_list.Count == 1 && _list[0] == null)
            {
                _list.Clear();
            }

            StartTrackingChanges();

            return(true);
        }
Esempio n. 6
0
        private async Task <FileContentDto> DownloadFile(SyncableFileRemote node, CancellationToken cancelToken)
        {
            FileContentDto ret = null;

            var list = await _client.Get <List <FileContentDto> >
                           (_urlPattern.f(node.Fid), cancelToken);

            if (list == null)
            {
                return(Error_(ret, "_client.Get<List<FileContentDto>>() == NULL", ""));
            }

            if (list.Count == 0)
            {
                return(Warn_(ret, "Remote file not found in server.", $"[nid: {node.Nid}]  {node.Name}"));
            }

            if (list.Count > 1)
            {
                return(Warn_(ret, "Duplicate files found in server.", string.Join(", ", list.Select(x => x.fid))));
            }

            return(Trace_(list[0], "Successfully downloaded file content from server", $"{node.Name}"));
        }