public PatchRequest2 ComposeReferencePatch( string referenceAttributeName, string referencedObjectUniqueIdentifier, OperationName operationName) { Assert.IsFalse(string.IsNullOrWhiteSpace(referenceAttributeName)); Assert.IsFalse(string.IsNullOrWhiteSpace(referencedObjectUniqueIdentifier)); IPath path; Assert.IsTrue(Path.TryParse(referenceAttributeName, out path)); OperationValue operationValue = new OperationValue() { Value = referencedObjectUniqueIdentifier }; PatchOperation operation = new PatchOperation() { Name = operationName, Path = path }; operation.AddValue(operationValue); PatchRequest2 result = new PatchRequest2(); result.AddOperation(operation); return(result); }
public void Update(string id, JObject body) { PatchRequest2Compliant patchRequest = null; PatchRequestSimple patchSimple = null; try { patchRequest = body.ToObject <PatchRequest2Compliant>(); } catch (Newtonsoft.Json.JsonException) { } if (patchRequest == null) { patchSimple = body.ToObject <PatchRequestSimple>(); } if (null == patchRequest && null == patchSimple) { string unsupportedPatchTypeName = patchRequest.GetType().FullName; throw new NotSupportedException(unsupportedPatchTypeName); } Core2User usertoModify = this._context.CompleteUsers().FirstOrDefault((user) => user.Identifier.Equals(id, StringComparison.Ordinal)); if (patchRequest != null) { if (usertoModify != null) { foreach (PatchOperation2SingleValued op in patchRequest.Operations) { if (op is PatchOperation2SingleValued singleValued) { PatchOperation patchOp = PatchOperation.Create(OperationValue.getOperationName(singleValued.OperationName), singleValued.Path.ToString(), singleValued.Value); usertoModify.Apply(patchOp); usertoModify.Metadata.LastModified = DateTime.Now; } } } } else if (patchSimple != null) { if (usertoModify != null) { foreach (PatchOperation op in patchSimple.Operations) { usertoModify.Apply(op); usertoModify.Metadata.LastModified = DateTime.Now; } } } this._context.SaveChanges(); }
public SettingsException(OperationValue operation, Exception innerException) : base(Messages[(int)operation], innerException) { Operation = operation; }
public PatchRequest2 ComposeUserPatch() { string value = Guid.NewGuid().ToString(SampleComposer.FormatUniqueIdentifierCompressed); IPath path; PatchOperation operation; OperationValue operationValue; PatchRequest2 result = new PatchRequest2(); Assert.IsTrue(Path.TryParse(AttributeNames.Active, out path)); operationValue = new OperationValue() { Value = bool.FalseString }; operation = new PatchOperation() { Name = OperationName.Replace, Path = path }; operation.AddValue(operationValue); result.AddOperation(operation); Assert.IsTrue(Path.TryParse(AttributeNames.DisplayName, out path)); operationValue = new OperationValue() { Value = value }; operation = new PatchOperation() { Name = OperationName.Replace, Path = path }; operation.AddValue(operationValue); result.AddOperation(operation); Assert.IsTrue(Path.TryParse(SampleComposer.PathExpressionPrimaryWorkElectronicMailAddress, out path)); string electronicMailAddressValue = string.Format( CultureInfo.InvariantCulture, SampleComposer.ElectronicMailAddressTemplate, value); operationValue = new OperationValue() { Value = electronicMailAddressValue }; operation = new PatchOperation() { Name = OperationName.Replace, Path = path }; operation.AddValue(operationValue); result.AddOperation(operation); Assert.IsTrue(Path.TryParse(SampleComposer.PathExpressionPostalCode, out path)); operationValue = new OperationValue() { Value = value }; operation = new PatchOperation() { Name = OperationName.Replace, Path = path }; operation.AddValue(operationValue); result.AddOperation(operation); return(result); }
public void TestLifecycleGroup() { Uri addressBase = new Uri(WebServiceUnitTest.AddressBase); IMonitor monitor = new ConsoleMonitor(); IAmazonWebServicesIdentityAnchoringBehavior anchoringBehavior = new AnchoringByIdentifierBehavior(); AmazonWebServicesProviderBase provider = new AmazonWebServicesProvider(WebServiceUnitTest.CredentialsProfileName, anchoringBehavior); Service webService = null; try { webService = new WebService(monitor, provider); webService.Start(addressBase); string identifierGroup; string identifierGroupExternal; string identifierMemberOne; string identifierMemberTwo; Uri resource; WebClient client = null; try { IDictionary<string, object> json; string characters; byte[] bytes; byte[] response; string responseCharacters; IReadOnlyDictionary<string, object> responseJson; Core2EnterpriseUser user; Member member; IReadOnlyCollection<Member> members; client = new WebClient(); identifierMemberOne = Guid.NewGuid().ToString(); string identifierMemberOneExternal = Guid.NewGuid().ToString(); user = new Core2EnterpriseUser() { Identifier = identifierMemberOne, ExternalIdentifier = identifierMemberOneExternal }; json = user.ToJson(); characters = WebServiceUnitTest.Serializer.Value.Serialize(json); bytes = Encoding.UTF8.GetBytes(characters); resource = new Uri(addressBase, WebServiceUnitTest.AddressRelativeUsers); client.Headers.Clear(); client.Headers.Add(HttpRequestHeader.ContentType, WebServiceUnitTest.ContentTypeJson); response = client.UploadData(resource.AbsoluteUri, WebRequestMethods.Http.Post, bytes); responseCharacters = Encoding.UTF8.GetString(response); responseJson = WebServiceUnitTest.Serializer.Value.Deserialize<Dictionary<string, object>>(responseCharacters); user = new Core2EnterpriseUserJsonDeserializingFactory().Create(responseJson); identifierMemberOne = user.Identifier; try { member = new Member() { Value = identifierMemberOne }; members = new Member[] { member }; identifierGroup = Guid.NewGuid().ToString(); identifierGroupExternal = Guid.NewGuid().ToString(); WindowsAzureActiveDirectoryGroup group = new WindowsAzureActiveDirectoryGroup() { Identifier = identifierGroup, ExternalIdentifier = identifierGroupExternal, Members = members }; json = group.ToJson(); characters = WebServiceUnitTest.Serializer.Value.Serialize(json); bytes = Encoding.UTF8.GetBytes(characters); resource = new Uri(addressBase, WebServiceUnitTest.AddressRelativeGroups); client.Headers.Clear(); client.Headers.Add(HttpRequestHeader.ContentType, WebServiceUnitTest.ContentTypeJson); response = client.UploadData(resource.AbsoluteUri, WebRequestMethods.Http.Post, bytes); responseCharacters = Encoding.UTF8.GetString(response); responseJson = WebServiceUnitTest.Serializer.Value.Deserialize<Dictionary<string, object>>(responseCharacters); group = new WindowsAzureActiveDirectoryGroupJsonDeserializingFactory().Create(responseJson); Assert.IsNotNull(group); Assert.IsNotNull( group .Schemas .SingleOrDefault( (string item) => string.Equals( SchemaIdentifiers.WindowsAzureActiveDirectoryGroup, item, StringComparison.Ordinal))); Assert.IsFalse(string.IsNullOrWhiteSpace(group.Identifier)); string identifierGroupAmazon = group.Identifier; try { Assert.IsNotNull(group.Metadata); Assert.IsFalse(string.IsNullOrWhiteSpace(group.Metadata.ResourceType)); Assert.IsFalse(string.Equals(identifierGroup, identifierGroupAmazon, StringComparison.OrdinalIgnoreCase)); string resourcePath = string.Format( CultureInfo.InvariantCulture, WebServiceUnitTest.AddressRelativeGroupTemplate, identifierGroupAmazon); resource = new Uri(addressBase, resourcePath); response = client.DownloadData(resource); responseCharacters = Encoding.UTF8.GetString(response); responseJson = WebServiceUnitTest.Serializer.Value.Deserialize<Dictionary<string, object>>(responseCharacters); group = new WindowsAzureActiveDirectoryGroupJsonDeserializingFactory().Create(responseJson); Assert.IsNotNull(group); Assert.IsNotNull( group .Schemas .SingleOrDefault( (string item) => string.Equals( SchemaIdentifiers.Core2Group, item, StringComparison.Ordinal))); Assert.IsFalse(string.IsNullOrWhiteSpace(group.Identifier)); Assert.IsTrue(string.Equals(group.Identifier, identifierGroupAmazon, StringComparison.OrdinalIgnoreCase)); Assert.IsFalse(string.IsNullOrWhiteSpace(group.ExternalIdentifier)); Assert.IsTrue(string.Equals(group.ExternalIdentifier, identifierGroupExternal, StringComparison.OrdinalIgnoreCase)); identifierMemberTwo = Guid.NewGuid().ToString(); string identifierMemberTwoExternal = Guid.NewGuid().ToString(); user = new Core2EnterpriseUser() { Identifier = identifierMemberTwo, ExternalIdentifier = identifierMemberTwoExternal }; json = user.ToJson(); characters = WebServiceUnitTest.Serializer.Value.Serialize(json); bytes = Encoding.UTF8.GetBytes(characters); resource = new Uri(addressBase, WebServiceUnitTest.AddressRelativeUsers); client.Headers.Clear(); client.Headers.Add(HttpRequestHeader.ContentType, WebServiceUnitTest.ContentTypeJson); response = client.UploadData(resource.AbsoluteUri, WebRequestMethods.Http.Post, bytes); responseCharacters = Encoding.UTF8.GetString(response); responseJson = WebServiceUnitTest.Serializer.Value.Deserialize<Dictionary<string, object>>(responseCharacters); user = new Core2EnterpriseUserJsonDeserializingFactory().Create(responseJson); identifierMemberTwo = user.Identifier; try { IResourceIdentifier resourceIdentifier = new ResourceIdentifier() { Identifier = identifierGroupAmazon, SchemaIdentifier = SchemaIdentifiers.WindowsAzureActiveDirectoryGroup }; IPath path = Microsoft.SystemForCrossDomainIdentityManagement.Path.Create(AttributeNames.Members); OperationValue operationValue; PatchOperation operation; IReadOnlyCollection<PatchOperation> operations; PatchRequest2 patch; operationValue = new OperationValue() { Value = identifierMemberTwo }; operation = new PatchOperation() { Name = OperationName.Add, Path = path }; operations = new PatchOperation[] { operation }; operation.AddValue(operationValue); patch = new PatchRequest2(); patch.AddOperation(operation); json = patch.ToJson(); characters = WebServiceUnitTest.Serializer.Value.Serialize(json); bytes = Encoding.UTF8.GetBytes(characters); resourcePath = string.Concat(WebServiceUnitTest.AddressRelativeGroup, identifierGroupAmazon); resource = new Uri(addressBase, resourcePath); client.Headers.Clear(); client.Headers.Add(HttpRequestHeader.ContentType, WebServiceUnitTest.ContentTypeJson); response = client.UploadData(resource.AbsoluteUri, WebServiceUnitTest.MethodPatch, bytes); operationValue = new OperationValue() { Value = identifierMemberTwo }; operation = new PatchOperation() { Name = OperationName.Remove, Path = path }; operations = new PatchOperation[] { operation }; operation.AddValue(operationValue); patch = new PatchRequest2(); patch.AddOperation(operation); json = patch.ToJson(); characters = WebServiceUnitTest.Serializer.Value.Serialize(json); bytes = Encoding.UTF8.GetBytes(characters); resourcePath = string.Concat(WebServiceUnitTest.AddressRelativeGroup, identifierGroupAmazon); resource = new Uri(addressBase, resourcePath); client.Headers.Clear(); client.Headers.Add(HttpRequestHeader.ContentType, WebServiceUnitTest.ContentTypeJson); response = client.UploadData(resource.AbsoluteUri, WebServiceUnitTest.MethodPatch, bytes); operationValue = new OperationValue() { Value = identifierMemberOne }; operation = new PatchOperation() { Name = OperationName.Remove, Path = path }; operations = new PatchOperation[] { operation }; operation.AddValue(operationValue); patch = new PatchRequest2(); patch.AddOperation(operation); json = patch.ToJson(); characters = WebServiceUnitTest.Serializer.Value.Serialize(json); bytes = Encoding.UTF8.GetBytes(characters); resourcePath = string.Concat(WebServiceUnitTest.AddressRelativeGroup, identifierGroupAmazon); resource = new Uri(addressBase, resourcePath); client.Headers.Clear(); client.Headers.Add(HttpRequestHeader.ContentType, WebServiceUnitTest.ContentTypeJson); response = client.UploadData(resource.AbsoluteUri, WebServiceUnitTest.MethodPatch, bytes); } finally { resourcePath = string.Concat(WebServiceUnitTest.AddressRelativeUser, identifierMemberTwo); resource = new Uri(addressBase, resourcePath); bytes = new byte[0]; client.UploadData(resource, WebServiceUnitTest.MethodDelete, bytes); } } finally { string resourcePath = string.Concat(WebServiceUnitTest.AddressRelativeGroup, identifierGroupAmazon); resource = new Uri(addressBase, resourcePath); bytes = new byte[0]; client.UploadData(resource, WebServiceUnitTest.MethodDelete, bytes); } } finally { string resourcePath = string.Concat(WebServiceUnitTest.AddressRelativeUser, identifierMemberOne); resource = new Uri(addressBase, resourcePath); bytes = new byte[0]; client.UploadData(resource, WebServiceUnitTest.MethodDelete, bytes); } } finally { if (client != null) { client.Dispose(); client = null; } } } finally { if (webService != null) { webService.Dispose(); webService = null; } } }
private void readDB_Click(object sender, RoutedEventArgs e) { if (!fromDatePicker.SelectedDate.HasValue || !toDatePicker.SelectedDate.HasValue) { return; } if (writeDBButton.IsEnabled) { switch (MessageBox.Show("There are changes not saved. Do you want to discard them?", "Load", MessageBoxButton.YesNo)) { case MessageBoxResult.No: return; } writeDBButton.IsEnabled = false; } DateTime from = fromDatePicker.SelectedDate.Value; DateTime to = toDatePicker.SelectedDate.Value; foreach (TabItem p in pagesTabControl.Items) { if (p.Content is ITimeLoadableControl) { (p.Content as ITimeLoadableControl).Load(from, to); } } if (operationsControl.OperationsList.Count == 0) { totalLabel.Content = "No data"; } else { OperationValue total = new OperationValue(0); OperationValue income = new OperationValue(0); OperationValue outcome = new OperationValue(0); foreach (var op in operationsControl.OperationsList) { if (op.Exception) { continue; } total.Value += op.OperationMove.Value; if (op.OperationMove.Value > 0) { income.Value += op.OperationMove.Value; } else { outcome.Value += op.OperationMove.Value; } } totalLabel.Content = string.Format("Start: {0} End: {1} Income: {2} Outcome: {3} Balance: {4}", operationsControl.OperationsList[0].CurrentBalance, operationsControl.OperationsList[operationsControl.OperationsList.Count - 1].CurrentBalance, income, outcome, total); } }