Why can I not find journalentries using their RefNumber in Quickbooks SDK? - quickbooks

I boiled this down to a simple example that always fails using QB Enterprise. (Oddly, I could swear this code used to work.)
Create a journal entry via SDK with a specific ref number "PTD1234"
Search for that specific journal entry in the same code block
Observe, no results found?
However, if I change the process to create the same journal entry by hand in QB, then the search code below works correctly and finds the journal entry.
Quickbooks qb = new Quickbooks();
qb.Connect(this);
IMsgSetRequest msr = qb.sm.CreateMsgSetRequest("US", 7, 0);
msr.Attributes.OnError = ENRqOnError.roeStop;
IJournalEntryAdd jea = msr.AppendJournalEntryAddRq();
jea.TxnDate.SetValue(new DateTime(2013, 3, 1));
jea.RefNumber.SetValue("PTD1234");
IJournalCreditLine jcl = jea.ORJournalLineList.Append().JournalCreditLine;
jcl.Amount.SetValue(1);
jcl.AccountRef.FullName.SetValue("Credit Card Batches:Paymentech");
jcl.EntityRef.FullName.SetValue("CHASE PAYMENTECH");
IJournalDebitLine jdl = jea.ORJournalLineList.Append().JournalDebitLine;
jdl.Amount.SetValue(1);
jdl.AccountRef.FullName.SetValue("Chase Deposits EUR");
jdl.EntityRef.FullName.SetValue("CHASE PAYMENTECH");
IMsgSetResponse msp = qb.sm.DoRequests(msr);
IResponse resp = msp.ResponseList.GetAt(0);
if (resp.StatusCode != 0)
{
Log("-------------\r\nError during test");
Log(resp.StatusMessage);
}
IJournalEntryRet jet = null;
msr = qb.sm.CreateMsgSetRequest("US", 7, 0);
msr.Attributes.OnError = ENRqOnError.roeStop;
IJournalEntryQuery q = msr.AppendJournalEntryQueryRq();
q.metaData.SetValue(ENmetaData.mdNoMetaData);
q.ORTxnQuery.TxnFilter.ORRefNumberFilter.RefNumberFilter.RefNumber.SetValue("PTD1234");
q.ORTxnQuery.TxnFilter.ORRefNumberFilter.RefNumberFilter.MatchCriterion.SetValue(ENMatchCriterion.mcContains);
q.ORTxnQuery.TxnFilter.AccountFilter.ORAccountFilter.FullNameList.Add("Chase Deposits EUR");
q.IncludeLineItems.SetValue(false);
msp = qb.sm.DoRequests(msr);
if (msp.ResponseList.Count > 0)
{
IResponseList rl = msp.ResponseList;
if (rl.Count >= 1)
{
IResponse r = rl.GetAt(0);
if (r.Detail == null)
Log("Fail: Detail was null");
if (r.StatusCode != 0)
Log("Fail: Status code was not zero");
if (r.Type.GetValue() == (short)ENResponseType.rtJournalEntryQueryRs)
{
IJournalEntryRetList crl = (IJournalEntryRetList)r.Detail;
if (crl != null && crl.Count == 1)
jet = crl.GetAt(0);
}
}
}
if (jet != null)
Log("Success!");
qb.Cleanup();

