Example #1
0
 public SafeComSimulationTask(SafeComSimulationController controller, SafeComSimulationActivityData activityData, IPrinterInfo device)
     : base()
 {
     _safecomController = controller;
     _taskConfig        = activityData;
     _device            = device;
 }
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _executionData = executionData;
            SafeComSimulationActivityData activityData = _executionData.GetMetadata <SafeComSimulationActivityData>();
            PluginExecutionResult         result       = new PluginExecutionResult(PluginResult.Passed);

            DeviceInfo assetInfo     = null;
            ServerInfo safecomServer = null;

            try
            {
                assetInfo     = (DeviceInfo)_executionData.Assets.GetRandom();
                safecomServer = _executionData.Servers.First();
                LogUsageData(assetInfo, safecomServer);
            }
            catch (ArgumentNullException ex)
            {
                return(new PluginExecutionResult(PluginResult.Error, ex));
            }
            catch (InvalidOperationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Error, ex));
            }

            if (_safecomController == null)
            {
                _safecomController = new SafeComSimulationController(_executionData.Credential, activityData.SafeComAuthenticationMode, assetInfo.Address, activityData.AssetMacAddress, safecomServer.HostName);
            }

            UpdateUI(safecomServer.HostName, assetInfo.Address);
            UpdateStatus("Starting SafeCom Pull Activity...");

            AssetLockToken lockToken = new AssetLockToken(assetInfo, TimeSpan.FromHours(12), TimeSpan.FromHours(12));

            //On error, Implement Retries before relinquishing the lock.
            ExecutionServices.CriticalSection.Run(lockToken, () =>
            {
                PluginRetryManager retryManager = new PluginRetryManager(_executionData, UpdateStatus);
                result = retryManager.Run(() => ExecuteTask(activityData, assetInfo));
            });

            return(result);
        }