public RegisterAuditMessage(User user)
 {
     AffectedEntity = new Entity
     {
         Type = UserTypeName,
         Id   = user.Id
     };
     Category          = "CREATED";
     Description       = $"User registered with email address {user.Email}";
     ChangedProperties = new List <PropertyUpdate>
     {
         PropertyUpdate.FromString(nameof(user.FirstName), user.FirstName),
         PropertyUpdate.FromString(nameof(user.LastName), user.LastName),
         PropertyUpdate.FromString(nameof(user.Email), user.Email),
         PropertyUpdate.FromString(nameof(user.Password), PasswordAuditValue),
         PropertyUpdate.FromString(nameof(user.Salt), SaltAuditValue),
         PropertyUpdate.FromString(nameof(user.PasswordProfileId), user.PasswordProfileId),
         PropertyUpdate.FromBool(nameof(user.IsActive), user.IsActive)
     };
     for (var i = 0; i < user.SecurityCodes.Length; i++)
     {
         var code = user.SecurityCodes[i];
         ChangedProperties.Add(PropertyUpdate.FromString($"{nameof(user.SecurityCodes)}[{i}].{nameof(code.Code)}", code.Code));
         ChangedProperties.Add(PropertyUpdate.FromString($"{nameof(user.SecurityCodes)}[{i}].{nameof(code.CodeType)}", code.CodeType.ToString()));
         ChangedProperties.Add(PropertyUpdate.FromDateTime($"{nameof(user.SecurityCodes)}[{i}].{nameof(code.ExpiryTime)}", code.ExpiryTime));
     }
 }
 private async Task AddAuditEntry(AddPayeToAccountCommand message, long accountId)
 {
     await _mediator.SendAsync(new CreateAuditCommand
     {
         EasAuditMessage = new EasAuditMessage
         {
             Category          = "CREATED",
             Description       = $"Paye scheme {message.Empref} added to account {accountId}",
             ChangedProperties = new List <PropertyUpdate>
             {
                 PropertyUpdate.FromString("Ref", message.Empref),
                 PropertyUpdate.FromString("AccessToken", message.AccessToken),
                 PropertyUpdate.FromString("RefreshToken", message.RefreshToken),
                 PropertyUpdate.FromString("Name", message.EmprefName),
                 PropertyUpdate.FromString("Aorn", message.Aorn)
             },
             RelatedEntities = new List <Entity> {
                 new Entity {
                     Id = accountId.ToString(), Type = "Account"
                 }
             },
             AffectedEntity = new Entity {
                 Type = "Paye", Id = message.Empref
             }
         }
     });
 }
        public RayTraceViewModel()
        {
            List <SceneEntry> scenes = new List <SceneEntry>();

            scenes.Add(new SceneEntry("Cover scene", "0"));
            scenes.Add(new SceneEntry("Materials", "1"));
            scenes.Add(new SceneEntry("Defocus Blur", "2"));
            scenes.Add(new SceneEntry("Test 1", "3"));

            _scenes       = new PropertyUpdate <List <SceneEntry> >(scenes, nameof(Scenes), OnPropertyChanged);
            _currentScene = new PropertyUpdate <SceneEntry>(scenes[0], nameof(CurrentScene), OnPropertyChanged);
            _render_cx    = new PropertyUpdate <int>(400, nameof(RenderWidth), OnPropertyChanged);
            _render_cy    = new PropertyUpdate <int>(200, nameof(RenderHeight), OnPropertyChanged);
            _samples      = new PropertyUpdate <int>(100, nameof(RenderSamples), OnPropertyChanged);
            _update_rate  = new PropertyUpdate <double>(0.1, nameof(RenderUpdateRate), (string name) => { OnPropertyChanged(name); OnPropertyChanged(nameof(RenderUpdateRateTip)); });
            _progress     = new PropertyUpdate <double>(0.0, nameof(Progress), (string name) => { OnPropertyChanged(name); OnPropertyChanged(nameof(ProgressTip)); });

            _saveImageCommad      = new RelayCommand(SaveImage, param => true);
            _applySettingsCommand = new RelayCommand(ApplySettings, param => true);

            _rt_model.ViewModel = this;

            // TODO $$$ do not start raytracing at startup?
            RestartRaytrace();
        }
