public static DataBlockService GetDataBlockManager()
        {
            lock (mutex)
            {
                if (_instance == null)
                {
                    _instance = new DataBlockService();
                }
            }

            return(_instance);
        }
Ejemplo n.º 2
0
        public Device Copy(Device source, Channel target)
        {
            Device device = source.CopyObject <Device>();

            try
            {
                if (device != null)
                {
                    using (TransactionScope transactionScope = new TransactionScope())
                    {
                        DataBlockService dataBlockService = new DataBlockService();
                        device.DataBlocks = device.DataBlocks;
                        device.ChannelId  = target.ChannelId;
                        device.DeviceId   = GetNewId(target);

                        device.DeviceName = $"{device.DeviceName}New";

                        TagService tagService = new TagService();
                        if (device.DataBlocks != null)
                        {
                            foreach (DataBlock dataBlock in device.DataBlocks)
                            {
                                dataBlock.Tags      = dataBlock.Tags;
                                dataBlock.ChannelId = (int)device.ChannelId;
                                dataBlock.DeviceId  = device.DeviceId;

                                foreach (Tag tag in dataBlock.Tags)
                                {
                                    tag.ChannelId   = dataBlock.ChannelId;
                                    tag.DeviceId    = dataBlock.DeviceId;
                                    tag.DataBlockId = dataBlock.DataBlockId;
                                }
                            }
                        }
                        transactionScope.Complete();
                    }
                }
                return(device);
            }
            catch (Exception ex)
            {
                EventscadaException?.Invoke(this.GetType().Name, ex.Message);
            }
            return(device);
        }
        public DataBlock Copy(DataBlock source, Device target)
        {
            DataBlock dataBlock = source.CopyObject <DataBlock>();

            try
            {
                if (dataBlock != null)
                {
                    //dataBlock.ChannelId =(int) target.ChannelId;
                    dataBlock.DeviceId = target.DeviceId;
                    DataBlockService dataBlockService = new DataBlockService();
                    using (TransactionScope transactionScope = new TransactionScope())
                    {
                        dataBlock.ChannelId     = dataBlock.ChannelId;
                        dataBlock.DeviceId      = dataBlock.DeviceId;
                        dataBlock.DataBlockId   = GetNewIdByIds(dataBlock.ChannelId, target);
                        dataBlock.DataBlockName = $"{dataBlock.DataBlockName}New";

                        TagService tagService = new TagService();
                        dataBlock.Tags = source.Tags;
                        foreach (Tag tag in dataBlock.Tags)
                        {
                            tag.ChannelId   = dataBlock.ChannelId;
                            tag.DeviceId    = dataBlock.DeviceId;
                            tag.DataBlockId = dataBlock.DataBlockId;
                        }
                        transactionScope.Complete();
                    }
                }
                return(dataBlock);
            }
            catch (Exception ex)
            {
                EventscadaException?.Invoke(GetType().Name, ex.Message);
            }
            return(dataBlock);
        }
Ejemplo n.º 4
0
 public DeviceService()
 {
     objDataBlockManager = new DataBlockService();
 }