private void recoverAccountItems(IsolatedStorageFile isolatedStorage, Dictionary<string, List<AccountItem>> transactionItems, List<string> fileMessages, List<Guid> accountIds, List<Guid> categoryIds = null) { var sum = 0; foreach (var pair in transactionItems) { var file = pair.Key; int num2 = 0; try { var allTasks = this.dataContext.TallyScheduleTable.Where(p => p.ProfileRecordType == ScheduleRecordType.ScheduledRecord) .ToList(); var taskId = Guid.Empty; TallySchedule taskInfo = allTasks.Count > 0 ? allTasks[0] : null; foreach (var item in pair.Value) { if (accountIds.Count(p => p == item.AccountId) > 0 && categoryIds.Count(p => p == item.CategoryId) > 0) { if (taskInfo != null && taskInfo.Id != item.AutoTokenId) { taskInfo = allTasks.FirstOrDefault(p => p.Id == item .AutoTokenId); } ExpenseOrIncomeScheduleHanlder.RecoverItemProcessor(item, taskInfo); sum++; } else { fileMessages.Add("Failed to add item: {0}, cause of account or category mismatched.".FormatWith(new object[] { item.Id })); } } } catch (System.Exception exception2) { num2++; string destinationFileName = pair.Key.Replace(".xml", ".err.xml"); fileMessages.Add("Failed to add items in file: {0}, cause of account or category mismatched. Have Renamed data file to {1}. details:\r\n{2}".FormatWith(new object[] { pair.Key, destinationFileName, exception2.Message })); isolatedStorage.MoveFile(file, destinationFileName); } if (num2 > 0) { this.SaveErrorsTo("recoveryDataError.log", new string[] { "Some items can't add to database.\r\n" + fileMessages.ToStringLine<string>("\r\n") }); } else { isolatedStorage.DeleteFile(file); } } this.dataContext.SubmitChanges(); }
private void recoverTransferingItems(IsolatedStorageFile isolatedStorage, Dictionary<string, List<TransferingItem>> transferingItems, List<string> fileMessages, List<Guid> accountIds) { var sum = 0; foreach (var pair in transferingItems) { var file = pair.Key; int num2 = 0; try { Deployment.Current.Dispatcher.BeginInvoke(() => { foreach (var item in pair.Value) { if ((accountIds.Count(p => p == item.FromAccountId) > 0) && (accountIds.Count(p => p == item.ToAccountId) > 0)) { sum++; TransferingItemTaskHandler.RecoverItemProcessor(item); } else { fileMessages.Add("Failed to add item: {0}, cause of account missed.".FormatWith(new object[] { item.Id })); } } }); } catch (System.Exception exception2) { num2++; string destinationFileName = pair.Key.Replace(".xml", ".err.xml"); fileMessages.Add("Failed to add items in file: {0}, cause of account or category mismatched. Have Renamed data file to {1}. details:\r\n{2}".FormatWith(new object[] { pair.Key, destinationFileName, exception2.Message })); isolatedStorage.MoveFile(file, destinationFileName); } if (num2 > 0) { this.SaveErrorsTo("recoveryDataError.log", new string[] { "Some items can't add to database.\r\n" + fileMessages.ToStringLine<string>("\r\n") }); } else { isolatedStorage.DeleteFile(file); } } this.dataContext.SubmitChanges(); }