|
Hi,
I'm trying do write a backup program in VB .NET. It needs to avoid backing up files that have already been backed up and so it compares the last write times of the source and backup files. If they are the same, the backup for the file is not performed.
If both the source file the backup file are on the local hard drive, the comparisons work correctly.
If both the source file the backup file are on a Network Attached Storage drive, the comparisons work correctly.
But if the source file is on the local hard drive and the backup file is on the Network Attached Storage drive, the comparison always says the they are different no matter what.
Code: (I'm using the CompareTo method.)
Dim SourceHasLaterDate As Int16 = SourceWriteTime.CompareTo(BackupWriteTime)
Is there any way I can get an accurate result for the third condition?
Thanks,
Mike
PS: I'm modifying the backup program written by Taner Riffit.
|
|
|
|
|
there are a couple of reasons why two DateTimes that should be equal actually can be different, here are the most important ones:
- some file systems only have a resolution of 2 seconds (long ago the date was stored in 16-bit, and the time in another 16-bit number (5-bit for the hour, 6-bit for the minutes, and 5 rather than 6 for the seconds).
- some file systems have a different way of dealing with daylight savings time (should the correction be applied dynamically, or should the corrected time be stored in the directory information?).
When I created my backup/synchronize utility years ago, I ended up comparing DateTimes with a tolerance: any pair of DateTime values that differed by -1, 0 or 1 hour give or take -2 to +2 seconds, I consider identical. And yes, that could lead to false identicals, but since I also compare file size and file name, chances are slim.
|
|
|
|
|
When I compensate for the differences in the storage devices by converting the last write date/time results to concatenated strings containing Year, Month, Day, Hour, and Second, the comparison works properly. With this approach I'm assuming that going to the second is accurate enough. You may want to use the same approach with yours.
Thanks for the explanation.
Here is my code:
Dim SourceWriteTime As DateTime = CDate(File.GetLastWriteTimeUtc(SourceFileName))
With SourceWriteTime
Test1 = .Year & "/" & .Month & "/" & .Day & "/" & .Hour & "/" & .Minute & "/" & .Second
End With
Dim BackupWriteTime As DateTime = CDate(File.GetLastWriteTimeUtc(BackupFileName))
With BackupWriteTime
Test2 = .Year & "/" & .Month & "/" & .Day & "/" & .Hour & "/" & .Minute & "/" & .Second
End With
Dim SourceHasLaterDate As Int16 = Test1.CompareTo(Test2)
If the SourceHasLaterDate > zero, I backup the file.
|
|
|
|
|
|
|
Thanks! I will move this post there.
|
|
|
|
|
Hiiiiiiii to all
Dear sir
any one can give link where to get about THREE TIER project in ASP.NET WEBSERVICES good tutorial and and also download small project THREE TIER programming in ASP.NET WEBSERVICES asap
rizvan sivally
|
|
|
|
|
- Don't repost your question in multiple places, found other one in ASP.NET forum[^]
sheemap wrote: Hiiiiiiii Can you please lift your cup from your keyboard, Why too much i there?
sheemap wrote: asap Don't use text like very urgent in your post. Questions in this site are answered by volunteers. Surely you can have answers so please wait for the responses.
sheemap wrote: any one can give link where to get about THREE TIER project in ASP.NET WEBSERVICES good tutorial Have you tried in web search?
sheemap wrote: also download small project THREE TIER programming in ASP.NET WEBSERVICES Read the previous point.
- For your information How to get an answer to your question[^]
thatraja
My Tip/Tricks My Dad had a Heart Attack on this day so don't...
All these are my opinions. Different people. different way of thinking. I am no one to judge others - Chandru
|
|
|
|
|
If Google is broken try bing
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Where can I find an exaustive guide or a well done tutorial, with/or commented examples about DATAREPEATER Control, distibuted together with Visual Basic Power Pack?
Thanks.
|
|
|
|
|
Have you tried Googling for "DataRepeater tutorial"?
|
|
|
|
|
On MSDN, off course. You can find an Introduction to the DataRepeater Control here[^]. There's a walk-through here[^], and your new homepage can be found here[^].
You're welcome. However, I didn't provide the material; the credits should go to MSDN
Bastard Programmer from Hell
|
|
|
|
|
|
Hi,
I am trying to enumerate system devices using .Net and keep receiving a null on the following code. How do I fix the problem? I saw several examples on the web, all showing similar code constructs.
try
{
clsidSystemDeviceEnum = new Guid("62BE5D10-60EB-11d0-BD3B-00A0C911CE86");
Type comType = Type.GetTypeFromCLSID(clsidSystemDeviceEnum);
object oEnum;
oEnum = null;
oEnum = Activator.CreateInstance(comType);
pSysDevEnum = oEnum as ICreateDevEnum;
if (null != pSysDevEnum)
pSysDevEnum.CreateClassEnumerator(clsidDeviceClass, out ppEnumMoniker, dwFlags);
else
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK);
}
Thanks in advance,
Sarah
|
|
|
|
|
Which line throws the NullReferenceException?
|
|
|
|
|
Hi,
Thank you for the response. Here is a better description of the problem. To answer your specific question, oEnum, the Activator.CreateInstance call.
I am trying to enumerate system devices using .Net. The problem that I have is that Activator.CreateInstance returns null, even though I pass in a valid System Device Enumeration GUIID class. You can search the registry and find it.
The result of Type.GetTypeFromCLSID(clsidSystemDeviceEnum, true) copy and pasted from the debugger window holding the oEnum variable is:
{Name = "__ComObject" FullName = "System.__ComObject"}
A Google search yielded a couple of hits that showed that Activator.CreateInstance will sometimes return a null when the type is "__ComObject" but the hits never went deeper. Several articles talk about device enumeration and all gave the same code, namely to start by enumerating the System Device Enumeration object.
You can see the code below. Please ignore the clsidDeviceClass. That is not relevant in the code below. That is used below in the part of the code not visible (in the etc., etc., etc. part). That variable will hold the SCSI Storage object, which is one of the system devices. Just to be specific, this variable will have the value, clsidDeviceClass = new Guid("2ACCFE60-C130-11D2-B082-00A0C91EFB8B");.
First thing is first and that is to resolve why I receive a null from the call to Activator.CreateInstance and of course how I can resolve the problem so that I get a valid object back.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Runtime.InteropServices.ComTypes;
using System.Collections;
public void CreateClassEnumerator([In] System.Guid clsidDeviceClass, [Out] out System.Runtime.InteropServices.ComTypes.IEnumMoniker ppEnumMoniker, [In] uint dwFlags)
{
Guid clsidSystemDeviceEnum;
ppEnumMoniker = null;
try
{
clsidSystemDeviceEnum = new Guid("62BE5D10-60EB-11d0-BD3B-00A0C911CE86");
Type comType = Type.GetTypeFromCLSID(clsidSystemDeviceEnum, true);
object oEnum;
oEnum = Activator.CreateInstance(comType);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK);
}
}
Thanks,
Sarah
|
|
|
|
|
I just created a console project with your code and it did not return a null. Did you ensure that the C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\uuids.h files exists as mentioned in the comments? Could be a missing COM interface.
|
|
|
|
|
Hi,
Thanks for the super quick response.
The header file is for informational purposes only and is not needed for compilation. I merely lifted the definition of the System Device Enumeration GUIID from that file. I figure that whomever wants to look at the code in the future should know where I got that GUIID from. Also, C# does not support header files, so...
I am glad that the code works on your end and that Activator.CreateInstance does not return a null on your end. My thought is that either the version of Visual Studio, OS version, or some other difference.
I use Microsoft Windows 7 Professional, 64-bit and Visual Studio 2010.
It might be a Visual Studio 2010 thing. I know that Microsoft ditched DirectShow from Visual Studio 2010, not that I am using DirectShow or need to, so might not be related, but mention. The reason the thought crossed my head is only because Direct<whatever> touches hardware in some form or fashion and that System Device Enumeration also touches hardware, although I am creating a COM object instance at this point in the code, so Activator.CreateInstance should return something other than null.
Thanks in advance,
Sarah
|
|
|
|
|
Yes, of course, C# doesn't need the header file to compile. But a missing header file can signal a missing COM component in the system. I use Win XP with Visual Studio 2010. And since you mentioned that you could in fact find the GUID in the registry, I was wondering what else could be wrong. Let me try with a Win 7 system.
|
|
|
|
|
I did a search to find the GUIID. I never even heard of that file before a search turned it up. As far as missing stuff, to my knowledge I have everything. I even installed a couple of days ago the latest Microsoft Windows SDK (v7.1) on my system.
Thanks for helping out Shameel!
|
|
|
|
|
I just tested it out in Windows 7 (32-bit) and Visual Studio 2010 and I got an object (Not null). Do you by any chance use 64-bit Win 7?
|
|
|
|
|
Yes, I run Widows 7, 64-bit.
|
|
|
|
|
As an alternative, you can try using WMI to enumerate system devices. This[^] article can get you started.
|
|
|
|
|
Thanks! I will take a look at the code.
I was hoping that .Net would behave a bit better on 64-bit (Win7). I guess Microsoft still has some bugs in their COM libraries (or would that be a .Net issue?). If a COM issue, that too is a bit surprising, as both 64-bit and COM has been around for some time. Even Adobe supports Flash on for 64-bit Windows. One would think that Microsoft would support true / full 64-bit COM, but I guess not.
|
|
|
|
|
COM Interop with 64-bit has always been a problem. This[^] post contains information about enumerating Sound devices, I think that is what you are looking for.
|
|
|
|