public void TopologyHelper_Client_PlugIn() { LeafRouter router = null; ITopologyProvider cluster = null; System.Type type; try { router = CreateLeaf("detached", "hub", Helper.NewGuid().ToString(), group); type = typeof(BasicTopology); Config.SetConfig(string.Format("topology-type={0}:{1}\r\nargs=cluster-ep=logical://foo", type.FullName, type.Assembly.Location)); cluster = TopologyHelper.OpenClient(router, "topology-type", "args"); Assert.AreEqual(type.FullName, cluster.GetType().FullName); Assert.IsTrue(cluster.IsClient); } finally { if (cluster != null) { cluster.Close(); } if (router != null) { router.Stop(); } Config.SetConfig(null); } }
private static StaticHashedTopology OpenServer(MsgRouter router, string dynamicScope, object target, string clusterEP, int instance) { System.Type type = typeof(StaticHashedTopology); Config.SetConfig(string.Format(ClusterConfig, type.FullName, type.Assembly.Location, clusterEP, instance)); return((StaticHashedTopology)TopologyHelper.OpenServer(router, dynamicScope, target, "clusterType", "clusterArgs")); }
public async Task <Persil> Upload([FromForm] EditPersilViewModel model) { var persil = await dbContext.Set <Persil>().FirstOrDefaultAsync(p => p.Id == model.PersilId); if (persil == null) { throw new NotFoundException(); } dbContext.Entry(persil).State = EntityState.Modified; persil.Status = model.PersilStatus; persil.TotalSize = model.PersilTotalSize; persil.TotalSubject = model.PersilTotalSubject; persil.DateModified = DateTime.Now; if (model.File != null) { var features = TopologyHelper.GetFeatureCollectionWgs84(model.File); persil.Geojson = TopologyHelper.GetGeojson(features); // Copy map file to disk var persilDirectoryPath = Path.Combine(_hostingEnvironment.WebRootPath, "persil"); var regionDirectoryPath = Path.Combine(persilDirectoryPath, persil.FkRegionId); var destinationFilePath = Path.Combine(regionDirectoryPath, persil.Id + ".zip"); await IOHelper.StreamCopyAsync(destinationFilePath, model.File); } await dbContext.SaveChangesAsync(); return(persil); }
private static StaticHashedTopology OpenClient(MsgRouter router, string clusterEP) { System.Type type = typeof(StaticHashedTopology); Config.SetConfig(string.Format(ClusterConfig, type.FullName, type.Assembly.Location, clusterEP, "")); return((StaticHashedTopology)TopologyHelper.OpenClient(router, "clusterType", "clusterArgs")); }
static void Main(string[] args) { var skipped = new List <string>(); var updated = new List <string>(); var failed = new List <FailureNotice>(); int current = 0; _whatIf = (args.Length > 0 && args[0].ToLowerInvariant() == "-whatif"); Console.CursorVisible = false; using (var client = new SessionAwareCoreServiceClient()) { var publications = client.GetSystemWideList(new PublicationsFilterData()); int total = publications.Length; if (_whatIf) { Console.WriteLine(Resources.NoChangesWillBeMade); } Console.WriteLine(GetResource(@"StartSummary"), total); Console.WriteLine(); ShowProgress(0, total); foreach (var publication in publications) { var amPublication = new Publication(new UserContext(), new TcmUri(publication.Id)); if (amPublication.Exists) { try { if (!_whatIf) { TopologyHelper.UpdateTopology(amPublication); } updated.Add(GetDescription(publication)); } catch (Exception ex) { failed.Add(new FailureNotice { Title = GetDescription(publication), Error = ex.Message }); } } else { skipped.Add(GetDescription(publication)); } ShowProgress(++current, total); } } OutputSummary(updated, failed, skipped); Quit(); }
public async Task<ToraMap> Upload([FromForm]UploadToraMapViewModel model) { var toraObject = await dbContext.Set<ToraObject>().FirstOrDefaultAsync(to => to.Id == model.ToraObjectId); if (toraObject == null) throw new NotFoundException(); var toraMap = await dbContext.Set<ToraMap>().FirstOrDefaultAsync(tm => tm.FkToraObjectId == toraObject.Id); if (toraMap == null) { toraMap = new ToraMap { FkToraObjectId = toraObject.Id }; dbContext.Entry(toraMap).State = EntityState.Added; } else { dbContext.Entry(toraMap).State = EntityState.Modified; } toraMap.FkRegionId = toraObject.FkRegionId; toraMap.Name = toraObject.Name; var features = TopologyHelper.GetFeatureCollectionWgs84(model.File); toraMap.Geojson = TopologyHelper.GetGeojson(features); toraMap.Size = TopologyHelper.GetArea(features); await dbContext.SaveChangesAsync(); // Copy map file to disk var toraMapDirectoryPath = Path.Combine(_hostingEnvironment.WebRootPath, "tora", "map"); var regionDirectoryPath = Path.Combine(toraMapDirectoryPath, toraObject.FkRegionId); var destinationFilePath = Path.Combine(regionDirectoryPath, toraMap.Id + ".zip"); await IOHelper.StreamCopyAsync(destinationFilePath, model.File); return toraMap; }
public void TopologyHelper_Server_PlugIn() { LeafRouter client = null; LeafRouter server = null; ITopologyProvider clientCluster = null; ITopologyProvider serverCluster = null; System.Type type; PropertyMsg reply; try { client = CreateLeaf("detached", "hub", Helper.NewGuid().ToString(), group); server = CreateLeaf("detached", "hub", Helper.NewGuid().ToString(), group); type = typeof(BasicTopology); Config.SetConfig(string.Format("topology-type={0}:{1}\r\nargs=cluster-ep=logical://foo", type.FullName, type.Assembly.Location)); clientCluster = TopologyHelper.OpenClient(client, "topology-type", "args"); Assert.AreEqual(type.FullName, clientCluster.GetType().FullName); Assert.IsTrue(clientCluster.IsClient); Config.SetConfig(string.Format("topology-type={0}:{1}\r\nargs=cluster-ep=logical://foo", type.FullName, type.Assembly.Location)); serverCluster = TopologyHelper.OpenServer(client, "A", this, "topology-type", "args"); Assert.AreEqual(type.FullName, serverCluster.GetType().FullName); Assert.IsFalse(serverCluster.IsClient); Thread.Sleep(2000); reply = (PropertyMsg)clientCluster.Query(null, new PropertyMsg()); Assert.AreEqual("Hello World!", reply["value"]); } finally { if (client != null) { client.Stop(); } if (server != null) { server.Stop(); } if (clientCluster != null) { clientCluster.Close(); } if (serverCluster != null) { serverCluster.Close(); } Config.SetConfig(null); } }
protected override void InitializeAlgorithm(IProblem problem) { base.InitializeAlgorithm(problem); Particles = Initialization.Initialize(problem, SwarmSize); //calculate fitness for each particle foreach (IParticle particle in Particles) { particle.CalculateFitness(Problem); } //initialize each neighbourhood best - only after fitness has been calculated for all particles foreach (IParticle particle in Particles) { particle.NeighbourhoodBest = TopologyHelper.GetNeighbourhoodBest(Particles, particle, Topology); } }
public async Task <VillageBorderMap> Upload([FromForm] UploadVillageBorderMapViewModel model) { var region = await dbContext.Set <Region>().FirstOrDefaultAsync(r => r.Id == model.RegionId); if (region == null) { throw new NotFoundException(); } var villageBorderMap = await dbContext.Set <VillageBorderMap>().FirstOrDefaultAsync(vbm => vbm.FkRegionId == model.RegionId); if (villageBorderMap == null) { villageBorderMap = new VillageBorderMap { FkRegionId = model.RegionId }; dbContext.Entry(villageBorderMap).State = EntityState.Added; } else { dbContext.Entry(villageBorderMap).State = EntityState.Modified; } villageBorderMap.Name = region.Name; var features = TopologyHelper.GetFeatureCollectionWgs84(model.File); villageBorderMap.Geojson = TopologyHelper.GetGeojson(features); villageBorderMap.Size = TopologyHelper.GetArea(features); await dbContext.SaveChangesAsync(); // Copy map file to disk var villageBorderMapDirectoryPath = Path.Combine(_hostingEnvironment.WebRootPath, "villagebordermap"); var regionDirectoryPath = Path.Combine(villageBorderMapDirectoryPath, region.Id); var destinationFilePath = Path.Combine(regionDirectoryPath, villageBorderMap.Id + ".zip"); await IOHelper.StreamCopyAsync(destinationFilePath, model.File); return(villageBorderMap); }
public async Task <BaseLayer> Upload([FromForm] UploadBaseLayerViewModel model) { BaseLayer baseLayer = null; if (model.Id > 0) { baseLayer = await dbContext.Set <BaseLayer>().FirstOrDefaultAsync(o => o.Id == model.Id); } if (baseLayer == null) { baseLayer = new BaseLayer(); dbContext.Entry(baseLayer).State = EntityState.Added; } else { dbContext.Entry(baseLayer).State = EntityState.Modified; } baseLayer.Label = model.Label; baseLayer.Color = model.Color; if (baseLayer.Id <= 0 || model.File != null) { var features = TopologyHelper.GetFeatureCollectionWgs84(model.File); baseLayer.Geojson = TopologyHelper.GetGeojson(features); await dbContext.SaveChangesAsync(); var baseLayerDirectoryPath = Path.Combine(_hostingEnvironment.WebRootPath, "baseLayer"); var destinationFilePath = Path.Combine(baseLayerDirectoryPath, baseLayer.Id + ".zip"); await IOHelper.StreamCopyAsync(destinationFilePath, model.File); } else { await dbContext.SaveChangesAsync(); } return(baseLayer); }
public override OptimizationSolution GetBestSolution() { IParticle best = TopologyHelper.GetBestParticle(Particles); return(new OptimizationSolution(best.BestPosition, best.BestFitness)); }
public Vector GetCenter(List <IParticle> particles) { return(TopologyHelper.GetBestParticle(particles).BestPosition); //TODO: should this be best position or position? }