How to define compile time variable on Shared Code Project code - visual-studio

I'm currently working on adding some code to a project (XrmFakeEasy) that uses a Shared Code Project as main code repository .
I want to make changes to the following code paths :
#if FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9
// Connect to the CRM web service using a connection string.
CrmServiceClient client = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);
return client;
#else
CrmConnection crmConnection = CrmConnection.Parse(connectionString);
OrganizationService service = new OrganizationService(crmConnection);
return service;
#endif
Currently, the code between #if FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9 and #else is greyed, and Intellisense/Debugging won't work on it.
Is there a way to get intellisense on the greyed code or to define the compile time variable on a shared code project ?

Is there a way to get intellisense on the greyed code or to define the
compile time variable on a shared code project ?
As far as I know, it is designed by that and there is no such option to change it.
In such project, the current if condition is not valid(due to false condition) and is in the inactive area, which means that this part of the project will not be executed and therefore cannot obtain its Intellisense.
As a suggestion, you can try to assign a true condition to #if, in your situation, please first use this:
1) use this
#if true
////you can obtain the intellisense for this
#else
.....
#endif
2) then change to this:
#if false
.........
#else
//////add your code here with the related Intellisense
#endif
3) then change to this:
#if FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9
.........
#else
........
#endif

Related

Can asynchronous module definitions be used with abstract syntax trees on v8 engine to read third party dependencies? [duplicate]

