|
the problem is like this:
Sometimes, the content of webpage is read !!!!!!!!!!!!!!!!!! But after a couple of readings on the same page/or/website, it gets stuck on this error. It's like some cookie is activated or something, and remembers that i was there before and not alowing me to enter anymore. And it's true for any page from that website after this thing happen. The problem is i don't know how to find and set that cookie from c#. I strongly believe is a cookie.
But if it's something else? Here is why i'm asking.
modified 5-Aug-19 20:13pm.
|
|
|
|
|
Well, if it's a cookie the site is looking for, you'd see that in a Fiddler trace.
|
|
|
|
|
i just downloaded Fiddler Web Debugger, and im looking in it. It's a very powerful tool from the first view, but i have no clue how to find my cookie with it. So far, i can see it is auto detecting my pages that are open, but unfortunatly, it open a bunch of other (background? maybe) pages. I look in them but is a bit overwhelming. I also find this neat thing where i can target the window. I also see in Inspectors - Cookies button, but it says "This request did not send any cookie data", and i just log out and log in from the page. Hmmm.
Tell me please how to use it in this little thing i want. And thank you so much for such a awesome tool. I love it, even i am very new to it and im looking like a cat at the OZN.
|
|
|
|
|
|
so its complicated, i get it.
Though i made some progress. I went on :
View Cookie Information | Progress Telerik Fiddler[^]
Capture HTTPS traffic from Firefox | Progress Telerik Fiddler[^]
and i start made these settings and that involved installing the addon to be able to see the cookies. I installed it and i can see the cookies now ! I succesfully exported and installed a certificate that was required. And now is awesome. hmmm. Now what?
You did an excelent job so far. Thank you very much.
You can hint me, give me a general idea how to proceed next in this Fidler software. No need to give me baby steps, i get its too much for you. But general and hopefully to the point directives you can easily give (if you say you know this stuff). I want these directives to know in what direction to concentrate my search, because until now im doing it blind. Thank you again for the help so far. I hope i will not get stuck.
|
|
|
|
|
|
|
They blocked your IP because your "poking" is being interpreted as hacking. Or they are throttling you. You're assuming only static content. The door is being locked. Verboten. They have your IP address. Quote: You tell 'em I'm comin' and Hell is comin' with me, you hear?
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
Instead of my program showing this:
Enter element value: 0
Enter element value: 1
Enter element value: 2
...and so forth it is currently showing this:
Enter element value: 0
Enter element value: 0
Enter element value: 0
What am I doing wrong?
using System;
class InputArrayValues
{
static void Main()
{
int[] nums = new int[5];
for (int i = 0; i < 5; i++)
{
Console.Write("Enter element value " + nums[i] + ": ");
nums[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine();
Console.Write("The array values you entered are: ");
for (int i = 0; i < 5; i++)
Console.Write(nums[i] + " ");
Console.WriteLine();
Console.WriteLine();
}
}
|
|
|
|
|
Console.Write("Enter element value " + nums[i] + ": ");
Should be:
Console.Write("Enter element value " + i + ": ");
Do you see why?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard is spot on with the problem you have noticed, but do yourself a favour and don't use Convert for user input. If the user mistypes - and everybody does - then Convert will fail and your app will crash. That's OKish with five values, but for a user it's very, very annoying if they type 19 of 20 and the app crashes and throws everything away!
Instead, use the TryParse methods:
int[] nums = new int[5];
for (int i = 0; i < 5; i++)
{
do
{
Console.Write("Enter element value " + i + ": ");
string input = Console.ReadLine();
if (int.TryParse(input, out nums[i]))
{
break;
}
Console.WriteLine(input + " is not a number!");
} while (true);
}
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
modified 5-Aug-19 2:21am.
|
|
|
|
|
I try to create a wrapper for measuring the execution time.
With actions its simple:
public static class StopWatch
{
public static TimeSpan MeasureAction(Action _action)
{
Stopwatch watch = Stopwatch.StartNew();
_action();
watch.Stop();
return watch.Elapsed;
}
}
Also, common return types are not a problem, I added an extra class for returning the duration plus the "normal" result (.Net 4.5, so the more modern Tuples whose contents have names beyond Item1 etc are not available):
internal class MeasuredExecution<T> : IMeasuredExecution<T>
{
public MeasuredExecution(TimeSpan _duration, T _result)
{
Duration = _duration;
Result = _result;
}
public TimeSpan Duration { get; }
public T Result { get; }
}
public static class StopWatch<T>
{
public static IMeasuredExecution<T> MeasureFunction(Func<T> _function)
{
Stopwatch watch = Stopwatch.StartNew();
T result = _function();
watch.Stop();
return new MeasuredExecution<T>(watch.Elapsed, result);
}
}
Now comes the problem I am looking for a better solution: the return value may be an IDisposable . In order to properly use it with a using clause, I need a wrapper exposing the IDisposable interface and calling Dispose on the Result . That wrapper part is easy, but what about the StopWatch ? I created another class:
internal class DisposableMeasuredExecution<T> : MeasuredExecution<T>, IDisposableMeasuredExecution<T> where T : IDisposable
{
public DisposableMeasuredExecution(TimeSpan _duration, T _result)
: base(_duration, _result) { }
public void Dispose()
{
Result.Dispose();
}
}
public static class StopWatchD<T> where T : IDisposable
{
public static IDisposableMeasuredExecution<T> MeasureFunction(Func<T> _function)
{
Stopwatch watch = Stopwatch.StartNew();
T result = _function();
watch.Stop();
return new DisposableMeasuredExecution<T>(watch.Elapsed, result);
}
}
Due to the extra constraint that T must now be an IDisposable , I failed to get that in the previous StopWatch class, even when using a different function name.
That feels like a WTF. Do you have any ideas how to accomplish that?
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
You can't overload a function based on the generic type constraints. And you can't add type constraints to a class-level type parameter just for one method.
What you can do is add the type parameter to the method instead of the class, and use a different function name.
public static class StopWatch
{
public static TimeSpan MeasureAction(Action _action)
{
Stopwatch watch = Stopwatch.StartNew();
_action();
watch.Stop();
return watch.Elapsed;
}
public static IMeasuredExecution<T> MeasureFunction<T>(Func<T> _function)
{
Stopwatch watch = Stopwatch.StartNew();
T result = _function();
watch.Stop();
return new MeasuredExecution<T>(watch.Elapsed, result);
}
public static IDisposableMeasuredExecution<T> MeasureFunctionDisposable<T>(Func<T> _function) where T : IDisposable
{
Stopwatch watch = Stopwatch.StartNew();
T result = _function();
watch.Stop();
return new DisposableMeasuredExecution<T>(watch.Elapsed, result);
}
} Alternatively, you could make IMeasuredExecution<T> implement IDisposable so that you wouldn't need a separate method:
public interface IMeasuredExecution<T> : IDisposable
{
TimeSpan Duration { get; }
T Result { get; }
}
internal class MeasuredExecution<T> : IMeasuredExecution<T>
{
public MeasuredExecution(TimeSpan _duration, T _result)
{
Duration = _duration;
Result = _result;
}
public TimeSpan Duration { get; }
public T Result { get; }
public void Dispose()
{
var value = Result as IDisposable;
if (value != null) value.Dispose();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: add the type parameter to the method instead of the class, and use a different function name That's where I failed orginally. But, after changing T to T1 - thus using a different name for the type parameter - it works.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
It'll be easier to call if you only put the type parameter on the method.
StopWatch.MeasureFunction(() => 42);
StopWatch.MeasureFunctionDisposable(CreateSomeDisposableThing);
StopWatch<int>.MeasureFunction(() => 42);
StopWatch<object>.MeasureFunctionDisposable(CreateSomeDisposableThing);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Those generic type parameters are still a cause of confusion for me...
Thanks for the hint, that's far easier, and the places where the methods are used are far better to read.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
If you "logged" from your stopwatch class, you wouldn't have to worry (so much) about the return values; seems the "api" would be simpler too.
The custom measurement calls could stay in permanently; activated or filtering at will.
You can go up the stack and tell who called who.
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
Hi all,
- I am very new to c# so please be easy on me -
I have this following code which works perfectly fine:
string directory = Path.Combine(assemblyDirectory, "lib", "NetworkConnections");
using (AssemblyCatalog assemblyCatalog = new AssemblyCatalog(typeof(NetworkConnectionsManager).Assembly))
using (DirectoryCatalog directoryCatalog = new DirectoryCatalog(directory))
using (AggregateCatalog aggregateCatalog = new AggregateCatalog(assemblyCatalog, directoryCatalog))
{
compositionContainer = new CompositionContainer(aggregateCatalog);
networkConnectionsManager = compositionContainer.GetExportedValue<NetworkConnectionsManager>();
}
networkConnectionsToUpstreamProxySettingsMap = networkConnectionsManager
.GetAllConnectionFullNames()
.ToDictionary(cn => cn, cn => networkConnectionsManager.GetCurrentProxySettingsForConnection(cn));
}
(There are dll's located in ./lib/NetworkConnections)
Now I want to embed everything into a single exe. I used Fody Costura, which worked as expected as produced a single exe, but when I run my code I got an exception about lib/NetworkConnections/Telerik.NetworkConnections.dll file not found.
I tried changing the line to this instead:
string directory = "/";
Which now gives a different exception:
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
on this line:
.ToDictionary(cn => cn, cn => networkConnectionsManager.GetCurrentProxySettingsForConnection(cn));
is anyone able to help me as to what I am doing wrong? thank you so much in advance!
|
|
|
|
|
adding double quote around variable add one backslash which causing issue at sql server level. see the below code where i am adding double quote around variable and when i am printing string variable value then i am seeing many extra back slash has been added to string variable. when i am sending that data to xml causing issue.
string abc = "<Broker Code=" + '"' + strbrokercode + '"' + " IsAllowEstimate=" + '"' + IsAllowEstimate + '"' + " ReviseDate=" + '"' + ReviseDate + '"' + " BrokerEarnings=" + '"' + BrokerEarnings + '"' + " BrokerName=" + '"' + BrokerName + '"' + "></Broker>";
i tried to replace back slash with empty string but that did not work. please give me some solution.
|
|
|
|
|
Two ways:
1) The standard way - escape it with a backslash:
string abc = "<Broker Code=\"" + strbrokercode + "\" IsAllowEstimate=\"" + IsAllowEstimate + "\" ReviseDate=\"" + ReviseDate + "\" BrokerEarnings=\"" + BrokerEarnings + "\" BrokerName=\""+ BrokerName + "\"></Broker>";
2) Disable the escape character and use two double quotes together:
string abc = @"<Broker Code=""" + strbrokercode + """ IsAllowEstimate=""" + IsAllowEstimate + """ ReviseDate=""" + ReviseDate + """ BrokerEarnings=""" + BrokerEarnings + """ BrokerName="""+ BrokerName + """></Broker>"; But a more readable way would be to use string interpolation if your compiler supports it:
string abc = $"<Broker Code=\"{strbrokercode}\" IsAllowEstimate=\"{IsAllowEstimate}\" ReviseDate=\"{ReviseDate}\" BrokerEarnings=\"{BrokerEarnings}\" BrokerName=\"{BrokerName}\"></Broker>";
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I test below code which did not compile
string abc = @"<Broker Code=""" + strbrokercode + """ IsAllowEstimate=""" + IsAllowEstimate + """ ReviseDate=""" + ReviseDate + """ BrokerEarnings=""" + BrokerEarnings + """ BrokerName="""+ BrokerName + """></Broker>";
please compile it.
|
|
|
|
|
If you're generating XML, then it would be better to actually generate XML. There are many "special" characters which need to be encoded for use in XML.
string abc = new System.Xml.Linq.XElement("Broker",
new System.Xml.Linq.XAttribute("Code", strbrokercode),
new System.Xml.Linq.XAttribute("IsAllowEstimate", IsAllowEstimate),
new System.Xml.Linq.XAttribute("ReviseDate", ReviseDate),
new System.Xml.Linq.XAttribute("BrokerEarnings", BrokerEarnings),
new System.Xml.Linq.XAttribute("BrokerName", BrokerName)
).ToString();
Mou_kol wrote: i am seeing many extra back slash has been added to string variable
It's more likely that you're seeing the debugger output, which shows you how the string would be declared in C#. It doesn't actually add the backslash characters to the string.
If you click on the "magnifying glass" button to the left of the string value in the data tip[^], you'll be able to view the actual string value.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks a lot for your answer.
see this code
string strbrokercode="ML";
string IsAllowEstimate="true";
string ReviseDate="true";
string BrokerEarnings="true";
string BrokerName="true";
StringBuilder sb = new StringBuilder();
string abc = "<Broker Code=" + '"' + strbrokercode + '"' + " IsAllowEstimate=" + '"' + IsAllowEstimate + '"' + " ReviseDate=" + '"' + ReviseDate + '"' + " BrokerEarnings=" + '"' + BrokerEarnings + '"' + " BrokerName=" + '"' + BrokerName + '"' + "></Broker>";
sb.Append(abc);
when i type sb.ToString() in immediate window then output print like below one which causing problem for me.
"<Broker Code=\"ML\" IsAllowEstimate=\"true\" ReviseDate=\"true\" BrokerEarnings=\"true\" BrokerName=\"true\"></Broker>"
Please share your suggestion. thanks
|
|
|
|
|
As I said, those backslashes do not exist in your string. The "immediate" window is encoding the string to match what you would have to type to declare it in your C# code.
Use the debugger visualizer instead.
Newlines in the immediate window – jaredpar's WebLog[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thanks
|
|
|
|