For unknown reasons, some journalentries won't show up using a JournalEntryQuery and the TxnFilter.ORRefNumberFilter.RefNumberFilter. However, a workaround is to use the ORTxnQuery.RefNumberList and then cycle through the Journal Lines and make sure the account matches.
public bool GetExactJournalTransaction(string sRefNum, string sAccount, out IJournalEntryRet jet)
{
jet = null;
IMsgSetRequest msr = sm.CreateMsgSetRequest("US", 4, 0);
msr.Attributes.OnError = ENRqOnError.roeStop;
IJournalEntryQuery q = msr.AppendJournalEntryQueryRq();
q.metaData.SetValue(ENmetaData.mdNoMetaData);
q.ORTxnQuery.RefNumberList.Add(sRefNum);
q.IncludeLineItems.SetValue(true);
IMsgSetResponse resp = sm.DoRequests(msr);
if (resp.ResponseList.Count == 0)
return false;
IResponseList rl = resp.ResponseList;
if (rl.Count == 1)
{
IResponse r = rl.GetAt(0);
if (r.Detail == null)
return false;
if (r.StatusCode != 0)
return false;
if (r.Type.GetValue() == (short)ENResponseType.rtJournalEntryQueryRs)
{
IJournalEntryRetList crl = (IJournalEntryRetList)r.Detail;
if (crl != null)
{
for (int i = 0; i < crl.Count; i++)
{
jet = crl.GetAt(i);
for (int j = 0; j < jet.ORJournalLineList.Count; j++)
{
IORJournalLine l = jet.ORJournalLineList.GetAt(j);
if (l.JournalCreditLine != null && l.JournalCreditLine.AccountRef.FullName.GetValue() == sAccount)
return true;
else if (l.JournalDebitLine != null && l.JournalDebitLine.AccountRef.FullName.GetValue() == sAccount)
return true;
}
}
}
}
}
return false;
}

Related

OpenXML not replacing FieldCode which having more than 41characters as display text not with result values

While a Field Code has more than 40 characters then OpenXML does not replace FieldCode with result values also Formating is not getting applied for the same. The below is working fine filed codes which have up to 40 characters but failed for more than 40 characters.
var format = "";
foreach (var paragraph in wordDocument.MainDocumentPart.RootElement.Descendants())
{
foreach (FieldCode fieldCode in paragraph.Descendants())
{
if (!String.IsNullOrEmpty(fieldCode.InnerText) && fieldCode.InnerText.Trim() != null && fieldCode.InnerText.Trim() != ""
&& (fieldCode.InnerText.Contains('#') || fieldCode.InnerText.Contains('#')))
{
if (fieldCode.InnerText.Contains('#'))
{
var indexofsymbol = fieldCode.InnerText.IndexOf('#') + 1;
format = fieldCode.InnerText.Substring(indexofsymbol, fieldCode.InnerText.Length - indexofsymbol);
}
else if (fieldCode.InnerText.Contains('#'))
{
var indexofsymbol = fieldCode.InnerText.IndexOf('#') + 1;
format = fieldCode.InnerText.Substring(indexofsymbol, fieldCode.InnerText.Length - indexofsymbol);
}
Run xxxfield = (Run)fieldCode.Parent;
Run rBegin = xxxfield.PreviousSibling<Run>();
Run rSep = xxxfield.NextSibling<Run>();
Run rText = rSep.NextSibling<Run>();
Run rEnd = rText.NextSibling<Run>();
if (null != xxxfield)
{
Text t = rEnd.GetFirstChild<Text>();
t = xxxfield.Descendants<Text>().FirstOrDefault();
if (t == null)
t = rText.GetFirstChild<Text>();
if (t != null)
{
var fieldName = t.Text.ToString().Substring(1, t.Text.Length - 2);
if (mergeFields.TryGetValue(fieldName, out dictValue))
{
if (fieldCode.InnerText.Contains('#'))
{
DateTime date = DateTime.Parse(dictValue);
t.Text = date.ToString(format); //Convert.ToDateTime(dictValue).ToString(format);
}
else if (fieldCode.InnerText.Contains('#'))
{
t.Text = Convert.ToDouble(dictValue).ToString(format);
}
}
}
}
}
}
}

Getting Illegal Instruction:4

