public static object CreateDialog <T>(this ICreator creator, Action <T> setting = null) where T : IScreen { var dlg = creator.Create <DlgViewModel>(); var content = creator.Create <T>(); setting?.Invoke(content); dlg.Content = content; return(dlg); }
private void PolygonButton_Click(object sender, EventArgs e) { currentCreator = new Figures.PolygonCreator(); currentFigure = currentCreator.Create(color, fillColor, penWidth); StateChange(currentCreator); }
public void Trigger(CreatorCommand command) { var username = new AuthUsername(command.GetUsername()); var password = new AuthPassword(command.GetPassword()); Creator.Create(username, password, command.GetFirstName(), command.GetLastName()); }
internal Result CreateResult(ICreator creator, IFunction hashFunction, long modulo) { var data = creator.Create().ToList(); var mappedValues = new Dictionary <long, long>(); var stopWatch = Stopwatch.StartNew(); foreach (long number in data) { var value = hashFunction.Hash(number, modulo); if (mappedValues.ContainsKey(value)) { mappedValues[value]++; } else { mappedValues.Add(value, 1); } } long max = mappedValues.Keys.Max(); for (int i = 0; i <= max; i++) { if (!mappedValues.ContainsKey(i)) { mappedValues[i] = 0; } } stopWatch.Stop(); return(CreateResult(stopWatch.Elapsed, mappedValues.OrderBy(x => x.Key).ToList(), modulo, hashFunction)); }
private void BrokenLinebutton_Click(object sender, EventArgs e) { currentCreator = new Figures.BrokenLineCreator(); currentFigure = currentCreator.Create(color, fillColor, penWidth); StateChange(currentCreator); }
public void MutationTest() { Random random = new Random(2014); ICreator creator = getCreator(random); for (int i = 0; i < 100; i++) { var specimen = creator.Create(); Assert.IsTrue(specimen.IsValid); var clone = specimen.Clone(); Assert.IsTrue(clone.IsValid); double cloneFitness = clone.Fitness; for (int i2 = 0; i2 < 100; i2++) { specimen.Mutate(); Assert.IsTrue(specimen.IsValid); } Assert.AreNotEqual(specimen.Fitness, clone.Fitness); Assert.AreEqual(cloneFitness, clone.Fitness); } }
public void Run(ICreator creator) { var numbers = creator.Create().ToList(); var referenceFilterStopwatch = Stopwatch.StartNew(); _data = new HashSet <int>(numbers); referenceFilterStopwatch.Stop(); var bloomFilterStopwatch = Stopwatch.StartNew(); foreach (var number in _data) { AddElement(number); } bloomFilterStopwatch.Stop(); var result = new Result() { BloomFilterMemory = _parameterConfiguration.FilterSize * sizeof(bool), BloomFilterTime = bloomFilterStopwatch.Elapsed, ReferenceFilterMemory = _data.Count * sizeof(int) * 8, ReferenceFilterTime = referenceFilterStopwatch.Elapsed }; ShowFilterBloom(result); }
public Game Update(Game game) { gameDeleter.Delete(game.GameID); gameCreator.Create(game); teamUpdater.Refresh(); return(game); }
public Portfolio Create() { return(new Portfolio() { Id = Guid.NewGuid(), PortfolioOwner = _personCreator.Create() }); }
public void Create(ICreator creator) { InitializeMaze(); creator.Create(this); Start = creator.DefineStart(this); Finish = creator.DefineFinish(this); }
private void RegularPolygonButton_Click(object sender, EventArgs e) { currentCreator = new Figures.RegularPolygonCreator(); currentFigure = currentCreator.Create(color, fillColor, penWidth); (currentFigure as Figures.RegularPolygon).numOfCorners = cornersNum; StateChange(currentCreator); }
public Pool(ICreator <T> creator, int preAllocated = 10) { this.creator = creator; internalStack = new Stack <T>(); for (int i = 0; i < preAllocated; i++) { internalStack.Push(creator.Create()); } }
public object CreateInstance(Type type) { if (!_typesDictionary.ContainsKey(type)) { throw new Exception($"Type {type.FullName} can not be created!"); } Type specificType = GetSpecificType(type); if (!specificType.GetConstructors().Any()) { throw new Exception($"Type {specificType.FullName} don`t have public constructors!"); } ConstructorInfo constructorInfo = specificType.GetConstructors().FirstOrDefault(); List <object> parametersList = new List <object>(); if (constructorInfo != null) { foreach (var parameterInfo in constructorInfo.GetParameters()) { var specificParameterInfoType = GetSpecificType(parameterInfo.ParameterType); parametersList.Add(_creator.Create(specificParameterInfoType, CreateParameters(specificParameterInfoType).ToArray())); } } var instance = _creator.Create(specificType, parametersList.ToArray()); if (specificType.GetCustomAttribute <ImportConstructorAttribute>() != null) { return(instance); } var properties = specificType.GetProperties() .Where(p => p.CustomAttributes.Any(a => a.AttributeType == typeof(ImportAttribute))); foreach (var property in properties) { var propertyInstance = _creator.Create(GetSpecificType(property.PropertyType), CreateParameters(GetSpecificType(property.PropertyType)).ToArray()); property.SetValue(instance, propertyInstance); } return(instance); }
private void PluginComboBox_SelectedIndexChanged(object sender, EventArgs e) { string pluginName = PluginComboBox.GetItemText(PluginComboBox.SelectedItem); currentFactory = plugin.GetPluginType(pluginName); currentCreator = (ICreator)Activator.CreateInstance(currentFactory); currentFigure = currentCreator.Create(color, fillColor, penWidth); StateChange(currentCreator); }
public void Trigger(WarehouseCommand command) { Creator.Create(command.GetName() , command.GetStateId() , command.GetAddressState() , command.GetAddress() , command.GetTelephone() , command.GetEmail() , command.GetDescription()); }
public void Add(ICreator newPlugin) { if (newPlugin == null) return; IPlugin found = newPlugin.Create(); if (found != null) { found.Setup(); } }
private void ExecuteCreate(ICreator creator, CreateAction create) { if (!creator.CanCreate(create)) { return; } var obj = creator.Create(create); State.Add(obj); }
/// <summary> 実行 </summary> private async void btnMarge_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; btnMarge.Visible = false; var sfd = new SaveFileDialog(); var dr = sfd.ShowDialog(); string saveFilePath; if (dr == DialogResult.OK) { saveFilePath = sfd.FileName; } else { return; } ICreator creator = Factory.SheetMargerFactory(txtRead.Text, saveFilePath); cancellationToken = new CancellationTokenSource(); creator.CancellationToken = cancellationToken; creator.Progress = new Progress <int>(x => { Pb.Value = x; this.Refresh(); }); if (!CheckInput(creator)) { return; } bool success = await Task.Run(() => creator.Create()); if (!success) { MessageBox.Show(creator.Message, "エラー"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.Cursor = Cursors.Default; btnMarge.Visible = true; Pb.Value = 0; } }
public string Serialize(string path) { var selializator = new JavaScriptSerializer(); path = path.Replace("\\", "/"); var rootFolder = fileSystemCreator.Create(path); selializator.RegisterConverters(new[] { new FolderConverter() }); var json = selializator.Serialize(rootFolder); return(json); }
public T Get() { if (_currentSegments.Count <= 0) { return(_creator.Create()); } var first = _currentSegments.First.Value; _currentSegments.RemoveFirst(); return(first); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } if (!Guid.Equals(Player.ID, Guid.Empty)) { playerUpdater.Update(Player); } else { playerCreator.Create(Player); } TempData["Message"] = "Player saved!"; return(RedirectToPage("./List")); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } if (!Guid.Equals(game.GameID, Guid.Empty)) { gameUpdater.Update(game); } else { gameCreator.Create(game); } TempData["Message"] = "Game saved!"; return(RedirectToPage("./List")); }
public void Open(string moduleName) { var module = Modules.FirstOrDefault(o => o.GetType().Name == moduleName); if (module != null) { if (!module.CanMultiCreate) { ActiveModule = module; return; } } module = m_creator.Create <IModule>(moduleName); if (module != null) { Modules.Add(module); ActiveModule = module; } }
private void OnCreated(object sender, FileSystemEventArgs args) { if (!CheckExtension(Path.GetExtension(args.FullPath))) { return; } _logger.Logging($"Найден новый файл: [ {args.Name} ]"); FileInfo file = new FileInfo(args.FullPath); // Todo: Сделать не так колхозно while (IsLocked(file)) { // logger.Logging($"Файл заблокирован"); } _creator.Create(file, _name == file.Name); _name = file.Name; }
public IObjects Create(IDBBase db) { if (db == null) { return(null); } Type type = db.GetType(); Type[] interfaces = type.GetInterfaces(); foreach (Type item in interfaces.Reverse()) { if (_creators.ContainsKey(item)) { ICreator creator = _creators[item]; return(creator.Create(db)); } } return(null); }
/// <summary> /// Create a new instance of a type /// </summary> public object Create(Type type) { Check.ArgumentNotNull(type, "type"); IResolver resolver; if (_Resolvers.TryGetValue(type, out resolver)) { ICreator creator = resolver as ICreator; if (creator != null) { return(creator.Create(this)); } } try { return(DefaultCreateInstance(type)); } catch { return(null); } }
public void WhenCreateThenNewContentListTest() { // TODO replace this non-sensible test with something usefulzzz --> const string expectedName = "test"; ContentList expectedContentList = createDummyContentList(expectedName); ICreator substCreator = Substitute.For <ICreator>(); substCreator.Create(Arg.Any <string>()).Returns(expectedContentList); IUtil util = Substitute.For <IUtil>(); Repository <ContentList> listRepository = new Repository <ContentList>() { Creator = substCreator, }; ContentList actualContentList = listRepository.Creator.Create(expectedName) as ContentList; Assert.NotNull(actualContentList); Assert.Equal(expectedName, actualContentList.Name); Assert.Equal(expectedContentList, actualContentList); }
public T Create() { if (creator == null) { Init(); } T item = CreateFromCache(); if (!CheckUseful(item)) { item = creator.Create(); } else { item.OnReset(); } item.OnCreate(); item.isRecycled = false; OnItemCreate(item); return(item); }
public override void Create(out INugetResolverData obj, FileInfo file) => _dataCreator.Create(out obj, file);
public override void Create(out INugetResolver obj, VersionMatchingStrategies assemblyMatchingStrategy, VersionMatchingStrategies packageMatchingStrategy, IEnumerable <DirectoryInfo> caches) => _resolverWithCacheCreator.Create(out obj, assemblyMatchingStrategy, packageMatchingStrategy, caches);
public T Retrieve() => internalStack.Count == 0 ? creator.Create() : internalStack.Pop();