I understand eval string-to-function is impossible to use on the browsers' application programming interfaces, but there must be another strategy to use third party dependencies without node.js on v8 engine, given Cloudflare does it in-house, unless they disable the exclusive method by necessity or otherwise on their edge servers for Workers. I imagine I could gather the AST of the commonjs module, as I was able to by rollup watch, but what might the actual steps be, by tooling? I mention AMD for it seems to rely on string-to-function (to-which I've notice Mozilla MDN says nothing much about it).
I have been exploring the require.js repositories, and they either use eval or AST
function DEFNODE(type, props, methods, base) {
if (arguments.length < 4) base = AST_Node;
if (!props) props = [];
else props = props.split(/\s+/);
var self_props = props;
if (base && base.PROPS) props = props.concat(base.PROPS);
var code = "return function AST_" + type + "(props){ if (props) { ";
for (var i = props.length; --i >= 0; ) {
code += "this." + props[i] + " = props." + props[i] + ";";
}
var proto = base && new base();
if ((proto && proto.initialize) || (methods && methods.initialize))
code += "this.initialize();";
code += "}}";
//constructor
var cnstor = new Function(code)();
if (proto) {
cnstor.prototype = proto;
cnstor.BASE = base;
}
if (base) base.SUBCLASSES.push(cnstor);
cnstor.prototype.CTOR = cnstor;
cnstor.PROPS = props || null;
cnstor.SELF_PROPS = self_props;
cnstor.SUBCLASSES = [];
if (type) {
cnstor.prototype.TYPE = cnstor.TYPE = type;
}
if (methods)
for (i in methods)
if (HOP(methods, i)) {
if (/^\$/.test(i)) {
cnstor[i.substr(1)] = methods[i];
} else {
cnstor.prototype[i] = methods[i];
}
}
//a function that returns an object with [name]:method
cnstor.DEFMETHOD = function (name, method) {
this.prototype[name] = method;
};
if (typeof exports !== "undefined") exports[`AST_${type}`] = cnstor;
return cnstor;
}
var AST_Token = DEFNODE(
"Token",
"type value line col pos endline endcol endpos nlb comments_before file raw",
{},
null
);
https://codesandbox.io/s/infallible-darwin-8jcl2k?file=/src/mastercard-backbank/uglify/index.js
https://www.youtube.com/watch?v=EF7UW9HxOe4
Is it possible to make a C++ addon just to add a default object for
node.js named exports or am I Y’ing up the wrong X
'.so' shared library for C++ dlopen/LoadLibrary (or #include?)
“I have to say that I'm amazed that there is code out there that loads one native addon from another native addon! Is it done by acquiring and then calling an instance of the require() function, or perhaps by using uv_dlopen() directly?”
N-API: An api for embedding Node in applications
"[there is no ]napi_env[ just yet]."
node-api: allow retrieval of add-on file name - Missing module in Init
Andreas Rossberg - is AST parsing, or initialize node.js abstraction for native c++, enough?
v8::String::NewFromUtf8(isolate, "Index from C++!");
Rising Stack - Node Source
"a macro implicit" parameter - bridge object between
C++ and JavaScript runtimes
extract a function's parameters and set the return value.
#include <nan.h>
int build () {
NAN_METHOD(Index) {
info.GetReturnValue().Set(
Nan::New("Index from C++!").ToLocalChecked()
);
}
}
// Module initialization logic
NAN_MODULE_INIT(Initialize) {
/*Export the `Index` function
(equivalent to `export function Index (...)` in JS)*/
NAN_EXPORT(target, Index);
}
New module "App" Initialize function from NAN_MODULE_INIT (an atomic?-macro)
"__napi_something doesn't exist."
"node-addon-API module for C++ code (N-API's C code's headers)"
NODE_MODULE(App, Initialize);
Sep 17, 2013, 4:42:17 AM to v8-u...#googlegroups.com "This comes up
frequently, but the answer remains the same: scrap the idea. ;)
Neither the V8 parser nor its AST are designed for external
interfacing. In particular (1) V8's AST does not necessarily reflect
JavaScript syntax 1-to-1, (2) we change it all the time, and (3) it
depends on various V8 internals. And since all these points are
important for V8, don't expect the situation to change.
/Andreas"
V8 c++: How to import module via code to script context (5/28/22, edit)
"The export keyword may only be used in a module interface unit.
The keyword is attached to a declaration of an entity, and causes that
declaration (and sometimes the definition) to become visible to module
importers[ - except for] the export keyword in the module-declaration, which is just a re-use of the keyword (and does not actually “export” ...entities)."
SyntheticModule::virtual
ScriptCompiler::CompileModule() - "Corresponds to the ParseModule abstract operation in the ECMAScript specification."
Local<Function> foo_func = ...;//external
Local<Module> module = Module::CreateSyntheticModule(
isolate, name,
{String::NewFromUtf8(isolate, "foo")},
[](Local<Context> context, Local<Module> module) {
module->SetSyntheticModuleExport(
String::NewFromUtf8(isolate, "foo"), foo_func
);
});
Context-Aware addons from node.js' commonjs modules
export module index;
export class Index {
public:
const char* app() {
return "done!";
}
};
import index;
import <iostream>;
int main() {
std::cout << Index().app() << '\n';
}
node-addon-api (new)
native abstractions (old)
"Thanks to the crazy changes in V8 (and some in Node core), keeping native addons compiling happily across versions, particularly 0.10 to 0.12 to 4.0, is a minor nightmare. The goal of this project is to store all logic necessary to develop native Node.js addons without having to inspect NODE_MODULE_VERSION and get yourself into a macro-tangle[ macro = extern atomics?]."
Scope Isolate (v8::Isolate), variable Local (v8::Local)
typed_array_to_native.cc
"require is part of the Asynchronous Module Definition AMD API[, without "string-to-function" eval/new Function()],"
node.js makes objects, for it is written in C++.
"According to the algorithm, before finding
./node_modules/_/index.js, it tried looking for express in the
core Node.js modules. This didn’t exist, so it looked in node_modules,
and found a directory called _. (If there was a
./node_modules/_.js, it would load that directly.) It then
loaded ./node_modules/_/package.json, and looked for an exports
field, but this didn’t exist. It also looked for a main field, but
this didn’t exist either. It then fell back to index.js, which it
found. ...require() looks for node_modules in all of the parent directories of the caller."
But java?
I won't accept this answer until it works, but this looks promising:
https://developer.oracle.com/databases/nashorn-javascript-part1.html
If not to run a jar file or something, in the Worker:
https://github.com/nodyn/jvm-npm
require and build equivalent in maven, first, use "dist/index.js".
Specifically: [ScriptEngineManager][21]
https://stackoverflow.com/a/15787930/11711280
Actually: js.commonjs-require experimental
https://docs.oracle.com/en/graalvm/enterprise/21/docs/reference-manual/js/Modules/
Alternatively/favorably: commonjs builder in C (v8 and node.js)
https://www.reddit.com/r/java/comments/u7elf4/what_are_your_thoughts_on_java_isolates_on_graalvm/
Here I will explore v8/node.js src .h and .cc for this purpose
https://codesandbox.io/s/infallible-darwin-8jcl2k?file=/src/c.cpp
I'm curious why there is near machine-level C operability in Workers if not to use std::ifstream, and/or build-locally, without node.js require.

