Umbraco 7 macro script, get node by id fails - razor

i been trying to get a node by a id with razor in a marco
but can't get it to work with all the samples.
My code look like this
#using umbraco.MacroEngines
#inherits umbraco.MacroEngines.DynamicNodeContext
#{
var temp = Parameter.myFolderId;
#temp;
var node = #Library.NodeById(temp);
}
I got the temp's value, but i can't get the node.
i also tried it like this
var node = #Model.NodeById(temp);
The only error Umbraco shows is
Error loading MacroEngine script (file: myfile.cshtml)
I'm kinda new to Umbraco, so i could be a rookie mistake

I'm thinking there shouldn't be a # before Library.NodeById, since you're already inside a code block?
#{
var temp = Parameter.myFolderId;
var node = Library.NodeById(temp);
}

Found the problem.
There was a problem with my indexes following this thread

Related

How to do a while loop for a MySQL query in Node.js?

I am currently trying to transform a php code into Node.js using Typescript & Express.
In a script, I am generating a random 6-digit code before querying the database to verify that the code doesn't exist, otherwise I generate a new one.
Here's the original PHP code :
$code = generate_random_int(); // Generate a random code
$existing_codes = exec_sql($db,"SELECT code FROM codes WHERE code = $code;"); // Check if the generated code already exists in the database
while(!empty($existing_codes)){ // While there is (at least) 1 occurence in the DB for the generated code
$code = generate_random_int(); // Generate a new random code
$existing_codes = exec_sql($db,"SELECT code FROM codes WHERE code = $code;"); // Update the check for the newly generated code.
// If an occurence is found, the while loop will be reiterated. Otherwise, the while loop will end with the last generated code.
}
However, Node.js MySQL library only allows callbacks, because the function is asynchronous, which prevent the behavior I've illustrated above.
I have looked here and there on the internet and haven't found any way to reproduce this behavior in Node.js, so that's why I'm writing here :)
I thought about using for loops with db.query calls in them with no success, same with while syntaxes and an updated boolean.
Here's my latest (unsuccessful) attempt :
let code = generateRandomInt()
// query is a simplified function for db.query() from MySQL
query(`SELECT code FROM codes WHERE code = ${code};`, result => {
if (result === []) {
res.send(String(code))
return
} else {
code = generateRandomInt()
// While loop creating a new SQL statement for the new code and regenerating it until the response is []
}
})
res.send(String(code))
Thanks a lot by advance for your help :)
PS : I'm a newbie to Express and I am not that used to post on StackOverflow, so please don't hesitate to tell me if I did something wrong or if you need any complementary information
Here is another approach. Once you have an array of existing codes, use a loop to find an unused one:
...
const go = async () => {
const existingCodes = await getExistingCodes(); // your function that returns a list
// of existing codes; return a Promise
// find an unused code
let code = generateRandomInt();
while (existingCodes.indexOf(code) !== -1) {
code = generateRandomInt();
}
// use your new code
console.log(`new code is: ${code}`);
};
go();

Can't parse <content:encoded> from RSS

This is what RSS looks like: https://reddit.0qz.fun/r/dankmemes/top.json
My script perfectly parses "title", "description" and other items tags from the RSS. But it doesn't parse "content:encoded".
I tried this:
item.getChild("content:encoded").getText();
And this:
item.getChild("encoded").getText();
And this (found on Stackoverflow):
item.getChild("http://purl.org/rss/1.0/modules/content/","encoded").getText();
But nothing works... Could you help me?
The namespace is important for the getChild and similar methods to parse the content successfully.
Your third example is close, but you have the parameter order backwards, and you need to use the XmlService.getNamespace method, not a raw string. (The signature is getChild(string, namespace), not getChild(string, string).)
This one is tricky as the namespace should be included for some of the elements, and not for others. I am not an XML expert, so I don't know if this is expected behavior or not. The minimal example script below does find and log the text of the <content:encoded> elements using getChild, but I was only able to figure out when to include or exclude the namespace through trial and error. (If anyone has further info on why this is, please let me know in the comments.)
function logContentEncoded() {
const result = UrlFetchApp.fetch("https://reddit.0qz.fun/r/dankmemes/top.json");
const document = XmlService.parse(result.getContentText());
const root = document.getRootElement();
const namespace = XmlService.getNamespace("http://purl.org/rss/1.0/modules/content/");
const channel = root.getChild("channel"); // fails if namespace is included
const item = channel.getChild("item"); // fails if namespace is included
const encoded = item.getChild("encoded", namespace); // fails if namespace is EXCLUDED
console.log(encoded.getText());
}
Adding this library to the project: 1Mc8BthYthXx6CoIz90-JiSzSafVnT6U3t0z_W3hLTAX5ek4w0G_EIrNw
You can scrape the page. With this code, i.e., You can get the first content of <content:encoded> tags.
function getDataFromJson() {
var url = "https://reddit.0qz.fun/r/dankmemes/top.json";
var fromText = '<content:encoded>';
var toText = '</content:encoded>';
var content = UrlFetchApp.fetch(url).getContentText();
var scraped = Parser
.data(content)
.from(fromText)
.to(toText)
.build();
Logger.log(scraped);
return scraped;
}

