If() Logic not working after xamarin update - xamarin.ios

Iam working with xamarin and monotouch and monodroid.
I have a strange problem - I just updated to the newest update in visual studio 2013 and monodroid.
In of of my classes I have the following code:
if (string.IsNullOrEmpty(Password) || string.IsNullOrEmpty(Username))
{
return;
}
Password and Username are property strings and no matter what it always
evaluate true. If both have values it still says true. Its very frustrating as
none of my code is working after the update.
Does anybody have a suggestion what to do
EDIT:
After some more digging I believe the debugger was playing a trick on me. It seemed that it hit the return when stepping - but actually it executed the subsequent code correct. However I needed to change the code. It was some simple date calculation.
var seventies = new DateTime (1970, 1, 1);
var time = DateTime.UtcNow - seventies.ToUniversalTime ();
However this triggered an out of range exception which stopped my appflow. I changed it to
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var d = DateTime.UtcNow.Subtract (epoch);
And now it seems to work. I don't like the fact that the debugger led me to believe something else was wrong. I don't like either that the datetime calculation which worked for the past year suddenly stops working.

Related

Error message "cannot find function getFullYear(...)" when entering date and trying to save the record

We are trying in a RESTLet to access the sublist "demandplandetail" from a NetSuite Item Demand Plan. Everything goes fine until a certain point. We are able to load it and process the demandplan for 2020. However, here it gets frustrating.
We know (can see from NetSuite) that there is data also for 2021. However, to access that from SuiteScript seems very difficult.
1st solution) The item demand plan has the field "year". OK, just set that to 2021, save and reload the record. Result: saving ignored, year still is 2020.
2nd solution) Set the year using a Date object as in:
var demandPlan = record.load(...)
var d = new Date();
demandPlan.setValue({
fieldId: 'year',
value: d
});
Gives the following:
:"TypeError: Cannot find function getFullYear in object NaN. (NLRecordScripting.scriptInit$lib#59)","stack":["setDatesForMonthAndYear(NLRecordScripting.scriptInit:108)","anonymous(N/serverRecordService)"
on saving the record. I also get the same using (various) strings adhering to acceptable date formats (as in '1/1/2021'). I have also tried the format package giving me a date string -> the same result.
Also read somewhere that you may need to set the start date (field 'startdate') in the record. Tried several variations but it stubbornly refuses :(.
Wonder if anyone has seen anything similar?
Best Regards,
Toni
Hi Please try the below code also check if you're passing date object to the field not the date string.
function formatDate() {
var dateROBD = format.parse({
value: new Date(),
type: format.Type.DATE
});
// this line optional if you want to try with or else ignore this
dateROBD = convertUTCDateToLocalDate(new Date(dateROBD));
return dateROBD;
}
function convertUTCDateToLocalDate(date) {
var newDate = new Date(date.getTime() + date.getTimezoneOffset() * 60 * 1000);
var offset = date.getTimezoneOffset() / 60;
var hours = date.getHours();
newDate.setHours(hours - offset);
return newDate;
}
OK, mystery solved. Turned out that this is not supported in SuiteScript 2.0 but you need to use 1.0.

Typescript Multi Dimensional Array's Values Not Updating (to null)

What I am Doing
I am trying to create a Sudoku solver and generator in Vue. Right now, I have the solving algorithm set up, and just need to generate new problems. I am generating problems by creating a completed Sudoku problem (complete with no bugs), then I have to remove nodes so that there is still only 1 solution to the problem.
The Problem
When I try to access a node from the multi-dimensional array that represents the board, and change it to null (what I am using to display a blank node), the board does not update that value. I am changing it with the following code: newGrid[pos[0]][pos[1]] = null; (where pos[0] is the row, pos[1] is the column , and newGrid is grid we want to mutate). Note that the array is an array with 9 arrays inside, and each of those arrays has 9 numbers (or null) which represent the values for that position in the grid. To elaborate on the bug, if I put a console.log(newGrid), there are normal looking values, and no null.
What I Know and Have Tried
I know it has to do with this specific line, and the fact that I am setting the value equal to null because changing null to another value (i.e. newGrid[pos[0]][pos[1]] = 0;) works and changes the array. The reason I don't just use a value other than null is: null renders and nothing and other values (0) render as something (null nodes should be blank), null is simple to understand in this situation (the logic is node has null, node has nothing, node is blank), and null is already implemented throughout my codebase.
Additionally, if I use console.log(newGrid[pos[0]][pos[1]]), null (the correct output) is outputted, even though console.log(newGrid) shows a number there, not null. Also, oddly enough, this works for one specific node. In row 1 (indexing starts at 0), column 8, null is set. Even though the input (completed) grid is always different, this node is always set to null. Edit: this bug had to do with the input grid already having null here, so it actually doesn't let any nulls be set.
To summarize: I expect an array with a null in a few positions I update, but I get a number instead. Also, there are no errors when the Typescript compiles to Javascript or during runtime.
Code
Given that I am not exactly sure where the problem may be (i.e. maybe I create the array wrong) I am including the minimum code with a pastebin link to the whole file (this is the full code). To restate, the goal of this function is to remove nodes from the list (by replacing them with null) in order to create a Sudoku puzzle with one solution. The code on Stack Overflow only includes some of the whole file, and the pastebin link includes the rest.
//global.d.ts
type Nullable<T> = T | null;
type Grid = Array<Array<number | null>>;
import { Solver } from './Solve';
// Inside the function that does the main work
const rowLen: number = grid.length;
const colLen: number = grid[0].length;
let newGrid: Grid = grid; // Grid is a argument for this function
let fullNodes = GetFirstFull(grid, colLen, rowLen);
let fullNodesLen: number = fullNodes.length;
// Some stuff that figures out how many solutions there are (we only want 1) is excluded
if (solutions != 1) {
fullNodesLen++;
rounds--;
} else {
newGrid[pos[0]][pos[1]] = null;
}
Note that if anything seems confusing check out the pastebin or ask. Thank you so much for taking the time to look at my problem!
Also, it isn't just 0 that works, undefined also makes it set correctly. So, this problem seems to be something with the null keyword...
EDIT:
Given that no one has responded yet, I assume: my problem is a bit hard, there isn't enough information, my post isn't good quality, or not enough people have seen it. To control the problem of not enough information, I would like to include the function that calls this function (just to see if that might be related).
generate(context: ActionContext<State, any>) {
let emptyArray = new Array(9);
for (let i = 0; i < 9; ++i)
emptyArray[i] = [null, null, null, null, null, null, null, null, null];
const fullGrid = Solver(emptyArray);
const puzzle = fullGrid ? Remover(fullGrid, 6) : state.gridLayout;
context.commit('resetBoard', puzzle);
},
Note: If you aren't familiar with Vuex, what context.commit does is changes the state (except it is changing a global state rather than a component state). Given that this function isn't refactored or very easy to read code in the first place, if you have any questions, please ask.
To solve other potential problems: I have been working on this, I have tried a lot of console.log()ing, changing the reference (newGrid) to a deepcopy, moving stuff out of the if statements, verifying code execution, and changing the way the point on the newGrid is set (i.e. by using newgrid.map() with logic to return that point as null). If you have any questions or I can help at all, please ask.

Online Word breaks when inserting a content control

I have tested this with Script Lab (https://www.microsoft.com/en-us/garage/profiles/script-lab/) and it seems saving a document (automatically) to One Drive breaks Word if the document has something in it inserted through an add in (reproduced with a different add in that uses the same piece of code).
This is the code for Script Lab:
$("#run").click(run);
var content = '<span>Hello, World!</span>';
async function run() {
Word.run(function (context) {
var range = context.document.getSelection();
var cc = range.insertContentControl();
var ccRange = cc.insertHtml(content, 'replace');
cc.tag = 'citation';
cc.select('end');
context.load(cc);
context.load(range);
context.load(ccRange);
return context.sync();
})
}
The code above successfully inserts content to selection. However, if I wait for a couple of moments after inserting, Word breaks on saving and asks me to send an error report. Same code does not produce any errors on the desktop version of Word. Also, same piece of code has been used by our add in for months now without any issues until now.
Any ideas what is this about? Is there something wrong with the online version of Word or should the code for inserting be somehow updated?

CLLocation does not have a Coordinates property

I am just working my way through the location services for the first time and everything appears to be working in that it correctly finds my location but I am having trouble extracting the coordinates.
The docs states that CLLocation has a "Coordinates" property and the compiler is happy with this piece of code. However at runtime the CLLocation only appears to return a string description.
I start the location manager
_locationManager = new CLLocationManager ();
_locationManager.DesiredAccuracy = 1000;
// handle the updated location method and update the UI
_locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
UpdateLocation (e.Locations [e.Locations.Length - 1], _destinationLatitude, _destinationLongitude);
};
if (CLLocationManager.LocationServicesEnabled)
_locationManager.StartUpdatingLocation ();
The event fires correctly
static public void UpdateLocation (CLLocation current, Double destinationLat, Double destinationLng)
{
//Make the start pairing
string start = current.Coordinate.Latitude.ToString() + "," + current.Coordinate.Longitude.ToString();
//Make the destination pairing
string destination = destinationLat.ToString() + "," + destinationLng.ToString();
}
However the app just crashes out. Catching it on a breakpoint I see the following which only appears to have a description property that contains.
Description "<+50.58198902,-3.67661728> +/- 65.00m (speed -1.00 mps / course -1.00) # 25/07/2013 13:11:28 British…" string
I can obviously extract the lat/lng from this text field but I get the feeling I shouldn't need to do this. Any help appreciated.
I moved the exact same code into a different controller and it worked fine. The only difference between the two controllers was that the failing controller was using the monotouch dialog reflection api to bind the screen elements. I can't see why this would make any difference but it is the only difference between the two controllers. Everything is working now, I will try to reproduce in a smaller sample if I get the time.

Issue in timezone with Node.js Module 'time'

I just came across an issue that has happened today (due to being 31st of January here in Australia Sydney). Basically, given a year,date,hour,minute,second. I want to create a date as if I am in a timezone (Australia/Sydney) and then convert it to UTC (i.e. getting the milliseconds).
This is done due to the fact that the database (and the server) works in UTC, where as the client can be in any given timezone (when a post request is done, the client provides both the timezone and the year,month,date,hour,minute,second values)
The problem is, that when I am creating a date for today, its throwing off the date all the way back to January the 3rd of this month, here is the code that illustrates the problem
var scheduled, someTime, time, timeinfo, timezone;
process.env.TZ = 'UTC';
time = require('time');
timeinfo = {
hour: 14,
minute: '47',
year: 2013,
month: 1,
date: 31
};
timezone = 'Australia/Sydney';
someTime = new Date(timeinfo.year, timeinfo.month - 1, timeinfo.date, timeinfo.hour, timeinfo.minute, 1, 1);
scheduled = time.Date(timeinfo.year, timeinfo.month - 1, timeinfo.date, timeinfo.hour, timeinfo.minute, 1, 1, timezone);
console.log(someTime);
console.log(scheduled);
When you run this in Node.js, the time outputted by console.log(scheduled); is completely off.
Note: I am using the time npm library.
Seems to be a bug with how node-time calculates timezones, related to the order of the operations when doing the transform. There's an open issue (#28) on github.com as of now.
I have submitted a pull request, try that in the mean-time and see if it works for your particular case.
Please try the following codes
1.For GMT Time
var GMTtimeObj = new Date();
2.For UTC Time:
var UTCtimeObj = +new Date();
Let me know does it works for your requirement.
Go through this post's answers as well it might help you..
This was a bug that was fixed recently, please look at https://github.com/TooTallNate/node-time/pull/30
Its working perfectly now

Resources