what is wrong with this use of goto?

I'm using a goto statement to skip a piece of code (as per documentation), just for testing purposes while I debug a block of code. I'm getting an error 1526, "goto into protected scope". This is totally trivial I know, but I want to know what is wrong with how I'm using the goto code:
#if defined(_PLAT_ANDROID)
_di_JIntent MyIntent;
MyIntent = TJIntent::JavaClass->init(TJIntent::JavaClass->ACTION_VIEW,
TJnet_Uri::JavaClass->parse(StringToJString("http://relayman.org/papers/2009_FDA_paper.pdf")));
TAndroidHelper::Activity->startActivity(MyIntent);
goto Skipit;
Androidapi::Jni::Graphicscontentviewtext::_di_JIntent intent = TJIntent::Create();
intent->setDataAndType(StringToJString("file://" + System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetSharedDownloadsPath(), "sample.pdf")), StringToJString(L"application/pdf"));
intent->setAction(TJIntent::JavaClass->ACTION_VIEW);
intent->setFlags(TJIntent::JavaClass->FLAG_GRANT_READ_URI_PERMISSION);
if (SharedActivity()->getPackageManager()->queryIntentActivities(intent, TJPackageManager::JavaClass->MATCH_DEFAULT_ONLY)->size() > 0) {
SharedActivity()->startActivity(intent);
} else {
ShowMessage("PDF viewer not found");
}
Skipit:
#endif
I'm working in 10.3.2 and building toward Android target.

How do I add global properties to generated Visual Studio projects and solutions via premake5?

