What's the difference between NSLocale currentLocale vs autoupdatingCurrentLocale? - foundation

What's the difference between NSLocale currentLocale vs autoupdatingCurrentLocale? It's not obvious from reading the documentation.

When the user changes their system locale settings, the autoupdating one automatically updates to the new locale.

The currentLocale only retrieve an locale object one time from the current user's settings. autoupdatingCurrentLocale updates the locale object on the fly so you don't need to validate. You might think autoupdateingCurrentLocale is the prefer way, it is per Apple documentation; however, since the returned object may be cached, you don't really need to hold on to it indefinitely when using currentLocale, verse autoupdateingCurrentLocale.
If you are using autoupdatingCurrentLocale, note that this API do not cache the locale object, so you will need a way to compute cache upon receipt. One way is to use notification such as NSCurrentLocaleDidChangeNotification method call.

Related

Catel using IEditableObject

I am testing Catel MVVM and I would like to use the implemented IEditableObject. I have got some questions, but the documentation I've found, isn't very detailed in this point.
Did someone have a helpful link, how I have to set this up or how it works, or something like this? Or should I really have a look to the source code, to get these points and get a feeling, how catel do the work.
The questions, that I have got, are these:
What exactly does the method SaveViewModelAsync()?
Where does it save the data, or where can I configurate it?
How can I use it with Orc.EntityFramework6, or do I have this manually?
What's the different between SaveViewModelAsync() and SaveAsync()?
What's the different between CancelViewModelAsync() and CancelAsync()?
I can only cancel the editing one time. If I edit the same ViewModel again, the cancel has no effect anymore.
I think there is only an BeginEdit() missing after the first cancel, like this documentation suggests. Here some informations to this point:
I edit the ViewModel and the Model set the new value
I execute CancelViewModelAsync(), the setter in the Model is not touched
I edit the ViewModel and the Model set the new value. The current value is the original value
I execute CancelViewModelAsync(), nothing happened
I edit the ViewModel and the Model set the new value. The current value is the edited value from step 3, like the View shows
Thanks for help
Lots of questions in a single question, but will try to answer them:
Q1) What exactly does the method SaveViewModelAsync()
It calls IEditableObject.EndEdit on all models that support it (and are decorated with the ModelAttribute
Q2) Where does it save the data, or where can I configurate it?
It just approves the changes to the model, it doesn't "save" anything. So for example, if you are using Catel models, it will commit the changes made by the VM. If you would cancel, it would revert the model back to the state it was when you initialized the VM.
Q3) How can I use it with Orc.EntityFramework6, or do I have this manually?
You have to do this manually. The VM's in Catel work with models, it's up to you when / where you persist them to (e.g. a database, disk, web service, etc)
Q4) What's the different between SaveViewModelAsync() and SaveAsync()?
SaveViewModelAsync is the public method being called and takes care of the plumbing for you. SaveAsync is a method you can override to add additional save logic (e.g. storing in database, update services, etc).
Q5) What's the different between CancelViewModelAsync() and CancelAsync()?
See Q4

How can I set the shipcarrier to More on a sales order using SuiteScript in a RESTlet?

SuiteScript v1, but I'll switch to SS v2 if it's the only way to make it work.
I've tried:
salesOrder.setFieldText('shipcarrier', 'More');
salesOrder.setFieldValue('shipcarrier', 'noups');
salesOrder.setFieldValue('shipcarrier', 'nonups');
But UPS is always selected once the record is saved.
shipcarrier is a bit of an odd thing.
I'm not sure it is actually sticky - in some contexts it appears to be and in some it doesn't.
It appears to be pointless to set unless you are also setting shipmethod.
salesOrder.setFieldValue('shipcarrier', ffShipCarrier); //'ups' || 'nonups'
salesOrder.setFieldValue('shipmethod', ffShipMethod)
PS from cja: My conclusion/solution: Setting shipmode does nothing unless recordmode is dynamic and shipmethod is set at the same time. If both those conditions are met then the value shipmode will be updated.
NetSuite support have warned me against using this solution:
"With regards to your concern, I am able to set the Ship carrier field on the Sales Order record in the client script(nlapiSetFieldValue('shipcarrier', 'ups');) however I was unable to set the value of the field in the server side script. Upon further investigation, the field (ship carrier) isn't exposed in the Record browser hence the field isn't officially exposed for scripting needs. Please refer to the following Suiteanswer article for your reference.
"I am really glad that the solution worked for you perfectly. In order to explain further, I would say it is not advisable to write scripts using unexposed fields in the record browser. It may change in the future without any prior notification and can cause problem and NetSuite will not hold any kind of responsibility for the same.
"User groups contains simple solution to complex tips and tricks provided by the experienced customers. On the other hand, NetSuite Support are stickly adhering to the official documentation/processes to assist any of its customer. The solutions provided in the User groups are totally upto the consent of the customers and can be implemented at their own risk if not confirmed in the official documentation or NetSuite Support."
You need to use setFieldValue and pass the internal id of the "More" ship carrier.
nlapiSubmitField('salesorder', recordid, 'shipcarrier', 'nonups');