Issues while upgrading from Microsoft.WindowsAzure.StorageClient 1.7 to Microsoft.WindowsAzure.Storage 4.2

I had this code previously working while using the StorageClient.dll:
CloudBlobContainer container = new CloudBlobContainer(courseName.ToLower(), blobClient);
container.CreateIfNotExist();
When upgrading to the Storage.dll and using the Storage.Blob I am unable to call the CreateIfNotExists method with empty parameters. I have looked at the documentation here http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.blob.cloudblobcontainer.createifnotexists.aspx
There are now 2 constructors:
CloudBlobContainer.CreateIfNotExists (BlobContainerPublicAccessType, BlobRequestOptions, OperationContext)
CloudBlobContainer.CreateIfNotExists (BlobRequestOptions, OperationContext)
I have attempted to creat the BlobRequestOptions and OperationContext and pass them in as follows but without joy:
CloudBlobContainer container = blobClient.GetContainerReference(courseName.ToLower());
var bro = new BlobRequestOptions();
var oc = new OperationContext();
container.CreateIfNotExist(bro,oc);
Any idea of what I am doing wrong here?
You can still call it as CreateIfNotExists(), since those arguments have default values. Also please note that GetContainerReference requires a name to be passed in, not a URL.

SSIS - In DFT, how to each row input to exe and read the output for each row?

In the Data Flow Task, I need re-direct each row to exe and get the output for each row, similar to script component.
I tried to use Process in Script Component, but it is throwing exception "StandardOut has not been redirected or the process hasn't started yet.".
The code used in Script Component is:
Process myApp = new Process();
myApp.StartInfo.FileName = #"Someexe.exe";
myApp.StartInfo.Arguments = "param1";
myApp.StartInfo.UseShellExecute = false;
myApp.StartInfo.RedirectStandardOutput = false;
myApp.Start();
while (!myApp.HasExited)
{
string result= myApp.StandardOutput.ReadToEnd();
}
Any suggestions? I would like to know if there is any better way to do this?
Your error message is helpful: "StandardOut has not been redirected..."
Since you want to capture the output, redirecting it to the Destination Component, don't you want to change the line:
myApp.StartInfo.RedirectStandardOutput = false;
to be:
myApp.StartInfo.RedirectStandardOutput = true;
Consider the example at this link, on BOL:
ProcessStartInfo.RedirectStandardOutput Property

as3 get vars from url

I found this post and I used the code almost exactly to how they suggested. It doesn't work. Do I need to add something in the php? What am I doing wrong?
Am I missing an import?
Thanks
Here is my code:
my php link is: www.mySite.com/example.php?id=true
var search:String = ExternalInterface.call("window.location.search");
var vars:URLVariables = new URLVariables(search);
if(vars.id)
{
/// Do something
}
Found answer here but doesn't work for me.
How to get/obtain Variables from URL in Flash AS3
You forgot to get rid of the page address:
var search:String = "www.mySite.com/example.php?id=true";
var vars:URLVariables = new URLVariables(search.substr(search.indexOf("?")+1));
if(vars.id) trace(vars.id);
Provided that you are sure that the address contains ? and actual variables you are looking for.