public void Short_byte_arrays_are_not_truncated()
        {
            var shortArray = new Guid("21EC2020-3AEA-4069-A2DD-08002B30309D").ToByteArray();
            var longerShortArray = shortArray.Concat(shortArray).ToArray();

            Assert.Equal("0x2020EC21EA3A6940A2DD08002B30309D", RelationalLoggerExtensions.FormatParameterValue(shortArray));
            Assert.Equal("0x2020EC21EA3A6940A2DD08002B30309D2020EC21EA3A6940A2DD08002B30309D", RelationalLoggerExtensions.FormatParameterValue(longerShortArray));
        }
        public void Long_byte_arrays_are_truncated()
        {
            var shortArray = new Guid("21EC2020-3AEA-4069-A2DD-08002B30309D").ToByteArray();
            var longArray = shortArray.Concat(shortArray).Concat(shortArray).ToArray();

            var builder = new StringBuilder();
            RelationalLoggerExtensions.FormatParameterValue(builder, longArray);

            Assert.Equal("'0x2020EC21EA3A6940A2DD08002B30309D2020EC21EA3A6940A2DD08002B30309D...'", builder.ToString());
        }
        public void MultipleOperations_CompletedOperations_Test()
        {
            IOperationsManager operationsManager = GetOperationsManager();

            int numberOfOperations = 500;
            Guid[] completed = new Guid[numberOfOperations];
            Guid[] running = new Guid[numberOfOperations];
            Guid[] failed = new Guid[numberOfOperations];
            Guid[] canceled = new Guid[numberOfOperations];
            Guid[] pendingCancelation = new Guid[numberOfOperations];
            for (int i = 0; i < numberOfOperations; i++)
            {
                completed[i] = operationsManager.RegistrOperation(OPERATION_DISPLAY_NAME);
                running[i] = operationsManager.RegistrOperation(OPERATION_DISPLAY_NAME);
                failed[i] = operationsManager.RegistrOperation(OPERATION_DISPLAY_NAME);
                canceled[i] = operationsManager.RegistrOperation(OPERATION_DISPLAY_NAME);
                pendingCancelation[i] = operationsManager.RegistrOperation(OPERATION_DISPLAY_NAME);
            }
            foreach (var guid in pendingCancelation)
            {
                operationsManager.SetOperationCancelFlag(guid);
            }
            foreach (var guid in completed)
            {
                operationsManager.SetOperationResult(guid, null);
            }
            foreach (var guid in failed)
            {
                operationsManager.SetOperationFailed(guid, new Exception(FAILURE_REASON));
            }
            foreach (var guid in canceled)
            {
                operationsManager.SetOperationCanceled(guid);
            }
            Guid[] completedOperations = operationsManager.GetCompletedOperations();
            CollectionAssert.AreEquivalent(completed.Concat(failed).Concat(canceled).ToArray(), completedOperations);
        }
 public GuidExecutionResults RemoveImportQueueRecordRange(Guid[] identifiers)
 {
     UpdateSessionCulture();
     using (var logSession = Helpers.Log.Session($"{GetType()}.{System.Reflection.MethodBase.GetCurrentMethod().Name}()", VerboseLog, RaiseLog))
         try
         {
             using (var rep = GetNewRepository(logSession))
             {
                 logSession.Add($"Try to get account import queue records with ids = '{identifiers.Concat(i => i.ToString(), ",")}' from database...");
                 var itemsToRemove = rep.Get<RoyaltyRepository.Models.ImportQueueRecord>(a => identifiers.Contains(a.ImportQueueRecordUID)).ToArray();
                 logSession.Add($"Accounts import queue records found for remove: {itemsToRemove.Length}");
                 rep.RemoveRange(itemsToRemove);
                 rep.SaveChanges();
                 return new GuidExecutionResults(itemsToRemove.Select(i => i.ImportQueueRecordUID).ToArray());
             }
         }
         catch (Exception ex)
         {
             ex.Data.Add(nameof(identifiers), identifiers.Concat(i => i.ToString(),","));
             logSession.Enabled = true;
             logSession.Add(ex);
             return new GuidExecutionResults(ex);
         }
 }
        /// <summary>
        /// Remove photo to employee
        /// </summary>
        /// <param name="employeeId">Employee identifier</param>
        /// <param name="photoIdentifier">Employee photo identifier</param>
        public Model.EmployeePhotoExecutionResults EmployeePhotosRemove(long employeeId, Guid[] photoIdentifiers)
        {
            UpdateSessionCulture();
            using (var logSession = Helpers.Log.Session($"{GetType()}.{System.Reflection.MethodBase.GetCurrentMethod().Name}()", VerboseLog, RaiseLog))
                try
                {
                    var emp = EmployeeGet(employeeId);
                    if (emp.Exception != null)
                        throw emp.Exception;

                    using (var rep = GetNewRepository(logSession))
                    {
                        photoIdentifiers.ToList().ForEach(photoIdentifier => {
                            var dbPhoto = rep.Get<Repository.Model.EmployeePhoto>(e => e.FileId == photoIdentifier).SingleOrDefault();
                            if (dbPhoto == null)
                                throw new Exception(string.Format(Properties.Resources.FILESERVICE_FileNotFound, photoIdentifier));
                            rep.Remove(dbPhoto, saveAfterRemove: false);
                        });
                        rep.SaveChanges(true);
                    }

                    return EmployeePhotosGet(employeeId);
                }
                catch (Exception ex)
                {
                    ex.Data.Add(nameof(employeeId), employeeId);
                    ex.Data.Add(nameof(photoIdentifiers), photoIdentifiers.Concat(i => i.ToString(),", "));
                    logSession.Enabled = true;
                    logSession.Add(ex);
                    return new EmployeePhotoExecutionResults(ex);
                }
        }
示例#6
0
 /// <summary>
 /// Get file infos by identifiers
 /// </summary>
 /// <param name="identifiers">File info identifiers</param>
 /// <returns>Files info</returns>
 public FileExecutionResults GetRange(Guid[] identifiers)
 {
     UpdateSessionCulture();
     using (var logSession = Helpers.Log.Session($"{GetType()}.{System.Reflection.MethodBase.GetCurrentMethod().Name}()", VerboseLog, RaiseLog))
         try
         {
             using (var rep = GetNewRepository(logSession))
             {
                 var res = rep.Get<RoyaltyRepository.Models.File>(f => identifiers.Contains(f.FileUID))
                     .ToArray()
                     .Select(f => Mapper.Map<Model.File>(f))
                     .ToArray();
                 return new FileExecutionResults(res);
             }
         }
         catch (Exception ex)
         {
             ex.Data.Add(nameof(identifiers), identifiers.Concat(i => i.ToString("N"), ","));
             logSession.Enabled = true;
             logSession.Add(ex);
             return new FileExecutionResults(ex);
         }
 }