|
 I played around and did a realy dirty and probably inefficent solution for the problem (SHA256 was additionally added to XML):
using (var reader = new XmlTextReader(@"c:\Users\andre\Documents\Test3.xml"))
{
List<string> myDir = new List<string>();
bool isFile = false;
bool isFileName = false;
bool isSHA = false;
bool isLength = false;
string curFile = "";
string curLength = "";
string curSHA = "";
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.XmlDeclaration:
break;
case XmlNodeType.Element:
if (reader.Name.ToString().Equals("Dir",StringComparison.OrdinalIgnoreCase))
{
myDir.Add(reader.GetAttribute("Name"));
isFile = false;
}
else if (reader.Name.ToString().Equals("File", StringComparison.OrdinalIgnoreCase))
{
isFile = true;
}
else if (reader.Name.ToString().Equals("Name", StringComparison.OrdinalIgnoreCase))
{
if (isFile)
{
isFileName = true;
}
else
{
Console.WriteLine("error on Line {0} Name <{1}> Value{2}",reader.LineNumber,reader.Name,reader.Value);
}
}
else if (reader.Name.ToString().Equals("Length", StringComparison.OrdinalIgnoreCase))
{
if (isFile)
{
isLength = true;
}
else
{
Console.WriteLine("error on Line {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
}
}
else if (reader.Name.ToString().Equals("SHA256", StringComparison.OrdinalIgnoreCase))
{
if (isFile)
{
isSHA = true;
}
else
{
Console.WriteLine("error on Line {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
}
}
else
{
Console.WriteLine("Unknown Element {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
}
break;
case XmlNodeType.Text:
if (isFileName)
{
curFile = reader.Value;
}
else if (isSHA){
curSHA = reader.Value;
}
else if (isLength)
{
curLength = reader.Value;
}
else
{
Console.WriteLine("Unknown Text Line {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
}
break;
case XmlNodeType.EndElement:
if (reader.Name.ToString().Equals("dir", StringComparison.OrdinalIgnoreCase))
{
myDir.Remove(myDir.Last());
isFile = false;
}
else if (reader.Name.ToString().Equals("File", StringComparison.OrdinalIgnoreCase))
{
isFile = false;
Console.WriteLine("Path: {0}",string.Join("\\", myDir.ToArray()));
if (!curSHA.Equals("")) {
Console.WriteLine(" File: {0} Length: {1} SHA256: {2}",curFile,curLength,curSHA);
}
else
{
Console.WriteLine(" File: {0} Length: {1}", curFile, curLength);
}
}
else if (reader.Name.ToString().Equals("Length", StringComparison.OrdinalIgnoreCase))
{
isLength = false;
}
else if (reader.Name.ToString().Equals("SHA256", StringComparison.OrdinalIgnoreCase))
{
isSHA = false;
}
else if (reader.Name.ToString().Equals("Name", StringComparison.OrdinalIgnoreCase))
{
isFileName = false;
}
else {
Console.WriteLine("Unknown End element {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
}
break;
}
}
}
(Note: string.Join()-Line destroys coloring)
Even it is not nice as it's not mucht better than just textparsing and manual decoding the XML , it works:
Path: Tmp\ConsoleApplication1\bin\Debug
File: ConsoleApplication1.exe Length: 4608
Path: Tmp\ConsoleApplication1\bin\Debug
File: ConsoleApplication1.pdb Length: 11776
Path: Tmp\ConsoleApplication1\bin\Debug
File: ConsoleApplication1.vshost.exe Length: 9568
Path: Tmp\ConsoleApplication1\bin\Debug
File: ConsoleApplication1.vshost.exe.manifest Length: 473
Path: Tmp\ConsoleApplication1\obj\Debug\TempPE
File: ConsoleApplication1.csproj.FileListAbsolute.txt Length: 322
Path: Tmp\ConsoleApplication1\obj\Debug\TempPE
File: ConsoleApplication1.exe Length: 4608
Path: Tmp\ConsoleApplication1\obj\Debug\TempPE
File: ConsoleApplication1.pdb Length: 11776
Path: Tmp\ConsoleApplication1\obj\Properties
File: AssemblyInfo.cs Length: 1454
Path: Tmp\ConsoleApplication1\obj
File: ConsoleApplication1.csproj Length: 2546
Path: Tmp\ConsoleApplication1\obj
File: ConsoleApplication1.sln Length: 937
Path: Tmp\ConsoleApplication1\obj
File: ConsoleApplication1.suo Length: 10752
Path: Tmp\ConsoleApplication1\obj
File: Program.cs Length: 269
If anyone has a better solution: youre welcome!!!
I'm still serious if theres not a easyser solution to revert back this (my current test) 1-Liner:
return new XElement("Dir",
new XAttribute("Name", di.Name),
from d in Directory.GetDirectories(source)
select CreateFileSystemXmlTree(d, progress),
from fi in di.GetFiles()
let myProgress = DoProgress(progress)
select new XElement("File",
new XElement("Name", fi.Name),
new XElement("Length", fi.Length),
new XElement("SHA256", GetChecksumBuffered(fi.FullName))
)
);
|
|
|
|
|
Member 2443306 wrote: myDir.Remove(myDir.Last());
myDir.RemoveAt(myDir.Count - 1); would be more efficient, and avoid a bug if multiple directories in the path have the same name (eg: Tmp\Path\Tmp\... ).
Better yet, replace the List<T> with Stack<T>[^], which is specifically designed for this type of scenario.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Aiks!!!
Thanks I overseen the problem with
myDir.Remove() against
myDir.RemoveAt(myDir.Count-1) .
I changed it to
Stack<T> but not realy see a advabntage.
|
|
|
|
|
|
Why not ask on the forum at the end of article? It's highly unlikely that the author is going to happen on this post?
This space for rent
|
|
|
|
|
The article was deleted in March 2015.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
No. If you look at the non-archived version[^], you'll see that the article was deleted in March 2015, and the source code was removed at the request of Mladen's employers.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
We got hit with that windows 10 upgrade today on 1/2 the computers.
So I wrote a console app to apply a tweak to Win 7 to stop the upgrades.
When I go to delete the folder with the disk image of Win10, I get an error saying this is a special file. How can I skip the error?
This is my first console app, and I'm new to c#
public static bool delete_win10Source(string winPath)
{
bool pValue = false;
try
{
DirectoryInfo dir = new DirectoryInfo(@winPath);
bool rV = dir.Exists;
if (rV)
Task.Factory.StartNew(path => dir.Delete(true), winPath);
pValue = true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
pValue = false;
}
return pValue;
}
|
|
|
|
|
Is it "speacial or just write protected?
I'm not shure but maybe something like this?
var directory = new DirectoryInfo(@winPath);
directory.Attributes &= ~FileAttributes.ReadOnly;
|
|
|
|
|
I need to run the program on a win7 machine again to see the message. I have a win8.1 machine.
Give me a day to do this, time to go home.
|
|
|
|
|
Guess my idea to just write a program to disable win10 upgrades was not a good idea.
Just FYI, the 2nd key is what the group policy does from what I read.
I can't access the LocalMachine Key, I just get a null back.
I did the click run as administrator.
Logged in as administrator.
I really don't want to manually adjust every computer in the office.
Guess Microsoft really tightened up the security which is good.
public static bool tweak_registry()
{
bool pValue = false;
const string subKey1 = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\OSUpgrade";
const string keyName1 = "AllowOSUpgrade";
const string keyName2 = "DisableOSUpgrade";
try
{
using (var _key = Registry.LocalMachine.OpenSubKey(subKey1, true))
{
_key.SetValue(keyName1, 0, RegistryValueKind.DWord);
_key.SetValue(keyName2, 1, RegistryValueKind.DWord);
}
pValue = true;
}
catch (Exception ex)
{
pValue = false;
if (ex.Message == "Attempted to perform an unauthorized operation.")
{
Console.WriteLine("");
Console.WriteLine("You must be an adminsitrator to perform this task!");
Console.WriteLine("Right Click on the program and select 'Run as Administrator'");
Console.WriteLine("Press any key to exit");
Console.ReadKey();
System.Environment.Exit(-1);
}
else
{
Console.WriteLine("ERROR: " + ex.Message);
Console.ReadKey();
}
}
return pValue;
}
|
|
|
|
|
Visual Studio? You have "AnyCPU as target?
As far as I know to access the registry with "AnyCPU" you need to take care of 32 and 64bit on the SOFTWARE key.
|
|
|
|
|
I just ran into that with running dsim, seems there's 2 of them.
I'll look into that!
Thanks
|
|
|
|
|
I didn't know that Any CPU had 2 different views of the registry, and calling programs like DSIM.
So I got that part working now for file execution and registry, but even elevating the UAC didn't allow me to edit that value and add a key.
Thanks for pointing that out to me!
|
|
|
|
|
Well I got 80% of what I wanted. Deployed it today on 14 machines. Just took 30 minutes.
The console program was a good experience for me. At least removing the updates was easy.
|
|
|
|
|
|
can I kowth the way to make slide panel dotnetbar tutorial c#
sliding pannel effects.... 
|
|
|
|
|
What's a dotnetbar?
This space for rent
|
|
|
|
|
An Internet Cafe in Yorkshire?
(Do T'Net Bar)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
I'm trying to work out why here, but I am stuck and also have no GoogleFu luck on Friday
I have a datagridview which I attach a combo box to a specific cell with the following code.
private void dg_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
DataGridView dg = sender as DataGridView;
DataGridViewComboBoxColumn combo = dg.Columns[0] as DataGridViewComboBoxColumn;
LogManager.Instance.Logger("Policy SI").Info("Edit Control Showing");
if (dg.CurrentCellAddress.X == combo.DisplayIndex)
{
LogManager.Instance.Logger("Policy SI").Info("We have a combo");
cb = e.Control as ComboBox;
if (cb != null)
{
cb.SelectedIndexChanged -= new EventHandler(cb_SelectedIndexChanged);
cb.DropDownStyle = ComboBoxStyle.DropDown;
cb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);
}
}
}
the SelectedIndexChanged event takes a copy of the selected value's text.
private void cb_SelectedIndexChanged(object sender, EventArgs e)
{
originalDescription = cb.Text;
}
This works great, for all the grids that the edit control showing event is subscribed too, but while tracing another problem I have noticed that when I am getting the row out of the combo box's datasource which is a bindinglist and reading the information to pass back to the database. with the following simplified event below. Each property that I read then fires the selected index event of the combobox.
private void dg_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
DataGridView dgB = sender as DataGridView;
if (dgB.CurrentRow.IsNewRow == true)
{
LogManager.Instance.Logger("Policy SI").Info("New Row ");
return;
}
if (e.ColumnIndex == 0)
{
LogManager.Instance.Logger("Policy SI").Info("Validating Col 1");
string newDescription = string.Empty;
newDescription = e.FormattedValue.ToString();
quoteTemplate = valuablesBinding.FirstOrDefault(p => p.Description == originalDescription || p.Description == policySumInsured.Description);
policySumInsured.ItemNo = (int)quoteTemplate.ItemNo;
policySumInsured.Description = quoteTemplate.Description;
policySumInsured.Section = quoteTemplate.Section;
}
else
{
if (e.ColumnIndex == 1)
{
}
}
}
Hopefully this all makes and sense and someone could possibley shed some light on why it keeps firing the cb_selectedIndexChanged event.
Thanks
Simon
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Maybe (probably) the following Setters
Simon_Whale wrote: policySumInsured.ItemNo = (int)quoteTemplate.ItemNo;
policySumInsured.Description = quoteTemplate.Description;
policySumInsured.Section = quoteTemplate.Section;
cause INotifyPropertyChanged to be called, and (depending on the chain of events that are raised afterwards) this affects your binding list and/or cb.SelectedIndexChanged.
...just a guess...
|
|
|
|
|
Hello Fellow Coders
I need your assistance on how I can copy files from one of our servers on the network to folders on two other servers on the same network.
Please provide sample code if possible
|
|
|
|
|