I need to create, through programming, a database in an elasticPoll.
To do this, I'm using the API version 2014-04-01, indicated in "Azure REST APIs > SQL Database > Databases > Create Or Update".
I create a new HttpWebRequest object and launch the .Create() method
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(string.Format("https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/servers/{2}/databases/{3}?api-version={4}", VariabiliGlobali.SubscriptionID, VariabiliGlobali.ResourceGroup, VariabiliGlobali.SqlServerName, databaseName, VariabiliGlobali.APIVersion));
and compile the properties:
request.Headers["Authorization"] = "Bearer" + token;
request.ContentType = "application/json; charset = utf-8";
request.Method = "PUT"
I create a new StreamWriter object
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(json);
streamWriter.Flush();
//streamWriter.Close();
}
and the .Write() mothod parameter, assign the complete Json code of the model shown in the "Databases - Create Or Update" example as below.
string json =
"{" +
"\"parameters\": {" +
"\"subscriptionId\": \"" + VariabiliGlobali.SubscriptionID + "\"," +
"\"resourceGroupName\": \"" + VariabiliGlobali.ResourceGroup + "\"," +
"\"serverName\": \"" + VariabiliGlobali.SqlServerName + "\"," +
"\"databaseName\": \"" + databaseName + "\"," +
"\"api-version\": \"" + VariabiliGlobali.APIVersion + "\"," +
"\"parameters\": {" +
"\"properties\": {" +
"\"elasticPoolName\": \"" + elasticPoolName + "\"" +
"}," +
"\"location\": \"West Europe\"" +
"}" +
"}," +
"\"responses\": {" +
"\"200\": {" +
"\"body\": {" +
"\"id\": \"/subscriptions/" + VariabiliGlobali.SubscriptionID + "/resourceGroups/" + VariabiliGlobali.ResourceGroup + "/providers/Microsoft.Sql/servers/" + VariabiliGlobali.SqlServerName + "/databases/" + databaseName + "\"," +
"\"name\": \"" + databaseName + "\"," +
"\"type\": \"Microsoft.Sql/servers/databases\"," +
"\"location\": \"West Europe\"," +
"\"kind\": \"v12.0,user\"," +
"\"properties\": {" +
"\"edition\": \"Standard\"," +
"\"status\": \"Online\"," +
"\"serviceLevelObjective\": \"S0\"," +
"\"collation\": \"SQL_Latin1_General_CP1_CI_AS\"," +
"\"creationDate\": \"2017-02-24T22:39:46.547Z\"," +
"\"maxSizeBytes\": \"268435456000\"," +
"\"currentServiceObjectiveId\": \"f1173c43-91bd-4aaa-973c-54e79e15235b\"," +
"\"requestedServiceObjectiveId\": \"f1173c43-91bd-4aaa-973c-54e79e15235b\"," +
"\"requestedServiceObjectiveName\": \"S0\"," +
"\"sampleName\": null," +
"\"defaultSecondaryLocation\": \"Japan West\"," +
"\"earliestRestoreDate\": \"2017-02-10T01:52:52.923Z\"," +
"\"elasticPoolName\": null," +
"\"containmentState\": 2," +
"\"readScale\": \"Disabled\"," +
"\"failoverGroupId\": null" +
"}" +
"}" +
"}," +
"\"201\": {" +
"\"body\": {" +
"\"id\": \"/subscriptions/" + VariabiliGlobali.SubscriptionID + "/resourceGroups/" + VariabiliGlobali.ResourceGroup + "/providers/Microsoft.Sql/servers/" + VariabiliGlobali.SqlServerName + "/databases/" + databaseName + "\"," +
"\"name\": \"" + databaseName + "\"," +
"\"type\": \"Microsoft.Sql/servers/databases\"," +
"\"location\": \"West Europe\"," +
"\"kind\": \"v12.0,user\"," +
"\"properties\": {" +
"\"edition\": \"Standard\"," +
"\"status\": \"Online\"," +
"\"serviceLevelObjective\": \"S0\"," +
"\"collation\": \"SQL_Latin1_General_CP1_CI_AS\"," +
"\"creationDate\": \"2017-02-24T22:39:46.547Z\"," +
"\"maxSizeBytes\": \"268435456000\"," +
"\"currentServiceObjectiveId\": \"f1173c43-91bd-4aaa-973c-54e79e15235b\"," +
"\"requestedServiceObjectiveId\": \"f1173c43-91bd-4aaa-973c-54e79e15235b\"," +
"\"requestedServiceObjectiveName\": \"S0\"," +
"\"sampleName\": null," +
"\"defaultSecondaryLocation\": \"Japan West\"," +
"\"earliestRestoreDate\": \"2017-02-10T01:52:52.923Z\"," +
"\"elasticPoolName\": null," +
"\"containmentState\": 2," +
"\"readScale\": \"Disabled\"," +
"\"failoverGroupId\": null" +
"}" +
"}" +
"}," +
"\"202\": { }" +
"}" +
"}";
Launch the .GetResponse() method of the HttpWebRequest object
var httpResponse = (HttpWebResponse)request.GetResponse();
and in response I get the following error:
{'Error': {"code": "InvalidRequestContent", "message": "The request content was invalid and could not be deserialized: 'Could not find member' parameters on object of type 'ResourceDefinition' , Line 1, position 14. '. "}}
Where am I wrong?
Thanks in advance.
I believe the documentation is incorrect. Correct request payload should be:
{"properties": {"elasticPoolName": "XXXXX"},"location": "West Europe"}
Related
This doesn't work (e.g.: https://www.w3schools.com/html/html5_draganddrop.asp)
var item = WebDriver.FindElement(By.XPath(#"//img[#src='img_w3slogo.gif']"), 30);
var container = WebDriver.FindElement(By.XPath(#"//div[#id='div2']"), 30);
var actions = new OpenQA.Selenium.Interactions.Actions(this.WebDriver);
actions.DragAndDrop(item, container).Build().Perform();
System.Threading.Thread.Sleep(3000);
If it helps....
public static void DragAndDrop(IWebElement element1, IWebElement element2)
{
WaitForElementEnabled(element1);
WaitForElementEnabled(element2);
var builder = new Actions(_webDriver);
var dragAndDrop = builder.ClickAndHold(element1).MoveToElement(element2).Release(element2).Build();
dragAndDrop.Perform();
}
public static void WaitForElementEnabled(IWebElement element)
{
try { _wait.Until(webDriver => element.Enabled); }
catch (StaleElementReferenceException) { if (!WaitForNotFoundElement_Enabled(element)) { LogFunctions.WriteError("Enabled - Stale Element Exception"); TakeScreenshot("elementNotFound"); throw; } }
}
The only way I was able to get this to work was by using the helper function located here: https://gist.github.com/druska/624501b7209a74040175 and executing javascript (Java example):
String simulateFunction = "function simulateDragDrop(sourceNode, destinationNode) {\n" +
" var EVENT_TYPES = {\n" +
" DRAG_END: 'dragend',\n" +
" DRAG_START: 'dragstart',\n" +
" DROP: 'drop'\n" +
" }\n" +
"\n" +
" function createCustomEvent(type) {\n" +
" var event = new CustomEvent(\"CustomEvent\")\n" +
" event.initCustomEvent(type, true, true, null)\n" +
" event.dataTransfer = {\n" +
" data: {\n" +
" },\n" +
" setData: function(type, val) {\n" +
" this.data[type] = val\n" +
" },\n" +
" getData: function(type) {\n" +
" return this.data[type]\n" +
" }\n" +
" }\n" +
" return event\n" +
" }\n" +
"\n" +
" function dispatchEvent(node, type, event) {\n" +
" if (node.dispatchEvent) {\n" +
" return node.dispatchEvent(event)\n" +
" }\n" +
" if (node.fireEvent) {\n" +
" return node.fireEvent(\"on\" + type, event)\n" +
" }\n" +
" }\n" +
"\n" +
" var event = createCustomEvent(EVENT_TYPES.DRAG_START)\n" +
" dispatchEvent(sourceNode, EVENT_TYPES.DRAG_START, event)\n" +
"\n" +
" var dropEvent = createCustomEvent(EVENT_TYPES.DROP)\n" +
" dropEvent.dataTransfer = event.dataTransfer\n" +
" dispatchEvent(destinationNode, EVENT_TYPES.DROP, dropEvent)\n" +
"\n" +
" var dragEndEvent = createCustomEvent(EVENT_TYPES.DRAG_END)\n" +
" dragEndEvent.dataTransfer = event.dataTransfer\n" +
" dispatchEvent(sourceNode, EVENT_TYPES.DRAG_END, dragEndEvent)\n" +
"} var toDrag =document.getElementById('drag1'); var toDrop = document.getElementById('div2');";
((JavascriptExecutor)driver).executeScript(simulateFunction + "simulateDragDrop(toDrag, toDrop);");
Did anyone get this working without javascript executor?
I'm running Selenium with C# for my automation testing on multiple browsers (IE, FF, Chrome) and there is one part of my test that passes for Chrome but not Firefox.
Is there a way to detect the browser type that is currently being used during the automated test?
You can install UAParser from Nugget :
https://www.nuget.org/packages/UAParser/
It will read the client header and Parse it.
Exemple:
//string uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3";
// Request the header
string uaString= HttpContext.Current.Request.UserAgent.ToString();
// get a parser with the embedded regex patterns
var uaParser = Parser.GetDefault();
// get a parser using externally supplied yaml definitions
// var uaParser = Parser.FromYamlFile(pathToYamlFile);
// var uaParser = Parser.FromYaml(yamlString);
ClientInfo c = uaParser.Parse(uaString);
Console.WriteLine(c.UserAgent.Family); // => "Mobile Safari"
Console.WriteLine(c.UserAgent.Major); // => "5"
Console.WriteLine(c.UserAgent.Minor); // => "1"
Console.WriteLine(c.OS.Family); // => "iOS"
Console.WriteLine(c.OS.Major); // => "5"
Console.WriteLine(c.OS.Minor); // => "1"
Console.WriteLine(c.Device.Family); // => "iPhone"
Use the following code
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string s = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n"
+ "Supports JavaScript Version = " +
browser["JavaScriptVersion"] + "\n";
I would like to add multiple maps of the Google Maps API to a page of my C# ASP.NET application. However, with my current code, only the last map is shown. All the other divs that should contain a map are empty. As you can see in my code, the maps already have unique names (not on a nice way, but it is unique). Can someone explain what I am doing wrong?
It would be really appreciated.
Initialize Google:
protected void loadGoogle()
{
var googleScript = "function loadScript() {" +
"var script = document.createElement(\"script\");" +
"script.type = \"text/javascript\";" +
"script.src = \"http://maps.google.com/maps/api/js?sensor=false& callback=initialize\"; " +
"document.body.appendChild(script);" +
"}" +
"window.onload = loadScript;";
ClientScript.RegisterStartupScript(typeof(Page), "CreateGoogleMapScript", googleScript, true);
}
Create maps (called multiple times):
protected void createMap(String mapId, String address)
{
var script = "function initialize() {" +
"var geocoder = new google.maps.Geocoder();" +
"var latlng = new google.maps.LatLng(-34.397, 150.644);" +
"var mapOptions" + mapId + " = {" +
"zoom: 16," +
"center: latlng," +
"mapTypeId: google.maps.MapTypeId.ROADMAP" +
"};" +
" var map" + mapId + " = new google.maps.Map(document.getElementById(" + mapId + "), mapOptions" + mapId + ");" +
"var address = \"" + address + "\";" +
"geocoder.geocode( { 'address': address}, function(results, status) {" +
"if (status == google.maps.GeocoderStatus.OK) {" +
"map" + mapId + ".setCenter(results[0].geometry.location);" +
"var marker = new google.maps.Marker({" +
"map: map" + mapId + "," +
"position: results[0].geometry.location" +
"});" +
"} else {" +
"alert(\"Geocode was not successful for the following reason: \" + status); " +
"}" +
"});" +
"}";
ClientScript.RegisterClientScriptBlock(typeof(Page), "CreateMapScript"+mapId, script, true);
}
Called by:
While loop, with a literal.Text that adds a new div, followed by createMap(mapId, address);
UPDATE:
My new code:
var script = "function initialize() { var geocoder = new google.maps.Geocoder();";
for (int i = 0; i < maps.Count; i++)
{
String currentId = maps[i] as String;
String currentLocation = locations[i] as String;
script += " " +
"var latlng = new google.maps.LatLng(" + 500 + "," + 400 + ");" +
"var myOptions = {" +
"zoom: 16," +
"center: latlng," +
"mapTypeId: google.maps.MapTypeId.ROADMAP" +
"};" +
"var map = new google.maps.Map(document.getElementById(\"" + currentId + "\"), myOptions);" +
"var address = \"" + currentLocation + "\";" +
"geocoder.geocode( { 'address': address}, function(results, status) {" +
"if (status == google.maps.GeocoderStatus.OK) {" +
"map.setCenter(results[0].geometry.location);" +
"var marker = new google.maps.Marker({" +
"map: map," +
"position: results[0].geometry.location" +
"});" +
"} else {" +
"alert(\"Geocode was not successful for the following reason: \" + status); " +
"}" +
"});";
}
script += "};";
Now all maps are drawn, but only the last map has the right location. The other ones are based on the latlng variable. Why can't the geocoder be used multiple times?
Perhaps just the last initialize function is firing in the browser? Try having just 1 initialise function that initialises all your maps.
i am trying to get the values of my controls like this:
function ConfirmWithUser()
{
var nodeText = '';
$('.mytreeview input[#type=checkbox]:checked').each(function() {
nodeText += $(this).next('a').text() + '\r';
});
var confirmationMessage;
confirmationMessage = "Please review the data before submitting:" + "\r"
+ "Sample Received Date: " + document.getElementById(received_dateTextbox).Value + "\r"
+ "Site of Ocurrence: " + document.getElementById(site_of_occurrenceTextBox).Value + "\r"
+ "Occurrence Date: " + document.getElementById(occurrence_dateTextBox).Value + "\r"
+ "Report Date: " + document.getElementById(report_byTextBox).Value + "\r"
+ "Specimen ID: " + document.getElementById(spec_idTextBox).Value + "\r"
+ "Batch ID: " + document.getElementById(batch_idTextBox).Value + "\r\n"
+ "Report Initiated By: " + document.getElementById(report_byTextBox).Value + "\r\n"
+ "Problem Identified By: " + $("input[#name=RadioButtonList1]:checked").val() + "\r\n"
+ "Problem List: " + nodeText;
HiddenFieldConfirmation.Value = confirmationMessage;
if (confirm(document.getElementById('HiddenFieldConfirmation').value) == true)
{ return true; }
else
{ return false; }
}
and the CONFIRM box is not firing at all! i do not get any pop up.
i tried to debug using firefox, and as soon as it go to this line:
confirmationMessage = "Please review the data before submitting:" + "\r"
+ "Sample Received Date: " + document.getElementById(re.......
it escapes out of the function
what am i doing wrong? how can i get the values of all the controls?
You need to use a lowercase "v" for value and quote your element ids. Eg:
document.getElementById("received_dateTextbox").value
Since it appears you are already using jQuery, you can make your code a little more concise. So document.getElementById("received_dateTextbox").value becomes:
$("#received_dateTextbox").val()
There is no variable named spec_idTextBox.
You probably want to pass a string literal.
Once you fix that, you need to use .value in lowercase
If you are using dynamic client ids, you have to render the ids inline or pass them to your function:
confirmationMessage = "Please review the data before submitting:" + "\r"
+ "Sample Received Date: " + document.getElementById('<% = received_dateTextbox.ClientID %>').value + "\r"
+ "Site of Ocurrence: " + document.getElementById('<% = site_of_occurrenceTextBox.ClientID %>').value + "\r"
+ "Occurrence Date: " + document.getElementById('<% = occurrence_dateTextBox.ClientID %>').value + "\r"
+ "Report Date: " + document.getElementById('<% = report_byTextBox.ClientID %>').value + "\r"
+ "Specimen ID: " + document.getElementById('<% = spec_idTextBox.ClientID %>').value + "\r"
+ "Batch ID: " + document.getElementById('<% = batch_idTextBox.ClientID %>').value + "\r\n"
+ "Report Initiated By: " + document.getElementById('<% = report_byTextBox.ClientID %>').value + "\r\n"
+ "Problem Identified By: " + $("input[#name=RadioButtonList1]:checked").val() + "\r\n"
+ "Problem List: " + nodeText;
I have the following bits of code:
public static void WriteHTML(string cFile, List<Movie> mList)
{
int lineID = 0;
string strMovie, strGenre, tmpGenre = null;
// initiates streamwriter for catalog output file
FileStream fs = new FileStream(cFile, FileMode.Create);
StreamWriter catalog = new StreamWriter(fs);
string strHeader = "<style type=\"text/css\">\r\n" + "<!--\r\n" + "tr#odd {\r\n" + " background-color:#e2e2e2;\r\n" + " vertical-align:top;\r\n" + "}\r\n" + "\r\n" + "tr#even {\r\n" + " vertical-align:top;\r\n" + "}\r\n" + "div#title {\r\n" + " font-size:16px;\r\n" + " font-weight:bold;\r\n" + "}\r\n" + "\r\n" + "div#mpaa {\r\n" + " font-size:10px;\r\n" + "}\r\n" + "\r\n" + "div#genre {\r\n" + " font-size:12px;\r\n" + " font-style:italic;\r\n" + "}\r\n" + "\r\n" + "div#plot {\r\n" + " height: 63px;\r\n" + " font-size:12px;\r\n" + " overflow:hidden;\r\n" + "}\r\n" + "-->\r\n" + "</style>\r\n" + "\r\n" + "<html>\r\n" + " <body>\r\n" + " <table>\r\n";
catalog.WriteLine(strHeader);
foreach (Movie m in mList)
{
strMovie = lineID == 0 ? " <tr id=\"odd\" style=\"page-break-inside:avoid\">" : " <tr id=\"even\" style=\"page-break-inside:avoid\">";
catalog.WriteLine(strMovie);
foreach (string genre in m.Genres)
tmpGenre += ", " + genre;
try
{ strGenre = tmpGenre.Substring(2); }
catch (Exception)
{ strGenre = null; }
strMovie = " <td>\r\n" + " <img src=\".\\images\\" + m.ImageFile + "\" width=\"75\" height=\"110\">\r\n" + " </td>\r\n" + " <td>\r\n" + " <div id=\"title\">" + m.Title + "</div>\r\n" + " <div id=\"mpaa\">" + m.Certification + " " + m.MPAA + "</div>\r\n" + " <div id=\"genre\">" + strGenre + "</div>\r\n" + " <div id=\"plot\">" + m.Plot + "</div>\r\n" + " </td>\r\n" + " </tr>\r\n";
catalog.WriteLine(strMovie);
lineID = lineID == 0 ? 1 : 0;
}
catalog.WriteLine(" </table>\r\n" + " </body>\r\n" + "</html>");
catalog.Close();
}
public static void WritePDF(string cFile, string pdfFile)
{
// Sets up PDF to write to
EO.Pdf.HtmlToPdf.Options.PageSize = new SizeF(8.5f, 11f);
EO.Pdf.HtmlToPdf.Options.OutputArea = new RectangleF(0.5f, .25f, 7.5f, 10.25f);
HtmlToPdf.ConvertUrl(cFile, pdfFile);
}
My HTML file writes fine, but when it tried to convert the HTML file to PDF I get an exception that it times out.
I did a test previously, and had it convert the code (not the file) within the WriteHTML function and it worked great. I have confirmed that the cFile exists and is a valid file (created previously in WriteHTML). The path to pdfFile is valid, and the documentation does not state the file needs to already exist (.ConvertHTML did not need an existing file).
Only thing I can think of is that the catalog.html file isn't released and ready to read yet. I made sure I closed it in the WriteHTML function. How can I test that the file is ready to be read?
Tried setting .MaxLoadWaitTime = 120000 with no luck.
Any clues would be greatly appreciated!
After a battery of further testing, and scouring the EO support forums, it appears to be a limitation of the free version of EO. It seems to have difficulty with HTML files over 3MB.
It's a shame since the EO product is very good, but not unfortunately not worth $250 IMO.