Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
So I'm trying to figure out how to build a Console Application in C# that essentially mimics google maps. I need to be able to enter an address (even if I abbreviate a word. EX: Silverbell Dr) and output the correct spelling (Silverbell Drive).
The goal here is to be able to enter an address in the search, even if the address spelling is incorrect, and output a value that is close enough to the user input that it won't send back a null value.
If anyone has anything that is similar to this, I would greatly appreciate the help!
Boss gave me this assignment knowing that I hardly have a base knowledge on the subject
One way to do it would be to use Googles geocode API. You can pass it a partial address and it will do it's best to return the normalized address for you. If the address isn't very specific, you will get back more than one.
Here's a code example for calling the API and parsing the results:
private static List<string> GetNormalizedAddresses(string address)
{
// Generate request Uri
var baseUrl = "http://maps.googleapis.com/maps/api/geocode/xml";
var requestUri = $"{baseUrl}?address={Uri.EscapeDataString(address)}&sensor=false";
// Get response
var request = WebRequest.Create(requestUri);
var response = request.GetResponse();
var xDoc = XDocument.Load(response.GetResponseStream());
var results = xDoc.Element("GeocodeResponse")?.Elements("result").ToList();
var normalizedAddresses = new List<string>();
// Populate results
if (results != null)
{
normalizedAddresses.AddRange(results
.Select(result => result.Element("formatted_address")?.Value)
.Where(formattedAddress => !string.IsNullOrWhiteSpace(formattedAddress)));
}
return normalizedAddresses;
}
Then, you could call it like so:
while(true)
{
Console.Write("Enter a partial address: ");
var partialAddress = Console.ReadLine();
Console.WriteLine(new string ('-', 25 + partialAddress.Length));
var normalizedAddress = GetNormalizedAddresses(partialAddress);
if (!normalizedAddress.Any())
{
Console.WriteLine("Sorry, couldn't find anything.");
}
else
{
Console.WriteLine("That address normalizes to:");
Console.WriteLine($" - {string.Join($"\n - ", normalizedAddress)}");
}
Console.WriteLine("\n");
}
Output
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I need to verify that in the web site, when fields are containing valid data, after clicking "Save" there is an alert shown that says that the "Information was saved successfully". For now I have a code to find the web element and fill the valid data like that:
IWebElement carName = driver.FindElement(By.XPath("..."));
carName.Click();
carName.SendKeys("Name of the car");
IWebElement saveButton = driver.FindElement(By.XPath("..."));
saveButton.Click();
I want when the message is shown to be verified that it was shown and the test passed.
Identify if pop-up element appears or not, if not the element count will be 0
List<IWebElement> elementList = new List<IWebElement>();
elementList.AddRange(driver.FindElements(By.XPath("..."));
if(elementList.Count > 0)
{
//If the count is greater than 0 your element exists.
Console.Write("pop up is present");
}else{
Console.Write("pop up not present");
}
Note: Make sure to use FindElements() instead of FindElement()
I suggest using webdriverwait as, depending on the form, there could be a delay before the success message.
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
var element = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("your xpath here")));
Assert.NotNull(element);
The assert format will differ based on your framework. That one is from xUnit.
Note: the package containing ExpectedConditions is not maintained, but they are pretty simple, and can be copied into your code, or own package, if you are worried about it.
public static Func<IWebDriver, IWebElement> ElementIsVisible(By locator)
{
return (driver) =>
{
try
{
return ElementIfVisible(driver.FindElement(locator));
}
catch (StaleElementReferenceException)
{
return null;
}
};
}
private static IWebElement ElementIfVisible(IWebElement element)
{
return element.Displayed ? element : null;
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to get blocked file extension and maximum file size for attachment set by admin in c# code .Below image displays what I actually want using c# code.
Please suggest me answer.
Please use the following code to get any property in the System Settings.
var query = new QueryExpression("organization")
{
ColumnSet = new ColumnSet("blockedattachments", "maxuploadfilesize")
};
EntityCollection orgCollection = _service.RetrieveMultiple(query);
if (orgCollection.Entities.Count > 0)
{
Entity org = orgCollection.Entities.First();
string blockedattachments = org.GetAttributeValue<string>("blockedattachments");
int numberMaxUploadFileSize = org.GetAttributeValue<int>("maxuploadfilesize");
}
Try using below code, it is tested and working fine.
var query = new QueryExpression("organization")
{
ColumnSet = new ColumnSet("blockedattachments", "maxuploadfilesize")
};
var record = service.RetrieveMultiple(query).Entities.FirstOrDefault();
if (record != null)
{
var blockedAttachments = record.GetAttributeValue<string>("blockedattachments");
var maxAttachmentSize = record.GetAttributeValue<int>("maxuploadfilesize");
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I get response string "true" from php file...
but ,my function always return false ... here is piece of code
public Boolean authorization(String korisnik, String zaporka) {
using (var client = new WebClient())
{
var values = new NameValueCollection();
values["korisnik"] = korisnik;
values["zaporka"] = zaporka;
var response = client.UploadValues("http://localhost/projectX/autorizacija.php", values);
String responseString = Encoding.Default.GetString(response);
System.Diagnostics.Debug.WriteLine(responseString);
if (responseString.Equals("true"))
{
return true;
}
else
{
return false;
}
}
}
Try:
if (responseString.Trim().Equals("true", StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
else
{
System.Diagnostics.Debug.WriteLine(responseString);
return false;
}
InvariantCultureIgnoreCase = compares strings in a linguistically relevant manner that ignores case
Trim = remove whitespaces
And if false, check output value
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to read from XML file.
I success to read an int. but when I want to convert it so string it doesn't works. I would like to get some help.
XML:
<Data>
<ServerClient>1</ServerClient>
<ClientIP>127.0.0.1</ClientIP>
<ClientPort>11000</ClientPort>
</Data>
The function getType reads good the int in the XML file.
private XmlDocument doc;
public int getType()
{
try
{
// Open the file again
doc.Load("ServerClientXML.xml");
// Read port
XmlNode node = doc.SelectSingleNode("/Data/ServerClient");
return int.Parse(node.InnerText); // 0 = Server, 1 = Client
}
catch
{
return -1;
}
}
public string getIP()
{
string ip;
XmlNode node;
try
{
// Open the file again
doc.Load("ServerClientXML.xml");
int Type = getType();
if (Type == 1) // Client type
{
// Read IP
node = doc.SelectSingleNode("/Data/ServerClient/ClientIP");
ip = doc.InnerXml;
}
else // Server Type
{
// Read IP
node = doc.SelectSingleNode("/Data/ServerClient/ServerIP");
ip = doc.InnerXml;
}
return ip;
}
catch
{
return null;
}
}
I have tried to to like getType but without any success :
return node.InnerText.toString(); // 0 = Server, 1 = Client
Your XPath doesn't match provided XML. It should be /Data/ClientIP and /Data/ServerIP
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I am using ASP.Net web api for my service, that is called from a third party application. When I test it in chrome postman it works fine in localhost and deployed server, but I have tried it in fiddler, hurl it and the string val is always null, should I be adding something else? I cant understand why it works fine in postman! Going kinda crazy with this one !
Thanks in advance
public bool PostProperty([FromBody] string val)
{
try
{
var reader = new StringReader(val);
var serializer = new XmlSerializer(typeof(property));
var instance = (property)serializer.Deserialize(reader);
}
}
Change your signature to be
public async Task<bool> PostProperty()
{
try
{
var reader = new StringReader(await Request.Content.ReadAsStringAsync());
var serializer = new XmlSerializer(typeof(property));
var instance = (property)serializer.Deserialize(reader);
}
}
or
public bool PostProperty([FromBody] property val)
{
}
If you do the second option, you might have to add the following line to your setup,
config.Formatters.XmlFormatter.UseXmlSerializer = true;