How to read value of property at uninstallation?

I have created one basic MSI project in InstallShield. I want to achieve one scenario. For this I'm setting one property at the time of installation using installScript function MsiSetProperty(). But I want also read the value of same property at the time of uninstallation. I need the value of property at uninstallation, which is set at the time of installation.
So is there any way to retrieve the value of property at uninstallation, which is set at the time of installation?
Reading a property at uninstallation is the same as reading it during installation: you call MsiGetProperty(), and if it's in a deferred context you have to pass it through the CustomActionData property. Note as well that setting a property during a deferred context doesn't do much.
However what's probably tripping you up is that properties, in general, are not preserved across Windows Installer sessions. There are exceptions, such as DirProperties for installed components, that are automatically preserved. But most properties are simply forgotten when the current action ends. The typical recommendation is to follow the 'remember property pattern' which, in a nutshell, consists of saving the value of the property to a registry key, and reading it back with a system search.
I just tried a workaround for this. I'm setting registry value at the time of installation & reading that property at uninstallation and setting a value of it to property.

Reverting CoreData data

I have an NSTableView which is populated via a CoreData-backed NSArrayController. Users are able to edit any field they choose within the NSTableView. When they select the rows that they have modified and press a button, the data is sent to a third-party webservice. Provided the webservice accepts the updated values, I want to commit those values to my persistent store. If, however, the webservice returns an error (or simply fails to return), I want the edited fields to revert to their original values.
To complicate matters, I have a number of other editable controls, backed by CoreData, which do not need to resort to this behaviour.
I believe the solution to this problem revolves around the creation of a secondary Managed Object context, which I would use only for values edited within that particular NSTableView. But I'm confused as to how the two MOC would interact with each other.
What's the best solution to this problem?
The easiest solution would be to implement Core Data's undo functionality. That way you make the changes to Core Data but if the server returns the error, you just rollback the changes. See the Core Data docs for details.

Creating Lotus Notes documents with specific created/modified/last accessed dates for testing

I'm currently writing an application that moves Notes documents between databases based on the amount of days that have elapsed from the creation/modified/last accessed dates. I would just like to get ideas on a simple and convenient way to create documents with specific dates, without having to change the time on the Domino server, so that I could test out my application.
The best way I found so far was to create a local replica and change the system clock to the date I want. Unfortunately there are problems associated with this method. It does not work on the modified date - I'm not sure how it is getting the modified date information when the location is set to Island (Disconnected) - and it also changes the modified and last accessed dates when the documents are replicated to the server replica.
Someone suggested trying to create a DXL of the document, modify the date time in the DXL file, then import it back into the database as a Notes document; but that does not work. It just takes on the date-time that it was created.
Can anyone offer any other suggestions?
You can set the created date for a document by setting the UNID (which is fundamentally a struct of timestamps, although the actual implementation has changed in recent versions). Accessed and modified times, though, would be unsettable from within the Notes/Domino environment, since the changes you make would be overwritten by the process of saving the changes. If you have a flair for adventure and a need to run with scissors, you could make the changes in the database file itself either programmatically from an external application, or manually with a hex editor. (Editing the binary will work -- folks have been using hex editors to clear the "hide design" flag safely for years. Keep in mind that signed docs will blow up badly, and that you need to ensure that local encryption is off for the database file.)
There's actually a very simple way to spoof the creation date/time: just add a field called $Created with whatever date/time you want. This is alluded to in the Notes C API header file nsfdata.h:
Time/dates associated with notes:
OID.Note Can be Timedate when the note was created
(but not guaranteed to be - look for $CREATED
item first for note creation time)
Obtained by NSFNoteGetInfo(_NOTE_OID) or
OID in SEARCH_MATCH.
Unfortunately, there's no analogous technique for spoofing the mod or access dates. At least none that's ever been documented, as far as I know.
I imagine given how dependent Lotus Notes is on timestamps (for replication, mainly), there isn't an API call that allows you to change the modified, created, or last access dates of a note. (More on the internals of Lotus Notes can be found here.)
I dug around the Notes C API documentation, and found only one mention on how to get/set information in the note's header, including the modified date. However, the documentation states that when you try to update that note (i.e. write it to disk), the last modified date will be overwritten with the date/time it is written to disk.
As an alternative, I would suggest creating your own set of date items within the documents that only you control, for example MyCreated, MyModified, and MyAccessed, and reference those in your code that moves documents based on dates. You would then be able to change these dates as easily as changing any other document item (via agents, forms, etc.)
For MyCreated, create a hidden calculated form field with the formula of #CREATED or #NOW. Set the type to computed when composed.
For MyModified, create a hidden calculated form field with the formula #NOW, and set the type to computed.
MyAccessed gets a bit tricky. If you can do without it, I suggest you live work with just the MyCreated and MyModified. If you need it, you should be able to manage it by setting a field value within the QueryOpen or PostOpen events. Problems occur if your users have only read access to a document - the code to update the MyAccessed field won't be able to store that value.
Hope this helps!

Resources