public ApiCollection GetDtoCollection(ApiCollection entityCollection, BaseSearchParams searchParams) { if (searchParams.Fields == null) { var items = _mapper.Map <IEnumerable <ValueReadDto> >(entityCollection.Items); return(new ApiCollection(items) { TotalCount = entityCollection.TotalCount }); } else { var newItems = new List <object>(); foreach (var item in entityCollection.Items) { newItems.Add(_mapper.DynamicMap(item, searchParams.Fields)); } var result = new ApiCollection(newItems); result.TotalCount = entityCollection.TotalCount; return(result); } }
public Battle(Province province, List <Army> friendlyArmies, List <Army> enemyArmies, int friendlyLosses, int enemyLosses) : base(MessageType.Battle) { Province = province.Api; FriendlyArmies = new ApiCollection <ArmyApi>(friendlyArmies); EnemeyArmies = new ApiCollection <ArmyApi>(enemyArmies); FriendlyLosses = friendlyLosses; EnemyLosses = enemyLosses; _countryA = friendlyArmies[0].Owner; _countryB = enemyArmies[0].Owner; _countryA.Player.MessageQueue.Enqueue(this); }
private static async void RunSample() { constBaseUrl = String.Format(constBaseUrl, constAccount, "{0}"); using (HttpClient client = new HttpClient()) { //set default RequestHeader client.DefaultRequestHeaders.Accept.Add( new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); //Set alternate credentials client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String( System.Text.ASCIIEncoding.ASCII.GetBytes( string.Format("{0}:{1}", _altUsername, _altPassword)))); //read all projects of the account ApiCollection <ProjectDefinition> projects = await LoadTeamProjects(client); Console.WriteLine("Choose one of the following projects: "); int projectNo = 0; //check if there are some projects available if (projects.Value.Count() == 0) { Console.WriteLine("There are no projects in your account."); Console.ReadLine(); return; } //select one of available projects foreach (ProjectDefinition item in projects.Value) { Console.WriteLine(String.Format("{0}: {1} - {2}", projectNo.ToString(), item.Name, item.ID)); projectNo++; } Console.Write("Select a project number: "); string number = Console.ReadLine(); //search for project in projects ProjectDefinition project = projects.GetIndex(projects.Value, Convert.ToInt32(number)); //load team project with capabilities //just for showing different return values for same DataContract LoadTeamProject(client, project); //load work items LoadWorkItems(client, project.Name); } Console.WriteLine("----------------------------------------------------------------------------------"); Console.ReadLine(); }
private IEnumerable <ApiItem> MapFromDb(IEnumerable <DbApiItem> dbApis, ILookup <int, DbApiItem> dbApiItemsByParentId) { foreach (var dbApiItem in dbApis) { ApiItem apiItem; if (dbApiItem.Type == ApiItemType.Api) { apiItem = new Api { Type = ApiItemType.Api, Url = dbApiItem.Url, Method = dbApiItem.Method, Inputs = MapChildrenFromDb(dbApiItem.Inputs, y => new ApiInput { Id = y.Id, Name = y.Name, DefaultValue = y.DefaultValue, InputType = y.InputType }).ToRxList(), Outputs = MapChildrenFromDb(dbApiItem.Outputs, y => new ApiOutput { Id = y.Id, Name = y.Name, Type = y.Type, Expression = y.Expression }).ToRxList(), Headers = MapChildrenFromDb(dbApiItem.Headers, y => new ApiHeader { Id = y.Id, Name = y.Name, Value = y.Value }).ToRxList(), Body = dbApiItem.RequestBody }; } else { apiItem = new ApiCollection { Type = ApiItemType.Collection, Items = MapFromDb(dbApiItemsByParentId[dbApiItem.Id], dbApiItemsByParentId).ToRxList() }; } apiItem.Id = dbApiItem.Id; apiItem.Created = dbApiItem.Created; apiItem.Title = dbApiItem.Title; itemsById = itemsById.Add(apiItem.Id, apiItem); Bind(apiItem, dbApiItem); yield return(apiItem); } }
public async Task AddApiCollectionWithChild() { var collection = new ApiCollection { Items = new RxList <ApiItem>(new Api()) }; await repository.AddItem(collection); var dbApiItem = await db.ApiItems.Include(x => x.Items).SingleAsync(x => x.Id == collection.Id); Assert.AreEqual(1, dbApiItem.Items.Count); }
public ApiCollectionModel(MainWindowModel mainWindow, ApiCollectionModel parent, ApiCollection apiCollection) : base(mainWindow, parent, apiCollection) { Model = apiCollection; if (apiCollection.Items != null) Items.AddRange(apiCollection.Items.Select(x => x.Type == ApiItemType.Collection ? (ApiItemModel)new ApiCollectionModel(mainWindow, this, (ApiCollection)x) : new ApiModel(mainWindow, this, (Api)x))); Items.SetUpSync( MainWindow.Repository, Model.Items, x => x.ItemModel); }
public ApiCollectionModel(MainWindowModel mainWindow, ApiCollectionModel parent, ApiCollection apiCollection) : base(mainWindow, parent, apiCollection) { Model = apiCollection; if (apiCollection.Items != null) { Items.AddRange(apiCollection.Items.Select(x => x.Type == ApiItemType.Collection ? (ApiItemModel) new ApiCollectionModel(mainWindow, this, (ApiCollection)x) : new ApiModel(mainWindow, this, (Api)x))); } Items.SetUpSync( MainWindow.Repository, Model.Items, x => x.ItemModel); }
public async Task InsertMinimalApiCollection() { var collection = new ApiCollection { Title = "test title", Type = ApiItemType.Collection, Created = new DateTime(2015, 1, 1) }; await repository.AddItem(collection); Assert.AreNotEqual(0, collection.Id); var dbApiItem = await db.ApiItems.SingleAsync(x => x.Id == collection.Id); Assert.AreEqual(collection.Title, dbApiItem.Title); Assert.AreEqual(collection.Type, dbApiItem.Type); Assert.AreEqual(collection.Created, dbApiItem.Created); }
public async Task <ApiCollection> Get(BaseSearchParams s) { var items = _context.Values.Include(v => v.Children); var count = items.Count(); items = items.DynamicSort(s.Sort); items = items.Page(s.Page.Value, s.Items.Value); IQueryable result = items; if (s.Fields != null) { result = await items.SelectAsync(string.Format("new ({0})", s.Fields)); } var apiCollection = new ApiCollection(await result.ToListAsync()) { TotalCount = count }; return(apiCollection); }
public async Task CreateThreeLevelHierarchy() { var rootCollection = new ApiCollection { Items = new RxList <ApiItem>(), Title = "Root" }; await repository.AddItem(rootCollection); await repository.WaitForIdle(); var childCollection = new ApiCollection { Items = new RxList <ApiItem>(), Title = "Child" }; rootCollection.Items.Add(childCollection); await repository.WaitForIdle(); var leaf = new Api { Title = "Leaf" }; childCollection.Items.Add(leaf); await repository.WaitForIdle(); var newRepository = new DbRepository(db); await newRepository.Load(); var loadedRootCollection = (ApiCollection)newRepository.Items.Single(); Assert.AreEqual(rootCollection.Title, loadedRootCollection.Title); var loadedChildCollection = (ApiCollection)loadedRootCollection.Items.Single(); Assert.AreEqual(childCollection.Title, loadedChildCollection.Title); var loadedLeaf = (Api)loadedChildCollection.Items.Single(); Assert.AreEqual(leaf.Title, loadedLeaf.Title); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var json = JObject.Load(reader); var type = (ApiItemType)JsonConvert.DeserializeObject(json.GetValue(nameof(ApiItem.Type)).ToString(Formatting.Indented), typeof(ApiItemType)); ApiItem item; switch (type) { case ApiItemType.Api: item = new Api(); break; case ApiItemType.Collection: item = new ApiCollection(); break; default: throw new Exception(); } serializer.Populate(json.CreateReader(), item); return(item); }
private async Task <ApiCollectionModel> OnAddApiCollection(ApiCollectionModel parent) { var apiCollection = ApiCollection.Create(); if (parent == null) { await Repository.AddItem(apiCollection); } var model = new ApiCollectionModel(this, parent, apiCollection); if (parent == null) { Items.Add(model); } else { parent.Items.Add(model); } SelectedItem = model; return(model); }
public static IValuesRepository GetValueRepositoryMock() { var mock = new Mock <IValuesRepository>(); mock.Setup(m => m.Get(It.IsAny <BaseSearchParams>())).Returns <BaseSearchParams>(s => { var task = Task.Factory.StartNew(() => { var items = values.AsQueryable(); var count = values.Count; if (s.Fields != null) { items = items.DynamicSelect(s.Fields); } items = items.DynamicSort(s.Sort); items = items.Page(s.Page.Value, s.Items.Value); var apiCollection = new ApiCollection(items.ToList()) { TotalCount = count }; return(apiCollection); }); return(task); }); mock.Setup(m => m.Get(It.IsAny <int>())).Returns <int>(i => Task.Factory.StartNew(() => { var value = values.First <Value, NotFoundException>(v => v.Id == i, string.Format("Value with id {0} not found.", i)); return(value); })); mock.Setup(m => m.Update(It.IsAny <int>(), It.IsAny <Value>())).Returns <int, Value>((i, v) => { var task = Task.Factory.StartNew(() => { var index = values.IndexOf(v); if (index == -1) { var toBeUpdated = values.First <Value, NotFoundException>(va => va.Id == i, string.Format("Value with id {0} not found.", i)); index = values.IndexOf(toBeUpdated); } values[index] = v; return(v); }); return(task); }); mock.Setup(m => m.Add(It.IsAny <Value>())).Returns <Value>(v => { var task = Task.Factory.StartNew(() => { values.Add(v); v.Id = values.Count; return(v); }); return(task); }); mock.Setup(m => m.Delete(It.IsAny <int>())).Returns <int>((i) => { var task = Task.Factory.StartNew(() => { var value = values.First <Value, NotFoundException>(v => v.Id == i, string.Format("Value with id {0} not found.", i)); values.Remove(value); }); return(task); }); return(mock.Object); }
private static void ApiCollectionSaveMapper(ApiCollection apiCollection, DbApiItem dbApiItem) { ApiItemSaveMapper(apiCollection, dbApiItem); dbApiItem.Type = ApiItemType.Collection; }
public static ApiCollectionModel Import(MainWindowModel mainWindow, ApiCollectionModel parent, ApiCollection apiCollection) { return new ApiCollectionModel(mainWindow, parent, apiCollection); }
public async Task UpdateCollectionAddApiChild() { var collection = new ApiCollection { Items = new RxList<ApiItem>() }; await repository.AddItem(collection); collection.Items.Add(new Api()); await repository.WaitForIdle(); var dbApiItem = await db.ApiItems.Include(x => x.Items).SingleAsync(x => x.Id == collection.Id); Assert.AreEqual(1, dbApiItem.Items.Count); }
public async Task CreateThreeLevelHierarchy() { var rootCollection = new ApiCollection { Items = new RxList<ApiItem>(), Title = "Root" }; await repository.AddItem(rootCollection); await repository.WaitForIdle(); var childCollection = new ApiCollection { Items = new RxList<ApiItem>(), Title = "Child" }; rootCollection.Items.Add(childCollection); await repository.WaitForIdle(); var leaf = new Api { Title = "Leaf" }; childCollection.Items.Add(leaf); await repository.WaitForIdle(); var newRepository = new DbRepository(db); await newRepository.Load(); var loadedRootCollection = (ApiCollection)newRepository.Items.Single(); Assert.AreEqual(rootCollection.Title, loadedRootCollection.Title); var loadedChildCollection = (ApiCollection)loadedRootCollection.Items.Single(); Assert.AreEqual(childCollection.Title, loadedChildCollection.Title); var loadedLeaf = (Api)loadedChildCollection.Items.Single(); Assert.AreEqual(leaf.Title, loadedLeaf.Title); }
public static ApiCollectionModel Import(MainWindowModel mainWindow, ApiCollectionModel parent, ApiCollection apiCollection) { return(new ApiCollectionModel(mainWindow, parent, apiCollection)); }