|
I've got a table in database in which I store URLs that users bookmark. But before inserting a url into database, I want to make sure it's not been bookmarked before by another user. To do so, I have to search for similar forms of a url. i.e. if someone inserts www.yahoo.com, I want to avoid inserting http://yahoo.com again to prevent duplicate entries. The first thing that came to my mind as a solution, was to make urls canonical before inserting them into database, i.e. remove www from the beginning of url (if any) and add http:// to it. This seems a good workaround. The problems is, I don't like to manipulate the initial urls. I mean, If a user wants to bookmark www.yahoo.com, I don't like to insert http://yahoo.com into database for some urls, will not open if you remove www from the beginning of them.
Any idea dudes?
|
|
|
|
|
Maysam Mahfouzi wrote: The problems is, I don't like to manipulate the initial urls
If you don't want to manipulate the URL, doesn't that actually mean you store each URL just as it is (just check that the exact URL isn't found)?
Maysam Mahfouzi wrote: The first thing that came to my mind as a solution, was to make urls canonical before inserting them into database
One thing is that you could make a canonical version first, store it in parent-table and then store the unmodified url in child-table. Something like
CanonicalUrl (
CanonicalUrlId int,
Url varchar(500)
)
Url (
UrlIdId int,
CanonicalUrl int,
Url varchar(500)
)
If you want you could also build a calculated column to Url table to represent the canonical form.
However all these add extra logic to the data handling. So I'm wondering why do you want to prevent storing similar url's at all. Of course storing exactly the same may not be wise, but that's easily prevented.
|
|
|
|
|
How i recive data from a UNIX server pc by using IP and port???? Any Code Reference???
|
|
|
|
|
Hi,
well I think it doesn't matter if you are trying to connect to a unix or windows server (despite the encoding issue maybe). If you can connect to the server using TCP than I suggest using the System.Net.TcpClient. If the server has to connect to your application use the System.Net.TcpListener. If you use these names with google, you will find tons of examples using them.
Regards
Sebastian
|
|
|
|
|
I have 3 servers X, Y and Z.
X will send Trap to Y.
In Z my SNMP application is running.
Z need to receive the Trap that is sent to Y by X.
Y has no running SNMP application.
Necessary port and IP of Y is known to Z.
Is it possible to implement with your code? If possible then how.
Thanks in advance.
Sharif
|
|
|
|
|
I was having problem (see below "TROUBLE") casting int/double to generics ... This is what I intended to write,
<br />
public T RecursiveGetNextRandom<t>(T Max, T Min, List<t> lstExcludedNum) <br />
{<br />
int nNextNum = 0;<br />
double dbNextNum 0;<br />
T NextNum;<br />
<br />
nMin = Convert.ToInt32(Min);<br />
nMax = Convert.ToInt32(Max);<br />
nNextNum = oRand.Next(nMin, nMax);<br />
if(Max is double)<br />
{<br />
dbNextNum = oRand.NextDouble() * nNextNum;<br />
NextNum = (T) dbNextNum; << TROUBLE: Can't cast to <t>!<br />
} else if (Max is int) {<br />
NextNum = (T) nNextNum; << TROUBLE: Can't cast to <t>!<br />
}<br />
<br />
return NextNum;<br />
}<br />
</t></t></t></t>
I ended up writing the following ugly code:
public static object RecursiveGetNextRandom(object Max, object Min, ArrayList lstExcludedNum) <br />
{<br />
object NextNum = 0;<br />
Random oRand = new Random(Guid.NewGuid().GetHashCode());<br />
double dbMin;<br />
double dbMax;<br />
int nNextNum;<br />
<br />
if (Min == null)<br />
{<br />
Min = Int32.MinValue;<br />
}<br />
<br />
if (Max == null)<br />
{<br />
Max = Int32.MaxValue;<br />
}<br />
<br />
if (!(Max is int || Max is double))<br />
{<br />
...<br />
}<br />
<br />
dbMin = Convert.ToInt32(Min);<br />
dbMax = Convert.ToInt32(Max);<br />
SwapIfGreater(ref dbMin, ref dbMax);<br />
nNextNum = oRand.Next(Convert.ToInt32(Math.Floor(dbMin)), Convert.ToInt32(Math.Floor(dbMax)));<br />
<br />
if (Max is double)<br />
{<br />
NextNum = (double)nNextNum * oRand.NextDouble();<br />
}<br />
else if (Max is int)<br />
{<br />
NextNum = (int)nNextNum;<br />
}<br />
<br />
if (lstExcludedNum != null)<br />
{<br />
if (lstExcludedNum.Contains(NextNum))<br />
{<br />
RecursiveGetNextRandom(Max, Min, lstExcludedNum);<br />
}<br />
}<br />
<br />
return NextNum;<br />
}<br />
Any suggestion? Thanks!
dev
|
|
|
|
|
You may be able to create a generic interface, and provide an implementation for each numric type you wish to support... could be an interesting solution if it works, I haven't tried it.
There's also an excellent article here on CP[^] about generic numerics.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
|
Thanks, I have used Convert class since birth of .NET but never seen ChangeType. Good to know!
dev
|
|
|
|
|
The generic interface method does work.
IRand<int> intVersion = new Rand(); ;
Console.WriteLine(intVersion.GetNext(1, 2, new List<int>()));
IRand<long> longVersion = new Rand(); ;
Console.WriteLine(longVersion.GetNext(1, 2, new List<long>()));
public interface IRand<T>
{
T GetNext(T min, T max, List<T> exclude);
}
public class Rand : IRand<int>, IRand<long>
{
public int GetNext(int min, int max, List<int> exclude)
{
int result = 0;
return result;
}
#region IRand<long> Members
public long GetNext(long min, long max, List<long> exclude)
{
long result = 0;
return result;
}
#endregion
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Thanks, I just found it. This is from Darwen[^], which involves declaring <t> as IConvertible.
<br />
class RangedRandom<t><br />
where T : IConvertible<br />
{<br />
private Random _random = new Random();<br />
private double _min;<br />
private double _range;<br />
private static readonly Type ElementType = typeof(T);<br />
<br />
public RangedRandom(T min, T max)<br />
{<br />
_min = Convert.ToDouble(min);<br />
_range = Convert.ToDouble(max) - _min;<br />
}<br />
<br />
public T Next()<br />
{<br />
double rand = _random.NextDouble();<br />
double value = _min + (rand * _range);<br />
return (T)Convert.ChangeType(value, ElementType);<br />
}<br />
}<br />
</t>
dev
|
|
|
|
|
Yeah, that could be a good way of achieving what you want. I'd use a try/catch either inside the method or inside the calling method as even if T implements IConvertible, there's no guarantee that the conversion can actually be done - it depends on the class/struct's individual implementation.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
For whatever reason, when I try to set the value of the DatGridView, it doesn't stick. I have been wrecking by brain over why this is Here is my code
Basically here I am just building the data into my data gridview and then since they will be editing I want the amounts to be loaded into the dgv which is what PopulateList() does.
private void bookList_Load(object sender, EventArgs e)
{
BLL = new BooksBLL("C");
dataGridView1.DataSource = BLL.allBooks();
if (isEdit)
{
PopulateList();
}
}
private void PopulateList()
{
foreach (OrderedBook ob in order.MyOrderedBooksCollection)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (ob.BookCode.ToString() == dataGridView1.Rows[i].Cells[2].Value.ToString())
if (ob.CopiesOrdered > 0)
dataGridView1.Rows[i].Cells[0].Value = ob.CopiesOrdered.ToString();
}
}
}
Now the interesting thing is that the value property hold and then somehow disappears when the form is loading because when i check the value immediately after a button is pressed without touching anything, it is already null. Note that the dgv works fine other than the fact that the Populate list feature won't load the values.
|
|
|
|
|
It certainly sounds like your grid's data source is somehow getting reset to its apparent starting value of BLL.allBooks(). Have you considered creating a DataSet, DataTable or DataView from BLL.allBooks and having your PopulateList method update the desired column with 'CopiesOrdered', accepting those changes, and then setting your grid data source to that object?
|
|
|
|
|
I am doing work in asp.net using c# in VS2008. I would like to give output in java script window because client dont want button and address, tool bars. so i need to design my own window for out put. I am very new in this field. I really don know which ddl i need to use and where i need to place code (in html, in page_load)
Can any one please help me in this regard?
thanks
|
|
|
|
|
Member 2842468 wrote: I am very new in this field.
Then you probably shouldn't have taken on the work.
only two letters away from being an asset
|
|
|
|
|
Tell your client you were ripping them off, then buy a book and read it before taking more work. also, when you have ASP.NEt questions, use the ASP.NEt forum.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Member 2842468 wrote: I would like to give output in java script window because client dont want button and address, tool bars.
That is not possible. Even if you open a new window using Javascript, you can't get rid of the address field.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
yes,
this is possible
from javascript, use:
window.open(url, targetFrame, "toolbar=no,width=500,height=500,resizable,scrollbars");
<< Nearly all men can stand adversity, but if you want to test a man's character, give him power. >>
|
|
|
|
|
No, it's not possible. That doesn't remove the address field.
(It might work it if the page is a file on your own computer, but that's not really relevant.)
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi.
How to get html from url requiring login, with c#? First login the page and then get html.
for instance this url: https://www.google.com/accounts/Login?continue=http://www.google.com/
|
|
|
|
|
Send the login information in a post to the login page and get the cookies that you get in the response. Put the cookies in the request when you get pages that require login.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I try this, but is not working. Not login.
CookieContainer cookie = new CookieContainer();
string pageData = string.Empty;
StreamReader respReader = null;
label1.Text = "Finding Site ...";
Application.DoEvents();
HttpWebRequest _mainRequest = (HttpWebRequest)WebRequest.Create("https://www.google.com/accounts/Login?continue=http://www.google.com/");
label1.Text = "Setting Parameters";
Application.DoEvents();
_mainRequest.Method = "POST";
_mainRequest.ContentType = "application/x-www-form-urlencoded";
_mainRequest.CookieContainer = cookie;
label1.Text = "Building String to Send";
Application.DoEvents();
StreamWriter reqWriter = new StreamWriter(_mainRequest.GetRequestStream());
label1.Text = "Sending Form data";
Application.DoEvents();
reqWriter.Write("Email=" + myMail + "&Passwd=" + myPass);
reqWriter.Close();
label1.Text = "Closing Response from Site";
Application.DoEvents();
_mainRequest.GetResponse().Close();
label1.Text = "Looking up secure Site";
Application.DoEvents();
_mainRequest = (HttpWebRequest)WebRequest.Create("http://www.google.com.tr");
_mainRequest.CookieContainer = cookie;
label1.Text = "Getting Response from Site";
Application.DoEvents();
respReader = new StreamReader(_mainRequest.GetResponse().GetResponseStream());
pageData = respReader.ReadToEnd();
label1.Text = "Cleaning up";
Application.DoEvents();
respReader.Close();
label1.Text = "Ready";
textBox1.Text = pageData;
Application.DoEvents();
|
|
|
|
|
You didn't get the cookies from the response.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
thank you. did work.
I using timer. but, page source code not refresh. Why?
|
|
|
|