Writing my own atomic increment for Firebase RTDB Unity SDK okay? - firebase

So it seems that the RTDB sdk for Unity is missing the atomic increment function that is available in the other SDKs..
this guy -> database.ServerValue.increment(1);
I've noticed all that it is doing is setting the database reference to this object
{
'.sv': {
increment: 5
}
}
I have tested setting this object manually myself as the value for the database reference.. and it works as expected!
My question is..
Is that okay to do? Will that possibly break in the future while i have my app live? Or will i have time to update it to something new if they DO change it?

Yup, writing the sentinel value yourself is fine. We can't guarantee it won't ever break, but the specific value is actually documented for the REST API - so it'd require a major version upgrade if that were to ever change.
There is an open feature request #649 to add it to the SDK, so I'd recommend also chiming in there.

Related

Possibility to modify or extend code in D365FO to suppress thrown error

Original class function creates an SQL query and executes it.
Since there is an syntax error in the query it throws an error. What's the correct way to achieve fixation? Class extension does not work, because CoC executes the complete original function.
originalFunction(..)
{
createSomeSQLQueryWithSyntayErrorInIt();
executeQuery();
}
The class in question is ReqDemPlanMissingForecastFiller. In method insertMissingDatesForecastEntries a direct SQL statement string is generated. The date variable nonFrozenForecastStartDate is added to the string, but is not escaped correctly as it seems.
If the SQL statement is executed, a syntax error occurs. If the statement is fixed, it can be executed e.g. in SQL Server Management Studio (SSMS).
In this specific case, based on your comments, you may be able to sidestep.
Create a new class ReqDemPlanMissingForecastFiller_Fix extending ReqDemPlanMissingForecastFiller then copy/paste the erroneous function and correct the mistake.
Create an extension class and change the newParameters static funcion.
[ExtensionOf(classStr(ReqDemPlanMissingForecastFiller))]
class ReqDemPlanMissingForecastFiller_Extention
{
public static ReqDemPlanMissingForecastFiller newParameters(
ReqDemPlanCreateForecastDataContract _dataContract,
ReqDemPlanAllocationKeyFilterTmp _allocationKeyFilter,
ReqDemPlanTaskLoggerInterface _logger = null)
{
ReqDemPlanMissingForecastFiller filler = next newParameters(_dataContract, _allocationKeyFilter, _logger);
filler = new ReqDemPlanMissingForecastFiller_Fix(); //Throw away previous value
filler.parmDataContract(_dataContract);
filler.parmAttributeManager(_dataContract.attributeManager());
filler.parmAllocationKeyFilter(_allocationKeyFilter);
filler.parmLogger(_logger);
filler.init();
return filler;
}
}
Code above was based on AX 2012 code. Stupid solution to a stupid problem.
It goes almost without saying that you should report the problem to Microsoft.
#Jan B. Kjeldsen's answer describes how the specific case can be solved without involving Microsoft.
Since overlayering is no longer possible, the solution involves copying a fair bit of standard code. This brings its own risks, because future changes by Microsoft for that code are not reflected in the copied code.
Though it cannot always be avoided, other options should be evaluated first:
As #Jan B. Kjeldsen mentioned, errors in the standard code should be reported to Microsoft (see Get support for Finance and Operations apps or Lifecycle Services (LCS)). This enables them to fix the error.
Pro: No further work needed.
Con: Microsoft may decline the fix or take a long time to implement it.
If unlike in this specific case the issue is not a downright error, but a lack of extension options, an extensibility request can be created with Microsoft. They will then add an extension option.
Pro: No further work needed.
Con: Microsoft may decline the extensibility request or take a long time to implement it.
For both errors as well as missing extension options, Microsoft also offers the Community Driven Engineering program (CDE). This enables you to develop changes in the standard code directly via a special Microsoft hosted repository where the standard code is not locked for changes.
Pro: Most flexible and fastest of all options involving Microsoft.
Con: You have to do the work yourself. Microsoft may decline the change. It can still take some time before the change is available in a GA version.
You can also consider a hybrid approach: For a quick solution, copy standard code and customize it as required. But also report an error, create an extensibility request or fix it yourself in the CDE program. When the change is available in standard code, you can then remove the copied code again.

Firestore Document get request promise doesn't resolve. How do I solve this problem?

