instruction stringlengths 0 30k ⌀ |
|---|
You can have multiple endpoints defined either on the server, or the client.
To do it on the client, you just need to edit your app.config file with a new endpoint with a different name, then define when you create your new client.
For example if you have an endpoint in your client app like:
<endpoint address="https://yourdomain.com/WCF/YourService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IYourService"
contract="MessagingService.IYourService"
name="BasicHttpBinding_IYourService" />
Which you call by:
YourServiceClient client = new YourServiceClient();
You can add a new endpoint with a new name:
<endpoint address="https://yourotherdomain.com/WCF/YourService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IYourService"
contract="MessagingService.IYourService"
name="BasicHttpBinding_IYourService_ENDPOINT2" />
Which you can call with:
YourServiceClient client = new YourServiceClient("BasicHttpBinding_IYourService_ENDPOINT2");
I just changed the domain above, but if you made a new binding configuration section, you could just change the "bindingConfiguration" value. |
You should be able to export the documents to word or excel and then use OpenOffice to open the documents. No additional set up required. |
If you just commit your working copy, you'll get a file list showing you your unversioned files, which you can tick to add as you commit. You don't have to add them explicitly before you commit. |
Wait until file is unlocked in .Net |
|.net|.net-3.5|file| |
What's the simplest way of blocking a thread until a file has been unlocked and is accessible for reading and renaming? EG: Is there a WaitOnFile() somewhere in the framework?
I have a service that uses a FileSystemWatcher to look for files that are to be transmitted to an FTP site, but the File Created event fires before the other process has finished writing the file.
The ideal solution would have a timeout period so the thread doesn't hang forever before giving up. |
Another totally different way of looking at it would be to pass a lambda expression (condition for populating the second collection) as a predicate to the first collection.
I know this is not the exact answer to the question. I think other users already gave the correct answer. |
Only a good amount of accumulated statistics from previous projects can help you to give precise estimates. If you have a well defined set of requirements, you can make a rough calculation of how many test cases you have. As I said you need to have some statistics for your team. You need to know average bugs-per-loc number to estimate total bugs count. If you don't have such numbers for your team, you can use [industry average numbers][1]. After you have estimated LOC (number of use cases * NLOC) and average bugs-per-lines, you can give more or less accurate estimation on time required to release project.
From my practical experience, time spent on bug-fixing is equal to or more (in 99% cases :) ) than time spent on original implementation.
[1]: http://amartester.blogspot.com/2007/04/bugs-per-lines-of-code.html |
Only a good amount of accumulated statistics from previous projects can help you to give precise estimates. If you have a well defined set of requirements, you can make a rough calculation of how many use cases you have. As I said you need to have some statistics for your team. You need to know average bugs-per-loc number to estimate total bugs count. If you don't have such numbers for your team, you can use [industry average numbers][1]. After you have estimated LOC (number of use cases * NLOC) and average bugs-per-lines, you can give more or less accurate estimation on time required to release project.
From my practical experience, time spent on bug-fixing is equal to or more (in 99% cases :) ) than time spent on original implementation.
[1]: http://amartester.blogspot.com/2007/04/bugs-per-lines-of-code.html |
Lists allow duplicate items, while Sets allow only one instance.
I'll use a Map whenever I'll need to perform a lookup.
For the specific implementations, there are order-preserving variations of Maps and Sets but largely it comes down to speed. I'll tend to use ArrayList for reasonably small Lists and HashSet for reasonably small sets, but there are many implementations (including any that you write yourself). HashMap is pretty common for Maps. Anything more than 'reasonably small' and you have to start worrying about memory so that'll be way more specific algorithmically.
[This page][1] has **lots** of animated images along with sample code testing LinkedList vs. ArrayList if you're interested in hard numbers.
[1]: http://www.roseindia.net/javatutorials/linkedlistvsarraylist.shtml |
Lists allow duplicate items, while Sets allow only one instance.
I'll use a Map whenever I'll need to perform a lookup.
For the specific implementations, there are order-preserving variations of Maps and Sets but largely it comes down to speed. I'll tend to use ArrayList for reasonably small Lists and HashSet for reasonably small sets, but there are many implementations (including any that you write yourself). HashMap is pretty common for Maps. Anything more than 'reasonably small' and you have to start worrying about memory so that'll be way more specific algorithmically.
[This page][1] has **lots** of animated images along with sample code testing LinkedList vs. ArrayList if you're interested in hard numbers.
**EDIT:** I hope the following links demonstrate how these things are really just items in a toolbox, you just have to think about what your needs are: See Commons-Collections versions of [Map][2], [List][3] and [Set][4].
[1]: http://www.roseindia.net/javatutorials/linkedlistvsarraylist.shtml
[2]: http://commons.apache.org/collections/api-release/org/apache/commons/collections/map/package-summary.html
[3]: http://commons.apache.org/collections/api-release/org/apache/commons/collections/list/package-summary.html
[4]: http://commons.apache.org/collections/api-release/org/apache/commons/collections/set/package-summary.html |
Best way to manage generated code in an automated build? |
|build-process|automation|nant|code-generation| |
In my automated NAnt build we have a step that generates a lot of code off of the database (using SubSonic) and the code is separated into folders that match the schema name in the database. For example:
- /generated-code
- /dbo
- SomeTable.cs
- OtherTable.cs
- /abc
- Customer.cs
- Order.cs
The schema names are there to isolate the generated classes that an app will need. For example, there is an ABC app, that will pull in the generated code from this central folder. I'm doing that on a pre-build event, like this:
> del /F /Q $(ProjectDir)Entities\generated\*.cs
> copy $(ProjectDir)..\..\generated-code\abc\*.cs $(ProjectDir)Entities\generated\*.cs
So on every build, the Nant script runs the generator which puts all the code into a central holding place, then it kicks off the solution build... which includes pre-build events for each of the projects that need their generated classes.
So here's the friction I'm seeing:
1) Each new app needs to setup this pre-build event. It kind of sucks to have to do this.
2) In our build server we don't generate code, so I actually have an IF $(ConfigurationName) == "Debug" before each of those commands, so it doens't happen for release builds
3) Sometimes the commands fail, which fails our local build. It will fail if:
- there is no generated code yet (just setting up a new project, no database yet)
- there is no existing code in the directory (first build)
usually these are minor fixes and we've just hacked our way to getting a new project or a new machine up and running with the build, but it's preventing me from my 1-click-build Nirvana.
So I'd like to hear suggestions on how to improve this where it's a bit more durable. Maybe move the copying of the code into the application folders into the NAnt script? This seems kind of backwards to me, but I'm willing to listen to arguments for it.
OK, fire away :)
|
Having worked on a lot of waterfall projects in the past and a lot of adhoc and agile projects more recently, there's a number of design artifacts I like to create although I can't state enough that it really depends on the details of the project (methodology/team structure/timescale/tools etc).
For a generic server-based 'enterprise application' I'd want the bare minimum to be something along these lines:
- A deitailed functional design document (aka spec). Generally something along the lines of Joel s' [WhatsTimeIsIt example spec][1], although probably with some UML use-case diagrams.
- A software techical design document. Not necessarily detailed for 100% system coverage but detailed in all the key areas and containing all the design decisions. Being a bit of an UML freak it's be nice to see lots of pictures along the lines of package diagrams, component diagrams, key feature class diagrams, and probably some sequence diagrams thrown in for good measure.
- An infrastructure design document. Probably with UML deployment diagram for the conceptual deisng and perhaps a network diagram for something more physical.
When I say document any of the above might be broken down into multiple documents, or perhaps stored on a wiki/some other tool.
As for their usefulness, my philosophy has always been that a development team should always be able to hand over an application to a support team without having to hand over their phone numbers. If the design artifacts don't clealry indicate what the application does, how it does it, and where it does it then you know the support team are going to give the app the same care and attention they would a rabid dog.
I should mention I'm not vindicating the practice of handing software over from a dev team to a support team once it's *finished*, which raises all manner of interesting issues, I'm just saying it should be possible if the management so desired.
[1]: http://www.joelonsoftware.com/articles/WhatTimeIsIt.html |
I'm not too sure what is going on here, but sometimes a particular file in my repository will change the case of it's name. e.g.,:
before:
File.h
after:
file.h
I don't really care why this is happening, but this causes git to think it is a new file, and then I have to go and change the file name back. Can you just make git ignore case changes? |
|windows|git| |
I'm not too sure what is going on here, but sometimes a particular file in my repository will change the case of it's name. e.g.,:
before:
File.h
after:
file.h
I don't really care why this is happening, but this causes git to think it is a new file, and then I have to go and change the file name back. Can you just make git ignore case changes?
[edit]
I suspect it is Visual Studio doing something weird with that particular file, because it seems to happen most often when I open and save it after changes. I don't have any way to fix bugs in VS however, but git should be a bit more capable I hope. |
A different approach, just for kicks:
Console.WriteLine(string.Join("\t", list.Cast<string>().ToArray())); |
You probably need the [http.proxyHost and http.proxyPort system properties][1] set. For example, `ANT_OPTS="-Dhttp.proxyHost=proxy.y.com" ant doc`
Alternatively, you could set the "offline" flag and provide a package list, but that could be a pain for the Java core.
[1]: http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html |
select foo from Bar order by newid() |
I really think you just need to agree on a clear definition of what you mean when you say "business logic". If you need to be "politically sensitive", you could even craft the definition around your team lead's understanding, then come up with another term ("domain rules"?) that defines what you want to talk about.
Words and terms are relatively subjective -- of course, once you leave that company you will need to 're-learn' industry standards, so it's always better to stick with them if you can, but the main goal is to communicate clearly and get work done. |
I suspect that the real issue here is that your test runner is copying your assembly to a different location. There's no way at runtime to tell where the assembly was copied from, but you can probably flip a switch to tell the test runner to run the assembly from where it is and not to copy it to a shadow directory.
Such a switch is likely to be different for each test runner, of course.
Have you considered embedding your XML data as resources inside your test assembly? |
Do you really want to do run the regexp twice? Without having checked (bad me) I would have thought that this would work well:
public static string StripStringFormating(string formattedString)
{
return rTest.Replace(formattedString, string.Empty);
}
If it does, you should see it run ~twice as fast... |
Cannot delete from the database...? |
|database|db2| |
So, I have 2 database instances, one is for development in general, another was copied from development for unit tests.
Something changed in the development database that I can't figure out, and I don't know how to see what is different.
When I try to delete from a particular table, with for example:
delete from myschema.mytable where id = 555
I get the following normal response from the unit test DB indicating no row was deleted:
> SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. SQLSTATE=02000
However, the development database fails to delete at all with the following error:
> DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0440N No authorized routine named "=" of type "FUNCTION" having compatible arguments was found. SQLSTATE=42884
My best guess is there is some trigger or view that was added or changed that is causing the problem, but I have no idea how to go about finding the problem... has anyone had this problem or know how to figure out what the root of the problem is?
(note that this is a DB2 database) |
Searching subversion history (full text) |
|full-text-search|subversion| |
Is there a way to perform a full text search of a subversion repository, including all the history?
For example, I've written a feature that I used somewhere, but then it wasn't needed, so I svn rm'd the files, but now I need to find it again to use it for something else. The svn log probably says something like "removed unused stuff", and there's loads of checkins like that. |
Is there a way to perform a full text search of a subversion repository, including all the history?
For example, I've written a feature that I used somewhere, but then it wasn't needed, so I svn rm'd the files, but now I need to find it again to use it for something else. The svn log probably says something like "removed unused stuff", and there's loads of checkins like that.
Note to Mark Biek, Jack M etc: svn log --verbose is not full text searching, that's searching the logs and filenames. |
Is there a way to perform a full text search of a subversion repository, including all the history?
For example, I've written a feature that I used somewhere, but then it wasn't needed, so I svn rm'd the files, but now I need to find it again to use it for something else. The svn log probably says something like "removed unused stuff", and there's loads of checkins like that.
Note to @[Mark Biek](#44234), @[Jack M](#44226) etc: svn log --verbose is not full text searching, that's searching the logs and filenames. |
|svn|full-text-search| |
Is there a way to perform a full text search of a subversion repository, including all the history?
For example, I've written a feature that I used somewhere, but then it wasn't needed, so I svn rm'd the files, but now I need to find it again to use it for something else. The svn log probably says something like "removed unused stuff", and there's loads of checkins like that. |
Maybe I just write buggy code, but I like having a 1:1 ratio between devs and tests. I don't wait until alpha to test, but rather do it throughout the whole project. The logic? Depending on your release schedule, there could be a good deal of time between when development starts and when your alpha, beta, and ship dates are. Furthermore, the earlier you catch bugs, the easier (and cheaper) they are to fix.
A good tester, who find bugs soon after each check-in, is invaluable. Simply put, I am still extremely familiar with my code, so most bug fixes become super simple. With this approach, I tend to leave roughly 15% of my dev time to bug fixing. At least when I do estimates. So in a 16 week run I'd leave around 2-3 weeks. |
Maybe I just write buggy code, but I like having a 1:1 ratio between devs and tests. I don't wait until alpha to test, but rather do it throughout the whole project. The logic? Depending on your release schedule, there could be a good deal of time between when development starts and when your alpha, beta, and ship dates are. Furthermore, the earlier you catch bugs, the easier (and cheaper) they are to fix.
A good tester, who find bugs soon after each check-in, is invaluable. (Or, better yet, before a check-in from a PR or DPK... you can tell I interned at MS.) Simply put, I am still extremely familiar with my code, so most bug fixes become super simple. With this approach, I tend to leave roughly 15% of my dev time to bug fixing. At least when I do estimates. So in a 16 week run I'd leave around 2-3 weeks. |
Having worked on a lot of waterfall projects in the past and a lot of adhoc and agile projects more recently, there's a number of design artifacts I like to create although I can't state enough that it really depends on the details of the project (methodology/team structure/timescale/tools etc).
For a generic server-based 'enterprise application' I'd want the bare minimum to be something along these lines:
- A deitailed functional design document (aka spec). Generally something along the lines of Joel s' [WhatsTimeIsIt example spec][1], although probably with some UML use-case diagrams.
- A software techical design document. Not necessarily detailed for 100% system coverage but detailed in all the key areas and containing all the design decisions. Being a bit of an UML freak it'd be nice to see lots of pictures along the lines of package diagrams, component diagrams, key feature class diagrams, and probably some sequence diagrams thrown in for good measure.
- An infrastructure design document. Probably with UML deployment diagram for the conceptual deisng and perhaps a network diagram for something more physical.
When I say document any of the above might be broken down into multiple documents, or perhaps stored on a wiki/some other tool.
As for their usefulness, my philosophy has always been that a development team should always be able to hand over an application to a support team without having to hand over their phone numbers. If the design artifacts don't clealry indicate what the application does, how it does it, and where it does it then you know the support team are going to give the app the same care and attention they would a rabid dog.
I should mention I'm not vindicating the practice of handing software over from a dev team to a support team once it's *finished*, which raises all manner of interesting issues, I'm just saying it should be possible if the management so desired.
[1]: http://www.joelonsoftware.com/articles/WhatTimeIsIt.html |
Having worked on a lot of waterfall projects in the past and a lot of adhoc and agile projects more recently, there's a number of design artifacts I like to create although I can't state enough that it really depends on the details of the project (methodology/team structure/timescale/tools etc).
For a generic, server-based 'enterprise application' I'd want the bare minimum to be something along these lines:
- A detailed functional design document (aka spec). Generally something along the lines of Joel s' [WhatsTimeIsIt example spec][1], although probably with some UML use-case diagrams.
- A software techical design document. Not necessarily detailed for 100% system coverage but detailed in all the key areas and containing all the design decisions. Being a bit of an UML freak it'd be nice to see lots of pictures along the lines of package diagrams, component diagrams, key feature class diagrams, and probably some sequence diagrams thrown in for good measure.
- An infrastructure design document. Probably with UML deployment diagram for the conceptual deisng and perhaps a network diagram for something more physical.
When I say document any of the above might be broken down into multiple documents, or perhaps stored on a wiki/some other tool.
As for their usefulness, my philosophy has always been that a development team should always be able to hand over an application to a support team without having to hand over their phone numbers. If the design artifacts don't clealry indicate what the application does, how it does it, and where it does it then you know the support team are going to give the app the same care and attention they would a rabid dog.
I should mention I'm not vindicating the practice of handing software over from a dev team to a support team once it's *finished*, which raises all manner of interesting issues, I'm just saying it should be possible if the management so desired.
[1]: http://www.joelonsoftware.com/articles/WhatTimeIsIt.html |
Use a ORM package, any half decent package will allow you to
1. Get simple result sets
2. Keep your complex SQL close to the data model
If you have very complex SQL, then views are also nice to making it more presentable to different layers of your application. |
[Guidelines for Handheld & Mobile Device User Interface][1]:
> While there has been much successful work in developing rules to guide the design and implementation of interfaces for desktop machines and their applications, the design of mobile device interfaces is still relatively unexplored and unproven. This paper discusses the characteristics and limitations of current mobile device interfaces, especially compared to the desktop environment. Using existing interface guidelines as a starting point, a set of practical design guidelines for mobile device interface is proposed.
[1]: http://www.scribd.com/doc/833751/Guidelines%2Dfor%2DHandheld%2DMobile%2DDevide%2DUser%2DInterface |
We were in a similar predicament at one time. We queried a specific table in a variety of ways, over 50+.
What we ended up doing was creating a single Fetch stored procedure that includes a parameter value for the WhereClause. The WhereClause was constructed in a Provider object, we employed the Facade design pattern, where we could **scrub** it for any SQL injection attacks.
So as far as maintenance goes, it is easy to modify. SQL Server is also quite the **chum** and caches the execution plans of dynamic queries so the the overall performance is pretty good.
You'll have to determine the **performance** drawbacks based on your own system and needs, but all and all, this works **very well** for us. |
When you run a schedule task you can have it run under a user. Verify the user that is running the schedule task has the same rights for the fax resource as you. Which is why you can run it when you double click in Windows explore. |
Examples of using semantic web technologies in real world applications |
|semantic-web|rdf| |
Are you working on a (probably commercial) product which uses RDF/OWL/SPARQL technologies? If so, can you please describe your product? |
How do I generate a Friendly URL in C#? |
|c#|friendly-url| |
How can I go about generating a Friendly URL in C#? Currently I simple replace spaces with an underscore, but how would I go about generating URL's like Stack Overflow?
For example how can I convert:
> How do I generate a Friendly URL in C#?
Into
> how-do-i-generate-a-friendly-url-in-C |
@Mark: Minor detail: `sizeof` gives you the size in chars, not bytes, so if you happen to be on a platform where a char is not the same size as a byte, you are subtly wrong :) |
@Mark: Minor detail: `sizeof` gives you the size in chars, not bytes, so if you happen to be on a platform where a char is not the same size as a byte, you are subtly wrong :)
Also, it is worth noting that `sizeof` doesn't help if you are dealing with a pointer to an array:
int a[10];
int* p = a;
assert(sizeof(a) / sizeof(a[0]) == 10);
assert(sizeof(p) == sizeof(void*)); |
So far, based on the lack of responses to <a href="http://stackoverflow.com/questions/31059/how-do-you-configure-an-openfiledialog-to-select-folders">my identical question</a>, I'd assume the answer is to roll your own dialog from scratch.
I've seen things here and there about subclassing the common dialogs from VB6 and I think this might be part of the solution, but I've never seen anything about modifying what the dialog thinks it's selecting. It'd be possible through .NET via PInvoke and some other tricks, but I have yet to see code that does it.
I *know* it's possible and it's not Vista-specific because Visual Studio has done it since VS 2003.
Here's hoping someone answers either yours or mine! |
Have you set a `:visited` setting in your stylesheet? |
Run your CSS file and your HTML file through the w3c validators. I had a similar problem when testing an application in Safari. The problem was in my code. |
An addition to Chris's post:
You may also have to upgrade the repository itself, if you run into "Retrieval of mergeinfo unsupported" messages. The command to run on the server to do this is,
svnadmin upgrade REPOS_PATH
where REPOS_PATH is the local path to your repository of course. |
**InternalsVisibleTo** attribute is one that is not that well known, but can come in increadibly handy in certain circumstances. It basically allows another assembly to be able to access "internal" elements of the defining assembly. |
[**@Orion**][1] has this *partially* correct - there is *one other way* to deal with these, and that is to cover the offending select lists with an iframe. This technique is used in [**Cody Lindley's ThickBox**][2] (written for jQuery). See the code for details on how to do it.
[1]: http://stackoverflow.com/questions/45267/how-do-i-make-autocompleteextender-render-above-select-controls-in-ie6#45284
[2]: http://jquery.com/demo/thickbox/ |
Getting an int representation of a String |
|java|performance|string| |
I am looking for a way to create an int\long representation of an arbitrary alpha-numeric String. Hash codes won't do it, because I can't afford hash collisions i.e. the representation must be unique and repeatable.
The numeric representation will be used to perform efficient (hopefully) compares. The creation of the numeric key will take some time, but it only has to happen once, whereas I need to perform vast numbers of comparisons with it - which will hopefully be much faster than comparing the raw Strings.
Any other idea's on faster String comparison will be most appreciated too...
Thanks! |
The easiest way is to make `www.mydomain.com/test` serve a HTML file which has a single frame with the plain IP address. However, this means that the URL in the (awesome) address bar always stays exactly the same, even if you click a link on the displayed page. (You can avoid this by adding `target=_top` in the `href`, but this would require some modifications to your "asp.net".)
The only other way I can think of is to make `www.mydomain.com` act as proxy. That is, at `/test` it has a script or something that gets the page from your "asp.net" and forwards it to the client. |
|functionalprogramming|lisp|scheme| |
|functional-programming|lisp|scheme| |
I'm kinda guessing here, but could it be because:
* You are trying to perform file operations in C: root? (there may be protection on this by Vista if you are using it - not sure?)
* You are trying to copy to a non-existant directory?
* The file already exists and may be locked? (i.e you have not closed another application instance)?
Sorry I cant be of more help, I have rarely experienced problems with File.Copy. |
About File permissions in C# |
|c#| |
While creating a file synchronization program in C# I tryed to make a method 'copy' from LocalFileItem class that uses sing System.IO.File.Copy(destination.Path, Path, true) where Path is a string.
After executing this code with destination.Path = "C:\\Test2" and this.Path = "C:\\Test\\F1.txt" I get an exception saying that I do not have the required file permissions to do this operation on C:\Test, but C:\Test is owned by myself(the current user). Does anybody knows what is going on, or how to get around this? |
While creating a file synchronization program in C# I tryed to make a method 'copy' from LocalFileItem class that uses sing System.IO.File.Copy(destination.Path, Path, true) where Path is a string.
After executing this code with destination.Path = "C:\\Test2" and this.Path = "C:\\Test\\F1.txt" I get an exception saying that I do not have the required file permissions to do this operation on C:\Test, but C:\Test is owned by myself(the current user). Does anybody knows what is going on, or how to get around this?
Here is the original code complete.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Diones.Util.IO
{
/// <summary>
/// An object representation of a file or directory.
/// </summary>
public abstract class FileItem : IComparable
{
protected String path;
public String Path
{
set { this.path = value; }
get { return this.path; }
}
protected bool isDirectory;
public bool IsDirectory
{
set { this.isDirectory = value; }
get { return this.isDirectory; }
}
/// <summary>
/// Delete this fileItem.
/// </summary>
public abstract void delete();
/// <summary>
/// Delete this directory and all of its elements.
/// </summary>
protected abstract void deleteRecursive();
/// <summary>
/// Copy this fileItem to the destination directory.
/// </summary>
public abstract void copy(FileItem fileD);
/// <summary>
/// Copy this directory and all of its elements
/// to the destination directory.
/// </summary>
protected abstract void copyRecursive(FileItem fileD);
/// <summary>
/// Creates a FileItem from a string path.
/// </summary>
/// <param name="path"></param>
public FileItem(String path)
{
Path = path;
if (path.EndsWith("\\") || path.EndsWith("/")) IsDirectory = true;
else IsDirectory = false;
}
/// <summary>
/// Creates a FileItem from a FileSource directory.
/// </summary>
/// <param name="directory"></param>
public FileItem(FileSource directory)
{
Path = directory.Path;
}
public override String ToString()
{
return Path;
}
public abstract int CompareTo(object b);
}
/// <summary>
/// A file or directory on the hard disk
/// </summary>
public class LocalFileItem : FileItem
{
public override void delete()
{
if (!IsDirectory) File.Delete(this.Path);
else deleteRecursive();
}
protected override void deleteRecursive()
{
Directory.Delete(Path, true);
}
public override void copy(FileItem destination)
{
if (!IsDirectory) File.Copy(destination.Path, Path, true);
else copyRecursive(destination);
}
protected override void copyRecursive(FileItem destination)
{
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(
Path, destination.Path, true);
}
/// <summary>
/// Create's a LocalFileItem from a string path
/// </summary>
/// <param name="path"></param>
public LocalFileItem(String path)
: base(path)
{
}
/// <summary>
/// Creates a LocalFileItem from a FileSource path
/// </summary>
/// <param name="path"></param>
public LocalFileItem(FileSource path)
: base(path)
{
}
public override int CompareTo(object obj)
{
if (obj is FileItem)
{
FileItem fi = (FileItem)obj;
if (File.GetCreationTime(this.Path).CompareTo
(File.GetCreationTime(fi.Path)) > 0) return 1;
else if (File.GetCreationTime(this.Path).CompareTo
(File.GetCreationTime(fi.Path)) < 0) return -1;
else
{
if (File.GetLastWriteTime(this.Path).CompareTo
(File.GetLastWriteTime(fi.Path)) < 0) return -1;
else if (File.GetLastWriteTime(this.Path).CompareTo
(File.GetLastWriteTime(fi.Path)) > 0) return 1;
else return 0;
}
}
else
throw new ArgumentException("obj isn't a FileItem");
}
}
}
|
|c#|files|copy| |
How do I create a Class using the Singleton Design Pattern in Ruby? |
|designpatterns|ruby| |
The singleton pattern is a design pattern that is used to restrict instantiation of a class to one object instance. Although I know how to code the singleton pattern in C++ and Java, I was wondering if anyone know how to implement it in Ruby? |
|ruby|designpatterns|singleton| |
|ruby|design-patterns|singleton| |
File Parse Design Pattern |
|designpatterns|fileparse| |
Does anybody recommend a design pattern for taking a binary data file, parsing parts of it into objects and storing the resultant data into a database?
I think a similar pattern could be used for taking an XML or tab-delimited file and parse it into their representative objects.
A common data structure would include:
> (Header) (DataElement1) (DataElement1SubData1) (DataElement1SubData2)(DataElement2) (DataElement2SubData1) (DataElement2SubData2) (EOF)
I think a good design would include a way to change out the parsing definition based on the file type or some defined metadata included in the header. So a [Factory Pattern][1] would be part of the overall design for the Parser part.
Keith
[1]: http://www.oodesign.com/factory-method-pattern.html |
|design-patterns|fileparse| |
Transactional Design Pattern |
|sharepoint|transaction|designpatterns| |
I have a need to create a "transactional" process using an external API that does not support COM+ or .NET transactions (Sharepoint to be exact)
What I need to do is to be able to perform a number of processes in a sequence, but any failure in that sequence means that I will have to manually undo all of the previous steps. In my case there are only 2 types of step, both af which are fairly easy to undo/roll back.
Does anyony have any suggestions for design patterns or structures that could be usefull for this ?
Thanks
|
Maybe I just write buggy code, but I like having a 1:1 ratio between devs and tests. I don't wait until alpha to test, but rather do it throughout the whole project. The logic? Depending on your release schedule, there could be a good deal of time between when development starts and when your alpha, beta, and ship dates are. Furthermore, the earlier you catch bugs, the easier (and cheaper) they are to fix.
A good tester, who find bugs soon after each check-in, is invaluable. (Or, better yet, before a check-in from a PR or DPK) Simply put, I am still extremely familiar with my code, so most bug fixes become super simple. With this approach, I tend to leave roughly 15% of my dev time to bug fixing. At least when I do estimates. So in a 16 week run I'd leave around 2-3 weeks. |
I agree that it is typically better to start out with a normalized DB and then denormalize to solve very specific problems, but I'd probably start at [Boyce-Codd Normal Form](http://en.wikipedia.org/wiki/Boyce-Codd_Normal_Form) instead of 3rd Normal Form. |
I'd look at the routing table. Whichever NIC has an 0.0.0.0 route AND is enabled AND has the lowest metric, is the nic that's currently sending packets to the internet.
So in my case, the top one is the 'internet nic'.
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.0.0.10 10.0.0.51 20
0.0.0.0 0.0.0.0 10.0.0.10 10.0.0.50 25
(much other stuff deleted)
Another alternative is to ping or GetBestInterface 4.2.2.2 - this is an old and venerable DNS server, currently held by GTEI; formerly by Sprint if I remember right.
|
I asked a similar question, and ended up writing an [answer][1] which used WMI to enum the group members. I had real problems with authentication in the system.directoryservices.accountmanagement stuff. YMMV, of course.
[1]: http://stackoverflow.com/questions/21514/enumerate-windows-user-group-members-on-remote-system-using-c#24075 |
the function you need is:
<code>CeRunAppAtTime( appname, time )</code>
that isn't the exact signature, there is also <code>CeRunAppAtEvent</code>, they should both be in the MSDN docs (but linking is useless the way MSDN urls always change)
The normal way to use these (and <code>RunAppAtTime</code> in the managed world via <code>OpenNETCF.Win32.Notify</code> ) is that for periodic execution, every time your app runs, it will rescedule itself for its next run-time.
If your app is running, the new instance should bring up the already running process. If it isn't running, then it is just like starting up normally - from mmory it passes some argument to the process so it can tell it is being scheduled and not started some other way.
|
I am not entirely up to date on the latest best practices, et cetera when it comes to code layout, but when I did my first GAE application, I used something along your second option, where the code and templates are next to eachother.
There was two reasons for this - one, it kept the code and template nearby, and secondly, I had the directory structure layout mimic that of the website - making it (for me) a bit easier too remember where everything was. |
Is it possible to forward ssh requests that come in over a certain port to another machine? |
|macos|ubuntu|ssh|port| |
I have a small local network. Only one of the machines is available to the outside world (this is not easily changeable). I'd like to be able to set it up such that ssh requests that don't come in on the standard port go to another machine. Is this possible? If so, how?
Oh and all of these machines are running either Ubuntu or OS X. |
You can use Port Fowarding to do this. Take a look here:
<http://portforward.com/help/portforwarding.htm>
There are instructions on how to set up your router to port forward request on this page:
<http://www.portforward.com/english/routers/port_forwarding/routerindex.htm> |
I primarily use NHibernate, both at work and on my freetime projects. This started as an attempt to break out of the norm at work to use ADO.NET datareaders/datasets and we now have a few projects using Hibernate/NHibernate. |
I have one word "debugging" - you never want to have to use it but you always do. In .Net if you're using Visual Studio you have a fantastic debugger when compared to trying to debug code on ASP. |
Well, there are a few minor improvements we could make. ;)
I would use a Timer to make sure callers don't have to wait for the method to return. And preventing more than one flashing operation at a time on a given window would be nice to.
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import javax.swing.JFrame;
public class WindowFlasher {
private final Timer timer = new Timer();
private final Map<JFrame, TimerTask> flashing
= new ConcurrentHashMap<JFrame, TimerTask>();
public void flashWindow(final JFrame window,
final long period,
final int blinks) {
TimerTask newTask = new TimerTask() {
private int remaining = blinks * 2;
@Override
public void run() {
if (remaining-- > 0)
window.setVisible(!window.isVisible());
else {
window.setVisible(true);
cancel();
}
}
@Override
public boolean cancel() {
flashing.remove(this);
return super.cancel();
}
};
TimerTask oldTask = flashing.put(window, newTask);
// if the window is already flashing, cancel the old task
if (oldTask != null)
oldTask.cancel();
timer.schedule(newTask, 0, period);
}
}
|
Well, there are a few minor improvements we could make. ;)
I would use a Timer to make sure callers don't have to wait for the method to return. And preventing more than one flashing operation at a time on a given window would be nice too.
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import javax.swing.JFrame;
public class WindowFlasher {
private final Timer timer = new Timer();
private final Map<JFrame, TimerTask> flashing
= new ConcurrentHashMap<JFrame, TimerTask>();
public void flashWindow(final JFrame window,
final long period,
final int blinks) {
TimerTask newTask = new TimerTask() {
private int remaining = blinks * 2;
@Override
public void run() {
if (remaining-- > 0)
window.setVisible(!window.isVisible());
else {
window.setVisible(true);
cancel();
}
}
@Override
public boolean cancel() {
flashing.remove(this);
return super.cancel();
}
};
TimerTask oldTask = flashing.put(window, newTask);
// if the window is already flashing, cancel the old task
if (oldTask != null)
oldTask.cancel();
timer.schedule(newTask, 0, period);
}
}
|
@Mark: Minor detail: `sizeof` gives you the size in chars, not bytes, so if you happen to be on a platform where a char is not the same size as a byte, you are subtly wrong :)
Also, it is worth noting that `sizeof` doesn't help if you are dealing with a pointer to an array:
int a[10];
int* p = a;
assert(sizeof(a) / sizeof(a[0]) == 10);
assert(sizeof(p) == sizeof(void*));
@Skizz: I am pretty sure you are wrong, although the best "source" I can give you at the moment is Wikipedia, from [the article on `sizeof`](http://en.wikipedia.org/wiki/Sizeof):
> `sizeof` is a compile-time operator that returns the size, in multiples of the size of `char`, of the variable or parenthesized type-specifier that it precedes. The size of `char` on most architectures is 1 byte (8 bits) so for all practical purposes `sizeof` effectively returns the size in bytes
(Additionally, of course, one byte need not be eight bits) |
@Mark: Minor detail: `sizeof` gives you the size in chars, not bytes, so if you happen to be on a platform where a char is not the same size as a byte, you are subtly wrong :)
Also, it is worth noting that `sizeof` doesn't help if you are dealing with a pointer to an array:
int a[10];
int* p = a;
assert(sizeof(a) / sizeof(a[0]) == 10);
assert(sizeof(p) == sizeof(void*));
@Skizz: I am pretty sure I am right, although the best "source" I can give you at the moment is Wikipedia, from [the article on `sizeof`](http://en.wikipedia.org/wiki/Sizeof):
> `sizeof` is a compile-time operator that returns the size, in multiples of the size of `char`, of the variable or parenthesized type-specifier that it precedes. The size of `char` on most architectures is 1 byte (8 bits) so for all practical purposes `sizeof` effectively returns the size in bytes
(Additionally, of course, one byte need not be eight bits) |
It is worth noting that `sizeof` doesn't help if you are dealing with a pointer to an array:
int a[10];
int* p = a;
assert(sizeof(a) / sizeof(a[0]) == 10);
assert(sizeof(p) == sizeof(void*));
---
@Skizz: The standard wins over Wikipedia any day of the week :)
@DrPizza: Wikipedia does not contradict that `sizeof(char)` is 1. In fact the article *defines* that `sizeof(char)` is 1 by saying that `sizeof` is relative to the size of char. (Note the difference between the "size of char" and "`sizeof(char)`" :)
So, while `sizeof(char) == 1`, that does not necessarily imply that a char occupies exactly one byte in memory. (But the standard apparently says so explicitly, so we're good) |
Untested, but it'll be something like this:
var matches = from o in objList
join i in intList on o.ID equals i.ID
select o;
|
Untested, but it'll be something like this:
var matches = from o in objList
join i in intList on o.ID equals i
select o;
@Konrad just tested it, and it does work - I just had a typo where I'd written "i.ID" rather than "i". |
MSMQ monitoring |