private static object DuplicateResponse(object result, RemoteJob remoteJob, RemoteJob localJob) { var stream = new MemoryStream(); remoteJob.SerializeResponse(stream, result); stream.Position = 0; return(localJob.DeserializeResponse(stream)); }
private static RemoteJob DuplicateJob(RemoteJob job) { var stream = new MemoryStream(); job.Serialize(stream); stream.Position = 0; var remoteJob = (RemoteJob)Activator.CreateInstance(job.GetType()); remoteJob.Deserialize(stream); return(remoteJob); }
Task <object> IRemoteJobExecuter.ExecuteJobAsync(RemoteJob job, CancellationToken cancellationToken) { if (job == null) { throw new ArgumentNullException(nameof(job)); } return(Task.Factory.StartNew( () => { using (var remoteJob = DuplicateJob(job)) { //remoteJob.PostData = d => job.NotifyDataReceived(new MemoryStream(d, false)); var result = remoteJob.ExecuteAsync(cancellationToken).Result; return DuplicateResponse(result, remoteJob, job); } } )); }
internal static Mock<IAuthenticationManager> Initialize(MoqMockingKernel kernel) { Configuration = new Configuration { Id = Guid.Empty, VersionId = 1, Name = "", Author = "Test", Description = "Test", InputSchema = new Schema { Delimiter = "-", Rows = new List<SchemaRow>() }, OutputSchema = new Schema { Delimiter = "@", Rows = new List<SchemaRow>() }, Rules = new List<RuleSet>(), Options = new Options { OutputAllRecords = true, OutputErrorCode = true, OutputErrorDescription = true, UseInputSettingsForErrors = true } }; Job = new RemoteJob { JobId = Guid.NewGuid(), JobName = "Unit test Job", IngestMediumSettings = new SerializableDictionary<string, string> { {PledgeGlobal.NamespaceKey, typeof (FakeIngest).AssemblyQualifiedName}, {PledgeGlobal.ImportFolderKey, UnitTestHelper.FakeIngestProperty}, {PledgeGlobal.FilePatternKey, UnitTestHelper.FakeIngestValue} }, PledgeSettings = new SerializableDictionary<string, string> { {PledgeGlobal.NamespaceKey, PledgeGlobal.BuiltInPledge}, {PledgeGlobal.ClientId, Guid.NewGuid().ToString()} }, EgestMediumSettings = new SerializableDictionary<string, string> { {PledgeGlobal.NamespaceKey, typeof (FakeEgest).AssemblyQualifiedName}, {PledgeGlobal.PassPrefixKey, UnitTestHelper.FakeEgestProperty}, {PledgeGlobal.FailPrefixKey, UnitTestHelper.FakeEgestValue} } }; var claims = new List<Claim> { new Claim(SecurityGlobal.UserGroupClaim, FakeUserGroupManager.IdGroupB.ToString()), new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", FakeUserGroupManager.IdUser2.ToString()) }; var identity = kernel.GetMock<IIdentity>(); identity.Setup(mock => mock.IsAuthenticated).Returns(true); identity.Setup(mock => mock.Name).Returns(FakeRepository.UserName); var claimsIdentity = new ClaimsIdentity(identity.Object, claims); var user = new ClaimsPrincipal(claimsIdentity); var authenticationManager = kernel.GetMock<IAuthenticationManager>(); authenticationManager.Setup(mock => mock.User).Returns(user); return authenticationManager; }
public void SaveLogsCreateFileProcessPledgeLogWithRemoteJobTest() { // Arrange var sessionId = Guid.NewGuid().ToString(); var configId = Guid.NewGuid(); var groupId = Guid.NewGuid().ToString(); var options = new Dictionary<string, string> { {PledgeGlobal.SessionId, sessionId} }; IRemoteJob job = new RemoteJob { JobId = Guid.NewGuid(), ConfigurationId = configId, JobName = _randomizer.GetString(32), EgestHandlerType = HandlerType.FileSystem, IngestHandlerType = HandlerType.FileSystem, IngestMediumSettings = new SerializableDictionary<string, string> { { PledgeGlobal.ImportFolderKey, _randomizer.GetString(20)}, { PledgeGlobal.FilePatternKey, _randomizer.GetString(20)} } }; // Act var log = _auditor.CreateFileProcessPledgeLog(new BaseConfiguration { Id = configId, GroupId = groupId }, job, options); // Assert Assert.AreEqual(configId.ToString(), log.ConfigId); Assert.AreEqual(sessionId, log.SessionId); Assert.AreNotEqual($"{job.IngestMediumSettings[PledgeGlobal.FilePatternKey]} (in) {job.IngestMediumSettings[PledgeGlobal.ImportFolderKey]}", log.Subject); Assert.AreEqual(RunType.WebsiteRun, log.RunType); Assert.AreNotEqual(default(DateTime), log.DateCreated); Assert.AreNotEqual(default(DateTime), log.StartTime); }
internal static IRemoteJob GetWebJobConfiguration(string fileName, string clientId) { lock (_syncLock) { if (_houseCleanerImport.IsCompleted) { _houseCleanerImport = new Task(() => RunHousekeeping(true, ImportDirectory)); } if (_houseCleanerExport.IsCompleted) { _houseCleanerExport = new Task(() => RunHousekeeping(false, ExportDirectory)); } if (_houseCleanerImport.Status != TaskStatus.Running && LastHousekeepingRunImport < DateTime.Now.AddHours(HousekeepingFrequencyImport)) { _houseCleanerImport.Start(); } if (_houseCleanerExport.Status != TaskStatus.Running && LastHousekeepingRunExport < DateTime.Now.AddHours(HousekeepingFrequencyExport)) { _houseCleanerExport.Start(); } } var webIngestConfiguration = new RemoteJob { JobName = "Web Ingest", IngestMediumSettings = new SerializableDictionary<string, string> { {PledgeGlobal.NamespaceKey, PledgeGlobal.BuiltInReader }, {PledgeGlobal.ImportFolderKey, ImportDirectory}, {PledgeGlobal.FilePatternKey, Path.GetFileName(fileName)} }, EgestMediumSettings = new SerializableDictionary<string, string> { {PledgeGlobal.NamespaceKey, PledgeGlobal.BuiltInWriter }, {PledgeGlobal.ExportFolderKey, ExportDirectory} }, PledgeSettings = new SerializableDictionary<string, string> { {PledgeGlobal.NamespaceKey, PledgeGlobal.BuiltInPledge }, {PledgeGlobal.ClientId, clientId } } }; return webIngestConfiguration; }
public void SaveConfiguration(RemoteJob remoteJob) { var user = AuthenticationManager.User; _pledgeManager.SaveRemoteJob(remoteJob, user.Identity.Name); }
private void SendJobBack(RemoteJob job) { Debug.Assert(job.OriginalJob != null); if (job.ParentSmasher.Connected) { Console.WriteLine("LIST - Sending job back {0}", job.Id); // TODO: Wait while receiving data! BinaryFormatter formatter = new BinaryFormatter(); NetworkStream stream = new NetworkStream(job.ParentSmasher); formatter.Serialize(stream, job.OriginalJob); if (JobReturned != null) JobReturned(job.OriginalJob); } else { Console.WriteLine("LIST - Oops, {0}'s parent socket has been closed", job.Id); } }
private async void Cleanup(RemoteJob job, PipelinePayload payload) { job.IngestMediumSettings = payload.IngestSettings; job.EgestMediumSettings = payload.EgestSettings; try { using (var client = new HttpClient()) { client.BaseAddress = new Uri(ApiAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var content = new StringContent($"grant_type=password&username={UserName}&password={Password}", Encoding.UTF8, "application/x-www-form-urlencoded"); var response = await client.PostAsync("Token", content); if (!response.IsSuccessStatusCode) { return; } var login = await response.Content.ReadAsAsync<AuthenticationResponse>(); var accessToken = login.AccessToken; client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}"); await client.PostAsJsonAsync("api/jobs/save/", job); } } catch (Exception error) { Console.WriteLine(error.Message); } }