I was trying to do this function in C but for some reason is giving me "Illegal instruction: 4"... From what I looked up it may be because I'm using iOs, but still I'm using VSCode and not a project so I have no idea how to correct it.
The function is the following:
void divideSocios(void){
int i;
for (i = 0; i < MAXFILA || socios[i].next != -1; i++){
if (socios[i].sc.pago >= 50){
if (semDiv[0].next == 0){
semDiv[0].next = -1;
semDiv[0].sc.id = socios[i].sc.id;
semDiv[0].sc.pago = socios[i].sc.pago;
strcpy(semDiv[0].sc.nome, socios[i].sc.nome);
}
else{
for (; i < MAXFILA && semDiv[i].next != -1; i++);
semDiv[i-1].next = i;
semDiv[i].next = -1;
semDiv[i].sc.pago = socios[i].sc.pago;
semDiv[i].sc.id = socios[i].sc.id;
strcpy(semDiv[i].sc.nome, socios[i].sc.nome);
}
} else {
if (comDiv[0].next == 0){
comDiv[0].next = -1;
comDiv[0].sc.id = socios[i].sc.id;
comDiv[0].sc.pago = socios[i].sc.pago;
strcpy(comDiv[0].sc.nome, socios[i].sc.nome);
}
else{
for (; i < MAXFILA && comDiv[i].next != -1; i++);
comDiv[i-1].next = i;
comDiv[i].next = -1;
comDiv[i].sc.pago = socios[i].sc.pago;
comDiv[i].sc.id = socios[i].sc.id;
strcpy(comDiv[i].sc.nome, socios[i].sc.nome);
}
}
}
}
I basically have 3 different linked lists by matrix, each node with a struct and the index of the current node, and depending on the "pago" atribute from the struct of the node I want to separate them from the original list between the other 2.

A star algorithm with multiple goals [duplicate]

