|
eblaschka wrote: this is the output of a disk analysis tool, that I need a human (management ) readable report of.
That would have helped if you put that in your original post. I wouldn't have suggested you start with the classes then.
I would agree with Bernhards use of the XSD tool to generate the classes for you. You could still use link over that object graph to your report data.
|
|
|
|
|
Thank you Dave for cleaning up my XML code, I really screwed up the format.
I definitely do not want to use XML as a database, but I do have an output file that I have to make human (rather: Management ) readable for reports.
Thanks Bernhard, I will have to look into the xsd stuff.
Thanks Richard, your "Descendant" method. It works great, BUT only if I cut the file between <drives> part. (The Structur is bigger).
That is not a big issue, but is there something like "get everything from <file> and <drive> " ???
(How does "GetFullPath" know where to stop?)
Thanks a lot to all.
|
|
|
|
|
If you reply to someone's message, then they get notified that you've replied. If you reply to yourself, then nobody else will be notified.
There's almost certainly a way to make it work, but without knowing the full structure of your XML file, we can only guess:
static string GetFullPath(XElement fileElement)
{
var names = new HashSet<XName> { "Drive", "Folder", "File" };
IEnumerable<string> pathParts = fileElements.AncestorsAndSelf()
.TakeWhile(el => el.Name != "Drives")
.Where(el => names.Contains(el.Name))
.Select(el => (string)el.Element("Name"))
.Reverse();
return string.Join("\\", pathParts);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Hi,
I have a C# WIndows Application Form with MySQL backend (which can be on Windows or Linux Server).
I want my application to send email notifications about the contracts data in my applications (contracts expiry notifications) by email according to a schedule(probably daily once)
What's the best cross platform way to do it which will work on windows and linux server?
Thanks
Technology News @ www.JassimRahma.com
|
|
|
|
|
There are some scripting languages available which can be used both on Linux and Windows, e.g. PERL. But do you really want to learn a new programming language just for that task, including all the WTFs of scripting languages?
I'd suggest to use a Windows Service which connects to your database to retrive the information and then sends the emails. Alternatively, a "normal" Windows console application is started as a "scheduled task" and does that job.
|
|
|
|
|
WIndows Services is fine but not when the user is away or traveling and don't have access to his PC which means the windows services will not run because his PC is switched off because the server side could be linux not windows!
Technology News @ www.JassimRahma.com
|
|
|
|
|
Jassim Rahma wrote: the windows services will not run because his PC is switched off Well, I do not know of any application or service to run on a switched-off computer...
|
|
|
|
|
What is Framework of .net and its features?
Shail...
|
|
|
|
|
Here you go. There's plenty of good material here[^].
|
|
|
|
|
Wow, Pete, you are a genius!
|
|
|
|
|
You can google this to find enough resources.Your question should be as specific and concise as possible.It would be good if it is related to a practical real time issue
Thanks
Do not forget to comment and rate the article if it helped you by any means.
|
|
|
|
|
I'm working on a WPF app that call through a ASP.Net MVC 4 Web API.
I make the following call:
public CompanyInfoAddressEntity AddCompanyInfoAddress(CompanyInfoAddressEntity entity)
{
WebAPIExecutor webAPIExecutor = new WebAPIExecutor("/CompanyInfoAddresses/AddCompanyInfoAddress/");
webAPIExecutor.AddParameter(entity, "entity");
CompanyInfoAddressEntity results = webAPIExecutor.Execute<CompanyInfoAddressEntity>();
return results;
}
When I call into Execute, it runs fine and the entity is passed to the controller, BL, and DAL fine. But when it returns back to here, the 'entity' object is null.
I have no idea what's wrong. How do I debug this sort of problem?
If it's not broken, fix it until it is
|
|
|
|
|
Google has no results for WebAPIExecutor - is that a custom class you've written?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
 It's a wrapper class for REST that I wrote. I'm 100% sure it's not the problem, but here's the code anyhow:
public class WebAPIExecutor
{
#region Private Fields
private RestClient client;
private RestRequest request;
#endregion
#region Properties
public string ServerName { get; private set; }
public string ServerAddress { get; private set; }
#endregion
#region CTOR
public WebAPIExecutor()
{
setupServerURL();
}
public WebAPIExecutor(string url, Method method = Method.POST)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentNullException("Url");
}
setupServerURL();
client = new RestClient(ServerAddress);
client.AddHandler("text/plain", new JsonDeserializer());
request = new RestRequest(url, method)
{
RequestFormat = RestSharp.DataFormat.Json
};
}
#endregion
#region Public Methods
public void AddParameter(object value, string name = "")
{
if (value == null)
{
throw new ArgumentNullException("value");
}
Type type = value.GetType();
bool isPrimitive = type.IsPrimitive;
if(isPrimitive || type == typeof(string) || type == typeof(decimal))
{
if (string.IsNullOrEmpty(name) && request.Method == Method.GET)
{
throw new ArgumentNullException("Parameter 'Name' cannot be empty for Get requests");
}
request.AddParameter(name, value);
}
else
{
request.AddBody(value);
}
}
public T Execute<T>() where T : new()
{
if (request.Resource.Trim().ToLower().Contains("controller"))
{
string message = string.Format("Controller names cannot contain the word 'Controller'. Called from request {0}", request.Resource);
MessageBox.Show(message, "WebAPI Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation);
throw new Exception(message);
}
var url = client.BaseUrl + request.Resource;
IRestResponse<T> result = client.Execute<T>(request);
int resultValue = (int)result.StatusCode;
if (resultValue >= 299)
{
string message = string.Format("An error occured calling the WebAPI. {0} The status code is '{1}'. {2} The error message is {3}",
Environment.NewLine, result.StatusCode, Environment.NewLine, result.Content );
MessageBox.Show(message, "WebAPI Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
throw new Exception(message);
}
return result.Data;
}
public void Execute()
{
IRestResponse result = null;
try
{
result = client.Execute(request);
int resultCode = (int)result.StatusCode;
if (resultCode > 299)
{
string message = string.Format("An error occured calling the WebAPI. {0} The status code is '{1}'. {2} The error message is {3}",
Environment.NewLine, result.StatusCode, Environment.NewLine, result.Content );
MessageBox.Show(message, "WebAPI Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
throw new Exception(message);
}
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region Private Methods
private void setupServerURL()
{
ServerName = ConfigurationManager.AppSettings["servername"];
string ipaddress = ConfigurationManager.AppSettings["ipaddress"];
string port = ConfigurationManager.AppSettings["port"];
ServerAddress = string.Format("http://{0}:{1}/api", ipaddress, port);
}
#endregion
}
}
If it's not broken, fix it until it is
|
|
|
|
|
Are RestClient , RestRequest and IRestResponse from Phil Haack's RestSharp[^] project? If so, are you using the latest version?
Have you tried calling the non-generic Execute method to make sure the returned Content and ContentType are what you were expecting?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
struct Connection *Database_open(const char *filename, char mode)
{
struct Connection *conn = malloc(sizeof(struct Connection));
if(!conn) die("Memory error");
conn->db = malloc(sizeof(struct Database));
if(!conn->db) die("Memory error");
if(mode == 'c') {
conn->file = fopen(filename, "w");
} else {
conn->file = fopen(filename, "r+");
if(conn->file) {
Database_load(conn);
}
}
if(!conn->file) die("Failed to open the file");
return conn;
}
|
|
|
|
|
it just check the mode you passed as a parameter is equal to 'c'. If it is equal to 'c' then create an empty file for output operations ("w"). else open a file for update ("r+") (both for input and output).
|
|
|
|
|
|
You are welcome 
|
|
|
|
|
That's C code, not C#. What are you expecting from this forum?
|
|
|
|
|
Hello community,
In advance, please excuse my lack of knowledge regarding the following topic, I have tried to familiarise myself with the topic using both google and the search function.
A friend of mine asked whether I could get data from a specific website for him, I answered "yes, I can try". I feel like I am pretty close and only need a final push. So let's go:
www.regelleistung.net -> this is the website in question
Menu item : Data for Control Reserve - in the following form he would normally specify what kind of data he is interested in and would then click the submit button .
Someone gave me the TAMPER information for the post request and I came up with the following code:
1. The request requires a jsession cookie which I retrieve + from TAMPER I saw that I require several other items of interest : __fp , _sourcePage and CSRFToken.
Because I do not know how to get those information without making an actual request - I just perform a testrequest and populate an array, which I will use for the actual request
BASEURL = @"https://www.regelleistung.net/ip/action/abrufwert";
public string[] ReceiveCookiesAndHiddenData()
{
string[] tempHidden = new string[4];
HttpWebRequest tempRequest = (HttpWebRequest)WebRequest.Create(BASEURL);
using (HttpWebResponse tempResponse = (HttpWebResponse)tempRequest.GetResponse())
{
HtmlDocument doc = new HtmlDocument();
doc.Load(tempResponse.GetResponseStream());
tempHidden[0] = doc.DocumentNode.SelectNodes("//input[@type='hidden' and @name='_sourcePage']")[0].Attributes["Value"].Value;
tempHidden[1] = doc.DocumentNode.SelectNodes("//input[@type='hidden' and @name='__fp']")[0].Attributes["Value"].Value;
tempHidden[2] = doc.DocumentNode.SelectNodes("//input[@type='hidden' and @name='CSRFToken']")[0].Attributes["Value"].Value;
tempHidden[3] = tempResponse.Headers["Set-Cookie"].Split(new Char[] { ';' })[0];
}
return tempHidden;
}
2. No I have to make the actual request. which requires the following information (according to Tamper):
http://pl.vc/3f5z0[^]
public void MakeActualRequest()
{
hiddenData = ReceiveCookiesAndHiddenData();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(BASEURL);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.Referer = "https://www.regelleistung.net/ip/action/abrufwert";
request.Headers.Add("Set-Cookie",hiddenData[3]);
NameValueCollection outgoingQueryString = HttpUtility.ParseQueryString(String.Empty);
outgoingQueryString.Add("von", "05.08.2014");
outgoingQueryString.Add("uenbld", "STXs440zwks=");
outgoingQueryString.Add("produkt", "MRL");
outgoingQueryString.Add("work", "anzeigen");
outgoingQueryString.Add("_sourcePage", hiddenData[0]);
outgoingQueryString.Add("__fp", hiddenData[1]);
outgoingQueryString.Add("CSRFToken", hiddenData[2]);
string postdata = outgoingQueryString.ToString();
byte[] data = Encoding.ASCII.GetBytes(postdata);
request.ContentLength = data.Length;
using(Stream requestStream = request.GetRequestStream())
{
requestStream.Write(data,0,data.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
using(StreamReader reader = new StreamReader(responseStream, Encoding.Default))
{
string content = reader.ReadToEnd();
}
}
I receive a WeException "Remote server error :(403)" in this line of code:
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
I would be thankfull for help. I know this is like the 1000000 time such a question has been posted, but I read all those threads and still cannot figure it out.
Thank you all!
|
|
|
|
|
Look at the action parameter of the form element
form action="/ip/action/abrufwert;jsessionid=v8fcThPBr1LQcMds3PrkXxwJNwYpzvQ6Zb9vcNyTMQhk9d96Bhb8!2134477355!-1323386705" method="post"
There's the URL you have to send the data to in MakeActualRequest , not BASEURL .
Also parameters "bis" and "download" are missing in your request.
|
|
|
|
|
Hi Bernhard,
thanks - Adding the jsessionid to the uri already helped solving my first issue - then changing uenbld to uenbId did the final trick.
Thanks for the quick and helpful response, highly appreciated.
Question answered!
|
|
|
|
|
i do not the main objective of using bar code but guessed that people store & hide info through bar code for to some extent security. may be i am not correct.....if anyone knows the exact objective for storing info in bar code then plzz share with me. thanks
tbhattacharjee
|
|
|
|