|
Information is look like this.
?d??♣♠ P????x?▬?♀?P↑???<
?+??♣♠ P??????u.??P↑?Z#G
?+??♣♠ P??lm→???→(P↑?X0?
If you can think then I Can.
|
|
|
|
|
You are going to have to look at the raw data bytes you get from the socket - it looks as if the conversion from ASCII to unicode is not good. That implies the data is probably in blocks of some form (there is a strong pattern to the data).
Try examining it as hex bytes: you may be able to discern a pattern, and work out what part is the data you are interested in.
Do you have any information about your data source?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
Dear Sir,
Can u please describe me in detail. I am already convert it to in ascii format.
Thanks for reply
If you can think then I Can.
|
|
|
|
|
You receive your data from the socket as a stream of bytes:
int bytes = socket.Receive(buffer); Examine the bytes, rather than converting them to a unicode string. I don't know what device you are getting your data from, so I can't be any more specific, but the strings you showed looked like that had a regular pattern indicating blocks of data of some kind. Somewhere in those blocks will probably be the data you want, but you will have to look for it.
If you have any instructions on the device you are talking to, those may help you.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
Hello Sir,
Pls describe me what is wrong with that.
do
{
bytes = s.Receive(buffer);
if (bytes > 0)
{
System.Text.ASCIIEncoding ascii = new ASCIIEncoding();
string url = ascii.GetString(buffer, 0, bytes);
try
{
url = url.Substring(url.IndexOf("GET") + 4, url.IndexOf("HTTP") - (url.IndexOf("GET") + 3) - 1);
Console.WriteLine("http//:" + url);
}
catch { }
}
} while (bytes > 0);
If you can think then I Can.
|
|
|
|
|
Do you want a list?
1) Never use empty catch blocks - they just hide your problems!
2) What if your URL is split across two receive blocks? I.e. if the first s.Recieve fetches 5 bytes, and the second fetches 25?
What is it doing (as if I couldn't guess: "it's not working")?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
Dear Sir,
Thanks for suggesting a good matter. But still i m waiting for the result oriented answer for that.
Thanks
If you can think then I Can.
|
|
|
|
|
Hi
I've been searching for any real world applications for C# keyword "dynamic"
Example 1 seems pretty lame as "interface" serves a purpose[^]
Example 2 - example don't seems to work, see code below.[^]
<br />
static void Test1()<br />
{<br />
System.Xml.XmlDocument xmlDoc = null;<br />
System.Xml.XmlElement xmlElement = null;<br />
<br />
try<br />
{<br />
xmlDoc = new System.Xml.XmlDocument();<br />
xmlDoc.LoadXml(("<!DOCTYPE root [<!ELEMENT root ANY><!ELEMENT Person ANY><!ELEMENT Customer EMPTY><!ELEMENT Team EMPTY><!ATTLIST Person SSN ID #REQUIRED><!ATTLIST Customer id IDREF #REQUIRED ><!ATTLIST Team members IDREFS #REQUIRED>]><root><Person SSN='A111' Name='Fred'/><Person SSN='A111'/><Person SSN='A222' Name='Tom'/><Customer id='A111'/><Customer id='A222334444'/><Team members='A222334444 A333445555'/></root>"));<br />
xmlElement = xmlDoc.GetElementById("A111");<br />
Console.WriteLine(xmlElement.OuterXml);<br />
<br />
}<br />
catch (Exception Ex)<br />
{<br />
Console.WriteLine(Ex.Message);<br />
}<br />
<br />
return;<br />
}<br />
<br />
static void Test2()<br />
{<br />
dynamic xmlDoc = null;<br />
dynamic xmlElement = null;<br />
<br />
try<br />
{<br />
xmlDoc = new System.Xml.XmlDocument();<br />
xmlDoc.LoadXml(("<!DOCTYPE root [<!ELEMENT root ANY><!ELEMENT Person ANY><!ELEMENT Customer EMPTY><!ELEMENT Team EMPTY><!ATTLIST Person SSN ID #REQUIRED><!ATTLIST Customer id IDREF #REQUIRED ><!ATTLIST Team members IDREFS #REQUIRED>]><root><Person SSN='A111' Name='Fred'/><Person SSN='A111'/><Person SSN='A222' Name='Tom'/><Customer id='A111'/><Customer id='A222334444'/><Team members='A222334444 A333445555'/></root>"));<br />
xmlElement = xmlDoc.A111;
Console.WriteLine(xmlElement.OuterXml);<br />
<br />
}<br />
catch (Exception Ex)<br />
{<br />
Console.WriteLine(Ex.Message);<br />
}<br />
<br />
return;<br />
}<br />
Example 3 - thus far, this seems to be best illustration: The Dynamic Keyword in C# 4.0. It shows how a method called can be done thru (i) Conventional OO interface, (ii) Reflection and (3) dynamic - but still in this example dynamic definitely beats reflection but conventional OO interface is type-safe, dynamic is not.[^]
I still haven't found one example where dynamic is "required" or shows a real promising use.
Anyone? Thanks
dev
|
|
|
|
|
I've used dynamic with COM interop, but like var and this, its a keyword thats often abused by lazy programmers. Reflection should always be your last resort since its super duper slow.
|
|
|
|
|
Have a look at Massive[^], a data access class written by Rob Conery.
|
|
|
|
|
Hi,
I've an assignment to make a program that should generate all the permutations of a string one by one. I know many algorithm of generating permutations using recursion, but question has asked to generate it one by one. So deliverable should contain a class called "PermutationIterator" which should have a method "hasNextPermutation" and "nextPermutation". They have given one hint, make a "tailIterator" object of type "PermutationIterator" inside a "PermutationIterator" class (like a node of LinkedList) and then do some funny things with it. I can't figure out where should I start....any help would be appreciated.
Note: You can't generate all permutations at one time, then store it into an array and then call each of them one by one. Please don not suggest this way.
Thank you
Shivam Kalra
|
|
|
|
|
I dunno; I don't do it[^] recursively.
|
|
|
|
|
Nonetheless, generating permutations is something that suits recursion. And the yield keyword would be useful too, see a little experiment here[^].
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc Pattyn wrote: generating permutations is something that suits recursion
I respectfully disagree.
|
|
|
|
|
Very nice article. I've bookmarked it. But in my case, if I do it non recursively then I'll get 0 marks because question clearly says USE RECURSION.
|
|
|
|
|
smells a lot like homework, and we don't do other people's homework...
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thank you guys.
I'm very excited right now because I've just finished the question, and I did it all by myself . It took 1/2 hour to think, 1 hour to write and 1 hour to correct it using hit and trial..But finally I succeeded. I'm attaching code below, it is in java but it will still run in C# because all syntax-es are same.
public class PermutationIterator
{
private String s;
private int index = 0;
private PermutationIterator tailIterator = null;
public PermutationIterator(String s)
{
this.s = s;
if(s.length() > 0)
tailIterator = new PermutationIterator(s.substring(1));
}
public boolean hasMorePermutations()
{
if(tailIterator == null)
return false;
if(s.length() == 1)
return true;
return index != s.length() - 1 || tailIterator.hasMorePermutations();
}
public String nextPermutation()
{
if(s.length() == 1)
{
tailIterator = null;
return s;
}
if(!tailIterator.hasMorePermutations())
tailIterator = new PermutationIterator(s.substring(0, ++index) +
s.substring(index + 1));
return s.charAt(index) + tailIterator.nextPermutation();
}
}
It is still less readable because I just used hit trial thing to correct array out of bound exceptions. I've started to love recursion..There are only few things in world that gives to pain and pleasure and one of them is recursion , lol I just made that up..
Anyways, if you could improve my code and I would really appreciate it.
Thanks
Shivam K
|
|
|
|
|
I haven't checked it at all, however it looks sufficiently clean for me to trust you either have it right or could easily get it right.
one comment: I would put some parentheses in this line, to make it even more obvious:
return index != s.length() - 1 || tailIterator.hasMorePermutations();
( )
Now here is something to think about: assume there could be some duplicate characters (say street), now generate all permutations without any duplicates. I'm not claiming this is easy! I could offer a hint if you were to need one.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
It sounds interesting and more practical. Give me hint, I'll try to work on it.
Shivam
|
|
|
|
|
think of a way to get all permutations in a simple ordered fashion, before you tackle the duplicates! It is very cheap, however it may well influence a lot of your code...
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
It still very hard to do. Let say you have string "aaabbbccc", you will get 9! combination..then you need to find repetitions using linear search for each of the element..it's gonna take too much time..is there any way of handling repetition within code so that it can be ignored and final result we get is list of length (9!/3!3!3!).
|
|
|
|
|
Shivamkalra wrote: It still very hard to do
not really.
all you need to do is, at each nesting level, not choose a letter you have already chosen at that level (in a previous iteration).
Now think. very hard, if you must.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
oh ya, that's actually easy and makes sense too. I found a good way..if u arrange letter so that repeated letters are together then it will even easier to skips letters in each iteration ex. "aabbcc".
This way you can skip alternating alphabet in each recursion..this is really interesting..I'm gonna give it a try right now.
Thanks
Shivam
|
|
|
|
|
Shivamkalra wrote: tailIterator = new PermutationIterator(s.substring(0, ++index) + s.substring(index + 1));
While fine in C#, I don't like it a bit; in other languages (e.g.C, C++) this statement's result would be undefined, as the big + operator is commutative (*) and nothing forces the left operator to be evaluated before the right one, so the right operand can't be sure the auto-increment has already been executed. Again, C# guarantees it, but a casual reader could port it to another language and inadvertently introduce something that goes wrong on some compilers or under some circumstances!
[ADDED]
(*) well, not fully commutative like an arithmetic addition, however both string operands could be evaluated in any order before they get concatenated.
[/ADDED]
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Friday, February 25, 2011 11:34 PM
|
|
|
|
|
I have written a service and it will start and run, but it terminates itself at variable times.
In the event viewer it only says that the service has terminated unexpectedly. Is there a best practice way to log this or capture this failure? I can't seem to figure out what is causing this failure, it does not fail when I launch the exe in debug mode.
Thanks for reading, here is my main thread code if that will help.
using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;
using System.Net;
using System.Collections;
using Microsoft.Win32;
namespace WindowsService
{
class WindowsService : ServiceBase
{
public WindowsService()
{
this.ServiceName = "Emailer";
this.EventLog.Log = "Emailer Application";
this.CanHandlePowerEvent = true;
this.CanHandleSessionChangeEvent = true;
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.CanStop = true;
}
static void Main()
{
ServiceBase.Run(new WindowsService());
Thread workerThread = new Thread(new ThreadStart(workThread));
workerThread.Start();
string logDate = dataLogging.Logging.returnDate(false, true);
}
static void workThread()
{
while (true)
{
try
{
RegistryKey scheduleEmailer = Registry.LocalMachine;
RegistryKey emailerKey = scheduleEmailer.OpenSubKey(@"SOFTWARE\s\ScheduleEmailer");
string dayOfWeek = emailerKey.GetValue("dayOfWeek").ToString();
string hourInArmyTime = emailerKey.GetValue("hourInArmyTime").ToString();
string minuteFloor = emailerKey.GetValue("minuteFloor").ToString();
string minuteCeiling = emailerKey.GetValue("minuteCeiling").ToString();
string isRunning = "false";
if ((DateTime.Now.DayOfWeek.ToString() == dayOfWeek) && (DateTime.Now.Hour == Convert.ToInt32(hourInArmyTime)) && (isRunning == "false"))
{
if ((DateTime.Now.Minute > Convert.ToInt32(minuteFloor)) && (DateTime.Now.Minute < Convert.ToInt32(minuteCeiling)) )
{
isRunning = "true";
htmParser.ScheduleParser.emailer();
string date = dataLogging.Logging.returnDate(false, true);
dataLogging.Logging.log(@"c:\program files\AllinOneService\logs\" + date + "_emaillog.txt", "*** Scheduled email has been sent out at minute " + DateTime.Now.Minute.ToString() + " . ***" + " ... Sleeping for 300 seconds" + System.Environment.NewLine, true);
Thread.Sleep(300000);
isRunning = "false";
}
}
string date2 = dataLogging.Logging.returnDate(false, true);
dataLogging.Logging.log(@"c:\program files\AllinOneService\logs\" + date2 + "_emaillog.txt", "Email wait loop occurring at minute " + DateTime.Now.Minute.ToString() + " . Registry is set to " + dayOfWeek + " " + hourInArmyTime + " " + minuteFloor + " to " + minuteCeiling + ". Comparing to " + DateTime.Now.DayOfWeek + " " + DateTime.Now.Hour + " " + DateTime.Now.Minute + " ... Sleeping for 60 seconds" + System.Environment.NewLine, true);
Thread.Sleep(60000);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw;
}
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
Main();
}
protected override void OnStop()
{
MessageBox.Show("Service is stopped");
base.OnStop();
}
protected override void OnPause()
{
base.OnPause();
}
protected override void OnContinue()
{
base.OnContinue();
}
protected override void OnShutdown()
{
MessageBox.Show("Service is shutdown");
base.OnShutdown();
}
protected override void OnCustomCommand(int command)
{
base.OnCustomCommand(command);
}
protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
{
return base.OnPowerEvent(powerStatus);
}
protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
base.OnSessionChange(changeDescription);
}
public static void scheduleEmail()
{
htmParser.ScheduleParser.emailer();
}
}
}
modified on Friday, February 25, 2011 6:32 PM
|
|
|
|