maxRequestLength - behind the scene details needed! - asp.net

What really happens to the currently executing request in IIS during a file upload, when the upload length exceed configured maxRequestLength.
Tried hard to find a decent article that talks about that, but there are none!!
Thanks

This is what exactly happens:
In class HttpRequest and in method GetEntireRawContent this condition is checked and will throw an exception:
if (length > maxRequestLengthBytes)
{
throw new HttpException(System.Web.SR.GetString("Max_request_length_exceeded"), null, 0xbbc);
}
Here is the whole of the method if you find useful:
private HttpRawUploadedContent GetEntireRawContent()
{
if (this._wr == null)
{
return null;
}
if (this._rawContent == null)
{
HttpRuntimeSection httpRuntime = RuntimeConfig.GetConfig(this._context).HttpRuntime;
int maxRequestLengthBytes = httpRuntime.MaxRequestLengthBytes;
if (this.ContentLength > maxRequestLengthBytes)
{
if (!(this._wr is IIS7WorkerRequest))
{
this.Response.CloseConnectionAfterError();
}
throw new HttpException(System.Web.SR.GetString("Max_request_length_exceeded"), null, 0xbbc);
}
int requestLengthDiskThresholdBytes = httpRuntime.RequestLengthDiskThresholdBytes;
HttpRawUploadedContent data = new HttpRawUploadedContent(requestLengthDiskThresholdBytes, this.ContentLength);
byte[] preloadedEntityBody = this._wr.GetPreloadedEntityBody();
if (preloadedEntityBody != null)
{
this._wr.UpdateRequestCounters(preloadedEntityBody.Length);
data.AddBytes(preloadedEntityBody, 0, preloadedEntityBody.Length);
}
if (!this._wr.IsEntireEntityBodyIsPreloaded())
{
int num3 = (this.ContentLength > 0) ? (this.ContentLength - data.Length) : 0x7fffffff;
HttpApplication applicationInstance = this._context.ApplicationInstance;
byte[] buffer = (applicationInstance != null) ? applicationInstance.EntityBuffer : new byte[0x2000];
int length = data.Length;
while (num3 > 0)
{
int size = buffer.Length;
if (size > num3)
{
size = num3;
}
int bytesIn = this._wr.ReadEntityBody(buffer, size);
if (bytesIn <= 0)
{
break;
}
this._wr.UpdateRequestCounters(bytesIn);
this.NeedToInsertEntityBody = true;
data.AddBytes(buffer, 0, bytesIn);
num3 -= bytesIn;
length += bytesIn;
if (length > maxRequestLengthBytes)
{
throw new HttpException(System.Web.SR.GetString("Max_request_length_exceeded"), null, 0xbbc);
}
}
}
data.DoneAddingBytes();
if ((this._installedFilter != null) && (data.Length > 0))
{
try
{
try
{
this._filterSource.SetContent(data);
HttpRawUploadedContent content2 = new HttpRawUploadedContent(requestLengthDiskThresholdBytes, data.Length);
HttpApplication application2 = this._context.ApplicationInstance;
byte[] buffer3 = (application2 != null) ? application2.EntityBuffer : new byte[0x2000];
while (true)
{
int num7 = this._installedFilter.Read(buffer3, 0, buffer3.Length);
if (num7 == 0)
{
break;
}
content2.AddBytes(buffer3, 0, num7);
}
content2.DoneAddingBytes();
data = content2;
}
finally
{
this._filterSource.SetContent(null);
}
}
catch
{
throw;
}
}
this._rawContent = data;
}
return this._rawContent;
}

Related

Converting Any Map or List to String and Back in Java

