/// <summary> /// Submits the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>An <see cref="EwsResult" /> containing the result of the HTTP request(s).</returns> /// <exception cref="System.Exception">Validation failed with contract provided.</exception> public EwsResult Submit(EwsRequest request) { ////Create XML file and validae with the respective XML schema depending on the Filter Type if (request.Validate()) { //Get the communication request List <PayloadDefinition> payloadDefinitions = EwsPayloadFactory.CreatePayloadDefinitions(request, Device.GetDeviceInfo().FirmwareRevision, _deviceFamily); //Applying on the device based on the ICommunicator return(CommunicateWithDevice(payloadDefinitions, request)); } throw new Exception("Validation failed with contract provided."); }
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)); }
/// <summary> /// Creates an <see cref="EwsRequest" /> of the specified type and subtype. /// </summary> /// <param name="requestType">The request type.</param> /// <param name="requestSubtype">The request subtype.</param> /// <returns>An <see cref="EwsRequest" />.</returns> public EwsRequest CreateRequest(string requestType, string requestSubtype) { return(new EwsRequest(requestType, requestSubtype, EwsPayloadFactory.SelectContract(_deviceFamily, requestType, Device.GetDeviceInfo().FirmwareRevision))); }