Let's consider a simple grid, where any point is connected with at most 4 other points (North-East-West-South neighborhood).
I have to write program, that computes minimal route from selected initial point to any of goal points, which are connected (there is route consisting of goal points between any two goals). Of course there can be obstacles on grid.
My solution is quite simple: I'm using A* algorithm with variable heuristic function h(x) - manhattan distance from x to nearest goal point. To find nearest goal point I have to do linear search (in O(n), where n - number of goal points). Here is my question: is there any more efficient solution (heuristic function) to dynamically find nearest goal point (where time < O(n))?
Or maybe A* is not good way to solve that problem?
How many goals, tens or thousands? If tens your way will work fine, if thousands then nearest neighbor search will give you ideas on setting up your data to search quickly.
The tradeoffs are obvious, spatially organizing your data to search will take time and on small sets brute force will be simpler to maintain. Since you're constantly evaluating I think that structuring the data will be worthwhile at very low numbers of points.
An alternate way to do this would be a modified flood fill algorithm that stops once it reaches a destination point during the flood.
First, decide whether you need to optimize, because any optimization is going to complicate your code, and for a small number of goals, your current solution is probably fine for a simple heuristic like Manhattan distance.
Before taking the first step, compute the heuristic for each goal. Remember the nearest goal as the currently selected goal, and move toward it, but subtract the maximum possible progress toward any goal from all the other distances. You can consider this second value a "meta-heuristic"; it is an optimistic estimate of the heuristic for other goals.
On subsequent steps, compute the heuristic for the current goal, and any goals with a "meta-heuristic" that is less than or equal to the heuristic. The other goals can't possibly have a better heuristic, so you don't need to compute them. The nearest goal becomes the new current goal; move toward it, subtracting the maximum possible progress from the others. Repeat until you arrive at a goal.
Use Dijkstra's algorithm, which has as it's output the minimal cost to all reachable points. Then you just select the goal points from the output.
you may consider this article If your goals not too much and want simple ways
If you want to search for any of several goals, construct a heuristic
h'(x) that is the minimum of h1(x), h2(x), h3(x), ... where h1, h2, h3
are heuristics to each of the nearby spots.
One way to think about this is that we can add a new zero-cost edge
from each of the goals to a new graph node. A path to that new node
will necessarily go through one of the goal nodes.
If you want to search for paths to all of several goals, your best
option may be Dijkstra’s Algorithm with early exit when you find all
the goals. There may be a variant of A* that can calculate these
paths; I don’t know.
If you want to search for spot near a single goal, ask A* search to
find a path to the center of the goal area. While processing nodes
from the OPEN set, exit when you pull a node that is near enough.
You can calculate the f score using the nearest target. As others said, for naive approach, you can directly calculate all target distance from current node and pick the minimum, if you only have few targets to search. For more than 100 targets, you can probably find the nearest by KDTree to speed up the process.
Here is a sample code in dart.
Iterable<Vector2> getPath(Vector2 from, Iterable<Vector2> targets,
{double? maxDistance, bool useAStar = false}) {
targets = targets.asSet();
clearPoints();
var projectedTargets = addPoints(targets).toSet();
var tree = useAStar ? IKDTree(targets) : null;
var q = PriorityQueue<Node>(_priorityQueueComparor);
Map<Vector2, Node> visited = {};
var node = Node(from);
visited[from] = node;
q.add(node);
while (q.isNotEmpty) {
var current = q.removeFirst();
// developer.log(
// '${current.point}#${current.distance}: ${getEdges(current.point).map((e) => e.dest)}');
for (var edge in getEdges(current.point)) {
if (visited.containsKey(edge.dest)) continue;
var distance = current.distance + edge.distance;
// too far
if (maxDistance != null && distance > maxDistance) continue;
// it is a target
if (projectedTargets.contains(edge.dest)) {
return reconstructPath(visited, current, edge.dest);
}
// we only interested in exploring polygon node.
if (!_polygonPoints.contains(edge.dest)) continue;
var f = 0.0;
if (tree != null) {
var nearest = tree
.nearest(edge.dest, maxDistance: maxDistance ?? double.infinity)
.firstOrNull;
f = nearest != null ? edge.dest.distanceToSquared(nearest) : 0.0;
}
node = Node(edge.dest, distance, current.count + 1, current.point, f);
visited[edge.dest] = node;
q.add(node);
}
}
return [];
}
Iterable<Vector2> reconstructPath(
Map<Vector2, Node> visited, Node prev, Vector2 point) {
var path = <Vector2>[point];
Node? currentNode = prev;
while (currentNode != null) {
path.add(currentNode.point);
currentNode = visited[currentNode.prev];
}
return path.reversed;
}
int _priorityQueueComparor(Node p0, Node p1) {
int r;
if (p0.f > 0 && p1.f > 0) {
r = ((p0.distance * p0.distance) + p0.f)
.compareTo((p1.distance * p1.distance) + p1.f);
if (r != 0) return r;
}
r = p0.distance.compareTo(p1.distance);
if (r != 0) return r;
return p0.count.compareTo(p1.count);
}
and the implementation of KDTree
class IKDTree {
final int _dimensions = 2;
late Node? _root;
IKDTree(Iterable<Vector2> points) {
_root = _buildTree(points, null);
}
Node? _buildTree(Iterable<Vector2> points, Node? parent) {
var list = points.asList();
if (list.isEmpty) return null;
var median = (list.length / 2).floor();
// Select the longest dimension as division axis
var axis = 0;
var aabb = AABB.fromPoints(list);
for (var i = 1; i < _dimensions; i++) {
if (aabb.range[i] > aabb.range[axis]) {
axis = i;
}
}
// Divide by the division axis and recursively build.
// var list = list.orderBy((e) => _selector(e)[axis]).asList();
list.sort(((a, b) => a[axis].compareTo(b[axis])));
var point = list[median];
var node = Node(point.clone());
node.parent = parent;
node.left = _buildTree(list.sublist(0, median), node);
node.right = _buildTree(list.sublist(median + 1), node);
update(node);
return node;
}
void addPoint(Vector2 point, [bool allowRebuild = true]) {
_root = _addByPoint(_root, point, allowRebuild, 0);
}
// void removePoint(Vector2 point, [bool allowRebuild = true]) {
// if (node == null) return;
// _removeNode(node, allowRebuild);
// }
Node? _addByPoint(
Node? node, Vector2 point, bool allowRebuild, int parentDim) {
if (node == null) {
node = Node(point.clone());
node.dimension = (parentDim + 1) % _dimensions;
update(node);
return node;
}
_pushDown(node);
if (point[node.dimension] < node.point[node.dimension]) {
node.left = _addByPoint(node.left, point, allowRebuild, node.dimension);
} else {
node.right = _addByPoint(node.right, point, allowRebuild, node.dimension);
}
update(node);
bool needRebuild = allowRebuild && criterionCheck(node);
if (needRebuild) node = rebuild(node);
return node;
}
// checked
void _pushDown(Node? node) {
if (node == null) return;
if (node.needPushDownToLeft && node.left != null) {
node.left!.treeDownsampleDeleted |= node.treeDownsampleDeleted;
node.left!.pointDownsampleDeleted |= node.treeDownsampleDeleted;
node.left!.treeDeleted =
node.treeDeleted || node.left!.treeDownsampleDeleted;
node.left!.deleted =
node.left!.treeDeleted || node.left!.pointDownsampleDeleted;
if (node.treeDownsampleDeleted) {
node.left!.downDeletedNum = node.left!.treeSize;
}
if (node.treeDeleted) {
node.left!.invalidNum = node.left!.treeSize;
} else {
node.left!.invalidNum = node.left!.downDeletedNum;
}
node.left!.needPushDownToLeft = true;
node.left!.needPushDownToRight = true;
node.needPushDownToLeft = false;
}
if (node.needPushDownToRight && node.right != null) {
node.right!.treeDownsampleDeleted |= node.treeDownsampleDeleted;
node.right!.pointDownsampleDeleted |= node.treeDownsampleDeleted;
node.right!.treeDeleted =
node.treeDeleted || node.right!.treeDownsampleDeleted;
node.right!.deleted =
node.right!.treeDeleted || node.right!.pointDownsampleDeleted;
if (node.treeDownsampleDeleted) {
node.right!.downDeletedNum = node.right!.treeSize;
}
if (node.treeDeleted) {
node.right!.invalidNum = node.right!.treeSize;
} else {
node.right!.invalidNum = node.right!.downDeletedNum;
}
node.right!.needPushDownToLeft = true;
node.right!.needPushDownToRight = true;
node.needPushDownToRight = false;
}
}
void _removeNode(Node? node, bool allowRebuild) {
if (node == null || node.deleted) return;
_pushDown(node);
node.deleted = true;
node.invalidNum++;
if (node.invalidNum == node.treeSize) {
node.treeDeleted = true;
}
// update and rebuild parent
var parent = node.parent;
if (parent != null) {
updateAncestors(parent);
bool needRebuild = allowRebuild && criterionCheck(parent);
if (needRebuild) parent = rebuild(parent);
}
}
void updateAncestors(Node? node) {
if (node == null) return;
update(node);
updateAncestors(node.parent);
}
void _removeByPoint(Node? node, Vector2 point, bool allowRebuild) {
if (node == null || node.treeDeleted) return;
_pushDown(node);
if (node.point == point && !node.deleted) {
node.deleted = true;
node.invalidNum++;
if (node.invalidNum == node.treeSize) {
node.treeDeleted = true;
}
return;
}
if (point[node.dimension] < node.point[node.dimension]) {
_removeByPoint(node.left, point, false);
} else {
_removeByPoint(node.right, point, false);
}
update(node);
bool needRebuild = allowRebuild && criterionCheck(node);
if (needRebuild) rebuild(node);
}
// checked
void update(Node node) {
var left = node.left;
var right = node.right;
node.treeSize = (left != null ? left.treeSize : 0) +
(right != null ? right.treeSize : 0) +
1;
node.invalidNum = (left != null ? left.invalidNum : 0) +
(right != null ? right.invalidNum : 0) +
(node.deleted ? 1 : 0);
node.downDeletedNum = (left != null ? left.downDeletedNum : 0) +
(right != null ? right.downDeletedNum : 0) +
(node.pointDownsampleDeleted ? 1 : 0);
node.treeDownsampleDeleted = (left == null || left.treeDownsampleDeleted) &&
(right == null || right.treeDownsampleDeleted) &&
node.pointDownsampleDeleted;
node.treeDeleted = (left == null || left.treeDeleted) &&
(right == null || right.treeDeleted) &&
node.deleted;
var minList = <Vector2>[];
var maxList = <Vector2>[];
if (left != null && !left.treeDeleted) {
minList.add(left.aabb.min);
maxList.add(left.aabb.max);
}
if (right != null && !right.treeDeleted) {
minList.add(right.aabb.min);
maxList.add(right.aabb.max);
}
if (!node.deleted) {
minList.add(node.point);
maxList.add(node.point);
}
if (minList.isNotEmpty && maxList.isNotEmpty) {
node.aabb = AABB()
..min = minList.min()
..max = maxList.max();
}
// TODO: Radius data for search: https://github.com/hku-mars/ikd-Tree/blob/main/ikd-Tree/ikd_Tree.cpp#L1312
if (left != null) left.parent = node;
if (right != null) right.parent = node;
// TODO: root alpha value for multithread
}
// checked
final minimalUnbalancedTreeSize = 10;
final deleteCriterionParam = 0.3;
final balanceCriterionParam = 0.6;
bool criterionCheck(Node node) {
if (node.treeSize <= minimalUnbalancedTreeSize) return false;
double balanceEvaluation = 0.0;
double deleteEvaluation = 0.0;
var child = node.left ?? node.right!;
deleteEvaluation = node.invalidNum / node.treeSize;
balanceEvaluation = child.treeSize / (node.treeSize - 1);
if (deleteEvaluation > deleteCriterionParam) return true;
if (balanceEvaluation > balanceCriterionParam ||
balanceEvaluation < 1 - balanceCriterionParam) return true;
return false;
}
void rebuildAll() {
_root = rebuild(_root);
}
// checked
Node? rebuild(Node? node) {
if (node == null) return null;
var parent = node.parent;
var points = flatten(node).toList();
// log('rebuilding: $node objects: ${objects.length}');
deleteTreeNodes(node);
return _buildTree(points, parent);
// if (parent == null) {
// _root = newNode;
// } else if (parent.left == node) {
// parent.left = newNode;
// } else if (parent.right == node) {
// parent.right = newNode;
// }
}
// checked
Iterable<Vector2> flatten(Node? node) sync* {
if (node == null) return;
_pushDown(node);
if (!node.deleted) yield node.point;
yield* flatten(node.left);
yield* flatten(node.right);
}
void deleteTreeNodes(Node? node) {
if (node == null) return;
_pushDown(node);
deleteTreeNodes(node.left);
deleteTreeNodes(node.right);
}
double _calcDist(Vector2 a, Vector2 b) {
double dist = 0;
for (var dim = 0; dim < _dimensions; dim++) {
dist += math.pow(a[dim] - b[dim], 2);
}
return dist;
}
// checked
double _calcBoxDist(Node? node, Vector2 point) {
if (node == null) return double.infinity;
double minDist = 0;
for (var dim = 0; dim < _dimensions; dim++) {
if (point[dim] < node.aabb.min[dim]) {
minDist += math.pow(point[dim] - node.aabb.min[dim], 2);
}
if (point[dim] > node.aabb.max[dim]) {
minDist += math.pow(point[dim] - node.aabb.max[dim], 2);
}
}
return minDist;
}
void _search(Node? node, int maxNodes, Vector2 point, BinaryHeap<Result> heap,
double maxDist) {
if (node == null || node.treeDeleted) return;
double curDist = _calcBoxDist(node, point);
double maxDistSqr = maxDist * maxDist;
if (curDist > maxDistSqr) return;
if (node.needPushDownToLeft || node.needPushDownToRight) {
_pushDown(node);
}
if (!node.deleted) {
double dist = _calcDist(point, node.point);
if (dist <= maxDistSqr &&
(heap.size() < maxNodes || dist < heap.peek().distance)) {
if (heap.size() >= maxNodes) heap.pop();
heap.push(Result(node, dist));
}
}
double distLeftNode = _calcBoxDist(node.left, point);
double distRightNode = _calcBoxDist(node.right, point);
if (heap.size() < maxNodes ||
distLeftNode < heap.peek().distance &&
distRightNode < heap.peek().distance) {
if (distLeftNode <= distRightNode) {
_search(node.left, maxNodes, point, heap, maxDist);
if (heap.size() < maxNodes || distRightNode < heap.peek().distance) {
_search(node.right, maxNodes, point, heap, maxDist);
}
} else {
_search(node.right, maxNodes, point, heap, maxDist);
if (heap.size() < maxNodes || distLeftNode < heap.peek().distance) {
_search(node.left, maxNodes, point, heap, maxDist);
}
}
} else {
if (distLeftNode < heap.peek().distance) {
_search(node.left, maxNodes, point, heap, maxDist);
}
if (distRightNode < heap.peek().distance) {
_search(node.right, maxNodes, point, heap, maxDist);
}
}
}
/// Find the [maxNodes] of nearest Nodes.
/// Distance is calculated via Metric function.
/// Max distance can be set with [maxDistance] param
Iterable<Vector2> nearest(Vector2 point,
{int maxNodes = 1, double maxDistance = double.infinity}) sync* {
var heap = BinaryHeap<Result>((e) => -e.distance);
_search(_root, maxNodes, point, heap, maxDistance);
var found = math.min(maxNodes, heap.content.length);
for (var i = 0; i < found; i++) {
yield heap.content[i].node.point;
}
}
int get length => _root?.length ?? 0;
int get height => _root?.height ?? 0;
}
class Result {
final Node node;
final double distance;
const Result(this.node, this.distance);
}
class Node {
Vector2 point;
int dimension = 0;
Node? parent;
Node? left;
Node? right;
int treeSize = 0;
int invalidNum = 0;
int downDeletedNum = 0;
bool deleted = false;
bool treeDeleted = false;
bool needPushDownToLeft = false;
bool needPushDownToRight = false;
bool treeDownsampleDeleted = false;
bool pointDownsampleDeleted = false;
AABB aabb = AABB();
Node(this.point);
int get length {
return 1 +
(left == null ? 0 : left!.length) +
(right == null ? 0 : right!.length);
}
int get height {
return 1 +
math.max(
left == null ? 0 : left!.height,
right == null ? 0 : right!.height,
);
}
int get depth {
return 1 + (parent == null ? 0 : parent!.depth);
}
}