I have made a pretty decently working Map to String + Back converter but I am wondering if there is an easier way to do this. I am basically just trying to store the Map into an sqlite database and read from it later.
public class mainFunctions {
public String toString(Object object) {
String objectClass = object.getClass().getName();
String objectString = String.format("%s[", objectClass);
int index = -1;
if(objectClass.contains("Map")) {
Map<Object, Object> map = null;
if (objectClass.contains(TreeMap.class.getName())) { map = (TreeMap) object; }
else if (objectClass.contains(HashMap.class.getName())) { map = (HashMap) object; }
else if (objectClass.contains(LinkedHashMap.class.getName())) { map = (LinkedHashMap) object; }
else { return null; }
for (Object key : map.keySet()) {
index ++;
Object value = map.get(key);
objectString = String.format("%s%s[\"%s\":\"%s\"]", objectString, index > 0 ? "," : "", key, value);
}
objectString = String.format("%s]", objectString);
return objectString;
} else {
List<Object> list;
if (objectClass.contains(ArrayList.class.getName())) { list = (ArrayList) object; }
else if (objectClass.contains(Vector.class.getName())) { list = (Vector) object; }
else if (objectClass.contains(LinkedList.class.getName())) { list = (LinkedList) object; }
else { return null; }
for (Object obj : list) {
index ++;
objectString = String.format("%s%s[\"%s\"]", objectString, index > 0 ? "," : "", obj);
}
objectString = String.format("%s]", objectString);
return objectString;
}
}
public Object fromString(String objectString) {
String objectClass = objectString.split("\\[")[0];
objectString = objectString.replace(String.format("%s[", objectClass), "");
objectString = objectString.substring(2, objectString.length() - 3);
String[] objectSplit = objectString.split("\"],\\[\"");
if(objectClass.contains("Map")) {
Map<Object, Object> map = null;
if (objectClass.contains(TreeMap.class.getName())) { map = new TreeMap<>(); }
else if (objectClass.contains(HashMap.class.getName())) { map = new HashMap<>(); }
else if (objectClass.contains(LinkedHashMap.class.getName())) { map = new TreeMap<>(); }
else { return null; }
int index = -1;
for (String entry : objectSplit) { String[] entrySplit = entry.split("\":\""); map.put(entrySplit[0], entrySplit[1]); }
return map;
} else {
List<Object> list;
if (objectClass.contains(ArrayList.class.getName())) { list = new ArrayList<>();
} else if (objectClass.contains(Vector.class.getName())) { list = new Vector<>();
} else if (objectClass.contains(LinkedList.class.getName())) { list = new LinkedList<>();
} else { return null; }
for (String entry : objectSplit) { list.add(entry); }
return list;
}
}
}
This is the usage:
TreeMap<String, Double> itemValues = new TreeMap<>();
itemValues.put("diamond", 111.11);
itemValues.put("netherite_ingot", 555.55);
itemValues.put("emerald", 2.22);
itemValues.put("gold_ingot", 12.22);
String itemString = this.functions.toString(itemValues);
this.log(String.format("%sitemValues String = %s", header, itemString));
TreeMap<String, Double> values;
values = (TreeMap<String, Double>) this.functions.fromString(itemString);
this.log(String.format("%sitemValues TreeMap = %s", header, values));
ArrayList<String> items = new ArrayList<>();
items.add("diamond");
items.add("netherite_ingot");
items.add("emerald");
items.add("gold_ingot");
String itemss = this.functions.toString(items);
this.log(String.format("%sitems String = %s", header, itemss));
ArrayList<String> valuesAr;
valuesAr = (ArrayList<String>) this.functions.fromString(itemss);
this.log(String.format("%sitems Array = %s", header, valuesAr));
And this is the Output:
itemValues String = java.util.TreeMap[["diamond":"111.11"],["emerald":"2.22"],["gold_ingot":"12.22"],["netherite_ingot":"555.55"]]
itemValues TreeMap = {diamond=111.11, emerald=2.22, gold_ingot=12.22, netherite_ingot=555.55}
items String = java.util.ArrayList[["diamond"],["netherite_ingot"],["emerald"],["gold_ingot"]]
items Array = [diamond, netherite_ingot, emerald, gold_ingot]
Seems to all work well but assuming there is a better way to do this.

Alternative to System.Web.Security.Membership.GeneratePassword in aspnetcore (netcoreapp1.0)

Is there any alternative to System.Web.Security.Membership.GeneratePassword in AspNetCore (netcoreapp1.0).
The easiest way would be to just use a Guid.NewGuid().ToString("n") which is long enough to be worthy of a password but it's not fully random.
Here's a class/method, based on the source of Membership.GeneratePassword of that works on .NET Core:
public static class Password
{
private static readonly char[] Punctuations = "!##$%^&*()_-+=[{]};:>|./?".ToCharArray();
public static string Generate(int length, int numberOfNonAlphanumericCharacters)
{
if (length < 1 || length > 128)
{
throw new ArgumentException(nameof(length));
}
if (numberOfNonAlphanumericCharacters > length || numberOfNonAlphanumericCharacters < 0)
{
throw new ArgumentException(nameof(numberOfNonAlphanumericCharacters));
}
using (var rng = RandomNumberGenerator.Create())
{
var byteBuffer = new byte[length];
rng.GetBytes(byteBuffer);
var count = 0;
var characterBuffer = new char[length];
for (var iter = 0; iter < length; iter++)
{
var i = byteBuffer[iter] % 87;
if (i < 10)
{
characterBuffer[iter] = (char)('0' + i);
}
else if (i < 36)
{
characterBuffer[iter] = (char)('A' + i - 10);
}
else if (i < 62)
{
characterBuffer[iter] = (char)('a' + i - 36);
}
else
{
characterBuffer[iter] = Punctuations[i - 62];
count++;
}
}
if (count >= numberOfNonAlphanumericCharacters)
{
return new string(characterBuffer);
}
int j;
var rand = new Random();
for (j = 0; j < numberOfNonAlphanumericCharacters - count; j++)
{
int k;
do
{
k = rand.Next(0, length);
}
while (!char.IsLetterOrDigit(characterBuffer[k]));
characterBuffer[k] = Punctuations[rand.Next(0, Punctuations.Length)];
}
return new string(characterBuffer);
}
}
}
I've omitted the do...while loop over the CrossSiteScriptingValidation.IsDangerousString. You can add that back in yourself if you need it.
You use it like this:
var password = Password.Generate(32, 12);
Also, make sure you reference System.Security.Cryptography.Algorithms.
System.Random doesn't provide enough entropy when used for security reasons.
https://cwe.mitre.org/data/definitions/331.html
Why use the C# class System.Random at all instead of System.Security.Cryptography.RandomNumberGenerator?
Please see the example below for a more secure version of #khellang version
public static class Password
{
private static readonly char[] Punctuations = "!##$%^&*()_-+[{]}:>|/?".ToCharArray();
public static string Generate(int length, int numberOfNonAlphanumericCharacters)
{
if (length < 1 || length > 128)
{
throw new ArgumentException("length");
}
if (numberOfNonAlphanumericCharacters > length || numberOfNonAlphanumericCharacters < 0)
{
throw new ArgumentException("numberOfNonAlphanumericCharacters");
}
using (var rng = RandomNumberGenerator.Create())
{
var byteBuffer = new byte[length];
rng.GetBytes(byteBuffer);
var count = 0;
var characterBuffer = new char[length];
for (var iter = 0; iter < length; iter++)
{
var i = byteBuffer[iter] % 87;
if (i < 10)
{
characterBuffer[iter] = (char)('0' + i);
}
else if (i < 36)
{
characterBuffer[iter] = (char)('A' + i - 10);
}
else if (i < 62)
{
characterBuffer[iter] = (char)('a' + i - 36);
}
else
{
characterBuffer[iter] = Punctuations[GetRandomInt(rng, Punctuations.Length)];
count++;
}
}
if (count >= numberOfNonAlphanumericCharacters)
{
return new string(characterBuffer);
}
int j;
for (j = 0; j < numberOfNonAlphanumericCharacters - count; j++)
{
int k;
do
{
k = GetRandomInt(rng, length);
}
while (!char.IsLetterOrDigit(characterBuffer[k]));
characterBuffer[k] = Punctuations[GetRandomInt(rng, Punctuations.Length)];
}
return new string(characterBuffer);
}
}
private static int GetRandomInt(RandomNumberGenerator randomGenerator)
{
var buffer = new byte[4];
randomGenerator.GetBytes(buffer);
return BitConverter.ToInt32(buffer);
}
private static int GetRandomInt(RandomNumberGenerator randomGenerator, int maxInput)
{
return Math.Abs(GetRandomInt(randomGenerator) % maxInput);
}
}

OrientDB: How to query a graph using dijkstra function while ignoring some edges

I am trying to query data from orientdb while ignoring some edges.
My query has the form:
select expand(dijkstra(#12:15,#12:20,'property','both'))
but as mentioned I want to ignore some edges of the graph.
Are there any suggestions?
Edit
Here is my graph structure .
Station as Vertex
Image Click
Path as Edge
Image Click
Thank you #Ivan Mainetti so much for answer i have try the testing main()
Here is my main()
String nomeDb = "Demo2";
try {
System.out.println("Before connect OServerAdmin");
OServerAdmin serverAdmin = new OServerAdmin("remote:128.199.xxx.xxx/"+nomeDb).connect("admin","password");
System.out.println("After connect");
if(serverAdmin.existsDatabase()){ // il db esiste
System.out.println("in if");
//connessione a db
OrientGraph g = new OrientGraph("remote:128.199.xxx.xxx/"+nomeDb);
DijkstraExcl d = new DijkstraExcl(g, "Path", "distance");
Set<String> ex =new HashSet<String>();
//------------------------------------------------
Vertex start = g.getVertex("#12:6");
Vertex end = g.getVertex("#12:11");
ex.add("#13:0");
Direction direction = Direction.OUT;
System.out.println(d.getPath(start,end,direction,ex));
System.out.println(d.getPathString(start,end,direction,ex));
System.out.println(d.getWeight(start,end,direction,ex));
//------------------------------------------------
//chiude db
g.shutdown();
}
else{
System.out.println("Il database '"+ nomeDb + "' non esiste");
}
serverAdmin.close();
} catch (IOException e) {
e.printStackTrace();
}
and the result after run the main() is
null
null
2147483647
The correct answer after ignore [#13:0] should be
[#12:6,#12:8,#12:10,#12:11]
Try the following JS function that has as parameters ridFrom, ridTo, property, direction and excludeEdges.
With Studio you can try it with this command:
select expand(result) from (select myFunction("12:6","12:11","distance","out","[#13:0]") as result)
The edges "edge1" and "edge2" are ignored.
var g=orient.getGraph();
var listEdges=excludeEdges.substring(1,excludeEdges.length-1).split(",");
var S=[], T=[] , id_weigth=[] , from , to , infinity = Number.MAX_VALUE;
step1();
step2();
return getPath();
// Initialization
function step1() {
var selectFrom=g.command("sql","select from V where #rid ="+ ridFrom);
var selectTo=g.command("sql","select from V where #rid ="+ ridTo);
if(selectFrom.length>0 && selectTo.length>0){
from=selectFrom[0];
to=selectTo[0];
S.push(from);
var selectAll=g.command("sql","select from V");
for (i=0;i<selectAll.length;i++) {
if (selectAll[i].getId()!=from.getId())
T.push(selectAll[i]);
}
var index=1;
for (i=0;i<selectAll.length;i++) {
var id = selectAll[i].getId();
if (selectAll[i].getId()!= from.getId()) {
id_weigth[index] = {id:id,weigth:infinity};
index++;
}
else
id_weigth[0] = {id:id,weigth:0};
}
setWeigth_Direction(from);
}
}
// Assignment permanent label
function step2(){
var stop = true;
do {
stop = true;
for (i=0;i<T.length;i++) {
var id = T[i].getId();
for (j=0;j<id_weigth.length;j++) {
if (id_weigth[j].id==id) {
if (id_weigth[j].weigth != infinity){
stop = false;
}
}
}
}
if (stop == true)
break;
else {
var index2 = 0; minWeigth = 0; j = null;
for (i=0;i<T.length;i++) {
var id = T[i].getId();
for (m=0;m<id_weigth.length;m++) {
if (id_weigth[m].id==id) {
if (index2 == 0) {
minWeigth = id_weigth[m].weigth;
index2++;
j = T[i];
}
else if (id_weigth[m].weigth < minWeigth) {
minWeigth = id_weigth[m].weigth;
j = T[i];
}
}
}
}
T.splice(getPositionInT(j.getId()),1);
S.push(j);
if (T.length == 0)
break;
else
step3(j);
}
} while (stop == false);
}
// Assignment temporary label
function step3(j) {
setWeigth_Direction(j);
}
function setWeigth(vertex,direction1,direction2) {
var edges=g.command("sql","select expand(" + direction1+"E()) from "+ vertex.getId());
for(m=0;m<edges.length;m++){
var myEdge=edges[m];;
var idEdge = myEdge.getId().toString();
var validEdge=true;
for (s=0;s<listEdges.length;s++) {
if(listEdges[s]==idEdge)
validEdge=false;
}
if(validEdge==true){
var myWeigth = myEdge.getProperty(property);
var myVertex=g.command("sql","select expand("+ direction2 + ") from " +myEdge.getId());
var id = myVertex[0].getId();
if(vertex!=from){
for (p=0;p<T.length;p++) {
if (T[p].getId()==id) {
var id_weight_i = getId_Weigth(id);
var id_weight_j = getId_Weigth(j.getId());
var weigthi = id_weight_i.weigth;
var weigthj = id_weight_j.weigth;
if (weigthi > weigthj + myWeigth) {
id_weight_i.weigth=weigthj + myWeigth;
id_weight_i.previous=vertex;
}
}
}
}
else{
for (q=0;q<id_weigth.length;q++) {
if (id_weigth[q].id==id) {
id_weigth[q].weigth=myWeigth;
id_weigth[q].previous=vertex;
}
}
}
}
}
}
function getId_Weigth(id) {
for (l=0;l<id_weigth.length;l++) {
if (id_weigth[l].id==id)
return id_weigth[l];
}
return null;
}
function getPath(){
var validPath = true, temp = [], path = [];
temp.push(to);
var npm = getId_Weigth(to.getId());
var v = npm.previous;
while (v != from) {
temp.push(v);
if (v == null) {
validPath = false;
break;
}
npm = getId_Weigth(v.getId());
v = npm.previous;
}
if (validPath == true) {
temp.push(from);
for (i = temp.length - 1; i >= 0; i--)
path.push(temp[i]);
}
return path;
}
function setWeigth_Direction(vertex){
if (direction == "both"){
setWeigth(vertex,"in","out");
setWeigth(vertex,"out","in");
}
else if (direction == "in")
setWeigth(vertex,"in","out");
else
setWeigth(vertex,"out","in");
}
function getPositionInT(id){
for (l=0;l<T.length;l++) {
if(T[l].getId()==id)
return l;
}
return null;
}
I created this class that find the dijkstra path including the option of excluding a specific list of edges by rid number.
DijkstraExcl.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
public class DijkstraExcl {
private OrientGraph g; //grafh DB
private Set<String> S; //visited rids
private Set<String> T; //to visit rids
private Map<String,Integer> f; //f(i) < #rid, weight_to_get_to_#rid >
private Map<String,String> J; //J(i) < #rid, previous_node_in_the_shortest_path >
private String eClass; //edge class to use
private String prop; //weight property to use on the edge
public DijkstraExcl(OrientGraph g, String e, String p){
this.g= g;
this.eClass = e;
this.prop = p;
S = new HashSet<String>();
T = new HashSet<String>();
f = new HashMap<String,Integer>();
J = new HashMap<String,String>();
}
//private methods
// (Vertex start_vertex, Vertex dest_vertex, Direction.IN/OUT/BOTH, Set of edge rids to exclude)
private void findPath(Vertex startV, Vertex endV, Direction dir, Set<String> excludeEdgeRids){
//init
S.clear();
T.clear();
f.clear();
J.clear();
//step1
Iterator<Vertex> vertici = g.getVertices().iterator();
while(vertici.hasNext()){
Vertex ver = vertici.next();
f.put(ver.getId().toString(), Integer.MAX_VALUE);
T.add(ver.getId().toString());
}
f.put(startV.getId().toString(), 0); //f(startV) = 0
J.put(startV.getId().toString(), null); //J(startV) = null
T.remove(startV.getId().toString()); //startV visited => removed from T
S.add(startV.getId().toString()); // and added in S
Iterator<Vertex> near = startV.getVertices(dir, eClass).iterator();
while(near.hasNext()){
Vertex vicino = near.next();
J.put(vicino.getId().toString(), startV.getId().toString()); //J(i) = startV
f.put(vicino.getId().toString(), weight(startV.getId().toString(), vicino.getId().toString(),dir,excludeEdgeRids)); //f(i) = weight(startV, i)
}
//step2
Boolean cont = false;
Iterator<String> t = T.iterator();
while(t.hasNext()){
String i = t.next();
if(f.get(i)!=Integer.MAX_VALUE){
cont = true;
}
}
while(cont){
String j = startV.getId().toString();
Integer ff = Integer.MAX_VALUE;
t = T.iterator();
while(t.hasNext()){
String i = t.next();
if(f.get(i)<=ff){
ff = f.get(i);
j = i;
}
}
T.remove(j);
S.add(j);
if(T.isEmpty()){
break;
}
//step3
near = g.getVertex(j).getVertices(dir, eClass).iterator();
while(near.hasNext()){
Vertex vic = near.next();
String i = vic.getId().toString();
if( (T.contains(i)) && (f.get(i) > (f.get(j) + weight(j,i,dir,excludeEdgeRids))) ){
if(weight(j,i,dir,excludeEdgeRids)==Integer.MAX_VALUE){
f.put(i, Integer.MAX_VALUE);
}else{
f.put(i, (f.get(j) + weight(j,i,dir,excludeEdgeRids)));
}
J.put(i, j);
}
}
//shall we continue?
cont = false;
t = T.iterator();
while(t.hasNext()){
String i = t.next();
if(f.get(i)!=Integer.MAX_VALUE){
cont = true;
}
}
}
}
private int weight(String rid_a, String rid_b, Direction dir, Set<String> excl){ //in case of multiple/duplicate edges return the lightest
Integer d = Integer.MAX_VALUE;
Integer dd;
rid_b = "v["+rid_b+"]";
if(excl==null){
excl = new HashSet<String>();
}
Vertex a = g.getVertex(rid_a);
Iterator<Edge> eS = a.getEdges(dir, eClass).iterator();
Set<Edge> goodEdges = new HashSet<Edge>();
while(eS.hasNext()){
Edge e = eS.next();
if((e.getProperty("out").toString().equals(rid_b) || e.getProperty("in").toString().equals(rid_b)) && !excl.contains(e.getId().toString())){
goodEdges.add(e);
}
}
Iterator<Edge> edges= goodEdges.iterator();
while(edges.hasNext()){
Edge e=edges.next();
dd = e.getProperty(prop);
if(dd<d){
d=dd;
}
}
return d;
}
//public methods
public List<Vertex> getPath (Vertex startV, Vertex endV, Direction dir, Set<String> exclECl){
String j,i;
List<Vertex> ppp = new ArrayList<Vertex>();
List<Vertex> path = new ArrayList<Vertex>();
findPath(startV, endV, dir, exclECl);
i = endV.getId().toString();
path.add(endV);
if(f.get(endV.getId().toString()) == Integer.MAX_VALUE){
return null;
}
while(!i.equals(startV.getId().toString())){
j = J.get(i);
if(j == null){
return null;
}
path.add(g.getVertex(j));
i = j;
}
for(int a=0, b=path.size()-1;a<path.size();a++, b--){
ppp.add(a, path.get(b));
}
return ppp;
}
public List<String> getPathString (Vertex startV, Vertex endV, Direction dir, Set<String> exclECl){
List<String> pathS = new ArrayList<String>();
List<Vertex> path = getPath(startV, endV, dir, exclECl);
if(path == null){
return null;
}
for(Vertex v : path){
pathS.add(v.getId().toString());
}
return pathS;
}
public Integer getWeight(Vertex startV, Vertex endV, Direction dir, Set<String> exclECl){
findPath(startV, endV, dir,exclECl);
return f.get(endV.getId().toString());
}
}
and hers's a testing main:
public class test_dijkstra {
public static void main(String[] args) {
String nomeDb = "dijkstra_test";
try {
OServerAdmin serverAdmin = new OServerAdmin("remote:localhost/"+nomeDb).connect("root", "root");
if(serverAdmin.existsDatabase()){ // il db esiste
//connessione a db
OrientGraph g = new OrientGraph("remote:localhost/"+nomeDb);
DijkstraExcl d = new DijkstraExcl(g, "arco", "peso");
Set<String> ex =new HashSet<String>();
//------------------------------------------------
Vertex start = g.getVertex("#9:0");
Vertex end = g.getVertex("#9:5");
ex.add("#12:4");
Direction direction = Direction.BOTH;
System.out.println(d.getPath(start,end,direction,ex));
System.out.println(d.getPathString(start,end,direction,ex));
System.out.println(d.getWeight(start,end,direction,ex));
//------------------------------------------------
//chiude db
g.shutdown();
}
else{
System.out.println("Il database '"+ nomeDb + "' non esiste");
}
serverAdmin.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
and its output:
[v[#9:0], v[#9:1], v[#9:2], v[#9:4], v[#9:5]]
[#9:0, #9:1, #9:2, #9:4, #9:5]
10
Here's the structure of my test db:
One approach would be to use the fact that OrientDB has some support for "Infinity", as illustrated by this "console.sh" typescript:
> select 1.0E400
----+------+--------
# |#CLASS|1
----+------+--------
0 |null |Infinity
----+------+--------
> select eval('0 < 1.0E400')
----+------+----
# |#CLASS|eval
----+------+----
0 |null |true
----+------+----
> select -1.0E400
----+------+---------
# |#CLASS|-1
----+------+---------
0 |null |-Infinity
----+------+---------
> select eval('0 < -1.0E400')
----+------+-----
# |#CLASS|eval
----+------+-----
0 |null |false
----+------+-----

paging gridview that is loaded with csv file with more than 300 lines

How do I page without having program require user to reload file? Here is the code. Please steer me in right direction, or show me code example.
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile.FileName == string.Empty)
{
return;
}
else
{
string[] FileExt = FileUpload1.FileName.Split('.');
string FileEx = FileExt[FileExt.Length - 1];
if (FileEx.ToLower() == "csv")
{
FileUpload1.SaveAs(Server.MapPath(" " + FileUpload1.FileName));
}
else
{
return;
}
}
CSVReader reader = new CSVReader(FileUpload1.PostedFile.InputStream);
string[] headers = reader.GetCSVLine();
DataTable dt = new DataTable();
foreach (string strHeader in headers)
dt.Columns.Add(strHeader);
string[] data;
while ((data = reader.GetCSVLine()) != null)
dt.Rows.Add(data);
foreach (DataRow row in dt.Rows)
{
string dateAndTime = row["Date and Time"].ToString();
string personName = row["Description #2"].ToString();
string doorType = row["Card number"].ToString();
DateTime dateEntered = Convert.ToDateTime(dateAndTime);
DoorType doorTypeEnum;
bool personExists = false;
foreach (object name in EmployeeListBox.Items)
{
if (name.ToString() == personName)
{
personExists = true;
break;
}
}
if (!personExists)
{
EmployeeListBox.Items.Add(personName);
}
switch (doorType)
{
case "A02 - Rear Entrance":
doorTypeEnum = DoorType.RearEntranceDoor;
break;
case "B12 - Exterior Main Floor Man Trap":
doorTypeEnum = DoorType.ExteriorMainFloorDoor;
break;
case "B12 - Interior Main Floor Man Trap":
doorTypeEnum = DoorType.InteriorMainFloorDoor;
break;
case "C13 - Rear Break Room Door":
doorTypeEnum = DoorType.RearBreakRoomDoor;
break;
case "B02 - Exterior Basement Man Trap":
doorTypeEnum = DoorType.ExteriorBasementDoor;
break;
case "B02 - Interior Basement Man Trap":
doorTypeEnum = DoorType.InteriorBasementDoor;
break;
case "D01 - Managed Services Main door":
doorTypeEnum = DoorType.ManagedServicesDoor;
break;
case "D01 - Managed Services Big Door":
doorTypeEnum = DoorType.ManagedServicesBigDoor;
break;
default:
doorTypeEnum = DoorType.None;
break;
}
peopleEntering.Add(new PersonEntered(personName, dateEntered, doorTypeEnum));
}
for (int i = 0; i < peopleEntering.Count; i++)
{
DateTime startDate = new DateTime();
DateTime endDate = new DateTime();
string personName = peopleEntering[i].PersonName;
if (peopleEntering[i].DoorEntered == DoorType.RearEntranceDoor)
{
startDate = peopleEntering[i].DateOfEntry;
for (int j = i + 1; j < peopleEntering.Count; j++)
{
if (peopleEntering[j].DoorEntered == DoorType.ExteriorBasementDoor && peopleEntering[j].PersonName == personName)
{
endDate = peopleEntering[j].DateOfEntry;
}
}
}
workSpans.Add(new WorkSpan(personName, startDate, endDate));
}
if (IsPostBack )
{
this.csvReaderGv.DataSource = new DataTable();
this.csvReaderGv.DataSource = dt;
this.csvReaderGv.DataBind();
}
}
protected void csvReaderGv_SelectedIndexChanged(object sender, EventArgs e)
{
if (IsPostBack)
{
EmployeeListBox.Visible = true;
messagePanelBox.Visible = true;
DateAndTime.Text = csvReaderGv.SelectedRow.Cells[2].Text;
Description1.Text = csvReaderGv.SelectedRow.Cells[3].Text;
Description2.Text = csvReaderGv.SelectedRow.Cells[4].Text;
Cardnumber.Text = csvReaderGv.SelectedRow.Cells[5].Text;
List<WorkSpan> listOfWorkSpans = new List<WorkSpan>();
string personName = csvReaderGv.Rows[0].Cells[0].ToString();
for (int j = 0; j < workSpans.Count; j++)
{
if (workSpans[j].PersonName == personName)
{
listOfWorkSpans.Add(workSpans[j]);
}
}
}
}
protected void EmployeeListBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (IsPostBack)
{
string personName = EmployeeListBox.Items[EmployeeListBox.SelectedIndex].ToString();
List<WorkSpan> listOfWorkSpan = new List<WorkSpan>();
foreach (WorkSpan workSpan in workSpans)
{
if (workSpan.PersonName == personName)
{
listOfWorkSpan.Add(workSpan);
}
}
int b;
b = Convert.ToInt32(csvReaderGv.Rows[0].ToString());
csvReaderGv.DataSource = listOfWorkSpan;
DateAndTime.Text = csvReaderGv.Rows[b].Cells[2].ToString();
Description1.Text = csvReaderGv.Rows[b].Cells[3].ToString();
Description2.Text = csvReaderGv.Rows[b].Cells[4].ToString();
DateTime startDate = System.Convert.ToDateTime(csvReaderGv.Rows[b].Cells[2].ToString());
DateTime endDate = System.Convert.ToDateTime(csvReaderGv.Rows[b].Cells[2].ToString());
TimeSpan difference = endDate - startDate;
if (true)
{
keyedInHoursLbl.Text = difference.ToString();
keyedInHoursLbl.Visible = true;
}
else
{
}
}
}
protected void csvReaderGv_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
DataTable dt = new DataTable();
csvReaderGv.DataSource = dt;
csvReaderGv.DataBind();
}
Please need assistance. Been staring at this problem, for days

j script runtime error: object requiered

I am working on the platform confirmit, which creates online surveys. This is a script node that results in the runtime error "object required", I would be grateful if you could help me fix it.. It is supposed to check whether certain codes hold 1 or 2 in the questions q2b and q3a (questions are referenced with the function f() - f(question id)[code]) - the
'//skip ?' part. Then it recodes a maximum of four of the codes into another question (h_q4) for further use.
var flag1 : boolean = false;
var flag2 : boolean = false;
//null
for(var i: int=0; i <9; i++)
{
var code = i+1;
f("h_q4")[code].set(null);
}
f("h_q4")['95'].set(null);
//skip ?
for(var k: int=1; k <16; k+=2)
{
var code = k;
if(f("q2b")[code].none("1", "2"))
flag1;
else
{
flag1 = 0;
break;
}
}
if(f("q3a")['1'].none("1", "2"))
flag2;
if(flag1 && flag2)
f("h_q4")['95'].set("1");
//recode
else
{
var fromForm = f("q2b");
var toForm = f("h_q4");
const numberOfItems : int = 4;
var available = new Set();
if(!flag1)
{
for( i = 1; i < 16; i+=2)
{
var code = i;
if(f("q2b")[i].any("1", "2"))
available.add(i);
}
}
if(!flag2)
{
available.add("9");
}
var selected = new Set();
if(available.size() <= numberOfItems)
{
selected = available;
}
else
{
while(selected.size() < numberOfItems)
{
var codes = available.members();
var randomNumber : float = Math.random()*codes.length;
var randomIndex : int = Math.floor(randomNumber);
var selectedCode = codes[randomIndex];
available.remove(selectedCode);
selected.add(selectedCode);
}
}
var codes = fromForm.domainValues();
for(var i = 0;i<codes.length;i++)
{
var code = codes[i];
if(selected.inc(code))
{
toForm[code].set("1");
}
else
{
toForm[code].set("0");
}
}
}
the first part of the code (//null) empties the 'recepient' question to ease testing
.set(), .get(), .any(), .none() are all valid

Resources