I'm writing a C++ Project template in VS 2010 using the Custom Wizard technique.
In the default.js, the file which holds the behind JavaScript code, I want to take the current generated project, and locate it in an existing VS solution, in a specific "apps" subfolder.
I have a C# working code which does the above, but I have to rewrite it in JavaScript.
My C# code is:
Projects ps = solution.Projects;
var item = ps.GetEnumerator();
while (item.MoveNext())
{
var project = item.Current as Project;
string name = project.Name;
if (name == "apps")
{
SolutionFolder folder = (SolutionFolder)project.Object;
p = folder.AddFromFile(newProjDir + "\\" + projName + ".vcxproj");
}
}
In JavaScript, I wrote:
var ps = Solution.Projects;
But now I don't succeed to iterate over the projects, as I did in c#.
When I'm trying to write in the JS file:
var item = ps.GetEnumerator();
I'm getting the run time error:
Object doesn't support this property or method
Do you know about any way to iterate over the Projects collection? Is there a JS function which behaves like GetEnumerator()?
As you of course know, JS is a client side language.
You cannot get information from the server (like Solution.Projects).
But you can write a web service and use it from the your web page to get the information.
I found my way:
for (var i = 1; i <= solution.Projects.Count; i++)
{
if(Solution.Projects.Item(i).Name == "apps")
{
appsFolder = Solution.Projects.Item(i);
project = appsFolder.Object.AddFromFile(newProjectPath + "\\" + strProjectName + "\\" + strProjectName + ".vcxproj");
break;
}
}
Thanks you all for trying help :)
Related
I have a javascript file script.js, which has the following code
var winLoc = String(this.window.location);
var pos = winLoc.indexOf("lang=");
var spacer = '?';
if(pos >0) {
var curLang = winLoc.substring(pos+5,pos+7);
winLoc = winLoc.replace('lang=' + curLang, 'lang='+newLang);
} else {
if(winLoc.indexOf("?") > 0) {
spacer = '&';
}
winLoc = winLoc + spacer + 'lang=' + newLang;
}
this.window.location = winLoc; //cross site scripting issue//
I have to add this java code for the variable winLoc
winLoc = ESAPI.encoder().encodeForHTML(winLoc);
and this encoder() method is in ESAPI jar which I need to add as well
I am using it to avoid XSS Cross-Site Scripting Reflected.
Help me out in adding this java code to the JS file or any alternative you have in mind?
Well, I dont know what are you intending to get done, but generally, you cant execute Java code inside JavaScript.
Javascript is client side, meaning its interpreted by users browser, while Java is compiled into bytecode and executed by JVM on server side.
However, you can run JSP in a element, but it has to return valid JS.
https://www.javatpoint.com/jsp-expression-tag
You’ll have to use a JavaScript based tool in stead. Look at something like DOMPurify or jquery encoder.
For the specific context you are asking, HTML escaping looks wrong. You probably use encodeURIComponent instead.
I write Windows 10 Apps in JavaScript and know, there are some limitations. If I look at the documentation for jumplists, Microsoft just writes »For information about creating or accessing this object, see Remarks.« for JavaScript and only gives examples for C#.
So how can I add a jumplist to my UWP Windows 10 App and how can I add and delete Listitems?
It's very similar to the c# code.
You can find an example here:
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/JumpList/js/js
The essential code is:
var Uri = Windows.Foundation.Uri;
var StartScreen = Windows.UI.StartScreen;
var JumpList = StartScreen.JumpList;
var JumpListItem = StartScreen.JumpListItem;
var item = JumpListItem.createWithArguments("key", "caption");
item.description = "Description";
item.groupName = GroupName.value;
item.logo = new Uri("ms-appx:///images/your-images.png");
jumpList.items.append(item);
jumpList.saveAsync();
Just for fun, i'm trying to implement a "15 puzzle", but with 16 images (from 1 music photo) instead.
The thing is split into 2 scripts / sides. 1 Python CGI script that will perform the Last.FM query + splitting the image in Y x Z chunks. When the python script finishes it outputs a JSON string that contains the location (on server), extension etc.
{"succes": true, "content": {"nrofpieces": 16, "size": {"width": 1096, "height": 961}, "directoryname": "Mako", "extension": "jpeg"}}
On the other side is a HTML, JS, (CSS) combo that will query the CGI script for the images.
$(document).ready(function () {
var artiest = $("#artiest")
var rijen = $("#rijen")
var kolommen = $("#kolommen")
var speelveld = $("#speelveld")
var search = $("#search")
$("#buttonClick").click(function () {
var artiestZ = artiest.val()
var rijenZ = rijen.val()
var kolommenZ = kolommen.val()
$.getJSON("http://localhost:8000/cgi-bin/cgiScript.py", "artiest=" + artiestZ + "&rijen=" + rijenZ + "&kolommen=" + kolommenZ, function (JsonSring) {
console.log("HIIIIII")
if (JsonSring.succes === true){
console.log(JsonSring)
var baseUrl = "http://localhost:8000/"
var extension = JsonSring.content.extension
var url = baseUrl + JsonSring.content.directoryname + "/"
var amountX = rijenZ
var amountY = kolommenZ
for (var i = 0; i < amountX; i += 1){
for (var p = 0; p < amountY; p += 1){
console.log("HI")
var doc = new Image
doc.setAttribute("src", url + JsonSring.content.directoryname + i + "_" + p + "." +extension)
document.getElementById("speelveld").appendChild(doc)
}
}
}else {
// Search failed. Deal with it.
}
})
})
})
where the various id's link to various HTML elements. (Text Fields & Buttons & Div's).
Beneath is a screenshot of the full folder that contains the image files.
Now, coming to the point. All the HTML img tags with src seem correct, yet. Some images don't load, yet other do. I also noticed that all images failed to load in 2s intervals. Is there some kind of timeout, or so?
All this is being ran from a local machine, so disk speed and cpu shouldn't really affect the matter. Also, from what I understand: The call for making the img tags etc is done in a callback from the getJson, meaning it'll only run when getJson has finished / had a reply.
Does the great StackOverFlow community have an idea what's happening here?
To share my knowledge/experiences with the great StackOverflow community,
Small backstory
After progressing a bit further into the project I started to run into various issues going from JSON parsing to not having Allow-Control-Allow-Origin: * headers, making it very hard to get the Ajax Request (Client ==> Python CGI) done.
In the meantime I also started dev'ing on my main desktop (which for some reason either has massive issues with Python versioning or has none). But due to the terminal on my desktop having Python 3.4+ , there was no module CGIHTTPServer. After a small amount of digging, I found that CGIHTTPServer had been transfered into http.server, yet when running plain old python -m http.server, I noticed the CGI script wouldn't run. It would just display. Ofcourse, I forgot the option -cgi.
Main solution
The times I was succesfully using CGIHTTPServer, I had troubles. The images wouldn't load as described above. I suspect that the module just couldn't take the decent amount of requests. Meaning that when suddenly Y x Z requests came in, it would struggle to deliver all the data. ==> Connection Refused.
Since switching to python -m http.server -cgi, no problems what so ever. Currently working on a Bootstrap Grid for all those images!
Thx #Lashane and #Ruud.
I'm working on a provider-hosted App for SharePoint and I used the "Hot Towel Angular" package from nuget to create a SPA. As far as I know one major benefit of having a provider-hosted app is the ability to execute server-side code. My question is: How do I do that in a SPA?
This is my attempt:
In the index.cshtml
#Html.ActionLink("RunWithElevatedPrivileges", "RunWithElevatedPrivileges", "Employee")
In the EmployeeController.cs
public ActionResult RunWithElevatedPrivileges()
{
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
//using (var clientContext = spContext.CreateUserClientContextForSPHost())
using (var clientContext = spContext.CreateAppOnlyClientContextForSPHost())
{
if (clientContext != null)
{
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
List list = clientContext.Web.Lists.GetByTitle("MyList3");
ListItemCreationInformation info = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem item = list.AddItem(info);
item["Title"] = "Created from CSOM";
item.Update();
clientContext.Load(item);
clientContext.ExecuteQuery();
}
}
return View("ItemCreated");
}
Is there a decent solution to just execute the code from JavaScript without changing the view? I want to code my solution with Angular and JavaScript and only call the C#-Code when necessary.
I am using the Javascript Ace text editor and need to load keywords into the (DynHighlightRules) to provide highlighting of the imported keywords. I have highlights working from static keywords in the
editor.getSession().setMode("ace/mode/highlightRules")
, but I need to import new rules after the editor is rendered. I found a great solution which works perfectly in an Apache server but not in the Web.py python server. I believe this is due to the template page not being at the root level of the server. Has anyone deployed the Ace editor in Webpy and solved this issue?
Ok, I found a solution to my problem. It's a work around and not the way I was originally going to solve the issue. My first attempts were to embed an ajax call in the "ace.define" function but it wouldn't process it correctly and parts would be missing causing errors. Then I tried to dynamically import the keywords but couldn't make that work in the python environment. Finally I thought to just wrap the whole thing in the success of the ajax call and now it works exactly right. I guess when embedded in the ace function the timing between the ajax events and the other parts of the definition were out of sync.
So the answer in short is to wrap the whole definition in the ajax success callback.
$.ajax({
url: "/readUserCreatedKeywords",
type: "POST",
success: function(response){
var keywordsString = "";
var tmpArr = response.split(",");
var tmpArrLen = tmpArr.length;
var s = 0;
var halfNum = 0;
while (s < tmpArrLen) { // Clean array and save keywords and args into respective arrays
halfNum = parseInt(s/2);
tmpArr[s] = tmpArr[s].replace("u'", "").replace("[", "").replace("'", "").replace("(u", "").replace(")", "").replace("]", "").replace("(", "").replace(" ", "");
if (s % 2 == 0){ //Store even values in keywords
keywordsString += tmpArr[s] + "|";
//console.log("tmpArr[" + s + "]" + tmpArr[s]);
}
s++;
}
ace.define("ace/mode/python_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
...............................................lots of code..........................................
exports.Mode = Mode;
});
}
});