Stream file from ftp in localhost working in azure no

Hi I using VisualStudio 2012 and I have created web site which reads info (from .csv) from external ftp site. When I running it on local host everything works fine, but then I deployed it to azure web sites it is not working, just show zeros everywhere were should be numbers. (Dont get info from ftp)
public static List<ApiClient.Models.StatsList> GetStatsData(string Ticket, DateTime start, DateTime end, int CampaignId, String CampaignName)
{
//--------------------------------------------------------------------------------------------------------
//Gets stats from GetAdsStats service (included: Banner id, impressions, and clicks)
//--------------------------------------------------------------------------------------------------------
List<ApiClient.Models.StatsList> FullList = GetAdStatsService.GetAdsStats(Ticket, start, end, CampaignId);
List<LikesDislikesList> LikeDislike = new List<LikesDislikesList>();
//--------------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------------
string day;
string month;
if (DateTime.Today.AddDays(-1).Day.ToString().Count() == 1)
{
day = "0" + DateTime.Today.AddDays(-1).Day;
}
else
{
day = DateTime.Today.AddDays(-1).Day.ToString();
}
if (DateTime.Today.Month.ToString().Count() == 1)
{
month = "0" + DateTime.Today.Month;
}
else
{
month = DateTime.Today.Month.ToString();
}
try
{
string uri = "ftp://siteAdres" + CampaignName.Replace(" ", "_") + "_Optimizing_events_" + day + "-" + month + "-" + DateTime.Today.Year + ".csv";
Uri serverUri = new Uri(uri);
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return FullList;
}
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
reqFTP.Credentials = new NetworkCredential("username", "password");
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = null;
reqFTP.UsePassive = false;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader csvStream = new StreamReader(response.GetResponseStream());
//--------------------------------------------------------------------------------------------------------
//Read Likes/Dislikes from csv file stream
//--------------------------------------------------------------------------------------------------------
using (var rd = csvStream)
{
int iname = -1;
int ilikes = -1;
int idislikes = -1;
while (!rd.EndOfStream)
{
var raw = rd.ReadLine().Split((char)9);
if (rd.Peek() == -1)
{
break;
}
if (ilikes == -1 || idislikes == -1)
{
for (int i = 0; i < raw.Length; i++)
{
if (raw[i] == "Event name")
iname = i;
if (raw[i] == "Custom Event 14")
ilikes = i;
if (raw[i] == "Custom Event 15")
{
idislikes = i;
raw = rd.ReadLine().Split((char)9);
}
}
}
else
{
LikeDislike.Add(new LikesDislikesList() { Likes = Convert.ToInt32(raw[ilikes]), Dislikes = Convert.ToInt32(raw[idislikes]), Name = raw[iname] });
}
}
}
response.Close();
}
catch(Exception ex)
{
log4net.Config.XmlConfigurator.Configure();
log.Warn("GetAdStatsService.cs " + ex);
}
//--------------------------------------------------------------------------------------------------------
//Add like/dislike values for certain banners
//--------------------------------------------------------------------------------------------------------
foreach (var element in FullList)
{
foreach (var el in LikeDislike)
{
if (element.name == el.Name)
{
element.Likes = el.Likes;
element.Dislikes = el.Dislikes;
}
}
}
return FullList;
}
}
}
Check FtpWebResponse.StatusCode before calling response.GetResponseStream(). You are probably having come kind of connection error. My guess would be firewall settings on your Azure VM.

