public NodeInfo GetNodeInfo(String id) { NodeDAO nodeDAO = new NodeDAO(); NodeDetailDAO nodeDetailDAO = new NodeDetailDAO(); NodeInfo node = new NodeInfo(); if (!nodeDAO.isNodeExist(id)) { return(null); } NodeDetail nodeDetail = nodeDetailDAO.GetDetailByNodeId(id); if (null == nodeDetail) { return(null); } node.NodeId = nodeDetail.NodeId; node.Humidity = nodeDetail.Humidity.Value; node.Raining = nodeDetail.Raining.Value; node.SoilMoisture = nodeDetail.SoilMoisture.Value; node.Temperature = nodeDetail.Temperature.Value; node.UpdateTime = nodeDetail.updateTime; node.NodeLocation = nodeDAO.FindNodeById(id).NodeLocation; return(node); }
public IHttpActionResult GetNode(string id) { nodeDAO = new NodeDAO(); nodeDetailDAO = new NodeDetailDAO(); NodeInfo node = new NodeInfo(); if (!nodeDAO.isNodeExist(id)) return NotFound(); NodeDetail nodeDetail = nodeDetailDAO.GetDetailByNodeId(id); if (null == nodeDetail) return NotFound(); node.NodeId = nodeDetail.NodeId; node.Humidity = nodeDetail.Humidity.Value; node.Raining = nodeDetail.Raining.Value; node.SoilMoisture = nodeDetail.SoilMoisture.Value; node.Temperature = nodeDetail.Temperature.Value; node.UpdateTime = nodeDetail.updateTime; node.NodeLocation = nodeDAO.FindNodeById(id).NodeLocation; if (node == null) { return NotFound(); } return Ok(node); }
protected override void BeginProcessing() { NodeDetail thisNode = null; SessionState s1 = this.SessionState; string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current); if (s1.Drive.Current is NosDBPSDriveInfo) { if (ConfigurationConnection.ConfigCluster == null) { throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION); } if (new NoSDbDetail(pathChunks, (PSDriveInfo)s1.Drive.Current).TryGetNodeDetail(out thisNode)) { } if (thisNode.NodeType.Equals(PathType.Shards)) { } else { throw new System.Exception("invalid Context, to Remove-Shard you must be in \n NoSDB:\\databasecluster\\Shards \n "); } } else { throw new System.Exception("invalid Context, to Remove-Shard you must be in \n NoSDB:\\databasecluster\\Shards \n "); } }
public async void InsertNodeDetail(NodeDetail nodeDetail) { if (null == nodeDetail) { return; } nodeDetails.Add(nodeDetail); await db.SaveChangesAsync(); }
public async Task<IHttpActionResult> PostNode(PostNode node) { if (null == node) return BadRequest(); if (!ModelState.IsValid) { return BadRequest(ModelState); } nodeDAO = new NodeDAO(); nodeDetailDAO = new NodeDetailDAO(); //<-Generate Node and NodeDetail-> Node newNode = new Node(); NodeDetail newDetail = new NodeDetail(); // <-Get Node Inform from Post Node-> newNode.NodeId = node.NodeId; newNode.NodeLocation = node.NodeLocation; newNode.Status = true; // <-Get NodeDetail Inform from Post Node-> newDetail.NodeId = node.NodeId; newDetail.Raining = node.Raining; newDetail.Humidity = node.Humidity; newDetail.SoilMoisture = node.SoilMoisture; newDetail.Temperature = node.Temperature; var dateTime = DateTime.Now; var dateTimeOffset = new DateTimeOffset(dateTime); var unixDateTime = dateTimeOffset.ToUnixTimeSeconds(); newDetail.updateTime = unixDateTime; try { if (!await nodeDAO.UpdateOrInsertNode(newNode)) { return BadRequest(); } if (!await nodeDetailDAO.InsertOrUpdateNodeDetail(newDetail)) { return BadRequest(); } } catch (DbUpdateException) { return BadRequest(); } return Ok(node); }
public async Task <Boolean> InsertOrUpdateNodeDetail(NodeDetail nodeDetail) { if (null == nodeDetail) { return(false); } var queryAllDetails = from detail in db.NodeDetail select detail; foreach (var detail in queryAllDetails) { if (detail.Equals(nodeDetail)) { return(false); } } db.NodeDetail.Add(nodeDetail); await db.SaveChangesAsync(); return(true); }
protected override void BeginProcessing() { string exceptionString = "invalid Context, to Stop-Shard you must be in \n NoSDB:\\databasecluster\\Shards \n "; NodeDetail thisNode = null; SessionState s1 = this.SessionState; string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current); if (s1.Drive.Current is NosDBPSDriveInfo) { if (ConfigurationConnection.ConfigCluster == null) { throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION); } if (new NoSDbDetail(pathChunks, (PSDriveInfo)s1.Drive.Current).TryGetNodeDetail(out thisNode)) { } if (thisNode.NodeType.Equals(PathType.Shards)) { if (string.IsNullOrEmpty(Name)) { throw new Exception("Specify value for parameter Name or try to stop shard from:\nNoSDB:\\databasecluster\\Shards\\shard. "); } } else if (thisNode.NodeType.Equals(PathType.Shard)) { Name = thisNode.NodeName; } else { throw new System.Exception(exceptionString); } } else { throw new System.Exception(exceptionString); } }
protected override void BeginProcessing() { NodeDetail thisNode = null; SessionState s1 = this.SessionState; string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current); if (s1.Drive.Current is NosDBPSDriveInfo) { if (ConfigurationConnection.ConfigCluster == null) { throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION); } if (!Path.EndsWith("\\")) { Path = Path + "\\"; } //Path = Path + ProviderUtil.CONFIGURATION_DUMP_FILE_NAME; if (ConfigurationConnection.ConfigCluster.Name.Equals(MiscUtil.CLUSTERED)) { ConfigurationConnection.UpdateClusterConfiguration(); } object[] configs = new object[2]; configs[0] = ConfigurationConnection.ConfigCluster; configs[1] = ConfigurationConnection.ClusterConfiguration; string configurationStr = JsonConvert.SerializeObject(configs, Newtonsoft.Json.Formatting.Indented); WriteConfigurationToFile(configurationStr, ConfigurationConnection.ClusterConfiguration.DisplayName); } else { throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION); } }
protected override void BeginProcessing() { ConfigurationConnection.UpdateClusterConfiguration(); List <string> shards = new List <string>(ConfigurationConnection.ClusterConfiguration.Deployment.Shards.Keys); if (shards == null || shards.Count == 0) { throw new Exception("No shard exist"); } if (string.IsNullOrEmpty(Shard)) { Shard = shards[0]; } else if (!shards.Contains(Shard)) { throw new Exception("Specified shard doesn't exist"); } _collectionName = GetCollectionName(Shard); string[] paramArray = null; NodeDetail thisNode = null; SessionState s1 = this.SessionState; string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current); if (s1.Drive.Current is NosDBPSDriveInfo) { if (ConfigurationConnection.ConfigCluster == null) { throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION); } //NodeDetail thisNode; if (new NoSDbDetail(pathChunks, s1.Drive.Current).TryGetNodeDetail(out thisNode)) { if (thisNode.NodeType.Equals(PathType.Database)) { if (_drop) { _databaseName = thisNode.NodeName; _connectionString = ProviderUtil.GetConnectionString(_databaseName); _database = Alachisoft.NosDB.Client.NosDB.InitializeDatabase(_connectionString); ConfigurationConnection.UpdateClusterConfiguration(); if (((DatabaseConfiguration)thisNode.Configuration).Storage.Collections.ContainsCollection( _collectionName)) { String query = "DROP COLLECTION $" + _collectionName + "$ {\"Database\":\"" + thisNode.NodeName + "\"}"; _database.ExecuteNonQuery(query); Thread.Sleep(5000); ConfigurationConnection.UpdateClusterConfiguration(); } } else { _databaseName = thisNode.NodeName; _connectionString = ProviderUtil.GetConnectionString(_databaseName); _database = Alachisoft.NosDB.Client.NosDB.InitializeDatabase(_connectionString); ConfigurationConnection.UpdateClusterConfiguration(); pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current); new NoSDbDetail(pathChunks, s1.Drive.Current).TryGetNodeDetail(out thisNode); if (!((DatabaseConfiguration)thisNode.Configuration).Storage.Collections.ContainsCollection( _collectionName)) { String query = "CREATE COLLECTION $" + _collectionName + "$ {\"Database\":\"" + thisNode.NodeName + "\", \"Shard\": \"" + Shard + "\"}"; try { _database.ExecuteNonQuery(query); } catch (Exception e) { if (!e.Message.Contains("Collection with name: " + _collectionName + " already exists")) { throw e; } } do { Thread.Sleep(2000); ConfigurationConnection.UpdateClusterConfiguration(); pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current); new NoSDbDetail(pathChunks, s1.Drive.Current).TryGetNodeDetail(out thisNode); } while ( !((DatabaseConfiguration)thisNode.Configuration).Storage.Collections .ContainsCollection( _collectionName)); } } } else { throw new Exception("You must be in NosDB:\\databasecluster\\databases\\database> for Test-Stress."); } } } else { throw new Exception("You must be in NosDB:\\databasecluster\\databases\\database> for Test-Stress."); } }
public List <Vector2> PathTo(Vector2 from, Vector2 to) { PathSegment startSegment = ClosestSegment(from); PathSegment endSegment = ClosestSegment(to); if (startSegment == endSegment || startSegment == null || endSegment == null) { return(new List <Vector2>() { to }); } //Simple brute force search Dictionary <PathNode, NodeDetail> nodeDetails = new Dictionary <PathNode, NodeDetail>(); List <NodeDetail> nodesToExplore = new List <NodeDetail>(); nodesToExplore.Add(new NodeDetail() { node = startSegment.To, g = (startSegment.To.transform.position2() - from).magnitude }); if (!startSegment.OneWay) { nodesToExplore.Add(new NodeDetail() { node = startSegment.From, g = (startSegment.From.transform.position2() - from).magnitude }); } bool found = false; NodeDetail endNodeDetail = null; while (!found && nodesToExplore.Any()) { nodesToExplore = nodesToExplore.OrderBy(it => it.g + (endSegment.From.transform.position - it.node.transform.position).magnitude ).ToList(); NodeDetail current = nodesToExplore[0]; nodesToExplore.RemoveAt(0); foreach (PathNode next in nodeNeighbors[current.node]) { float delta = (next.transform.position - current.node.transform.position).magnitude; float newG = current.g + delta; if (nodeDetails.ContainsKey(next)) { NodeDetail nextDetail = nodeDetails[next]; if (newG < nextDetail.g) { nextDetail.g = newG; nextDetail.parent = current; } } else { NodeDetail nextDetail = new NodeDetail() { node = next, parent = current, g = newG }; if (next == endSegment.From) { found = true; endNodeDetail = nextDetail; break; } if (!endSegment.OneWay && next == endSegment.To) { found = true; endNodeDetail = nextDetail; break; } nodeDetails[next] = nextDetail; nodesToExplore.Add(nextDetail); } } } if (endNodeDetail == null) { return(null); } List <Vector2> path = new List <Vector2>() { endNodeDetail.node.transform.position, to }; NodeDetail previous = endNodeDetail.parent; while (previous != null) { path.Insert(0, previous.node.transform.position); previous = previous.parent; } return(path); }
protected override void BeginProcessing() { if (Query.Equals(string.Empty) && InputFile.Equals(string.Empty)) { throw new Exception("Invoke the command with argument Query|InputFile"); } if (Query != string.Empty && InputFile != string.Empty) { throw new Exception("The Query and the InputFile options are mutually exclusive"); } string dbName = string.Empty; NodeDetail thisNode = null; SessionState s1 = this.SessionState; string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current); if (s1.Drive.Current is NosDBPSDriveInfo) { if (ConfigurationConnection.ConfigCluster == null) { throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION); } new NoSDbDetail(pathChunks, (PSDriveInfo)s1.Drive.Current).TryGetNodeDetail(out thisNode); if (thisNode is IDatabaseContext) { dbName = ((IDatabaseContext)thisNode).DatabaseName; _databaseContext = true; } else { dbName = "$sysdb"; } //conString = "nosdb://" + ConfigurationConnection.Current.ConfigServerIP + ":" + // ConfigurationConnection.Current.Port + "/" + // ConfigurationConnection.ClusterConfiguration.Name + "/" + dbName; bool localInstance; if (ConfigurationConnection.ClusterConfiguration.Name.Equals("local", StringComparison.InvariantCultureIgnoreCase)) { localInstance = true; } else { localInstance = false; } conString = ProviderUtil.GetConnectionString(dbName); //conString = "Data Source=" + ConfigurationConnection.Current.ConfigServerIP + ";" + "Port=" + // ConfigurationConnection.Current.Port + ";" + "Database=" + dbName + ";" + "Local Instance="+localInstance+";"; } if (InputFile != string.Empty) { if (!File.Exists(InputFile)) { throw new Exception("Input file does't exist"); } string text = File.ReadAllText(InputFile); text = text.Replace("\r\n", ""); queryArr = text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } }