示例#1
0
        private async Task <bool> AddNow(T node, CancellationToken tkn)
        {
            if (!CanExecute(node))
            {
                return(false);
            }

            D7NodeBase dto;

            try { dto = D7FieldMapper.Map(node); }
            catch (Exception ex) { return(LogError("D7FieldMapper.Map", ex)); }

            if (dto == null)
            {
                return(Error_n("Failed to map to D7 fields.", ""));
            }

            D7NodeBase saved;

            try { saved = await Client.Post(dto, tkn); }
            catch (Exception ex) { return(LogError("_client.Post", ex)); }

            if (saved == null || saved.nid < 1)
            {
                return(Error_n("Failed to add item to repo.", ""));
            }

            _addedCount += 1;
            return(RaiseProgressInfo());
        }
示例#2
0
        private async Task <bool> EditNow(T node, CancellationToken tkn)
        {
            if (!CanExecute(node))
            {
                return(false);
            }

            ID7NodeRevision dto;

            try { dto = D7FieldMapper.Map(node).As <ID7NodeRevision>(); }
            catch (Exception ex)
            { return(LogError("D7FieldMapper.Map(item)", ex)); }

            if (dto == null)
            {
                return(false);
            }
            dto.nid = node.nid;
            dto.vid = node.As <ID7NodeRevision>().vid;
            if (!await Client.Put(dto, tkn))
            {
                return(false);
            }

            _editedCount += 1;
            return(RaiseProgressInfo());
        }
示例#3
0
        private async Task <bool> AddItem(TClass item, CancellationToken tkn)
        {
            D7NodeBase dto;

            try   { dto = D7FieldMapper.Map(item); }
            catch (Exception ex) { return(LogError("D7FieldMapper.Map", ex)); }

            if (dto == null)
            {
                return(Error_n("Failed to map to D7 fields.", ""));
            }

            D7NodeBase node;

            try   { node = await _client.Post(dto, tkn); }
            catch (Exception ex) { return(LogError("_client.Post", ex)); }

            if (node == null || node.nid < 1)
            {
                return(Error_n("Failed to add item to repo.", ""));
            }

            RaiseOneChangeCommitted();
            return(true);
        }
示例#4
0
        public void TestValue2()
        {
            var prop1  = Fake.Word;
            var prop2a = Fake.Word;
            var prop2b = Fake.Word;

            var input = new TestClass1
            {
                Prop1  = prop1,
                Prop2a = prop2a,
                Prop2b = prop2b// + "s"
            };

            var expctd = new TestClass1D7
            {
                type        = "testclass1",
                field_prop1 = und.Values(prop1),
                field_prop2 = und.Value1_2(prop2a, prop2b)
            };

            var actual = D7FieldMapper.Map(input) as TestClass1D7;

            var expctdStr = Json.Write(expctd, true);
            var actualStr = Json.Write(actual, true);

            actualStr.MustBe(expctdStr);
        }
示例#5
0
        public D7NodeBase ToNodeDTO(int userID)
        {
            var dto = new T();

            dto.CopyValuesFrom(this);

            var node = D7FieldMapper.Map(dto);

            node.uid = userID;
            node.nid = this.nid;
            //node.vi
            return(node);
        }
示例#6
0
        private async Task <bool> BatchPost
            (IEnumerable <T> newItems, CancellationToken tkn)
        {
            D7NodeBase dto;
            var        nodes = new List <T>();

            foreach (var item in newItems)
            {
                try { dto = D7FieldMapper.Map(item); }
                catch (Exception ex) { return(LogError("D7FieldMapper.Map", ex)); }

                if (dto == null)
                {
                    return(Error_n("Failed to map to D7 fields.", ""));
                }

                nodes.Add(dto as T);
            }
            return(await Client.Post(nodes, _pageSize, tkn));
        }
示例#7
0
        private async Task <bool> UpdateItem(TClass item, CancellationToken tkn)
        {
            Throw.IfNull(item, "node to update");
            Throw.IfNull(_client, "‹ID7Client›_client instance");

            ID7NodeRevision dto;

            try { dto = D7FieldMapper.Map(item).As <ID7NodeRevision>(); }
            catch (Exception ex)
            { return(LogError("D7FieldMapper.Map(item)", ex)); }

            if (dto == null)
            {
                return(false);
            }
            dto.nid = item.nid;
            dto.vid = item.As <ID7NodeRevision>().vid;
            if (!await _client.Put(dto, tkn))
            {
                return(false);
            }
            RaiseOneChangeCommitted();
            return(true);
        }