Пример #1
0
            public IList <ReadTask> ReadItems(IList <ReadRequest> values, Duration?timeout)
            {
                Func <Task <VTQ[]>, DataItemValue[]> f = task => {
                    VTQ[] vtqs = task.Result;
                    if (vtqs.Length != values.Count)
                    {
                        throw new Exception("ReadDataItems returned wrong number of VTQs");
                    }
                    DataItemValue[] divalues = new DataItemValue[vtqs.Length];
                    for (int i = 0; i < vtqs.Length; ++i)
                    {
                        divalues[i] = new DataItemValue(values[i].ID, vtqs[i]);
                    }
                    return(divalues);
                };

                if (ItemGroups.Length == 1 || values.Count == 1)
                {
                    string                 group = ItemGroups.Length == 1 ? ItemGroups[0].ID : MapItem2GroupID[values[0].ID];
                    Task <VTQ[]>           t     = Instance.ReadDataItems(group, values, timeout);
                    Task <DataItemValue[]> tt    = t.ContinueWith(f);
                    return(new ReadTask[] { new ReadTask(tt, values.Select(x => x.ID).ToArray()) });
                }
                else
                {
                    return(values.GroupBy(x => MapItem2GroupID[x.ID]).Select(group => {
                        ReadRequest[] items = group.ToArray();
                        Task <VTQ[]> t = Instance.ReadDataItems(group.Key, items, timeout);
                        Task <DataItemValue[]> tt = t.ContinueWith(f);
                        return new ReadTask(tt, items.Select(x => x.ID).ToArray());
                    }).ToArray());
                }
            }
Пример #2
0
        public WriteManager(IList <DataItemValue> writeRequests, Func <DataItemValue, REF> f)
        {
            int N = writeRequests.Count;

            this.writeRequests = writeRequests;
            this.failures      = new List <FailedDataItemWrite>();
            this.refs          = new List <REF>(N);
            this.mapIdx        = new int[N];
            for (int i = 0; i < N; ++i)
            {
                DataItemValue request = writeRequests[i];
                try {
                    REF refItem = f(request);
                    mapIdx[refs.Count] = i;
                    refs.Add(refItem);
                }
                catch (Exception exp) {
                    failures.Add(new FailedDataItemWrite(request.ID, exp.Message));
                }
            }
        }