Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

Commit

Permalink
Merge pull request #16 from kungfux/webqa
Browse files Browse the repository at this point in the history
Resolve issue #15
  • Loading branch information
kungfux authored Jun 16, 2016
2 parents f6e7d1c + b78594a commit c6594ca
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 119 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ WebQA/packages/*
WebQA/*.suo
WebQA/*.user
WebQA/*.sln
WebQA.Tests/get.pyc
WebQA/.vs/*
WebQA.Tests/*.pyc
143 changes: 49 additions & 94 deletions WebQA/Logic/AsynchronousSocketListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,55 +120,60 @@ public void ReadCallback(IAsyncResult ar)
StateObject state = (StateObject)ar.AsyncState;
Socket handler = state.workSocket;

string clientIp = handler.RemoteEndPoint.ToString();
string clientName = Dns.GetHostEntry(
IPAddress.Parse(handler.RemoteEndPoint.ToString().Substring(0, handler.RemoteEndPoint.ToString().IndexOf(":")))).HostName;

Trace.Instance.Add(
string.Format("Client connected: {1} [{0}]",
handler.RemoteEndPoint.ToString(),
Dns.GetHostEntry(
IPAddress.Parse(handler.RemoteEndPoint.ToString().Substring(0,handler.RemoteEndPoint.ToString().IndexOf(":")))).HostName),
Trace.Color.Yellow);
string.Format("Client connected: {1} [{0}]", clientIp, clientName,
Trace.Color.Yellow));

// Read data from the client socket
int bytesRead = handler.EndReceive(ar);

if (bytesRead > 0)
{
// There might be more data, so store the data received so far
state.receivedData.Append(Encoding.UTF8.GetString(
state.buffer, 0, bytesRead));

int space1 = state.receivedData.ToString().IndexOf(" ");
int space2 = state.receivedData.ToString().IndexOf(" ", space1 + 1);
state.url = state.receivedData.ToString().Substring(space1 + 2, space2 - space1 - 2);

Trace.Instance.Add(
string.Format("URL: {0}", state.url), Trace.Color.Yellow);

if (state.url.StartsWith("favicon.ico"))
{

}
else
{
// Call RQS instance to process request
Send(handler, rqs.ProcessRequest(state.url).ToString());
}

//if (content.IndexOf("<EOF>") > -1)
//{
// // All the data has been read from the
// // client. Display it on the console.
// Console.WriteLine("Read {0} bytes from socket. \n Data : {1}",
// content.Length, content);
// // Echo the data back to the client.
// Send(handler, content);
//}
//else
//{
// // Not all data received. Get more.
// handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
// new AsyncCallback(ReadCallback), state);
//}
}
// Store the data received
state.receivedData.Append(Encoding.UTF8.GetString(state.buffer, 0, bytesRead));

int space1 = state.receivedData.ToString().IndexOf(" ");
int space2 = 0;

if (state.receivedData.Length > 1)
{
space2 = state.receivedData.ToString().IndexOf(" ", space1 + 1);
}

if (space1 < 0 ||
state.receivedData.Length - space1 < 1 ||
space2 - space1 - 2 < 0)
{
// if empty request or has no requested data
Trace.Instance.Add("URL: Wrong request received", Trace.Color.Yellow);
Send(handler, rqs.ProcessRequest(state.url).ToString());
return;
}

state.url = state.receivedData.ToString().Substring(space1 + 2, space2 - space1 - 2);

//// Store the data received
//state.receivedData.Append(Encoding.UTF8.GetString(state.buffer, 0, bytesRead));

//string[] request = state.receivedData.ToString().Split(null);

//if (request.Length < 2 || string.IsNullOrEmpty(request[1]))
//{
// // if empty request or has no requested data
// Trace.Instance.Add("URL: Wrong or empty request received", Trace.Color.Yellow);
// Send(handler, rqs.ProcessRequest(state.url).ToString());
// return;
//}

//state.url = request[1];

Trace.Instance.Add(
string.Format("URL: {0}", state.url), Trace.Color.Yellow);

// Call RQS instance to process request
Send(handler, rqs.ProcessRequest(state.url).ToString());
}

private void Send(Socket handler, String data)
Expand All @@ -187,13 +192,6 @@ private void Send(Socket handler, String data)
// Begin sending the data to the remote device
handler.BeginSend(byteData, 0, header.Length + data.Length, 0,
new AsyncCallback(SendCallback), handler);

//int sent = 0;
//while (sent < data.Length)
//{
// handler.Send(StringToByte(data.Substring(sent, sent < data.Length ? 1024 : data.Length - sent)), SocketFlags.Truncated);
// sent += 1024;
//}
}

private byte[] StringToByte(string str)
Expand Down Expand Up @@ -222,48 +220,5 @@ private void SendCallback(IAsyncResult ar)
Trace.Instance.Add("EXCEPTION: " + e.ToString(), Trace.Color.Red);
}
}

//public string GetContent(string file_path)
//{
// string ext = "";
// int dot = file_path.LastIndexOf(".");
// if (dot >= 0)
// ext = file_path.Substring(dot, file_path.Length - dot).ToUpper();
// if (Contents[ext] == null)
// return "application/" + ext;
// else
// return (string)Contents[ext];
//}

//public void WriteHeaderToClient(string content_type, long length)
//{
// string str = "HTTP/1.1 200 OK\nContent-type: " + content_type
// + "\nContent-Encoding: 8bit\nContent-Length:" + length.ToString()
// + "\n\n";
// Client.GetStream().Write(Encoding.ASCII.GetBytes(str), 0, str.Length);
//}

//public void WriteToClient(string request)
//{
// string file_path = GetPath(request);
// if (file_path.IndexOf("..") >= 0 || !File.Exists(file_path))
// {
// Error_Message = "Source file not found on server side.\r\nStack trace: " + file_path + " not found.";
// WriteHeaderToClient("text/plain", Error_Message.Length);
// Client.GetStream().Write(Encoding.ASCII.GetBytes(Error_Message), 0, Error_Message.Length);
// return;
// }
// FileStream file = File.Open(file_path, FileMode.Open);
// WriteHeaderToClient(GetContent(file_path), file.Length);
// byte[] buf = new byte[1024];
// int len;
// while ((len = file.Read(buf, 0, 1024)) != 0)
// Client.GetStream().Write(buf, 0, len);
// file.Close();
// if (file_path.Contains("~tmp"))
// {
// File.Delete(file_path);
// }
//}
}
}
10 changes: 5 additions & 5 deletions WebQA/Logic/RQS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ private void GetRequirements(string by, string[] criteria, string file_filter)
"<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td><td>{8}</td></tr>",
// internal id and fr id
result.Rows[a].ItemArray[1] != null ?
string.Format("<a href='/?by=id&value={0}' title='Search by FR ID {1}'>{1}</a>",
string.Format("<a href='/?by=id&value={0}' title='Search by FR ID: {1}'>{1}</a>",
result.Rows[a].ItemArray[0], result.Rows[a].ItemArray[1]) :
"&nbsp;",
// fr tms task number
result.Rows[a].ItemArray[2] != null && !result.Rows[a].ItemArray[2].ToString().Equals("") ?
string.Format("<a href='/?by=tms&value={0}' title='Search by TMS Task {0}'>{0}</a>",
string.Format("<a href='/?by=tms&value={0}' title='Search by TMS Task: {0}'>{0}</a>",
result.Rows[a].ItemArray[2]) :
"&nbsp;",
// fr object number
Expand All @@ -315,7 +315,7 @@ private void GetRequirements(string by, string[] criteria, string file_filter)
// fr status
result.Rows[a].ItemArray[9] != null ? result.Rows[a].ItemArray[9] : "&nbsp;",
// source/file
string.Format("<a href='/?by={0}&value={1}&filter={2}' title='Repeat searching in this source only.'>{2}</a>",
string.Format("<a href='/?by={0}&value={1}&filter={2}' title='Repeat search using this source only'>{2}</a>",
by,
value,
result.Rows[a].ItemArray[10])));
Expand All @@ -330,7 +330,7 @@ private void GetRequirements(string by, string[] criteria, string file_filter)
{
Trace.Instance.Add("Requirements NOT found", Trace.Color.Yellow);
}
html.Append("<div><p align='center'><font color='maroon'>No results to display. </font><a href='/?help#sr'> Want to read help?</a></p></div>");
html.Append("<div><p align='center'><font color='maroon'>No results to display. </font><a href='/?help'> Want to read help?</a></p></div>");
}
}

Expand All @@ -342,7 +342,7 @@ private void GetRequirements(string by, string[] criteria, string file_filter)
"<br>",
"<table border=0 width=100% style='text-align: right; padding: 1em; font-size: 80%; white-space: nowrap; color: #cccccc;'>",
"<tr>",
"<td style='text-align: center;'>Powered by WebQA<br>Generated on {0}</td>",
"<td style='text-align: center;'>Powered by <a href='http://github.com/kungfux/rqs' title='View project on GitHub'>WebQA</a><br>Generated on {0}</td>",
//"<td style='text-align: left;'></td>",
"</tr></table></div>"),
DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss:fff")));
Expand Down
10 changes: 5 additions & 5 deletions WebQA/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WebQA")]
[assembly: AssemblyDescription("Web server that provide web utils for QA department")]
[assembly: AssemblyDescription("Web server that provides search requirements feature")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Fuks Alexander")]
[assembly: AssemblyCompany("Alexander Fuks")]
[assembly: AssemblyProduct("WebQA")]
[assembly: AssemblyCopyright("Copyright © Fuks Alexander 2013-2015")]
[assembly: AssemblyCopyright("Copyright © Alexander Fuks 2013-2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.10")]
[assembly: AssemblyFileVersion("1.0.0.10")]
36 changes: 22 additions & 14 deletions WebQA/WebPages/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
body, p, table { font: 14px "atrament-web-1", "atrament-web-2", Georgia, Serif; }
h1 { font: bold 18px "atrament-web-1", "atrament-web-2", Georgia, Serif; }
h2 { font: bold 16px "atrament-web-1", "atrament-web-2", Georgia, Serif; }
table { border-collapse: collapse; }
table, th, td { border: 1px solid black; }
th, td { padding: 5px; }
</style>
</head>
<body>
Expand Down Expand Up @@ -56,9 +59,13 @@ <h2 id='sr'>Search requirements</h2>
<li>"Search" button</li><br>
Press "Search" button to perform searching.
</ul>

<p>WebQA allows to search requirements by FR ID, FR TMS Task and FR text. You should specify search criteria by selecting appropriate option from the "Search by" list and then define search keyword(s). <u>All searching is case-insensitive.</u></p>

<p>Search keywords can be separated by comma or semicolon. In this case found requirements will contain all specified keywords (AND logic). There is one more option available and can be used for searching groups of requirements by FR ID only. For this purpose specify two numbers separated by dash. This lind of search is called as "FR ID diapason" and has limitation by 5000 numbers.</p>

<b>There are examples of search keywords:</b>

<table border=1 style=' text-align: left; '>
<tr>
<th>Search by</th>
Expand All @@ -68,62 +75,62 @@ <h2 id='sr'>Search requirements</h2>
<tr>
<td>FR ID</td>
<td>FR1</td>
<td>will search for requirement with number 'FR1'</td>
<td>search for requirement with number 'FR1'</td>
</tr>
<tr>
<td>FR ID</td>
<td>FR1;fr3</td>
<td>will search requirements with numbers 'FR1' or 'FR3'</td>
<td>search for requirements with numbers 'FR1' or 'FR3'</td>
</tr>
<tr>
<td>FR ID</td>
<td>FR1,fr3</td>
<td>will search requirements with numbers 'FR1' or 'FR3'</td>
<td>search for requirements with numbers 'FR1' or 'FR3'</td>
</tr>
<tr>
<td>FR ID</td>
<td>FR1-FR3</td>
<td>will search requirements with numbers 'FR1' or 'FR2' or 'FR3'</td>
<td>search for requirements with numbers 'FR1' or 'FR2' or 'FR3'</td>
</tr>
<tr>
<td>FR ID</td>
<td>FR1-3</td>
<td>will search requirements with numbers 'FR1' or 'FR2' or 'FR3'</td>
<td>search for requirements with numbers 'FR1' or 'FR2' or 'FR3'</td>
</tr>
<tr>
<td>FR ID</td>
<td>NFR1-3</td>
<td>will search requirements with numbers 'NFR1' or 'NFR2' or 'NFR3'</td>
<td>search for requirements with numbers 'NFR1' or 'NFR2' or 'NFR3'</td>
</tr>
<tr>
<td>FR TMS Task</td>
<td>PCC-43345</td>
<td>will search requirements which contain in FR TMS Task 'PCC-43345'</td>
<td>search for requirements which contain in FR TMS Task 'PCC-43345'</td>
</tr>
<tr>
<td>FR TMS Task</td>
<td>PCC;mar5</td>
<td>will search requirements which contain in FR TMS Task 'PCC' and 'MAR5'</td>
<td>search for requirements which contain in FR TMS Task 'PCC' and 'MAR5'</td>
</tr>
<tr>
<td>FR TMS Task</td>
<td>PCC,mar5</td>
<td>will search requirements which contain in FR TMS Task 'PCC' and 'MAR5'</td>
<td>search for requirements which contain in FR TMS Task 'PCC' and 'MAR5'</td>
</tr>
<tr>
<td>FR Text</td>
<td>OE_param_micro</td>
<td>will search requirements which contain in text specified keyword</td>
<td>search for requirements which contain in text specified keyword</td>
</tr>
<tr>
<td>FR Text</td>
<td>oe;specimen;collect;receive</td>
<td>will search requirements which contain in text all the keywords specified</td>
<td>search for requirements which contain in text all the keywords specified</td>
</tr>
<tr>
<td>FR Text</td>
<td>oe,specimen,collect,receive</td>
<td>will search requirements which contain in text all the keywords specified</td>
<td>search for requirements which contain in text all the keywords specified</td>
</tr>
</table>

Expand Down Expand Up @@ -163,7 +170,8 @@ <h2 id='l'>Licence and disclaimer</h2>
or (at your option) any later version.<br>WebQA is designed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU General Public Licence</a> for more details.</p>
<p><b><u>Disclaimer:</b></u> Use WebQA on your own risk; nobody respond in case search results are wrong.<br>Author, hereby disclaims all copyright interest in the program WebQA (which makes passed at compilers).</p>

<p style='text-align: right;'>Written by <a href='mailto:[email protected]'>Fuks Alexander</a></p>

<p>View project on <a href='http://github.com/kungfux/rqs'>GitHub</a></p>

</body>
</html>

0 comments on commit c6594ca

Please sign in to comment.