Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="clientObj"></param>
        /// <param name="valueStatusTimestamp"></param>
        public void Write(object clientObj, ValueStatusTimestamp valueStatusTimestamp)
        {
            if (DataGrpcList is null || DataGrpcList.Disposed)
            {
                return;
            }

            ClientObjectInfo?modelItem;

            if (!ModelItemsDictionary.TryGetValue(clientObj, out modelItem))
            {
                return;
            }

            if (modelItem.DataGrpcListItemWrapper is null || modelItem.DataGrpcListItemWrapper.DataGrpcListItem is null || modelItem.DataGrpcListItemWrapper.DataGrpcListItem.StatusCode != StatusCode.OK)
            {
                return;
            }

            ClientElementValueListItem dataGrpcElementValueListItem = modelItem.DataGrpcListItemWrapper.DataGrpcListItem;

            try
            {
                dataGrpcElementValueListItem.PrepareForWrite(valueStatusTimestamp);

                try
                {
                    DataGrpcList.CommitWriteElementValueListItems();
                }
                catch
                {
                }
            }
            catch (Exception ex)
            {
                Logger.LogWarning(ex, "DataGrpcList.CommitWriteElementValueListItems() exception");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Returns clientObjs whose write failed.
        ///     If connection error, no throw and returns all clientObjs.
        /// </summary>
        /// <param name="clientObjs"></param>
        /// <param name="valueStatusTimestamps"></param>
        /// <returns></returns>
        public object[] Write(object[] clientObjs, ValueStatusTimestamp[] valueStatusTimestamps)
        {
            if (DataGrpcList is null || DataGrpcList.Disposed)
            {
                return(clientObjs);
            }

            int i      = -1;
            var result = new List <object>();

            foreach (var clientObj in clientObjs)
            {
                i++;

                ClientObjectInfo?modelItem;
                if (!ModelItemsDictionary.TryGetValue(clientObj, out modelItem))
                {
                    result.Add(clientObj);
                    continue;
                }

                if (modelItem.DataGrpcListItemWrapper is null ||
                    modelItem.DataGrpcListItemWrapper.DataGrpcListItem is null ||
                    modelItem.DataGrpcListItemWrapper.DataGrpcListItem.StatusCode != StatusCode.OK)
                {
                    result.Add(clientObj);
                    continue;
                }
                ClientElementValueListItem dataGrpcElementValueListItem = modelItem.DataGrpcListItemWrapper.DataGrpcListItem;
                dataGrpcElementValueListItem.PrepareForWrite(valueStatusTimestamps[i]);
            }

            IEnumerable <ClientElementValueListItem> failedItems;

            try
            {
                failedItems = DataGrpcList.CommitWriteElementValueListItems();
            }
            catch
            {
                return(clientObjs);
            }

            foreach (var dataGrpcElementValueListItem in failedItems)
            {
                var o = dataGrpcElementValueListItem.Obj as DataGrpcListItemWrapper;
                if (o is null)
                {
                    throw new InvalidOperationException();
                }
                foreach (var modelItem in o.ClientObjectInfosCollection)
                {
                    if (modelItem.ClientObj is not null)
                    {
                        result.Add(modelItem.ClientObj);
                    }
                }
            }

            return(result.ToArray());
        }