Пример #1
0
        protected override string SignIn(string sessionId)
        {
            PayloadDefinition definition = EwsPayloadFactory.GetPayLoad(Device.GetDeviceInfo().FirmwareRevision, "Jedi", "SignIn", string.Empty, 1);

            EwsRequest signInRequest = new EwsRequest("SignIn", "SignIn", null);

            signInRequest.Add("Password", Password.Replace("admin:", string.Empty));
            string signInPayload  = definition.PreparePayload(signInRequest);
            string targetUrl      = string.Format(CultureInfo.CurrentCulture, JediDeviceSignInUrl, Device.Address);
            var    signInResponse = ExecuteRequest(new Uri(targetUrl), signInPayload, definition, null);

            sessionId = signInResponse.Headers.GetValues("Cookie")?.FirstOrDefault()?.Split(';').FirstOrDefault();
            sessionId = sessionId?.Replace("sessionId=", string.Empty);

            return(sessionId);
        }
        /// <summary>
        /// Execution Entry Point
        /// </summary>
        /// <param name="executionData"></param>
        /// <returns></returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            if (executionData == null)
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "Execution Data is empty!"));
            }

            _activityData = executionData.GetMetadata <EwsHeadlessActivityData>();
            var printDeviceInfo = (PrintDeviceInfo)executionData.Assets.First();

            _device = DeviceConstructor.Create(printDeviceInfo);
            IEwsCommunicator communicator = EwsCommunicatorFactory.Create(_device);

            EwsPayloadFactory.AddContractLocation(Path.Combine(executionData.Environment.PluginSettings["DATPayLoadRepository"], "EWSContractFiles"));
            EwsPayloadFactory.AddContractLocation(Path.Combine(executionData.Environment.PluginSettings["DATPayLoadRepository"], "EWSPayLoads"));

            if (_activityData.Operation.Equals(_activityData.DeviceSpecificOperation))
            {
                _activityData.DeviceSpecificOperation = string.Empty; //to match the subfilter type in the XML
            }

            //create request to access EWS DAT payloads
            EwsRequest ewsRequest = communicator.CreateRequest(_activityData.Operation, _activityData.DeviceSpecificOperation);

            foreach (var configurationValue in _activityData.ConfigurationValues)
            {
                string valueToBePassed = configurationValue.Value;
                if (valueToBePassed.Equals("[CurrentUser]", StringComparison.OrdinalIgnoreCase))
                {
                    valueToBePassed = executionData.Credential.UserName;
                }

                if ((_device is SiriusDevice) && (_activityData.Operation.Equals("Administration")) && (configurationValue.Key.Equals("Password")))
                {
                    var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(valueToBePassed);
                    valueToBePassed = Convert.ToBase64String(plainTextBytes);
                }
                ewsRequest.Add(configurationValue.Key, valueToBePassed);
            }

            EwsResult result = communicator.Submit(ewsRequest);

            return(result.Exception != null ? new PluginExecutionResult(PluginResult.Failed, result.Exception) : new PluginExecutionResult(PluginResult.Passed));
        }