Example #1
0
        public void SetOperationCodes(IEnumerable <OperationCode> operationCodes)
        {
            var operationCodesList = operationCodes as IList <OperationCode> ?? operationCodes.ToList();

            if (operationCodesList.Any(p => !OperationCodeMetadata.IsCodeOfOperationType(p, NotificationType)))
            {
                throw new InvalidOperationException(string.Format("This notification {0} can only have {1} operation codes.", Id, NotificationType));
            }

            OperationInfosCollection.Clear();

            foreach (var operationCode in operationCodesList)
            {
                OperationInfosCollection.Add(new OperationInfo(operationCode));
            }
        }
Example #2
0
        public static OperationCodesList CreateForNotification(ImportNotification notification,
                                                               IEnumerable <OperationCode> operationCodes)
        {
            var codes = operationCodes as OperationCode[] ?? operationCodes.ToArray();

            if (!codes.Any())
            {
                throw new ArgumentException("Operation codes can't be empty", "operationCodes");
            }

            if (!codes.IsUnique())
            {
                throw new ArgumentException("Operation codes must be unique", "operationCodes");
            }

            if (codes.Any(p => !OperationCodeMetadata.IsCodeOfOperationType(p, notification.NotificationType)))
            {
                throw new ArgumentException(
                          string.Format("This notification {0} can only have {1} operation codes.",
                                        notification.Id, notification.NotificationType), "operationCodes");
            }

            return(new OperationCodesList(codes));
        }