Esempio n. 4
0
        public async Task UT_WebDavClient_PropPatchSet()
        {
            var mockHandler = new MockHttpMessageHandler();

            var testFile = UriHelper.CombineUrl(WebDavRootFolder, TestFile, true);
            var requestContentProppatch  = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:propertyupdate xmlns:D=\"DAV:\"><D:set><D:prop><D:displayname>TestFileDisplayName</D:displayname></D:prop></D:set></D:propertyupdate>";
            var responseContentProppatch = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:multistatus xmlns:D=\"DAV:\"><D:response><D:href>http://127.0.0.1/TextFile1.txt</D:href><D:propstat><D:prop><D:displayname/></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response></D:multistatus>";

            mockHandler.When(WebDavMethod.PropPatch, testFile).WithContent(requestContentProppatch).Respond(HttpStatusCode.OK, new StringContent(responseContentProppatch));

            var propertyUpdate = new PropertyUpdate();
            var set            = new Set();

            var prop = new Prop()
            {
                DisplayName = "TestFileDisplayName"
            };

            set.Prop             = prop;
            propertyUpdate.Items = new object[] { set };

            using (var client = CreateWebDavClient(mockHandler))
            {
                var response = await client.PropPatchAsync(testFile, propertyUpdate);

                var multistatusPropPatch = await WebDavResponseContentParser.ParseMultistatusResponseContentAsync(response.Content);

                Assert.IsNotNull(multistatusPropPatch);
                Assert.IsTrue(response.IsSuccessStatusCode);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Create new resolver with new properties, use original key value pairs
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="ignoreDuplicates">true, will not add keys already set</param>
        /// <returns>new property resolver</returns>
        public IPropertyResolver With(string key, string value, PropertyUpdate propertyUpdate)
        {
            key.Verify(nameof(key)).IsNotEmpty();
            value.Verify(nameof(value)).IsNotEmpty();

            return(With(new KeyValuePair <string, string>[] { new KeyValuePair <string, string>(key, value) }, propertyUpdate));
        }
 public CardState With(
     PropertyUpdate <bool> showAtomicNumber = null,
     PropertyUpdate <bool> showSymbol       = null,
     PropertyUpdate <bool> showName         = null)
 =>
 new CardState(
     showAtomicNumberbool: showAtomicNumber.GetUpdatedValue(ShowAtomicNumber),
     showSymbol: showSymbol.GetUpdatedValue(ShowSymbol),
     showName: showName.GetUpdatedValue(ShowName));
Esempio n. 7
0
        public void UIT_WebDavClient_PropPatch()
        {
            var client   = CreateWebDavClientWithDebugHttpMessageHandler();
            var testFile = UriHelper.CombineUrl(this.webDavRootFolder, TestFile, true);

            // Put file.
            var content            = new StreamContent(File.OpenRead(TestFile));
            var response           = client.PutAsync(testFile, content).Result;
            var putResponseSuccess = response.IsSuccessStatusCode;

            // PropPatch (set).
            var propertyUpdate = new PropertyUpdate();
            var set            = new Set();
            var prop           = new Prop();

            prop.DisplayName     = "TestFileDisplayName";
            set.Prop             = prop;
            propertyUpdate.Items = new object[] { set };
            response             = client.PropPatchAsync(testFile, propertyUpdate).Result;
            var propPatchResponseSuccess = response.IsSuccessStatusCode;

            // PropFind.
            PropFind pf = PropFind.CreatePropFindWithEmptyProperties("displayname");

            response = client.PropFindAsync(testFile, WebDavDepthHeaderValue.Zero, pf).Result;
            var propFindResponseSuccess = response.IsSuccessStatusCode;
            var multistatus             = (Multistatus)WebDavResponseContentParser.ParseMultistatusResponseContentAsync(response.Content).Result;
            var displayName             = ((Propstat)multistatus.Response[0].Items[0]).Prop.DisplayName;
            // IIS ignores display name and always puts the file name as display name.
            var displayNameResult = "TestFileDisplayName" == displayName || TestFile == displayName;

            // PropPatch (remove).
            propertyUpdate = new PropertyUpdate();
            var remove = new Remove();

            prop                 = Prop.CreatePropWithEmptyProperties("displayname");
            remove.Prop          = prop;
            propertyUpdate.Items = new object[] { remove };
            response             = client.PropPatchAsync(testFile, propertyUpdate).Result;
            var propPatchRemoveResponseSuccess = response.IsSuccessStatusCode;

            multistatus = (Multistatus)WebDavResponseContentParser.ParseMultistatusResponseContentAsync(response.Content).Result;
            var multistatusResult = ((Propstat)multistatus.Response[0].Items[0]).Prop.DisplayName;

            // Delete file.
            response = client.DeleteAsync(testFile).Result;
            var deleteResponseSuccess = response.IsSuccessStatusCode;

            Assert.IsTrue(putResponseSuccess);
            Assert.IsTrue(propPatchResponseSuccess);
            Assert.IsTrue(propFindResponseSuccess);
            Assert.IsTrue(displayNameResult);
            Assert.IsTrue(propPatchRemoveResponseSuccess);
            Assert.AreEqual(string.Empty, multistatusResult);
            Assert.IsTrue(deleteResponseSuccess);
        }
 public ElementState With(
     PropertyUpdate <byte> atomicNumber = null,
     PropertyUpdate <CardState> front   = null,
     PropertyUpdate <CardState> back    = null,
     PropertyUpdate <bool> concealed    = null)
 =>
 new ElementState(
     atomicNumber.GetUpdatedValue(AtomicNumber),
     front: front.GetUpdatedValue(Front),
     back: back.GetUpdatedValue(Back),
     concealed: concealed.GetUpdatedValue(Concealed));
        private async Task CreateAuditEntries(CreateUserAccountCommand message, CreateUserAccountResult returnValue, string hashedAccountId, User user)
        {
            //Account
            await _mediator.SendAsync(new CreateAuditCommand
            {
                EasAuditMessage = new EasAuditMessage
                {
                    Category          = "CREATED",
                    Description       = $"Account {message.OrganisationName} created with id {returnValue.AccountId}",
                    ChangedProperties = new List <PropertyUpdate>
                    {
                        PropertyUpdate.FromLong("AccountId", returnValue.AccountId),
                        PropertyUpdate.FromString("HashedId", hashedAccountId),
                        PropertyUpdate.FromString("Name", message.OrganisationName),
                        PropertyUpdate.FromDateTime("CreatedDate", DateTime.UtcNow),
                    },
                    AffectedEntity = new Entity {
                        Type = "Account", Id = returnValue.AccountId.ToString()
                    },
                    RelatedEntities = new List <Entity>()
                }
            });

            //Membership Account
            await _mediator.SendAsync(new CreateAuditCommand
            {
                EasAuditMessage = new EasAuditMessage
                {
                    Category          = "CREATED",
                    Description       = $"User {message.ExternalUserId} added to account {returnValue.AccountId} as owner",
                    ChangedProperties = new List <PropertyUpdate>
                    {
                        PropertyUpdate.FromLong("AccountId", returnValue.AccountId),
                        PropertyUpdate.FromString("UserId", message.ExternalUserId),
                        PropertyUpdate.FromString("Role", Role.Owner.ToString()),
                        PropertyUpdate.FromDateTime("CreatedDate", DateTime.UtcNow)
                    },
                    RelatedEntities = new List <Entity>
                    {
                        new Entity {
                            Id = returnValue.AccountId.ToString(), Type = "Account"
                        },
                        new Entity {
                            Id = user.Id.ToString(), Type = "User"
                        }
                    },
                    AffectedEntity = new Entity {
                        Type = "Membership", Id = message.ExternalUserId
                    }
                }
            });
        }
Esempio n. 10
0
 public ActivatedAuditMessage(User user)
 {
     AffectedEntity = new Entity
     {
         Type = UserTypeName,
         Id   = user.Id
     };
     Category          = "ACTIVATED";
     Description       = $"User {user.Email} (id: {user.Id}) activated their account";
     ChangedProperties = new List <PropertyUpdate>
     {
         PropertyUpdate.FromBool(nameof(user.IsActive), user.IsActive)
     };
 }
Esempio n. 11
0
 public MessageQueueReplayAuditMessage(QueueMessage message)
 {
     AffectedEntity = new Entity
     {
         Type = "QueueMessage",
         Id   = message.Id
     };
     Category          = "REPLAY_QUEUE_MESSAGE";
     Description       = $"Replay queue message of id : {message.Id} with CorrelationId : {message.OriginalMessage.CorrelationId}";
     ChangedProperties = new List <PropertyUpdate>
     {
         PropertyUpdate.FromString("meessage", JsonConvert.SerializeObject(message.OriginalMessage?.UserProperties))
     };
 }
 public MessageQueueDeleteAuditMessage(IEnumerable <string> ids)
 {
     AffectedEntity = new Entity
     {
         Type = "QueueMessages",
         Id   = Guid.NewGuid().ToString()
     };
     Category          = "DELETE_QUEUE_MESSAGES";
     Description       = $"Delete queue messages";
     ChangedProperties = new List <PropertyUpdate>
     {
         PropertyUpdate.FromString("ids", JsonConvert.SerializeObject(ids))
     };
 }
Esempio n. 13
0
 public FailedLoginAuditMessage(string emailAddress, User user)
 {
     Category       = "FAILED_LOGIN";
     AffectedEntity = new Audit.Types.Entity
     {
         Type = UserTypeName,
         Id   = user.Id
     };
     Description       = $"User {user.Email} (id: {user.Id})attempted to login with the incorrect password";
     ChangedProperties = new List <PropertyUpdate>
     {
         PropertyUpdate.FromInt(nameof(user.FailedLoginAttempts), user.FailedLoginAttempts)
     };
 }
Esempio n. 14
0
 public CompleteChangeEmailAuditMessage(User user, string oldEmail)
 {
     AffectedEntity = new Entity
     {
         Type = UserTypeName,
         Id   = user.Id
     };
     Category          = "UPDATE";
     Description       = $"User {user.Email} completed changing their email address from {oldEmail}";
     ChangedProperties = new List <PropertyUpdate>
     {
         PropertyUpdate.FromString(nameof(user.Email), user.Email)
     };
 }
 public AccountLockedAuditMessage(User user)
 {
     Category       = "ACCOUNT_LOCKED";
     Description    = $"User {user.Email} (id: {user.Id}) has exceeded the limit of failed logins and the account has been locked";
     AffectedEntity = new Entity
     {
         Type = UserTypeName,
         Id   = user.Id
     };
     ChangedProperties = new List <PropertyUpdate>
     {
         PropertyUpdate.FromInt(nameof(user.FailedLoginAttempts), user.FailedLoginAttempts),
         PropertyUpdate.FromBool(nameof(user.IsLocked), user.IsLocked)
     };
 }
Esempio n. 16
0
 public UnlockedAuditMessage(User user)
 {
     AffectedEntity = new Entity
     {
         Type = UserTypeName,
         Id   = user.Id
     };
     Category          = "UNLOCK";
     Description       = $"User {user.Email} (id: {user.Id}) unlocked their account";
     ChangedProperties = new List <PropertyUpdate>
     {
         PropertyUpdate.FromBool(nameof(user.IsLocked), user.IsLocked),
         PropertyUpdate.FromInt(nameof(user.FailedLoginAttempts), user.FailedLoginAttempts)
     };
 }
 public RequestChangeEmailAuditMessage(User user, SecurityCode code)
 {
     AffectedEntity = new Entity
     {
         Type = UserTypeName,
         Id   = user.Id
     };
     Category          = "CHANGE_EMAIL";
     Description       = $"User {user.Email} (id: {user.Id}) has requested to change their email to {code.PendingValue}. They have been issued code {code.Code}";
     ChangedProperties = new List <PropertyUpdate>
     {
         PropertyUpdate.FromString("SecurityCodes.Code", code.Code),
         PropertyUpdate.FromDateTime("SecurityCodes.ExpiryTime", code.ExpiryTime)
     };
 }
 public PasswordResetAuditMessage(User user)
 {
     Category       = "PASSWORD_RESET";
     AffectedEntity = new Entity
     {
         Type = UserTypeName,
         Id   = user.Id
     };
     Description       = $"User {user.Email} (id: {user.Id}) has reset their password";
     ChangedProperties = new List <PropertyUpdate>
     {
         PropertyUpdate.FromString(nameof(user.Password), PasswordAuditValue),
         PropertyUpdate.FromString(nameof(user.Salt), SaltAuditValue)
     };
 }
Esempio n. 19
0
        public ResendActivationCodeAuditMessage(User user)
        {
            var activationCode = user.SecurityCodes.Where(x => x.CodeType == SecurityCodeType.AccessCode)
                                 .OrderByDescending(x => x.ExpiryTime)
                                 .FirstOrDefault();

            AffectedEntity = new Entity
            {
                Type = UserTypeName,
                Id   = user.Id
            };
            Category          = "RESEND_ACTIVATION_CODE";
            Description       = $"User {user.Email} (id: {user.Id}) has request activation code {activationCode?.Code} be resent";
            ChangedProperties = new List <PropertyUpdate>
            {
                PropertyUpdate.FromString(nameof(user.SecurityCodes), activationCode?.Code)
            };
        }
Esempio n. 20
0
        private async Task <IFlurlResponse> UpdateAsync(PropertyUpdate data)
        {
            IFlurlResponse responseHttp = await $"{_odata}({data.PropertyId})".WithOAuthBearerToken(token.Content).PatchJsonAsync(data);
            string         responseBody = await responseHttp.GetStringAsync();

            if (!responseHttp.ResponseMessage.IsSuccessStatusCode && responseHttp.StatusCode != 401)
            {
                _logger.Error($"Bad update in the database, Message: {responseBody}, StatusCode: {responseHttp.StatusCode}, Json for request: {JsonConvert.SerializeObject(data)}");
            }
            else if (!responseHttp.ResponseMessage.IsSuccessStatusCode && responseHttp.StatusCode == 401)
            {
                await AuthorizeStart();

                return(await UpdateAsync(data));
            }

            return(responseHttp);
        }
Esempio n. 21
0
        public PasswordResetCodeAuditMessage(User user)
        {
            //Get the latest security code
            var securityCode = user.SecurityCodes.Where(x => x.CodeType == SecurityCodeType.PasswordResetCode)
                               .OrderByDescending(x => x.ExpiryTime)
                               .FirstOrDefault();

            Category       = "PASSWORD_RESET_CODE";
            AffectedEntity = new Entity
            {
                Type = UserTypeName,
                Id   = user.Id
            };
            Description       = $"User {user.Email} (id: {user.Id}) has reset their security code";
            ChangedProperties = new List <PropertyUpdate>
            {
                PropertyUpdate.FromString("SecurityCode", securityCode?.Code)
            };
        }
        private void PatchProperty(PropertyUpdate propertyUpdate, Product productToPatch)
        {
            try
            {
                propertyUpdate.PatchProperty(productToPatch);
            }
            catch (ArgumentException)
            {
                IsSuccesful = false;

                Error propertyError = new Error()
                {
                    Message = "The given value does not match the expected type for property \"" + propertyUpdate.Property
                              + "\". This most likely happened because a string was supplied instead."
                };
                Logger.Warn("Update Attempt, could not patch property: {property}", propertyUpdate.Property);
                Logger.Warn(propertyError.Message);

                Errors.Add(propertyError);
            }
        }
 public ElementsMatchGameState With(
     PropertyUpdate <MatchType> matchType                  = null,
     PropertyUpdate <byte?> expectedElement                = null,
     PropertyUpdate <string> expectedElementDisplayText    = null,
     PropertyUpdate <bool> showElementGroup                = null,
     PropertyUpdate <bool> highlighElementsInExpectedGroup = null,
     PropertyUpdate <int> totalMatched         = null,
     PropertyUpdate <int> totalMismatched      = null,
     PropertyUpdate <byte[]> availableElements = null,
     PropertyUpdate <ReadOnlyDictionary <byte, ElementState> > elementStates = null)
 =>
 new ElementsMatchGameState(
     matchType: matchType.GetUpdatedValue(MatchType),
     expectedElement: expectedElement.GetUpdatedValue(ExpectedElement),
     expectedElementDisplayText: expectedElementDisplayText.GetUpdatedValue(ExpectedElementDisplayText),
     showElementGroup: showElementGroup.GetUpdatedValue(ShowElementGroup),
     highlighElementsInExpectedGroup: highlighElementsInExpectedGroup.GetUpdatedValue(HighlighElementsInExpectedGroup),
     totalMatched: totalMatched.GetUpdatedValue(TotalMatched),
     totalMismatched: totalMismatched.GetUpdatedValue(TotalMismatched),
     availableElements: availableElements.GetUpdatedValue(AvailableElements),
     elementStates: elementStates.GetUpdatedValue(ElementStates));
Esempio n. 24
0
 private async Task CreateAuditEntry(AcceptInvitationCommand message, User user, Invitation existing)
 {
     await _auditService.SendAuditMessage(new EasAuditMessage
     {
         Category    = "UPDATED",
         Description =
             $"Member {user.Email} has accepted and invitation to account {existing.AccountId} as {existing.Role}",
         ChangedProperties = new List <PropertyUpdate>
         {
             PropertyUpdate.FromString("Status", InvitationStatus.Accepted.ToString())
         },
         RelatedEntities = new List <Entity>
         {
             new Entity {
                 Id = $"Account Id [{existing.AccountId}], User Id [{user.Id}]", Type = "Membership"
             }
         },
         AffectedEntity = new Entity {
             Type = "Invitation", Id = message.Id.ToString()
         }
     });
 }
 private async Task AddAuditEntry(long accountId, string employerAgreementId)
 {
     await _mediator.SendAsync(new CreateAuditCommand
     {
         EasAuditMessage = new EasAuditMessage
         {
             Category          = "UPDATED",
             Description       = $"EmployerAgreement {employerAgreementId} removed from account {accountId}",
             ChangedProperties = new List <PropertyUpdate>
             {
                 PropertyUpdate.FromString("Status", EmployerAgreementStatus.Removed.ToString())
             },
             RelatedEntities = new List <Entity> {
                 new Entity {
                     Id = accountId.ToString(), Type = "Account"
                 }
             },
             AffectedEntity = new Entity {
                 Type = "EmployerAgreement", Id = employerAgreementId
             }
         }
     });
 }
Esempio n. 26
0
        public async Task UpdateOrUploadAsync(RealtyObjectsResponse data)
        {
            if (data == null)
            {
                return;
            }

            ODataSelectPropertyRecord flurlSelect = await SelectAsync <ODataSelectPropertyRecord>(data);

            if (flurlSelect == null || flurlSelect?.Value == null || flurlSelect?.Value.Length == 0)
            {
                PropertyUpload propertyUpload = new PropertyUpload(data);
                await UploadAsync(propertyUpload).ConfigureAwait(false);
            }
            else
            {
                foreach (ODataSelectRecord property in flurlSelect.Value)
                {
                    PropertyUpdate propertyUpdate = new PropertyUpdate(data, status: property.Status, propertyId: property.Property);
                    await UpdateAsync(propertyUpdate).ConfigureAwait(false);
                }
            }
        }
Esempio n. 27
0
        public async Task UT_WebDavClient_PropPatchRemove()
        {
            var mockHandler = new MockHttpMessageHandler();

            var testFile = UriHelper.CombineUrl(WebDavRootFolder, TestFile, true);
            var requestContentProppatch  = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:propertyupdate xmlns:D=\"DAV:\"><D:remove><D:prop><D:displayname /></D:prop></D:remove></D:propertyupdate>";
            var responseContentProppatch = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:multistatus xmlns:D=\"DAV:\"><D:response><D:href>http://127.0.0.1/TextFile1.txt</D:href><D:propstat><D:prop><D:displayname/></D:prop><D:status>HTTP/1.1 204 No Content</D:status></D:propstat></D:response></D:multistatus>";

            mockHandler.When(WebDavMethod.PropPatch, testFile).WithContent(requestContentProppatch).Respond(HttpStatusCode.NoContent, new StringContent(responseContentProppatch));

            var propertyUpdate = new PropertyUpdate();
            var remove         = new Remove();
            var prop           = Prop.CreatePropWithEmptyProperties(PropNameConstants.DisplayName);

            remove.Prop          = prop;
            propertyUpdate.Items = new object[] { remove };

            using (var client = new WebDavClient(mockHandler))
            {
                var response = await client.PropPatchAsync(testFile, propertyUpdate);

                Assert.IsTrue(response.IsSuccessStatusCode);
            }
        }
Esempio n. 28
0
 private async Task AddAuditEntry(SignEmployerAgreementCommand message, long accountId, long agreementId)
 {
     await _mediator.SendAsync(new CreateAuditCommand
     {
         EasAuditMessage = new EasAuditMessage
         {
             Category          = "UPDATED",
             Description       = $"Agreement {agreementId} added to account {accountId}",
             ChangedProperties = new List <PropertyUpdate>
             {
                 PropertyUpdate.FromString("UserId", message.ExternalUserId),
                 PropertyUpdate.FromString("SignedDate", message.SignedDate.ToString("U"))
             },
             RelatedEntities = new List <Entity> {
                 new Entity {
                     Id = accountId.ToString(), Type = "Account"
                 }
             },
             AffectedEntity = new Entity {
                 Type = "Agreement", Id = agreementId.ToString()
             }
         }
     });
 }
        /// <summary>
        /// Gets a PropertyUpdate from the properties changed for a WebDavSessionItem.
        /// </summary>
        /// <returns></returns>
        internal PropertyUpdate GetPropertyUpdate()
        {
            if (!HasChanged)
            {
                return(null);
            }

            var setProp         = new Prop();
            var removeProp      = new Prop();
            var setRequested    = false;
            var removeRequested = false;

            // If property has changed and is not null/has a value now, it's a set operation.
            // DateTime values (as string) should have the format of ISO8601.
            if (this.creationDateChanged && this.CreationDate.HasValue)
            {
                setProp.CreationDateString = this.CreationDate.Value.ToString("o");
                setRequested = true;
            }

            if (this.displayNameChanged && !string.IsNullOrEmpty(this.DisplayName))
            {
                setProp.DisplayName = this.DisplayName;
                setRequested        = true;
            }

            if (this.contentLanguageChanged && !string.IsNullOrEmpty(this.ContentLanguage))
            {
                setProp.GetContentLanguage = this.ContentLanguage;
                setRequested = true;
            }

            if (this.contentTypeChanged && !string.IsNullOrEmpty(this.ContentType))
            {
                setProp.GetContentType = this.ContentType;
                setRequested           = true;
            }

            if (this.lastModifiedChanged && this.LastModified.HasValue)
            {
                setProp.GetLastModifiedString = this.LastModified.Value.ToString("o");
                setRequested = true;
            }

            if (this.defaultDocumentChanged && !string.IsNullOrEmpty(this.DefaultDocument))
            {
                setProp.DefaultDocument = this.DefaultDocument;
                setRequested            = true;
            }

            if (this.isReadonlyChanged && this.IsReadonly.HasValue)
            {
                setProp.IsReadonlyString = this.IsReadonly.Value ? "1" : "0";
                setRequested             = true;
            }

            if (this.lastAccessedChanged && this.lastAccessed.HasValue)
            {
                setProp.LastAccessedString = this.LastAccessed.Value.ToString("o");
                setRequested = true;
            }

            if (this.additionalProperties.HasChanged)
            {
                var xElementList = additionalProperties.GetChangedAndAddedProperties();

                if (xElementList.Count > 0)
                {
                    setProp.AdditionalProperties = xElementList;
                    setRequested = true;
                }
            }

            // If a property has changed and is null/has no value now, it's a remove operation.
            var removePropertyNames = new List <string>();

            if (this.creationDateChanged && !this.CreationDate.HasValue)
            {
                removePropertyNames.Add(PropNameConstants.CreationDate);
                removeRequested = true;
            }

            if (this.displayNameChanged && string.IsNullOrEmpty(this.DisplayName))
            {
                removePropertyNames.Add(PropNameConstants.DisplayName);
                removeRequested = true;
            }

            if (this.contentLanguageChanged && string.IsNullOrEmpty(this.ContentLanguage))
            {
                removePropertyNames.Add(PropNameConstants.GetContentLanguage);
                removeRequested = true;
            }

            if (this.contentTypeChanged && string.IsNullOrEmpty(this.ContentType))
            {
                removePropertyNames.Add(PropNameConstants.GetContentType);
                removeRequested = true;
            }

            if (this.lastModifiedChanged && !this.LastModified.HasValue)
            {
                removePropertyNames.Add(PropNameConstants.GetLastModified);
                removeRequested = true;
            }

            if (this.defaultDocumentChanged && string.IsNullOrEmpty(this.DefaultDocument))
            {
                removePropertyNames.Add(PropNameConstants.DefaultDocument);
                removeRequested = true;
            }

            if (this.isReadonlyChanged && !this.IsReadonly.HasValue)
            {
                removePropertyNames.Add(PropNameConstants.IsReadonly);
                removeRequested = true;
            }

            if (this.lastAccessedChanged && !this.lastAccessed.HasValue)
            {
                removePropertyNames.Add(PropNameConstants.LastAccessed);
                removeRequested = true;
            }

            removeProp = Prop.CreatePropWithEmptyProperties(removePropertyNames.ToArray());

            if (this.additionalProperties.HasChanged)
            {
                var xElementList = this.additionalProperties.GetRemovedProperties();

                if (xElementList.Count > 0)
                {
                    removeProp.AdditionalProperties = xElementList;
                    removeRequested = true;
                }
            }

            // Build up PropertyUpdate.
            var propertyUpdate      = new PropertyUpdate();
            var propertyUpdateItems = new List <object>();

            if (setRequested)
            {
                var set = new Set()
                {
                    Prop = setProp
                };

                propertyUpdateItems.Add(set);
            }

            if (removeRequested)
            {
                var remove = new Remove()
                {
                    Prop = removeProp
                };

                propertyUpdateItems.Add(remove);
            }

            propertyUpdate.Items = propertyUpdateItems.ToArray();
            return(propertyUpdate);
        }
Esempio n. 30
0
        private async Task CreateAuditEntries(CreateAccountCommand message, CreateAccountResult returnValue, string hashedAccountId, User user)
        {
            //Account
            await _mediator.SendAsync(new CreateAuditCommand
            {
                EasAuditMessage = new EasAuditMessage
                {
                    Category          = "CREATED",
                    Description       = $"Account {message.OrganisationName} created with id {returnValue.AccountId}",
                    ChangedProperties = new List <PropertyUpdate>
                    {
                        PropertyUpdate.FromLong("AccountId", returnValue.AccountId),
                        PropertyUpdate.FromString("HashedId", hashedAccountId),
                        PropertyUpdate.FromString("Name", message.OrganisationName),
                        PropertyUpdate.FromDateTime("CreatedDate", DateTime.UtcNow),
                    },
                    AffectedEntity = new Entity {
                        Type = "Account", Id = returnValue.AccountId.ToString()
                    },
                    RelatedEntities = new List <Entity>()
                }
            });

            //LegalEntity
            var changedProperties = new List <PropertyUpdate>
            {
                PropertyUpdate.FromLong("Id", returnValue.LegalEntityId),
                PropertyUpdate.FromString("Name", message.OrganisationName),
                PropertyUpdate.FromString("Code", message.OrganisationReferenceNumber),
                PropertyUpdate.FromString("RegisteredAddress", message.OrganisationAddress),
                PropertyUpdate.FromString("OrganisationType", message.OrganisationType.ToString()),
                PropertyUpdate.FromString("PublicSectorDataSource", message.PublicSectorDataSource.ToString()),
                PropertyUpdate.FromString("Sector", message.Sector)
            };

            if (message.OrganisationDateOfInception != null)
            {
                changedProperties.Add(PropertyUpdate.FromDateTime("DateOfIncorporation", message.OrganisationDateOfInception.Value));
            }

            await _mediator.SendAsync(new CreateAuditCommand
            {
                EasAuditMessage = new EasAuditMessage
                {
                    Category          = "CREATED",
                    Description       = $"Legal Entity {message.OrganisationName} created of type {message.OrganisationType} with id {returnValue.LegalEntityId}",
                    ChangedProperties = changedProperties,
                    AffectedEntity    = new Entity {
                        Type = "LegalEntity", Id = returnValue.LegalEntityId.ToString()
                    },
                    RelatedEntities = new List <Entity>()
                }
            });

            //EmployerAgreement
            await _mediator.SendAsync(new CreateAuditCommand
            {
                EasAuditMessage = new EasAuditMessage
                {
                    Category          = "CREATED",
                    Description       = $"Employer Agreement Created for {message.OrganisationName} legal entity id {returnValue.LegalEntityId}",
                    ChangedProperties = new List <PropertyUpdate>
                    {
                        PropertyUpdate.FromLong("Id", returnValue.EmployerAgreementId),
                        PropertyUpdate.FromLong("LegalEntityId", returnValue.LegalEntityId),
                        PropertyUpdate.FromString("TemplateId", hashedAccountId),
                        PropertyUpdate.FromInt("StatusId", 2),
                    },
                    RelatedEntities = new List <Entity> {
                        new Entity {
                            Id = returnValue.EmployerAgreementId.ToString(), Type = "LegalEntity"
                        }
                    },
                    AffectedEntity = new Entity {
                        Type = "EmployerAgreement", Id = returnValue.EmployerAgreementId.ToString()
                    }
                }
            });

            //AccountEmployerAgreement Account Employer Agreement
            await _mediator.SendAsync(new CreateAuditCommand
            {
                EasAuditMessage = new EasAuditMessage
                {
                    Category          = "CREATED",
                    Description       = $"Employer Agreement Created for {message.OrganisationName} legal entity id {returnValue.LegalEntityId}",
                    ChangedProperties = new List <PropertyUpdate>
                    {
                        PropertyUpdate.FromLong("AccountId", returnValue.AccountId),
                        PropertyUpdate.FromLong("EmployerAgreementId", returnValue.EmployerAgreementId),
                    },
                    RelatedEntities = new List <Entity>
                    {
                        new Entity {
                            Id = returnValue.EmployerAgreementId.ToString(), Type = "LegalEntity"
                        },
                        new Entity {
                            Id = returnValue.AccountId.ToString(), Type = "Account"
                        }
                    },
                    AffectedEntity = new Entity {
                        Type = "AccountEmployerAgreement", Id = returnValue.EmployerAgreementId.ToString()
                    }
                }
            });

            //Paye
            await _mediator.SendAsync(new CreateAuditCommand
            {
                EasAuditMessage = new EasAuditMessage
                {
                    Category          = "CREATED",
                    Description       = $"Paye scheme {message.PayeReference} added to account {returnValue.AccountId}",
                    ChangedProperties = new List <PropertyUpdate>
                    {
                        PropertyUpdate.FromString("Ref", message.PayeReference),
                        PropertyUpdate.FromString("AccessToken", message.AccessToken),
                        PropertyUpdate.FromString("RefreshToken", message.RefreshToken),
                        PropertyUpdate.FromString("Name", message.EmployerRefName)
                    },
                    RelatedEntities = new List <Entity> {
                        new Entity {
                            Id = returnValue.AccountId.ToString(), Type = "Account"
                        }
                    },
                    AffectedEntity = new Entity {
                        Type = "Paye", Id = message.PayeReference
                    }
                }
            });

            //Membership Account
            await _mediator.SendAsync(new CreateAuditCommand
            {
                EasAuditMessage = new EasAuditMessage
                {
                    Category          = "CREATED",
                    Description       = $"User {message.ExternalUserId} added to account {returnValue.AccountId} as owner",
                    ChangedProperties = new List <PropertyUpdate>
                    {
                        PropertyUpdate.FromLong("AccountId", returnValue.AccountId),
                        PropertyUpdate.FromString("UserId", message.ExternalUserId),
                        PropertyUpdate.FromString("RoleId", Role.Owner.ToString()),
                        PropertyUpdate.FromDateTime("CreatedDate", DateTime.UtcNow)
                    },
                    RelatedEntities = new List <Entity>
                    {
                        new Entity {
                            Id = returnValue.AccountId.ToString(), Type = "Account"
                        },
                        new Entity {
                            Id = user.Id.ToString(), Type = "User"
                        }
                    },
                    AffectedEntity = new Entity {
                        Type = "Membership", Id = message.ExternalUserId
                    }
                }
            });
        }