Summary
I am using react-native-firebase in my project, and I am running pure react-native (No Expo). However, on putting a get request to any document on Firestore never gives a response. That is, in a try-catch block, neither does it resolve, nor does it get rejected, it keeps on going forever and ever.
(And yeah, I know about promises and I am using await/async so its not about waiting for the promise to complete, in fact, the main thing is that promises are not getting resolved/rejected)
The main issue is that this problem comes randomly, its not like it fails every time, it does it randomly. On close observation, I also observed that this happens mostly when I am constantly doing get requests, for example, I have a query which checks for the latest version in a document, now whenever I reload the app, this get query is made, and on 2-3 frequent reloads, this query never resolves.
I can do all other Firebase stuffs, like checking authentication, setting documents data, deleting, modifying editing etc. But this doesn't work out
A Bit of Background Story
This is my first project in react-native and react-native-firebase. In the past, I have been working on Ionic, and native Android (Java). I never faced this issue there. I have been searching on the internet a lot, and a few solutions that I got were mainly for the Firebase Web SDK, and not for react-native-firebase.
I found one solution, about resetting user from the Authentication console, but that never worked either. I am putting forward the link which I found (for reference, as my problem is quite similar to this, and mainly differs in the fact that I use react-native-firebase, and not the Firebase Web SDK).
https://github.com/firebase/firebase-js-sdk/issues/533
Code Samples
Get Queries (Few Code Samples which I am using)
let updateData = await firebase.firestore().doc('Updates And Errors/Updates').get();
var expensesDoc = await firebase.firestore().doc(`NewExpenses/${dateToday}`).get()
Expected Output
All Get queries should function at all times.
Actual Output
Get Queries only work when they are not called frequently. (I know its quite weird)
Have you tried using regular promise (then/catch) syntax? I have personally noticed some promise inconsistencies while using the react-native-firebase library with redux-saga's call as well (it simply didn't work, just like you mentioned). To solve my issue, I simply wrapped all the requests in functions that return a new, actual promise, which somehow worked. Still a mystery why though.
Example:
function get (query) {
return new Promise((resolve, reject) => {
query.get()
.then(data => resolve(data))
.catch(err => reject(err))
})
}
// Later use:
await get(firebase.firestore().doc('yourDoc'))
If you ever find a proper solution, please let me know, as this code obviously smells.

How to create multiple USE statements in sniff

I'm working on a sniff for PHP_CodeSniffer 3.x. For example, the class declaration class NoInlineFullyQualifiedClassNameUnitTestInc extends \PSR2R\Base\AbstractBase should be split into a uses and class AbstractBase. The sniff detects similar issues for method signatures.
I believe the problem is that I'm generating and inserting multiple use statements at the same line (i.e., same token), but doing so in separate fixer->beginChangeset() ... fixer->endChangeset() sequences. The fixer treats multiple sets of changes to the same token as a conflict, and things get messy (and wrong).
The GitHub issue is here: https://github.com/php-fig-rectified/psr2r-sniffer/issues/9
Has anyone figured out how to do this writing custom sniffs for the latest 3.x CodeSniffer?
You can also use SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff
It turns this
Into this
How to use it?
The best is to use it with EasyCodingStandard like this:
# easy-coding-standard.neon
checkers:
- SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff
Install it:
composer require --dev symplify\easy-coding-standard
Run it:
vendor/bin/ecs check src
Fix it:
vendor/bin/ecs check src --fix
Enjoy and let me know how it works for you.
If any troubles come up, just create an issue here. I'm happy to improve this tool as much as possible.
The problem is multiple Sniffer (fixer) changesets editing the same token. I was able to get the Sniff to work by collecting a list of USE statements and inserting them at the end of the Sniff's processing.
I identified the end of processing by searching backwards from the last token to find the first token of the list of registered tokens.
Edit: Here is the sniff: https://github.com/php-fig-rectified/psr2r-sniffer/blob/master/PSR2R/Sniffs/Namespaces/NoInlineFullyQualifiedClassNameSniff.php

Using a collection that already exists in Meteor

How do you access a Meteor collection that already exists? It's easy enough when you have created the collection in the session because you have a variable that references it, but you can't access a collection by name.
What happens if for example you want to retrieve documents from an existing collection in a new session where it is not being created for the first time. I have tried to 're-create' it hoping that it would just assign the existing collection to the new variable name (seeing that I can't find it by name), but it just throws an error to tell you that the collection already exists.
I've got some externally generated collections that I'm accessing via meteor. I'm not 100% sure that this will answer your question, but I hope it'll at least help.
One gotcha (doesn't apply to you it sounds like, here for completeness) is that if your collection was not created by Meteor, you'll need to export an environment variable to point Meteor to your DB.
For example, if the following env. variable is exported in the shell:
MONGO_URL=mongodb://localhost:3002/foo
...and then you invoke the meteor application, it'll point to the db "foo" in MongoDb, at which point you simply defined your collections as #Akshat mentions above in his comment:
collection = new Meteor.Collection("fooCollection") // this lives inside the foo DB.
If you're dealing with collections that have already been created by Meteor, by default they'll be inside the meteor db, eg:
MONGO_URL=mongodb://localhost:3002/meteor
...and you should be able to simply hook into them the same way; by simply declaring your collection and using it as you would. No need to create, obviously.
It sounds like you're already doing this but for other newcomers like me: in cases like this it's really handy to use the console in Chrome, Firefox, etc. and do some inserts that way - you'll see where your data lands, or you'll see other good bits of information that will help you home in on the issue - console.log() has saved my bacon a couple of times.
At any rate, it's worth validating exactly where the Meteor app is pointing vs. where you think it's pointing. Your collections should be accessible and should Just Work...

How to make global variables in android?

After google i found three ways:
1. static variables
2. extending Application and using getApplicationContext
3. SharedPreferences
EDIT: read comments pls, i don't want to delete it, because it may help other who fell into the same trap...
Be careful with static variables!! I wrote an app which uses them, but on some devices it works, on some it doesn't. the problem is, if one activity edits that variable, finishes and the focus returns to another activity, the changes are not recognized. i haven't found a solution for this and somehow i don't get it working with getApplicationContext either...
Usually i would say that i made a mistake, but in both cases, it is working on an SGSII with Android 4.0.4 but it isn't on SGSIII with 4.1... :(
So as a consequence i assume that they've changed the use of global variables, maybe out of security reasons, so that every activity gets an own instance of that variable or so, i have no idea

Resources