public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            var activityData = executionData.GetMetadata <ControlPanelActivityData>();

            ConcurrentDictionary <string, PluginExecutionResult> results = new ConcurrentDictionary <string, PluginExecutionResult>();
            TimeSpan lockTimeout = TimeSpan.FromMinutes(5);
            TimeSpan holdTimeout = TimeSpan.FromMinutes(5);

            //if the assets are not found then skip it
            if (!executionData.Assets.OfType <IDeviceInfo>().Any())
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "No Assets found for execution"));
            }

            Parallel.ForEach(executionData.Assets.OfType <IDeviceInfo>(),
                             asset =>
            {
                if (!asset.Attributes.HasFlag(AssetAttributes.ControlPanel))
                {
                    results.AddOrUpdate(asset.AssetId,
                                        new PluginExecutionResult(PluginResult.Skipped, "Device does not have control panel"),
                                        (key, oldValue) =>
                                        new PluginExecutionResult(PluginResult.Skipped, "Device does not have control panel"));
                    return;
                }
                AssetLockToken assetToken = new AssetLockToken(asset, lockTimeout, holdTimeout);
                ExecutionServices.CriticalSection.Run(assetToken, () =>
                {
                    var printDevice             = DeviceConstructor.Create(asset);
                    ControlPanelWrapper wrapper = new ControlPanelWrapper(printDevice, executionData.Credential,
                                                                          activityData.ControlPanelAction, activityData.ParameterValues);
                    var result = wrapper.Execute();
                    results.AddOrUpdate(asset.AssetId, result, (key, oldValue) => wrapper.Execute());
                    printDevice.Dispose();
                });
            });

            return(results.Any(x => x.Value.Result != PluginResult.Passed) ? new PluginExecutionResult(PluginResult.Failed) : new PluginExecutionResult(PluginResult.Passed));
        }
Exemplo n.º 2
0
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed);
            var activityData             = executionData.GetMetadata <ControlPanelActivityData>();

            TimeSpan lockTimeout = TimeSpan.FromMinutes(5);
            TimeSpan holdTimeout = TimeSpan.FromMinutes(5);

            //if the assets are not found then skip it
            if (!executionData.Assets.OfType <IDeviceInfo>().Any())
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "No Assets found for execution"));
            }

            var asset = executionData.Assets.OfType <IDeviceInfo>().FirstOrDefault();

            if (!asset.Attributes.HasFlag(AssetAttributes.ControlPanel))
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "Device does not have control panel"));
            }
            AssetLockToken assetToken = new AssetLockToken(asset, lockTimeout, holdTimeout);

            ExecutionServices.CriticalSection.Run(assetToken, () =>
            {
                ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(executionData, asset));
                var printDevice             = DeviceConstructor.Create(asset);
                ControlPanelWrapper wrapper = new ControlPanelWrapper(printDevice, executionData.Credential,
                                                                      activityData.ControlPanelAction, activityData.ParameterValues);
                wrapper.ScreenCapture += (s, e) => UpdateScreenShot(e.ScreenShotImage);
                wrapper.StatusUpdate  += (s, e) => UpdateStatus(e.StatusMessage);
                result = wrapper.Execute();
                printDevice.Dispose();
            });

            return(result);
        }