I would like to add two conditional properties to my project configuration to target a non-default vcpkg triplet: https://github.com/microsoft/vcpkg/blob/master/docs/users/integration.md#with-msbuild
My project files are generated by premake. How would I go about this?
you could try to override the global function from the visual studio generator some thing like this ... not tested ...
local vs2010 = premake.vstudio.vs2010
function vcPkgOverride(prj)
-- go trough the configs and platforms and figure out which conditions to put
for _, cfg in pairs(prj.cfgs) do
local condition = vs2010.condition(cfg)
if cfg.platform == "Win32" then
vs2010.vc2010.element("VcpkgTriplet ", condition, "x86-windows-static")
else if cfg.platform == "x64" then
vs2010.vc2010.element("VcpkgTriplet ", condition, "x64-windows-static")
end
end
end
premake.override(vc2010.elements, "globals", function (oldfn, prj)
local elements = oldfn(prj)
elements = table.join(elements, {
vcPkgOverride
})
end
return elements
end)
UPDATE
The code above doesn't seem to work for premake5.0.0-alpha14 so I tweaked it based on the docs and here you have a less general, but working version:
require('vstudio')
local vs = premake.vstudio.vc2010
local function premakeVersionComment(prj)
premake.w('<!-- Generated by Premake ' .. _PREMAKE_VERSION .. ' -->')
end
local function vcpkg(prj)
premake.w('<VcpkgTriplet>x64-windows-static</VcpkgTriplet>')
premake.w('<VcpkgEnabled>true</VcpkgEnabled>')
end
premake.override(premake.vstudio.vc2010.elements, "project", function(base, prj)
local calls = base(prj)
table.insertafter(calls, vs.xmlDeclaration, premakeVersionComment)
return calls
end)
premake.override(premake.vstudio.vc2010.elements, "globals", function(base, prj)
local calls = base(prj)
table.insertafter(calls, vs.globals, vcpkg)
return calls
end)
Add this at the start of your main premake5.lua script, or find a way to include it from somewhere else (I don't know much about lua or premake I just needed to fix this and wanted to show it to the community)
Have you tried using CMake instead? It's a far more sophisticated build system that should handle this trivially.

How to disable all visitors cookies in Joomla 3.x

I'm trying to disable all visitor cookies for my Joomla website.
I found some tutorials, but they are for Joomla version:1.x
Any suggestions?
The solution is very similar to solution to remove cookies in Joomla version 1.x and 2.x. So we will use the same condition and principle.
If you change this two files then maybe something other will not work. Change this only if you know what are you doing and if you know that will everyting else work. Because you can break the whole website!
You must edit two files /libraries/src/Application/CMSApplication.php and libraries/joomla/session/handler/native.php
In libraries/src/Application/CMSApplication.php change code around line 166 and add if condition for whole code in method if (substr($_SERVER['SCRIPT_NAME'] , 0 , 14) == "/administrator"){
public function checkSession()
{
if (substr($_SERVER['SCRIPT_NAME'] , 0 , 14) == "/administrator"){ // added condition
$db = \JFactory::getDbo();
$session = \JFactory::getSession();
$user = \JFactory::getUser();
// ... rest of code
}
}
In libraries/joomla/session/handler/native.php change code around line 229 add if condition for whole code in method like in previous file
private function doSessionStart()
{
if (substr($_SERVER['SCRIPT_NAME'] , 0 , 14) == "/administrator"){ // added condition
// Register our function as shutdown method, so we can manipulate it
register_shutdown_function(array($this, 'save'));
// ... rest of code
}
}
This works in Joomla 3.8.2
Note: after every Joomla update you must edit this two files again and test if this solution still works.
Set the cookie-path "/administrator" in the Admin Joomla Settings (System => Configuration).
Then the session cookies are created only for the admin area.
To avoid all cookies for normal visitors, you need to follow the below steps.
First of all: Deactivate site statistics! Global configuration -> Statistics -> Statistics: No. This will stop the "mosvisitor" cookie.
Don't use the Template Chooser module, because it uses a cookie named "jos_user_template".
Be careful with components: Some might start their own PHP session.
Now to the main point: comment out line 697 of /includes/joomla.php like this:
// setcookie( $sessionCookieName, '-', false, '/' );
Additional: Comment out line 25 in /offline.php:
// session_start();
This seams to be an artifact of old versions.

Updating A Program's Directory

I have a program that uses forms. The forms are pointing to files in c:\filepath1 as set forth in main.prg (set defa, set path). I make a test copy of the files, change the path in main.prg, the forms are still referencing the files in the old path. I don't want to have to recreate all the data environments in all the forms. How can I avoid doing so? Any help on this would be kindly appreciated.
Missy.
When Dataenvironment is used AND the path recorded in DataEnvironment tables exist, then that path is used no matter what the current path is. If you don't want to touch Dataenvironment at all (even programmatically) then you must remove that path (rename for example).
As a side note: I have:
UpdateDE(this)
in my DataEnvironment.BeforeOpenTables method. In UpdateDE.prg I have code that loops all the cursors in DE and set their path to the one that I want to use as "current".
EDIT: Here is a sample UpdateDE.prg:
Lparameters toDE
Do setups && prg keeping common "set" entries
Local Array aDEMembers[1]
Local lnMembers,ix,lcMembers
If !(Type('oApp')='O' And !Isnull(m.oApp))
Public oApp
oApp = Createobject('myApp')
Endif
lnMembers = Amembers(aDEMembers,m.toDE,2)
For ix=1 To m.lnMembers
With Evaluate('toDe.'+aDEMembers[m.ix])
If Lower(.BaseClass) == 'cursor'
If Atc(oApp.cAppDBC,.Database) > 0
.Database = Addbs(oApp.cAppDataPath)+oApp.cAppDBC
Else
.CursorSource = Addbs(oApp.cAppDataPath)+Justfname(.CursorSource)
Endif
Endif
Endwith
Endfor
Define Class myApp As Custom
cAppDBC = 'myDatabase.dbc'
cAppDataPath=Fullpath('data')
cCurPath = ''
Procedure Init
This.cCurPath = Set('path')
If File('dbparam.dbf') && a small dbf that holds path to current data folder
Select dataLoc From dbparam Where locType == 'DATABASE' Into Array arrDataLoc
If _Tally > 0
This.cAppDataPath = arrDataLoc
Set Path To (arrDataLoc[1]+';'+This.cCurPath)
Endif
Use In 'dbparam'
Endif
Endproc
Procedure Destroy
Set Path To (This.cCurPath)
Endproc
Enddefine
I ended up renaming the default path then going through all the screens in the program then recompiling. Thank you for your help. I did understand it and is probably another good solution.

Resources