private void RefreshListView() { ModelService modelService = new ModelService(); List <DrugFrom> modelList = modelService.GetAllDrugFrom(); this.FillDataGridView(modelList); }
public async Task DoesNotLogInWhenRetrievingOauthTokenFails() { var apiClient = Substitute.For <IApiClient>(); apiClient.HostAddress.Returns(HostAddress.GitHubDotComHostAddress); apiClient.GetOrCreateApplicationAuthenticationCode( Args.TwoFactorChallengCallback, Args.String, Args.Boolean) .Returns(Observable.Throw <ApplicationAuthorization>(new NotFoundException("", HttpStatusCode.BadGateway))); apiClient.GetUser().Returns(Observable.Return(CreateUserAndScopes("jiminy"))); var hostCache = new InMemoryBlobCache(); var modelService = new ModelService(apiClient, hostCache, Substitute.For <IAvatarProvider>()); var loginCache = new TestLoginCache(); var host = new RepositoryHost(apiClient, modelService, loginCache, Substitute.For <ITwoFactorChallengeHandler>()); await Assert.ThrowsAsync <NotFoundException>(async() => await host.LogIn("jiminy", "cricket")); await Assert.ThrowsAsync <KeyNotFoundException>( async() => await hostCache.GetObject <AccountCacheItem>("user")); var loginInfo = await loginCache.GetLoginAsync(HostAddress.GitHubDotComHostAddress); Assert.Equal("jiminy", loginInfo.UserName); Assert.Equal("cricket", loginInfo.Password); Assert.False(host.IsLoggedIn); }
public ActionResult Cars(int modelId) { var cars = Mapper.Map <IEnumerable <CarDTO>, IList <CarViewModel> >(carService.GetAllCars(modelId)); var car = new CarViewModel(); if (cars.Count() == 0) { IModelService modelService = new ModelService(); var model = modelService.GetModel(modelId); ViewBag.BrandPhoto = model.Brand.Photo; ViewBag.ModelName = model.Name; ViewBag.ModelPhoto = model.PhotoUrl; car.BrandId = model.BrandId; TempData["BrandID"] = model.BrandId; TempData["modelID"] = model.Id; } else { car = cars.First(); ViewBag.BrandPhoto = car.Brand.Photo; ViewBag.ModelName = car.Model.Name; ViewBag.ModelPhoto = car.Model.PhotoUrl; TempData["BrandID"] = car.BrandId; TempData["modelID"] = car.ModelId; } ViewBag.Colors = Auxiliary.GetStringMassOfColorEnums(); ViewBag.VolEngines = Auxiliary.GetStringMassOfVolumeEngine(); return(View(car)); }
private void RefreshListView() { ModelService modelService = new ModelService(); List <Storehouse> modelList = modelService.GetAllStorehouse(); this.FillDataGridView(modelList); }
public async Task <ActionResult <PageResultDto <RequestStateListDto> > > GetByRequestId(int requestId, CancellationToken cancellationToken) { //var result = await new PageResultDto<RequestStateListDto>( // ModelService.AsQueryable(r => r.RequestId == requestId) // .Select(p => new RequestStateListDto // { // Id = p.Id, // RequestId = p.RequestId, // WorkflowStepId = p.WorkflowStepId, // WorkflowStep = p.WorkflowStep, // StartStepDate = p.StartStepDate, // FinishedDate = p.FinishedDate, // Description = p.Description, // IsDone = p.IsDone, // AgentId = p.AgentId, // }), new PageRequestDto(100, 1)) // .GetPage(cancellationToken); var result = await GetPageResultAsync( ModelService.AsQueryable(i => i.RequestId == requestId), new PageRequestDto(100, 0), new NullFilter <RequestState>(), cancellationToken); return(result); }
public async Task CanRetrieveUserFromCacheAndAccountsFromApi() { var orgs = new[] { CreateOctokitOrganization("github"), CreateOctokitOrganization("fake") }; var apiClient = Substitute.For <IApiClient>(); apiClient.GetOrganizations().Returns(orgs.ToObservable()); var cache = new InMemoryBlobCache(); var modelService = new ModelService(apiClient, cache, Substitute.For <IAvatarProvider>()); await modelService.InsertUser(new AccountCacheItem(CreateOctokitUser("octocat"))); var fetched = await modelService.GetAccounts(); Assert.Equal(3, fetched.Count); Assert.Equal("octocat", fetched[0].Login); Assert.Equal("github", fetched[1].Login); Assert.Equal("fake", fetched[2].Login); var cachedOrgs = await cache.GetObject <IReadOnlyList <AccountCacheItem> >("octocat|orgs"); Assert.Equal(2, cachedOrgs.Count); Assert.Equal("github", cachedOrgs[0].Login); Assert.Equal("fake", cachedOrgs[1].Login); var cachedUser = await cache.GetObject <AccountCacheItem>("user"); Assert.Equal("octocat", cachedUser.Login); }
// GET: Exhibition public ActionResult Index(User user) { List <Country> countries = ModelService.getCountries().FindAll().ToList(); ViewBag.CountryList = countries.Select(s => new SelectListItem() { Text = s.Name, Value = s.Id.ToString() }).ToList(); List <City> cities = ModelService.getCities().FindAll().ToList(); user.City = cities.FirstOrDefault(f => f.Id == user.CityId); user.Country = countries.FirstOrDefault(f => f.Id == user.CountryId); if (ModelState.IsValid) { user.Status = false; if (ModelService.AddUser(user) && user.FullName != null) { if (TempData.ContainsKey("User")) { TempData["User"] = user; } else { TempData.Add("User", user); } return(RedirectToAction("AfterRegistration")); } } return(View()); }
public async Task <IModelService> CreateAsync(IConnection connection) { ModelService result; await cacheLock.WaitAsync(); try { if (!cache.TryGetValue(connection, out result)) { result = new ModelService( await apiClientFactory.Create(connection.HostAddress), await graphQLClientFactory.CreateConnection(connection.HostAddress), await hostCacheFactory.Create(connection.HostAddress), avatarProvider); result.InsertUser(AccountCacheItem.Create(connection.User)); cache.Add(connection, result); } } finally { cacheLock.Release(); } return(result); }
protected override void Insert() { if (IsValid()) { Category category = null; if (Status == ModelStatus.OnEdit) { category = CurrentItem; } if (category == null) { category = new Category(); } category.Name = CurrentItem.Name; category.Description = CurrentItem.Description; if (ModelService.Insert(category)) { Global.SubmissionSuceeded(ModelWindow); Load(); } else { Global.SubmissionFailed(ModelWindow); } } }
App() { if (_enforcer.ShouldApplicationExit()) { Shutdown(); } try { new Thread(() => DataS = new DbService()) { Priority = ThreadPriority.Highest }.Start(); new Thread(() => ModelS = new ModelService()) { Priority = ThreadPriority.Highest }.Start(); } catch (Exception e) { MessageBox.Show(e.Message); Current.Shutdown(); } // todo : Login Form Here }
public ActionResult Index() { //dbcontext.Database.ExecuteSqlCommand("TRUNCATE TABLE [PostalCode]"); if (CountNumberOfItems("PostalCode") <= 0) { ModelService.InsertPostalCodes(); } if (CountNumberOfItems("ConfigParams") <= 0) { ModelService.InsertConfigParams(); } if (CountNumberOfItems("County") <= 0) { ModelService.InsertCounty(); } if (CountNumberOfItems("Constituency") <= 0) { ModelService.InsertConstituency(); } if (CountNumberOfItems("Ward") <= 0) { ModelService.InsertWard(); } if (CountNumberOfItems("period") != 2) { dbcontext.Posting.RemoveRange(dbcontext.Posting); dbcontext.SaveChanges(); ModelService.InsertPosting(); } return(View()); }
internal static Selection SelectAll(EditingContext context, bool local) { if (context == null) { throw new ArgumentNullException("context"); } ModelService requiredService = context.Services.GetRequiredService <ModelService>(); Selection s = context.Items.GetValue <Selection>(); Selection selection = new Selection(); ModelItem primarySelection = s.PrimarySelection; if (local && primarySelection != null) { if (!SelectionImplementation.IsMultiSelection(s) && primarySelection.Content != (ModelProperty)null) { selection = SelectionImplementation.SelectContent(primarySelection); if (selection.PrimarySelection == null && primarySelection.Parent != null) { selection = SelectionImplementation.SelectContent(primarySelection.Parent); } } else if (SelectionImplementation.AreSiblings(s)) { selection = SelectionImplementation.SelectContent(primarySelection.Parent); } } if (selection.PrimarySelection == null) { selection = new Selection(SelectionImplementation.EnumerateContents(requiredService.Root)); } context.Items.SetValue((ContextItem)selection); return(selection); }
internal static Selection SelectParent(EditingContext context) { if (context == null) { throw new ArgumentNullException("context"); } ModelService requiredService = context.Services.GetRequiredService <ModelService>(); Selection s = context.Items.GetValue <Selection>(); Selection selection = new Selection(); ModelItem primarySelection = s.PrimarySelection; if (SelectionImplementation.AreSiblings(s)) { selection = new Selection(new ModelItem[1] { primarySelection.Parent }); } if (selection.PrimarySelection == null) { selection = new Selection(new ModelItem[1] { requiredService.Root }); } context.Items.SetValue((ContextItem)selection); return(selection); }
public async Task RetriesUsingOldScopeWhenAuthenticationFailsAndIsEnterprise() { var enterpriseHostAddress = HostAddress.Create("https://enterprise.example.com/"); var apiClient = Substitute.For <IApiClient>(); apiClient.HostAddress.Returns(enterpriseHostAddress); apiClient.GetOrCreateApplicationAuthenticationCode(Args.TwoFactorChallengCallback, null, false, true) .Returns(Observable.Throw <ApplicationAuthorization>(new ApiException("Bad scopes", (HttpStatusCode)422))); apiClient.GetOrCreateApplicationAuthenticationCode(Args.TwoFactorChallengCallback, null, true, false) .Returns(Observable.Return(new ApplicationAuthorization("T0k3n"))); apiClient.GetUser().Returns(Observable.Return(CreateUserAndScopes("jiminy"))); var hostCache = new InMemoryBlobCache(); var modelService = new ModelService(apiClient, hostCache, Substitute.For <IAvatarProvider>()); var loginCache = new TestLoginCache(); var usage = Substitute.For <IUsageTracker>(); var host = new RepositoryHost(apiClient, modelService, loginCache, Substitute.For <ITwoFactorChallengeHandler>(), usage); await host.LogIn("jiminy", "aPassowrd"); Assert.True(host.IsLoggedIn); var loginInfo = await loginCache.GetLoginAsync(enterpriseHostAddress); Assert.Equal("jiminy", loginInfo.UserName); Assert.Equal("T0k3n", loginInfo.Password); }
public static Selection Toggle(EditingContext context, ModelItem itemToToggle) { if (context == null) { throw new ArgumentNullException("context"); } if (itemToToggle == null) { throw new ArgumentNullException("itemToToggle"); } List <ModelItem> list = new List <ModelItem>(context.Items.GetValue <Selection>().SelectedObjects); if (list.Contains(itemToToggle)) { list.Remove(itemToToggle); } else { list.Insert(0, itemToToggle); } if (list.Count == 0) { ModelService service = context.Services.GetService <ModelService>(); if (service != null) { list.Add(service.Root); } } Selection selection = new Selection((IEnumerable <ModelItem>)list); context.Items.SetValue((ContextItem)selection); return(selection); }
// // Multi-threaded implementation - see http://msdn.microsoft.com/en-us/library/ff650316.aspx // // This approach ensures that only one instance is created and only when the instance is needed. // Also, the variable is declared to be volatile to ensure that assignment to the instance variable // completes before the instance variable can be accessed. Lastly, this approach uses a syncRoot // instance to lock on, rather than locking on the type itself, to avoid deadlocks. // // NOTE : This singleton instance causes memory leaks ;) #endregion #region SerializeWorkflow public StringBuilder SerializeWorkflow(ModelService modelService) { var builder = GetActivityBuilder(modelService); var text = GetXamlDefinition(builder); return(text); }
public async Task CanRetrieveAndCacheLicenses() { var licenses = new[] { new LicenseMetadata("mit", "MIT", new Uri("https://github.com/")), new LicenseMetadata("apache", "Apache", new Uri("https://github.com/")) }; var apiClient = Substitute.For <IApiClient>(); apiClient.GetLicenses().Returns(licenses.ToObservable()); var cache = new InMemoryBlobCache(); var modelService = new ModelService(apiClient, cache, Substitute.For <IAvatarProvider>()); var fetched = await modelService.GetLicenses(); Assert.Equal(3, fetched.Count); Assert.Equal("None", fetched[0].Name); Assert.Equal("MIT", fetched[1].Name); Assert.Equal("Apache", fetched[2].Name); var cached = await cache.GetObject <IReadOnlyList <ModelService.LicenseCacheItem> >("licenses"); Assert.Equal(2, cached.Count); Assert.Equal("mit", cached[0].Key); Assert.Equal("apache", cached[1].Key); }
public void RefreshListView() { ModelService service = new ModelService(); List <Storehouse> modelList = service.GetAllStorehouses(); this.dataGridView1.Rows.Clear(); foreach (Storehouse model in modelList) { DataGridViewRow row = new DataGridViewRow(); DataGridViewCell cell = null; cell = new DataGridViewCheckBoxCell(); row.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = model.Code; row.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = model.Name; row.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = model.Actived ? "否" : "是"; row.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = model.Remark; row.Cells.Add(cell); this.dataGridView1.Rows.Add(row); row.Tag = model; } }
protected override void InternalDeployWebModel(ProvisionServiceContext context) { var clientContext = context.Context as ClientContext; var model = context.Model; ModelService.DeployModel(WebModelHost.FromClientContext(clientContext), model); }
public IObservable <Unit> LogOut() { if (!IsLoggedIn) { return(Observable.Return(Unit.Default)); } log.Info(CultureInfo.InvariantCulture, "Logged off of host '{0}'", hostAddress.ApiUri); return(loginCache.EraseLogin(Address) .Catch <Unit, Exception>(e => { log.Warn("ASSERT! Failed to erase login. Going to invalidate cache anyways.", e); return Observable.Return(Unit.Default); }) .SelectMany(_ => ModelService.InvalidateAll()) .Catch <Unit, Exception>(e => { log.Warn("ASSERT! Failed to invaldiate caches", e); return Observable.Return(Unit.Default); }) .ObserveOn(RxApp.MainThreadScheduler) .Finally(() => { IsLoggedIn = false; })); }
private void SearchModelList(string searchCond) { ModelService modelServices = new ModelService(); List <Storehouse> modelList = modelServices.SearchStorehouse(searchCond); this.FillDataGridView(modelList); }
public IObservable <AuthenticationResult> LogInFromCache() { Func <Task <AuthenticationResult> > f = async() => { try { var user = await loginManager.LoginFromCache(Address, ApiClient.GitHubClient); var accountCacheItem = new AccountCacheItem(user); usage.IncrementLoginCount().Forget(); await ModelService.InsertUser(accountCacheItem); if (user != null) { IsLoggedIn = true; return(AuthenticationResult.Success); } else { return(AuthenticationResult.VerificationFailure); } } catch (AuthorizationException) { return(AuthenticationResult.CredentialFailure); } }; return(f().ToObservable()); }
public async Task <WebAppUserProfileDto> Profile(CancellationToken cancellationToken) { var user = await ModelService.AsQueryable(u => u.Id == _userProvider.Id) .Select(u => new WebAppUserProfileDto { Id = u.Id, LanguageId = u.Id, Email = u.Email, UserName = u.UserName, CountryId = u.CountryId, CountryName = u.Country == null ? "" : u.Country.Name, City = u.City, Address01 = u.Address01, Address02 = u.Address02, FirstName = u.FirstName, LastName = u.LastName, IsActive = u.IsActive, IsConfirmed = u.IsConfirmed, MiddleName = u.MiddleName, ZipCode = u.ZipCode, VatCode = u.VatCode, Phone01 = u.Phone01, Phone02 = u.Phone02, RegistrationDate = u.RegistrationDate, UserPicture = u.UserPicture, UserPictureTumblr = u.UserPictureTumblr, }).FirstAsync(cancellationToken); //user.UserPicture = _pathProvider.GetImageApiPath<UserAccount>(nameof(UserAccount.UserPicture), user.Id.ToString()); //user.UserPictureTumblr = _pathProvider.GetImageApiPath<UserAccount>(nameof(UserAccount.UserPictureTumblr), user.Id.ToString()); return(user); }
private void SearchModelList(string searchCond) { ModelService modelServices = new ModelService(); List <CompanyType> modelList = modelServices.SearchCompanyType(searchCond); this.FillDataGridView(modelList); }
public async Task LogsTheUserInSuccessfullyAndCachesRelevantInfo() { var apiClient = Substitute.For <IApiClient>(); apiClient.HostAddress.Returns(HostAddress.GitHubDotComHostAddress); apiClient.GetOrCreateApplicationAuthenticationCode( Args.TwoFactorChallengCallback, Args.String, Args.Boolean) .Returns(Observable.Return(new ApplicationAuthorization("S3CR3TS"))); apiClient.GetUser().Returns(Observable.Return(CreateUserAndScopes("baymax"))); var hostCache = new InMemoryBlobCache(); var modelService = new ModelService(apiClient, hostCache, Substitute.For <IAvatarProvider>()); var loginCache = new TestLoginCache(); var host = new RepositoryHost(apiClient, modelService, loginCache, Substitute.For <ITwoFactorChallengeHandler>()); var result = await host.LogIn("baymax", "aPassword"); Assert.Equal(AuthenticationResult.Success, result); var user = await hostCache.GetObject <AccountCacheItem>("user"); Assert.NotNull(user); Assert.Equal("baymax", user.Login); var loginInfo = await loginCache.GetLoginAsync(HostAddress.GitHubDotComHostAddress); Assert.Equal("baymax", loginInfo.UserName); Assert.Equal("S3CR3TS", loginInfo.Password); Assert.True(host.IsLoggedIn); }
private void RefreshListView() { ModelService modelService = new ModelService(); List <CompanyType> modelList = modelService.GetAllCompanyTypes(); this.FillDataGridView(modelList); }
public async Task UsesUsernameAndPasswordInsteadOfAuthorizationTokenWhenEnterpriseAndAPIReturns404() { var enterpriseHostAddress = HostAddress.Create("https://enterprise.example.com/"); var apiClient = Substitute.For <IApiClient>(); apiClient.HostAddress.Returns(enterpriseHostAddress); // Throw a 404 on the first try with the new scopes apiClient.GetOrCreateApplicationAuthenticationCode(Args.TwoFactorChallengCallback, null, false, true) .Returns(Observable.Throw <ApplicationAuthorization>(new NotFoundException("Not there", HttpStatusCode.NotFound))); // Throw a 404 on the retry with the old scopes: apiClient.GetOrCreateApplicationAuthenticationCode(Args.TwoFactorChallengCallback, null, true, false) .Returns(Observable.Throw <ApplicationAuthorization>(new NotFoundException("Also not there", HttpStatusCode.NotFound))); apiClient.GetUser().Returns(Observable.Return(CreateUserAndScopes("Cthulu"))); var hostCache = new InMemoryBlobCache(); var modelService = new ModelService(apiClient, hostCache, Substitute.For <IAvatarProvider>()); var loginCache = new TestLoginCache(); var host = new RepositoryHost(apiClient, modelService, loginCache, Substitute.For <ITwoFactorChallengeHandler>()); var result = await host.LogIn("Cthulu", "aPassword"); Assert.Equal(AuthenticationResult.Success, result); // Only username and password were saved, never an authorization token: var loginInfo = await loginCache.GetLoginAsync(enterpriseHostAddress); Assert.Equal("Cthulu", loginInfo.UserName); Assert.Equal("aPassword", loginInfo.Password); Assert.True(host.IsLoggedIn); }
// // Multi-threaded implementation - see http://msdn.microsoft.com/en-us/library/ff650316.aspx // // This approach ensures that only one instance is created and only when the instance is needed. // Also, the variable is declared to be volatile to ensure that assignment to the instance variable // completes before the instance variable can be accessed. Lastly, this approach uses a syncRoot // instance to lock on, rather than locking on the type itself, to avoid deadlocks. // // NOTE : This singleton instance causes memory leaks ;) #endregion #region SerializeWorkflow public StringBuilder SerializeWorkflow(ModelService modelService) { var builder = EnsureImplementation(modelService); var text = GetXamlDefinition(builder); return(text); }
private void SearchModelList(string searchCond) { ModelService modelServices = new ModelService(); List <DrugFrom> modelList = modelServices.SearchDrugFrom(searchCond); this.FillDataGridView(modelList); }
private void OpenWorkflow() { OpenFileDialog fileDialog = WorkflowFileDialogFactory.CreateOpenFileDialog(); if (fileDialog.ShowDialog() == true) { WorkflowViewModel workspaceViewModel = new WorkflowViewModel(this.disableDebugViewOutput); workspaceViewModel.FullFilePath = fileDialog.FileName; WorkflowDocumentContent content = new WorkflowDocumentContent(workspaceViewModel); ModelService modelService = workspaceViewModel.Designer.Context.Services.GetService <ModelService>(); if (modelService != null) { List <Type> referencedActivities = this.GetReferencedActivities(modelService); this.AddActivitiesToToolbox(referencedActivities); } content.Title = workspaceViewModel.DisplayNameWithModifiedIndicator; content.Show(this.dockingManager); this.dockingManager.ActiveDocument = content; content.Closing += new EventHandler <CancelEventArgs>(workspaceViewModel.Closing); } this.ViewPropertyInspector(); if (this.HasValidationErrors) { this.ViewErrors(); this.SetSelectedTab(ContentTypes.Errors); } }
public FingerprintCommandBuilderIntTest() { bassAudioService = new BassAudioService(); naudioAudioService = new NAudioService(); modelService = new SqlModelService(); fingerprintCommandBuilder = new FingerprintCommandBuilder(); queryFingerprintService = new QueryFingerprintService(); }
public void Execute() { var ms = new ModelService<VehicleDetailModel>(); var vd = ms.Get(new ModelServiceArgs() { Id=1}); }