public Printer() { _userService = new UserService(); _users = _userService.Get(); _view = new Views(); _creation = new Creations(); }
public async Task ImportCreationAsync(string creationFilename) { using (await _asyncLock.LockAsync()) { var creationJson = await File.ReadAllTextAsync(creationFilename); var creation = JsonConvert.DeserializeObject <Creation>(creationJson); var creationName = creation.Name; if (!IsCreationNameAvailable(creationName)) { for (var suffix = 1; suffix < 1000; suffix++) { var newCreationName = $"{creationName} {suffix}"; if (IsCreationNameAvailable(newCreationName)) { creationName = newCreationName; break; } } } creation.Name = creationName; await _creationRepository.InsertCreationAsync(creation); Creations.Add(creation); } }
public async Task<bool> IsCreationNameAvailableAsync(string creationName) { using (await _asyncLock.LockAsync()) { return Creations.All(c => c.Name != creationName); } }
public async Task DeleteCreationAsync(Creation creation) { using (await _asyncLock.LockAsync()) { await _creationRepository.DeleteCreationAsync(creation); Creations.Remove(creation); } }
public async Task<Creation> AddCreationAsync(string creationName) { using (await _asyncLock.LockAsync()) { var creation = new Creation { Name = creationName }; await _creationRepository.InsertCreationAsync(creation); Creations.Add(creation); return creation; } }
public async Task LoadCreationsAndSequencesAsync() { using (await _asyncLock.LockAsync()) { Creations.Clear(); var creations = await _creationRepository.GetCreationsAsync(); foreach (var creation in creations) { Creations.Add(creation); } Sequences.Clear(); var sequences = await _creationRepository.GetSequencesAsync(); foreach (var sequence in sequences) { Sequences.Add(sequence); } } }
private bool IsCreationNameAvailable(string creationName) { return(Creations.All(c => c.Name != creationName)); }
/// <summary> /// Increments the number of times the given type has been created /// </summary> /// <param name="type">The type</param> public static void InstanceCreated(Type type) { Creations.AddOrUpdate(type, 1, (type1, i) => i + 1); }