示例#1
0
        private static void OnAtomicWriteFileRequest(BacnetClient sender, BacnetAddress adr, byte invoke_id, bool is_stream, BacnetObjectId object_id, int position, uint block_count, byte[][] blocks, int[] counts, BacnetMaxSegments max_segments)
        {
            lock (m_lockObject)
            {
                try
                {
                    if (object_id.Type != BacnetObjectTypes.OBJECT_FILE)
                    {
                        throw new Exception("File Reading on non file objects ... bah!");
                    }
                    else if (object_id.Instance != 0)
                    {
                        throw new Exception("Don't know this file");
                    }

                    //this is a test file for performance measuring
                    //don't do anything with the content

                    //adjust size though
                    int filesize     = m_storage.ReadPropertyValue(object_id, BacnetPropertyIds.PROP_FILE_SIZE);
                    int new_filesize = position + counts[0];
                    if (new_filesize > filesize)
                    {
                        m_storage.WritePropertyValue(object_id, BacnetPropertyIds.PROP_FILE_SIZE, new_filesize);
                    }
                    if (counts[0] == 0)
                    {
                        m_storage.WritePropertyValue(object_id, BacnetPropertyIds.PROP_FILE_SIZE, 0);                      //clear file
                    }
                    //send confirm
                    HandleSegmentationResponse(sender, adr, invoke_id, max_segments, (seg) =>
                    {
                        sender.WriteFileResponse(adr, invoke_id, seg, position);
                    });
                }
                catch (Exception)
                {
                    sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_ATOMIC_WRITE_FILE, invoke_id, BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_OTHER);
                }
            }
        }