Ejemplo n.º 1
0
        protected FusionStaticAsset FusionAddAsset(IFusionAsset asset)
        {
            try
            {
                uint key = 1;

                while (_fusionAssets.ContainsKey(key))
                {
                    key++;
                }

                Fusion.AddAsset(eAssetType.StaticAsset, key, asset.Name, asset.AssetType.ToString().SplitCamelCase(),
                                Guid.NewGuid().ToString());

                _fusionAssets.Add(key, asset);

                var newAsset = Fusion.UserConfigurableAssetDetails[key].Asset as FusionStaticAsset;

                if (newAsset == null)
                {
                    return(null);
                }

                newAsset.ParamMake.Value              = asset.ManufacturerName;
                newAsset.ParamModel.Value             = asset.ModelName;
                newAsset.Connected.InputSig.BoolValue = asset.DeviceCommunicating;

                newAsset.AddSig(eSigType.String, 1, "Device Address", eSigIoMask.InputSigOnly);
                newAsset.AddSig(eSigType.String, 2, "Serial Number", eSigIoMask.InputSigOnly);
                newAsset.AddSig(eSigType.String, 3, "Version Info", eSigIoMask.InputSigOnly);

                asset.DeviceCommunicatingChange += FusionAssetOnDeviceCommunicatingChange;

                var deviceWithPower = asset as IPowerDevice;

                if (deviceWithPower != null)
                {
                    deviceWithPower.PowerStatusChange  += FusionAssetOnPowerStatusChange;
                    newAsset.PowerOn.InputSig.BoolValue = deviceWithPower.Power;
                }
            }
            catch (Exception e)
            {
                CloudLog.Error("Error registering Fusion asset: {0} ({1}), {2}", asset.GetType().Name, asset.AssetType,
                               e.Message);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public FusionAssetBase Add(IFusionAsset asset)
        {
            uint newId = 0;

            for (uint id = 1; id <= 249; id++)
            {
                if (!this.Fusion.Room.Fusion.FusionRoom.UserConfigurableAssetDetails.Contains(id))
                {
                    newId = id;
                    break;
                }
            }

            if (newId > 0)
            {
                if (asset is IFusionStaticAsset)
                {
                    this.Fusion.Room.Fusion.FusionRoom.AddAsset(eAssetType.StaticAsset, newId, asset.Name,
                                                                asset.AssetTypeName.ToString().SplitCamelCase(), Guid.NewGuid().ToString());
                }
                else if (asset is IFusionDynamicAsset)
                {
                    this.Fusion.Room.Fusion.FusionRoom.AddAsset(eAssetType.DynamicAsset, newId, asset.Name,
                                                                asset.AssetTypeName.ToString().SplitCamelCase(), Guid.NewGuid().ToString());
                }

                Assets[newId] = this.Fusion.Room.Fusion.FusionRoom.UserConfigurableAssetDetails[newId].Asset;

                asset.AssignFusionAsset(this.Fusion, Assets[newId]);

                if (!(asset is Devices.IDevice) || !(asset is IFusionStaticAsset))
                {
                    return(Assets[newId]);
                }
                ((FusionStaticAsset)Assets[newId]).ParamMake.Value  = ((Devices.IDevice)asset).DeviceManufacturer;
                ((FusionStaticAsset)Assets[newId]).ParamModel.Value = ((Devices.IDevice)asset).DeviceModel;

                return(Assets[newId]);
            }
            return(null);
        }