blackberry app download issue

I am building an AppWorld sort of thing in blackberry.I have Categories,sub categories and apps within.I want to do in-app download,but as of now i am calling the browser and passing the url and downloading of the content happens.How to make in-app download or download from within my app just like the AppWorld of blackberry.
YOu need to use code module manager API to download and install applications.
Code in bits and pieces
_moduleGroup = new CodeModuleGroup(appVendorName);
_moduleGroup.setVersion(JADParser.getValue("MIDlet-Version"));
_moduleGroup.setVendor(vendorName);
_moduleGroup.setFriendlyName(appName);
_moduleGroup.setDescription(JADParser.getValue("MIDlet-Description"));
String dependency = JADParser.getValue("RIM-COD-Module-Dependencies");
if (dependency != null)
{
dependency = dependency.trim();
String[] dependencyList = vStringUtils.split(dependency, ',');
for (int i = 0; i < dependencyList.length; i++)
{
_moduleGroup.addDependency(dependencyList[i]);
}
}
for (i = 0; i < count; i++)
{
if (!writeCODFile(getCodFileData(i), getCodFileName(i)))
{
throw new Exception();
}
}
private boolean writeCODFile(byte[] data, String fileName)
{
boolean isSuccess = true;
int moduleId = 0;
if (data.length > MODULE_SIZE_LIMIT)
{
moduleId = CodeModuleManager.createNewModule(data.length, data, MODULE_SIZE_LIMIT);
isSuccess = CodeModuleManager.writeNewModule(moduleId, MODULE_SIZE_LIMIT, data, MODULE_SIZE_LIMIT, data.length - MODULE_SIZE_LIMIT);
}
else
{
moduleId = CodeModuleManager.createNewModule(data.length, data, data.length);
}
if (moduleId > 0 && isSuccess)
{
int ret = CodeModuleManager.saveNewModule(moduleId, true, _transactionId);
if (ret == CodeModuleManager.CMM_OK_MODULE_OVERWRITTEN || ret == CodeModuleManager.CMM_OK)
{
return true;
}
}
return false;
}

Resources