|
beh7606 wrote:
but when i delete, my app notify that it already delete..when i recheck again..the file still available but it cannot be opened..window prompt "the file is not exist..do u want to create new"
i google and found that i is bcos of the file is being shared between 2 activity which is, system watcher and stream reader...
can anyone help me how can i solve my problem...??
I haven't used the <a href="http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx">FileSystemWatcher</a>[<a href="http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx" target="_blank" title="New Window">^</a>] yet, but it might help to split the task into two separate tasks;
Once you processed a file, add it's path to a list.
Have a background-thread remove the files in that list.
Bastard Programmer from Hell
|
|
|
|
|
A couple of things to watch for:
1.
FileSystemWatcher looks for file system activity, and fires events when some file operations happen (or start to happen). The number of events is undefined; creating and filling a big file may generate several Changed events.
2.
FileSystemWatcher does NOT signal the end of a file operation, so you won't know when the writing process is done writing.
3.
One way to cope with the above is by inserting a delay: after a Created or a Changed event, just wait one minute, and only then do what you intended.
4.
Another work-around is using two files (this assumes you control the producer: have it create the actual file of interest, and when done, create a small "semaphore" file, optimally using simple code such as
File.WriteAllText("someFolder\semaphore.dat", "there is a new file called someFolder\myActualDataFile.txt");
Then have your FileSystemWatcher watch for the semaphore file only.
5.
When reading files or file streams, you must mjake sure to close them properly. Calling Close() or Dispose() normally takes care of that. Applying a using construct is a very good way to make sure it always happens:
using (StreamWriter swFromFile = new StreamWriter(logFileName)) {
swFromFile.Write(textToAdd);
...
swFromFile.Write(textToAdd);
}
|
|
|
|
|
hai! your solution is good!! thanks you...i will try to do it your way..hopefully it successful..thank you...!!! -sharing is caring- *_*
|
|
|
|
|
hi,
I want to use regular expressions for analyzing a url, but I can't get the regex groups as I would expect them to be.
My regular expression is:
@"member/filter(.*)(/.+)*"
The strings to match:
1) "member/filter-one"
2) "member/filter-two/option"
3) "member/filter-three/option/option"
I expect to get the following groups:
1) member/filter-one, /filter-one
2) member/filter-two/option, /filter-two, /option
3) member/filter-three/option/option, /filter-three, /option(with 2 captures)
I get the result for the first string, but fore the 2 others I get:
2) member/filter-two/option, /filter-two/option, empty string
3) member/filter-three/option/option, /filter-three/option/option, empty string
What can be the issue?
|
|
|
|
|
We do have a Regular expressions forum[^] - you should use that in future.
But, it's a Sunday, and I'm feeling generous!
If you name your groups instead of using anonymous groups it becomes clearer what the problem is:
member/filter(?<Prefix>.*)(?<Option>/[^/]+)*
Shows that all of the matches are in the Prefix group: nothing gets as far as the Option group because the "any character, repeated" clause in the prefix swallows the option text as well.
Get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
modified 11-Dec-11 8:02am.
|
|
|
|
|
I second using the correct forum in the future.
benams wrote: (/.+)*
I've never gotten that sort of thing to work, so I expect it won't.
Try @"member/filter([^/]*)/([^/]*)/([^/]*)"
(And I like to name my groups too.)
|
|
|
|
|
I plan to make a Winforms app to sell, and am wondering how to avoid having it be pirated. I was thinking I could first get the user to create a UUID, inside of which there is his motherboard serial # and hardcode each distribution such that upon app start, there would be a check of that motherboard serial #, with the app actually running only if that matches. (I would set up a way for the customer to get a new distribution from me for other computers he may get.)
But there probably is a better way. Any ideas?
|
|
|
|
|
swampwiz wrote: But there probably is a better way. Any ideas?
Yes, don't bother.
You're wasting time on people who for the most part are not going to pay anyway, no matter what you do. You could use that time to actually make your program better. The idea you describe (and most others) only make it harder for legitimate users to use the program - suddenly they have to go through some sort process when they get a new computer? And the pirated version will just skip the UUID check (or whatever) entirely. Many paying users will then pirate the app even though they paid.
There are a couple of things that work to some degree:
- dongles (or other custom hardware). These things always break and cost a fortune for you just to set up the infrastructure. Only worth it for corporate applications that cost thousands per seat or if you intend to create a whole new platform.
- moving the functionality to a server. Works best if it's inherently an online program (multiplayer game etc), otherwise users will hate you.
- making the app free. Maybe with ads, or in-app purchases. Some may mess with that, but large scale piracy is unlikely because there isn't much to save.
Anything else can be broken, and will be, if the app is popular enough. And if it isn't popular, why waste time on such things?
|
|
|
|
|
Spot on!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
If you want to avoid piracy then only distribute your app on a single box that is disconnected from the internet. Otherwise there is no foolproof method. If they want it badly enough they will hack it
No comment
|
|
|
|
|
swampwiz wrote: how to avoid having it be pirated
Just make it so no one wants it (which is very likely anyway) and no one will steal it.
I'd rather have a lot of people using my free program.
modified 10-Dec-11 15:27pm.
|
|
|
|
|
Anything that runs on the users machine can be pirated, simply by duplicating the complete environment. ..and you don't want to;
Pirates aren't people who would have bought your product, hence, you are not losing any money (forget what the ad on copy-protection says), but you are gaining a user-base and valuable market-share.
Microsofts dominance is due to the fact that the product was easily pirated, and that has made it the most distributed OS. Once that particular pirate needs your product in a formal setting (say, within their company), they'll close that buy - and that's a sale that you loose if your product is hard to distribute.
Bastard Programmer from Hell
|
|
|
|
|
First get them hooked, then get them paying... Does make me think of some other market which seems to be very profitable
Cheers, AT
Cogito ergo sum
|
|
|
|
|
Addy Tas wrote: First get them hooked, then get them paying...
Called a vendor-lock in.
Addy Tas wrote: Does make me think of some other market which seems to be very profitable
Marketing?
Bastard Programmer from Hell
|
|
|
|
|
I have created a wcf service which is returning data in json format.
Only issue is that when i call the function it is creating a file instead of returning it as a string,
can any one help where i am doing wrong
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(BodyStyle= WebMessageBodyStyle.Wrapped,
RequestFormat=WebMessageFormat.Json,
ResponseFormat=WebMessageFormat.Json,
UriTemplate="players"
)]
List<Person> GetAll();
}
<services>
<service name="coopWCF.Service1" behaviorConfiguration="Service1Behavior">
<endpoint
address=""
binding="webHttpBinding"
contract="coopWCF.IService1"
behaviorConfiguration="AjaxBehavior">
</endpoint>
</service>
<behavior name="AjaxBehavior">
<webHttp defaultOutgoingResponseFormat="Json" />
</behavior>
|
|
|
|
|
You may get better help on this by posting it in the correct forum[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I am really new to c# and need help with my 8 queens project. (First semester)
So far I have the the main form, the program class, Board class, and the Queens class.
I have the chessboard built but the problem is I do not know where to put the code to make the queen move on the chessboard. I have seen many apps like this but not in the C# coding.
This is what I have so far:
**Board.cs:**
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Resources;
namespace _8_Queens
{
class Board:UserControl
{
public Board()
{
}
protected override void OnPaintBackground(PaintEventArgs chess)
{
Graphics color = chess.Graphics;
int size = this.Height / 8;
bool isBlack = true;
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
Brush paint;
if (isBlack)
paint = Brushes.Black;
else
paint = Brushes.Gray;
color.FillRectangle(paint, new Rectangle(j * size, i * size, size, size));
isBlack = !isBlack;
}
isBlack = !isBlack;
}
}
}
}
I have nothing in the queens class because I do not know where to start and would like help in:
1. making the queens display on the chessboard (need to know what class to put it in and how to display it when the button on the form is clicked)
2. Also, I was wondering if I even need a queens class and, instead, do everything on the chessboard class.
Thank you! It would be helpful since I'm not great with the8queens algorithm and get confused when trying to type the code in.
|
|
|
|
|
Hi,
1.
in general there are many ways to organize things, many bad ways, some good ones, maybe one or several excellent ones. In this instance, your fundamental question is: should there be a Queen class, and if so what would be its role? To solve that question, think about it both ways.
With a full-fledged Queen class, each Queen instance would represent one chess piece, it would know where it is, paint itself, but having 8 Queen instances would not directly help at solving the problem, as they need to know each other's position in order to solve the problem, i.e. the problem is not at the level of the individual Queen.
Without a Queen class, the Board would need to know there are 8 queens, with their positions. It would have to figure out a set of positions that satisfies the requirements, then paint the 32 white and 32 black squares and the 8 queens.
Thirdly, one could opt for a way in the middle; a limited Queen class could take care of painting the symbol, and maybe help in deciding which squares are attacked by it.
And finally, one could even create a Square class, where a board is just a collection of 64 instances of Square, each square knowing where it is and painting itself (and not doing anything else, as board squares are really stupid).
Now it is up to you to choose. All these approaches are valid, one could be simpler than another, and one could be more academic.
2.
Member 8466234 wrote: I ... get confused when trying to type the code in.
That is indicative of a lack of "design". You should sit down and think about your approach before you start typing anything. Come up with an architecture, don't try and put bricks one on top of another until you happen to have the house you wanted to build. Make a plan first.
3.
On coding style: you have chosen not to have a Square class, which is fine as painting the 64 cells at once isn't hard at all. You did surprise me a lot by having that as a BackgroundPaint though. If the class is Board, then painting itself is a regular Paint IMO, not a background. But it is still OK.
Yhe names you have chosen for identifiers are really confusing; your paint is a Brush, why not call it brush then? your color is the entire Graphics object, so it is NOT a color. If you have a cat, would you call it "Dog"?
Finally your isBlack manipulations seem correct, however I would do it slightly different, probably like so:
graphics.FillRectangle((i+j)%2==0?Brushes.Black:Brushes.Gray), new Rectangle(...));
that would not need a separate variable, but more importantly it would not rely on sequential painting of the cells, each cell now calculates its color on its own, i.e. less error prone without significantly adding to the calculation cost.
4.
You're not the first one to attempt the 8 queens problem. The internet holds hundreds of attempts. There are some articles on the subject here at CodeProject. Did you look at any of them? Are you familiar with the CodeProject search facilities? Did you consider asking Google? You would get a number examples (of different quality levels) that could guide and insipre you.
|
|
|
|
|
The reason I went graphic first is because I already had a algorithm code. The problem with the algorithm is that it runs perfectly on console but i do not know how to make it run on windows form. Here is what I have:
It is changed up because I tried to make it a form
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication7
{
class Program
{
public enum Square
{
size = 8
}
public class EightQueen
{
public static int count = 0;
public static bool isValidMove(int[,] Array, int row, int col)
{
for (int i = 0; i < Square.size.GetHashCode(); i++)
if (Array[row, i] == 1)
return false;
for (int i = 0; i < Square.size.GetHashCode(); i++)
if (Array[i, col] == 1)
return false;
int tempCol = col + 1, tempRow = row;
for (int i = row + 1; i < Square.size.GetHashCode(); i++)
{
if (tempCol < Square.size.GetHashCode())
{
if (Array[i, tempCol] == 1)
return false;
else
tempCol++;
}
else
break;
}
tempCol = col - 1;
for (int i = row - 1; i >= 0; i--)
{
if (tempCol >= 0)
{
if (Array[i, tempCol] == 1)
return false;
else
tempCol--;
}
else
break;
}
tempCol = col - 1;
for (int i = row + 1; i < Square.size.GetHashCode(); i++)
{
if (tempCol >= 0)
{
if (Array[i, tempCol] == 1)
return false;
else
tempCol--;
}
else
break;
}
tempCol = col + 1;
for (int i = row - 1; i >= 0; i--)
{
if (tempCol < Square.size.GetHashCode())
{
if (Array[i, tempCol] == 1)
return false;
else
tempCol++;
}
else
break;
}
return true;
}
public static void DisplayChessBoard(int[,] boardArr)
{
int count = 0;
for (int i = 0; i < Square.size.GetHashCode(); i++)
for (int j = 0; j < Square.size.GetHashCode(); j++)
if (boardArr[i, j] == 1)
count++;
if (count >= 8)
ShowBoard(boardArr);
}
public static void ShowBoard(int[,] boardArray)
{
for (int i = 0; i < Square.size.GetHashCode(); i++)
{
for (int j = 0; j < Square.size.GetHashCode(); j++)
Console.Write("{0} ", boardArray[i, j]);
Console.WriteLine();
}
count++;
Console.WriteLine();
}
public static void Chessboard(int[,] boardArr, int row, int col)
{
for (int i = row; i < Square.size.GetHashCode(); i++)
{
for (int j = 0; j < Square.size.GetHashCode(); j++)
{
if (isValidMove(boardArr, i, j))
{
boardArr[i, j] = 1;
DisplayChessBoard(boardArr);
Chessboard(boardArr, i + 1, j + 1);
boardArr[i, j] = 0;
}
}
}
}
static void Main()
{
Application.EnableVisualStyles();
int[,] boardArr = new int[Square.size.GetHashCode(), Square.size.GetHashCode()];
for (int i = 0; i < Square.size.GetHashCode(); i++)
for (int j = 0; j < Square.size.GetHashCode(); j++)
boardArr[i, j] = 0;
Chessboard(boardArr, 0, 0);
Console.WriteLine("Total Solutions {0}", count);
Application.Run(new Form1());
}
}
}
}
|
|
|
|
|
Member 8466234 wrote: I already had a algorithm code
you could have said that right away.
I'm not impressed by your algorithm; there is no need to check for queens in the same row; just put one in each row to begin with. And put them all in different columns too, that reduces the problem to just the permutations of the numbers 1 thru 8. All that needs checking then is for the absence of diagonal attacks.
you did tackle it without a Queen class, why would you suddenly consider having one?
And what is with all that GetHashCode()?
Why can't you just paint some symbol where a queen is supposed to surface? use Graphics.DrawImage with some small Bitmap.
|
|
|
|
|
I seen a couple of c++ users and vb.net users using queen classes and thought I needed it. The GetHashCode() was the only code I knew how to use.
The main thing i'm just having trouble with is putting this into a form program. It seems like its a whole new concept. For example, I can imagine clicking the button and its suppose to do the calculations and pop up on the chessboard but I don't know what code goes where.
Should I throw the whole algorithm/graphics under btnClick?
Main question: How would I throw the Graphics.DrawImage in the algorithm? Sorry I been studying this since beginning of fall and didnt have a great teacher.
|
|
|
|
|
GetHashCode() makes no sense at all here, throw it away completely. Have you any idea what a hash code is? How could it be justified here?
Member 8466234 wrote: Should I throw the whole algorithm/graphics under btnClick?
No.
1. Graphics operations must go in the Paint handler. Here[^] is an article that explains how things should be done.
2. You can do calculations (but not the graphics painting!) in a Click handler, provided they're done in less than say 50 msec. If they take longer, you ought to put them in a separate thread (maybe a BackgroundWorker) otherwise your program will be non-reponsive to Windows events and that is not acceptable to the users. You are clearly not ready for threads though.
Member 8466234 wrote: I been studying this since beginning of fall
I strongly suggest you choose, buy and study an introductory book on C# programming, so you can get rid of some bad habits, and learn how to do things properly. There are lots of good books, look at ten books and choose the one or two that appeal most to you.
|
|
|
|
|
Personally, I wouldn't even think about how it's presented before I have the algorithm working.
|
|
|
|
|
Timezone parsing issue - borrowing code from here[^]
When parsing for example “4:01PM EST”, we offset the time by five hours – date string becomes “4:01PM -0500″, all good. This said, "Date" is wrong. It is 10 DEC 2011 (This is "Tomorrow") but it should really be 8 DEC 2011 - (but offset in terms of hours/minutes correct)
Note, I’m now in Hong Kong 9 DEC 2011 12pm translates to 8 DEC 2011 23:02 in NYC (i.e. HK is 13 hrs ahead of NYC).
ConvertedDate = Convert.ToDateTime(NewDateStr);
What do I need to do? Manually compensate for this by subtracting two days off?
ConvertedDate = ConvertedDate.AddDays(-2);
Thanks
dev
modified 8-Dec-11 23:25pm.
|
|
|
|
|
Check that your input conforms to the rules as laid down here[^]. You should not need to do any further modifications to your results from the parsing operation.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|