永发信息网

需要调用什么命名空间才可以应用Encoding

答案:1  悬赏:10  手机版
解决时间 2021-01-26 14:12
需要调用什么命名空间才可以应用Encoding
最佳答案
.net framework自有类里边没有包含UpdatePassInfo这个方法,如果你做的项目是涉及到重写硬盘,彻底删除某文件的话,那么你说的UpdatePassInfo或许就是下边这段代码里的那个。代码里UpdatePassInfo只是代表某个事件的私有调用。其实和程序本身意图无关,只是通知调用者事件触发而已。
using System;
using System.IO;
using System.Security.Cryptography;

namespace SharpWipe
{
class Wipe
{
///
/// Deletes a file in a secure way by overwriting it with
/// random garbage data n times.
///

/// Full path of the file to be deleted
/// Specifies the number of times the file should be overwritten
public void WipeFile(string filename, int timesToWrite)
{
try
{
if (File.Exists(filename))
{
// Set the files attributes to normal in case it's read-only.
File.SetAttributes(filename, FileAttributes.Normal);

// Calculate the total number of sectors in the file.
double sectors = Math.Ceiling(new FileInfo(filename).Length/512.0);

// Create a dummy-buffer the size of a sector.
byte[] dummyBuffer = new byte[512];

// Create a cryptographic Random Number Generator.
// This is what I use to create the garbage data.
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

// Open a FileStream to the file.
FileStream inputStream = new FileStream(filename, FileMode.Open);
for (int currentPass = 0; currentPass < timesToWrite; currentPass++)
{
UpdatePassInfo(currentPass + 1, timesToWrite);

// Go to the beginning of the stream
inputStream.Position = 0;

// Loop all sectors
for (int sectorsWritten = 0; sectorsWritten < sectors; sectorsWritten++)
{
UpdateSectorInfo(sectorsWritten + 1, (int) sectors);

// Fill the dummy-buffer with random data
rng.GetBytes(dummyBuffer);
// Write it to the stream
inputStream.Write(dummyBuffer, 0, dummyBuffer.Length);
}
}
// Truncate the file to 0 bytes.
// This will hide the original file-length if you try to recover the file.
inputStream.SetLength(0);
// Close the stream.
inputStream.Close();

// As an extra precaution I change the dates of the file so the
// original dates are hidden if you try to recover the file.
DateTime dt = new DateTime(2037, 1, 1, 0, 0, 0);
File.SetCreationTime(filename, dt);
File.SetLastAccessTime(filename, dt);
File.SetLastWriteTime(filename, dt);

File.SetCreationTimeUtc(filename, dt);
File.SetLastAccessTimeUtc(filename, dt);
File.SetLastWriteTimeUtc(filename, dt);

// Finally, delete the file
File.Delete(filename);

WipeDone();
}
}
catch(Exception e)
{
WipeError(e);
}
}

# region Events
public event PassInfoEventHandler PassInfoEvent;
private void UpdatePassInfo(int currentPass, int totalPasses)
{
PassInfoEvent(new PassInfoEventArgs(currentPass, totalPasses));
}

public event SectorInfoEventHandler SectorInfoEvent;
private void UpdateSectorInfo(int currentSector, int totalSectors)
{
SectorInfoEvent(new SectorInfoEventArgs(currentSector, totalSectors));
}

public event WipeDoneEventHandler WipeDoneEvent;
private void WipeDone()
{
WipeDoneEvent(new WipeDoneEventArgs());
}

public event WipeErrorEventHandler WipeErrorEvent;
private void WipeError(Exception e)
{
WipeErrorEvent(new WipeErrorEventArgs(e));
}
# endregion
}

# region Events
# region PassInfo
public delegate void PassInfoEventHandler(PassInfoEventArgs e);
public class PassInfoEventArgs : EventArgs
{
private readonly int cPass;
private readonly int tPass;

public PassInfoEventArgs(int currentPass, int totalPasses)
{
cPass = currentPass;
tPass = totalPasses;
}

/// Get the current pass
public int CurrentPass { get { return cPass; } }
/// Get the total number of passes to be run
public int TotalPasses { get { return tPass; } }
}
# endregion

# region SectorInfo
public delegate void SectorInfoEventHandler(SectorInfoEventArgs e);
public class SectorInfoEventArgs : EventArgs
{
private readonly int cSector;
private readonly int tSectors;

public SectorInfoEventArgs(int currentSector, int totalSectors)
{
cSector = currentSector;
tSectors = totalSectors;
}

/// Get the current sector
public int CurrentSector { get { return cSector; } }
/// Get the total number of sectors to be run
public int TotalSectors { get { return tSectors; } }
}
# endregion

# region WipeDone
public delegate void WipeDoneEventHandler(WipeDoneEventArgs e);
public class WipeDoneEventArgs : EventArgs
{
}
# endregion

# region WipeError
public delegate void WipeErrorEventHandler(WipeErrorEventArgs e);
public class WipeErrorEventArgs : EventArgs
{
private readonly Exception e;

public WipeErrorEventArgs(Exception error)
{
e = error;
}

public Exception WipeError{get{ return e;}}
}
# endregion
# endregion
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
女子美容院地址好找么,我有些事要过去
昨晚做梦邻居掉河里被我救了
根据所给提示,写出相对应的历史知识。(1)
我家的机顶盒坏了,修电视那能修吗?
现在买什麼手机最好?
成语明效大验的意思是什么啊?有知道释义的请
Greece today is a small country in southea
钻戒1.02克H色SI13EX怎么样
vivo 手机的充电器头子可以用oppo 手机充电器
兰州大学汉语言文学怎么样
红土坡镇派出所怎么去啊,我要去那办事
容园美美容工作室地址在什么地方,想过去办事
植食动物、肉食动物、杂食动物在生物圈中充当
成语摩拳擦掌的意思是什么啊?有知道释义的请
求哈利波特7部电影百度云资源,谢谢!
推荐资讯
平板型晶闸管的使用
dnf未完成的臂铠和英雄的荣誉那个好
我叫钟家健,请问一下有什么英文名字适合我
艾灸后月经一直不干净,已经超过天了,怎么办
大连到宽甸的客车有几点的
请问我之前有三次酒驾。现在是第四次而且是醉
简述蒙特威尔第与“两种常规”的思想?
五年级同学栽树90棵,活了87棵.没有活的棵数是
一般纳税人发生的下列应税行为中,可以选择适
云维集团怎么样?
贾静雯与前夫孙志浩离婚原因是什么
属马的女生和属羊的男生配吗?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?