|
Bueno !
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it. A few hundred years later another traveler despairing as myself, may mourn the disappearance of what I may have seen, but failed to see.» Claude Levi-Strauss (Tristes Tropiques, 1955)
|
|
|
|
|
I need to add authentication to my Web API, so user must add token, or password to access the Web API.
Under Controller folder i have :
[AcceptVerbs("GET")]
public Reservation RPCStyleMethodFetchFirstEmployees()
{
return listEmp.FirstOrDefault();
}
[HttpGet]
[ActionName("GetReservation")]
public List<reservation> Get()
{
string source = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
SqlConnection conn = new SqlConnection(source);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
string sql = "Select s.Id,a.Room_No ,s.Room_Description,s.Room_Capacity, b.Description, s.Location,s.Start_Date,s.Start_Time,CONVERT(VARCHAR(20),CONVERT(Varchar(50),( Concat(CONVERT(VARCHAR, s.Start_Date, 126),'T',CONVERT(VARCHAR, s.End_Time, 127)) ),105),131)+'.00Z',s.End_Time,s.Meeting_Title,s.Reservation_Reason, s.Status,s.Attendance,s.Remarks,s.Mail_To,s.Mail_CC, s.Created_User, s.Created_Password, s.Created_Access_Key from Reservation s , Rooms a, Room_Type b Where s.Room_No = a.ID And s.Room_Type = b.ID";
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
Reservation emp = null;
conn.Open();
reader = cmd.ExecuteReader();
List<reservation> emps = new List<reservation>();
while (reader.Read())
{
emp = new Reservation();
emp.Id = Convert.ToInt32(reader.GetValue(0));
emp.Room_No = reader.GetValue(1).ToString();
emp.Room_Description = reader.GetValue(2) as string;
emp.Room_Capacity = (reader.GetValue(3) as int?) ?? 0;
emp.Room_Type = reader.GetValue(4) as string;
emp.Location = reader.GetValue(5) as string;
emp.Start_Date = reader.GetValue(6).ToString();
emp.Start_Time = reader.GetValue(7).ToString();
emp.Start_Date_Time = reader.GetValue(8).ToString();
emp.End_Time = reader.GetValue(9).ToString();
emp.Meeting_Title = reader.GetValue(10) as string;
emp.Reservation_Reason = reader.GetValue(11) as string;
emp.Status = reader.GetValue(12) as string;
emp.Attendance = (reader.GetValue(13) as int?) ?? 0;
emp.Remarks = reader.GetValue(14) as string;
emp.Mail_To = reader.GetValue(15) as string;
emp.Mail_CC = reader.GetValue(16) as string;
emp.Created_User = reader.GetValue(17) as string;
emp.Created_Password = reader.GetValue(18) as string;
emp.Created_Access_Key = reader.GetValue(19) as string;
emps.Add(emp);
}
conn.Close();
return emps;
}
and under Models i have
public class Reservation
{
public int Id { get; set; }
public string Room_No { get; set; }
public string Room_Description { get; set; }
public int Room_Capacity { get; set; }
public string Room_Type { get; set; }
public string Location { get; set; }
public string Start_Date { get; set; }
public string Start_Time { get; set; }
public string Start_Date_Time { get; set; }
public string End_Time { get; set; }
public string Meeting_Title { get; set; }
public string Reservation_Reason { get; set; }
public string Status { get; set; }
public int Attendance { get; set; }
public string Remarks { get; set; }
public string Mail_To { get; set; }
public string Mail_CC { get; set; }
public string Created_User { get; set; }
public string Created_Password { get; set; }
public string Created_Access_Key { get; set; }
}
How to add Authentication before they start get the data
Please i don't have clear information about classes and authentication, also i don't have startup.cs
please i need easy way
|
|
|
|
|
Hello, everyone
I am trying to create a program that can click button with its name of an form automatically to submit an form.
For example: There is a page that includes input-fields username and password, and two input buttons with the same tag "input" and same type "submit", but different names like "reset" and "authorize".
I am using the class IHtmlFormElement to get the HTML Form and use one of the input buttons to submit that form.
Here is my code:
IHTMLFormElement form = GetForm(0);
if (form.item("authorize", 0) != null)
{
var authorizeSubmit = form.item("authorize", 0);
}
form.submit();
My Question is, how could i tell the compiler to click the submit button with name "authorize" not "reset"? It there another way to do it better?
Thank you very much!
Carvin
|
|
|
|
|
Hello!
I want to represent a WPF-Menu based on a XML-file.
The file looks like this:
<menues>
<menu title="One">
<item title="USB-Stick" value="1234" />
</menu>
<menu title="Two">
<item title="CD" value="4321" />
</menu>
<menu title="Three">
<item title="USB-Stick" value="9876" />
<item title="Diskette" value="5667" />
<menu title="CC">
<item title="Test1" value="3234" />
<item title="Test2" value="2332" />
<item title="Test3" value="3213" />
</menu>
</menu>
</menues>
The goal is to be able to expand the menu at any time.
I hope someone can help me.
Best regards!
|
|
|
|
|
Help with what exactly? Reading XML, generating a menu, or all of it?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Preferably all of it.
I know, how to read a XML-file, but I cant display the data as a menu.
So I don't know the connection of these things ...
|
|
|
|
|
Member 13100573 wrote: Preferably all of it. In that case you'd be asking for a developer for hire.
Member 13100573 wrote: I know, how to read a XML-file, but I cant display the data as a menu. Creating a menu dynamically isn't that hard in WinForms, so I would expect it not to be too hard in WPF either. You could search for an example and give it a try - if you get stuck and have a specific question we can help.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Deserialize the XML document to a collection of say Menu objects. Then do the necessary binding to reflect what you want in the view.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
|
|
|
|
|
And what, exactly, do you want to happen when the user clicks on a menu item? If you want to know how to construct the menu itself, search for articles on MVVM menus with WPF.
This space for rent
|
|
|
|
|
You should start to read about XmlDataProvider and how to use bindings to XML-documents with XPath.
A good starting point can be How to: Bind to XML Data Using an XMLDataProvider and XPath Queries | Microsoft Docs[^]
In the example a ListBox is populated but you should be able to replace it with a Menu bound to an XmlDataProvider as ItemsSource with a customized ItemContainerStyle that sets the Header of the MenuItem to the title attribute.
Good luck.
|
|
|
|
|
i want to shutdown remote pc connected in LAn network through by using their pcname ,,how can i do in c# help me plz?
|
|
|
|
|
Read this[^], and use the Process class to execute.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I can't seem to figure this out. Tried searching but didn't know what to call the first date format.
If it ain't broke don't fix it
|
|
|
|
|
Is it an int or a string ?
Integer:
int input = 20171005;
int year = Math.DivRem(input, 10000, out input);
int month = Math.DivRem(input, 100, out input);
DateTime dt = new DateTime(year, month, input); String:
string input = "20171005";
DateTime dt = DateTime.ParseExact(input, "yyyyMMdd", CultureInfo.InvariantCulture);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
It's a string. I didn't think that DateParse would translate that string. hmm
I did examples of Date Parse, but I didn't know what my input format was called.
I'll give it a shot, Thanks Richard!
If it ain't broke don't fix it
|
|
|
|
|
|
string date1 = $"{DateTime.Now:MM/dd/yyyy}";
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
That looks interesting.
Actually my final output model is string for the date.
I'm gonna look into this.
If it ain't broke don't fix it
|
|
|
|
|
I have an XML file that I'm pulling data in and out of some lines are nothing more than crlf
<KEY FIELDID="451">
</KEY>
The property in the POCO class is structured like this
[XmlText]
public string Value { set; get; }
I can serialize the file and 451 comes back empty or when I save it saves as empty
<KEY FIELDID="451" />
I can update it to "\r\n" and it puts it back in the saved file.
var returned = MyType.Load("D:\\Sample.xml");
returned.AddUpdate(451,"\r\n");
MyType.Save(returned,"D:\\Output.xml");
Other Records with \r\n in them with additional data work with no problems
|
|
|
|
|
Not sure what you are talking about.
You have a 'element' which has a name of 'KEY'. The value of that element is some whitespace.
The element also has an 'attribute'. And the attribute name is 'FIELDID' with a value of '451'.
The element and attribute are not the same.
Without knowing the actual usage of the element (not attribute) I cannot speak to the value of it but certainly if you want a specific value then you must set it.
End of line characters shouldn't be in an attribute at all, so presumably you are referring to the element.
But an element that has nothing but whitespace, especially when it is named 'KEY' should be irrelevant and not needed.
So in summary.
1. If you want to change the value of the element then set it.
2. If you want to change the value of the attribute then set that (different than 1) and do not attempt to be end of line characters in it.
|
|
|
|
|
Let me try this again then. The item in question is not a whitespace it is a crlf which is needed by a separate app. (Yea I know, don't ask)
The XML file has a series of Key Elements each element has a FieldID and a value
<KEY FIELDID="72">TX</KEY>
I have my serializer working great except for the instances where the value is a crlf
<KEY FIELDID="451">
</KEY>
In this instance the serializer strips out the crlf and returns an null value.
I have other Keys that have data like
<pre> <KEY FIELDID="510">This one works
Really well
</KEY>
I'm having trouble understanding why the one with just a crlf comes back null and the multi line works fine. My Ultimate question is there a parameter/markup I need to add so that the crlf line works like the multi line.
I am reasonably new to XML most of my career I've worked heavily with Databases and only ever had to read output from a service and save it as xml. so this is out side of my wheelhouse.
|
|
|
|
|
XML and white-space don't generally work well together:
2.10 White Space Handling | Extensible Markup Language (XML) 1.1[^]
Unfortunately, the usual workarounds don't seem to apply to XML deserialization. Adding xml:space="preserve" , or passing in an XmlReader set to not ignore white-space, makes no difference to the result.
The only way I can see for you to preserve the white-space in an empty node is to use a CDATA element:
<KEY FIELDID="1"><![CDATA[</KEY>
[Serializable]
[XmlType("KEY")]
public class KeyType
{
[XmlAttribute("FIELDID")]
public int FieldId { set; get; }
[XmlText]
public string Value { set; get; }
[XmlElement("")]
public XmlCDataSection Content
{
get
{
return new XmlDocument().CreateCDataSection(Value);
}
set
{
if (value == null)
{
Value = null;
}
else
{
Value = value.Value;
}
}
}
}
c# - How do you serialize a string as CDATA using XmlSerializer? - Stack Overflow[^]
NB: ALL white-space within the CDATA element will be returned. So if your XML is:
<DATA>
<KEY FIELDID="1"><![CDATA[</KEY>
</DATA> your content will include the white-space at the start of the next line. If you wanted just the line break, the closing ]]> would need to be the first thing on the line, with no indentation.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Well crap that is not the answer I was looking for. again its not whitespace it is literally a crlf. Perhaps XML treats it the same. Just wanted to make sure I was clear. Our current reader / writer is almost 200 lines of code that is unbelievably slow. If I can get over that one hurdle I can replace it with 10 poco classes and this method
public static MyType Load(string filename)
{
var ser = new XmlSerializer(typeof(MyType));
var returned = (MyType)ser.Deserialize(new FileStream(filename, FileMode.Open));
return returned;
}
Guess its time to get the other Guy to test my output and see if it breaks his app, if not I'm good. I was trying to open an existing file and save it as an exact match with the exception of
<Key FIELDID="123"></Key>
becoming
<Key FIELDID="123"/>
Thanks again for all your help.
If I have to keep the crlf in the file and find a way I'll post it here
I can't be the only moron to ever need to do this
|
|
|
|
|
C. David Johnson wrote: its not whitespace it is literally a crlf
CrLf is white-space!
Whitespace character - Wikipedia[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
C. David Johnson wrote: Well crap that is not the answer I was looking for
Presumably you are not passing the xml data but rather a string.
So once you have the string use string (not xml) insertion to add the whitespace.
And ALSO add a comment both in the xml handling code and the string insertion code to explain why you are doing that.
|
|
|
|