本文整理汇总了C#中System.IO.FileInfo.Refresh方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileInfo.Refresh方法的具体用法?C# System.IO.FileInfo.Refresh怎么用?C# System.IO.FileInfo.Refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo
的用法示例。
在下文中一共展示了System.IO.FileInfo.Refresh方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareOutputFileForCompilation
private static void PrepareOutputFileForCompilation(string sourceFile, string outputFile, string emptyFileConents)
{
// create a temporary file if it doesnt already exist so we can add to project etc if needed
if (!System.IO.File.Exists(outputFile))
System.IO.File.WriteAllText(outputFile, emptyFileConents);
// ensure output file is in our project
TsWspHelpers.AddOutputFileToSourceFilesProject(sourceFile, outputFile);
// check it ouf if needed
// (this doesnt work for Sourcegear Vault....)
if (!TsWspHelpers.CheckOutFileFromSourceControl(outputFile))
{
//abort on failed checkout
throw new ApplicationException("Failed to check out file " + outputFile);
}
// make non read only if permitted
System.IO.FileInfo fi = new System.IO.FileInfo(outputFile);
if (fi.Exists == true && fi.IsReadOnly)
{
if (TsWspSettings.Instance.OverwriteReadonly == true)
TsWspHelpers.EnsureNotReadonly(outputFile);
fi.Refresh();
if (fi.IsReadOnly)
{
string msg = $"TsWspCompilation\r\nWill not be able to write file {outputFile}\r\nfrom source {sourceFile}\r\n{outputFile} is read only";
throw new ApplicationException(msg);
}
}
}
示例2: DumpBody
/// <summary>
/// Dumps the body of this entity into a file
/// </summary>
/// <param name="path">path of the destination folder</param>
/// <param name="name">name of the file</param>
/// <returns><see cref="System.IO.FileInfo" /> that represents the file where the body has been saved</returns>
public System.IO.FileInfo DumpBody( System.String path, System.String name )
{
System.IO.FileInfo file = null;
if ( name!=null ) {
#if LOG
if ( log.IsDebugEnabled )
log.Debug ("Found attachment: " + name);
#endif
name = System.IO.Path.GetFileName(name);
// Dump file contents
try {
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo ( path );
dir.Create();
try {
file = new System.IO.FileInfo (System.IO.Path.Combine (path, name) );
} catch ( System.ArgumentException ) {
file = null;
#if LOG
if ( log.IsErrorEnabled )
log.Error(System.String.Concat("Filename [", System.IO.Path.Combine (path, name), "] is not allowed by the filesystem"));
#endif
}
if ( file!=null && dir.Exists ) {
if ( dir.FullName.Equals (new System.IO.DirectoryInfo (file.Directory.FullName).FullName) ) {
if ( !file.Exists ) {
#if LOG
if ( log.IsDebugEnabled )
log.Debug (System.String.Concat("Saving attachment [", file.FullName, "] ..."));
#endif
System.IO.Stream stream = null;
try {
stream = file.Create();
#if LOG
} catch ( System.Exception e ) {
if ( log.IsErrorEnabled )
log.Error(System.String.Concat("Error creating file [", file.FullName, "]"), e);
#else
} catch ( System.Exception ) {
#endif
}
bool error = !this.DumpBody (stream);
if ( stream!=null )
stream.Close();
stream = null;
if ( error ) {
#if LOG
if ( log.IsErrorEnabled )
log.Error (System.String.Concat("Error writting file [", file.FullName, "] to disk"));
#endif
if ( stream!=null )
file.Delete();
} else {
#if LOG
if ( log.IsDebugEnabled )
log.Debug (System.String.Concat("Attachment saved [", file.FullName, "]"));
#endif
// The file should be there
file.Refresh();
// Set file dates
if ( this.Header.ContentDispositionParameters.ContainsKey("creation-date") )
file.CreationTime = anmar.SharpMimeTools.SharpMimeTools.parseDate ( this.Header.ContentDispositionParameters["creation-date"] );
if ( this.Header.ContentDispositionParameters.ContainsKey("modification-date") )
file.LastWriteTime = anmar.SharpMimeTools.SharpMimeTools.parseDate ( this.Header.ContentDispositionParameters["modification-date"] );
if ( this.Header.ContentDispositionParameters.ContainsKey("read-date") )
file.LastAccessTime = anmar.SharpMimeTools.SharpMimeTools.parseDate ( this.Header.ContentDispositionParameters["read-date"] );
}
#if LOG
} else if ( log.IsDebugEnabled ) {
log.Debug("File already exists, skipping.");
#endif
}
#if LOG
} else if ( log.IsDebugEnabled ) {
log.Debug(System.String.Concat ("Folder name mistmatch. [", dir.FullName, "]<>[", new System.IO.DirectoryInfo (file.Directory.FullName).FullName, "]"));
#endif
}
#if LOG
} else if ( file!=null && log.IsErrorEnabled ) {
log.Error ("Destination folder does not exists.");
#endif
}
dir = null;
#if LOG
} catch ( System.Exception e ) {
if ( log.IsErrorEnabled )
log.Error ("Error writting to disk: " + name, e);
#else
} catch ( System.Exception ) {
#endif
try {
if ( file!=null ) {
file.Refresh();
if ( file.Exists )
file.Delete ();
//.........这里部分代码省略.........
示例3: CheckDbFile
private string CheckDbFile(ref bool noerrors, string fileDB, out DateTime dtDB)
{
//TimeSpan ts = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
dtDB = DateTime.Now;
System.IO.FileInfo fi = new System.IO.FileInfo(fileDB);
fi.Refresh();
if (fi.Exists && fi.Length > 0)
{
dtDB = fi.LastWriteTime.AddHours(_timeShift);
return string.Format("Дата файла Базы\n {0}: \n{1} \n", fileDB,
dtDB.ToString("dd.MM.yyyy HH:mm"));
}
else
{
noerrors = noerrors & false;
return string.Format("Файл Базы \n{0} \nне найден!\n", fileDB);
}
}
示例4: m_RefreshTimer_Elapsed
private void m_RefreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
if (isUpdating)
return;
isUpdating = true;
if (m_ImageUri == null)
return;
if (m_ImageUri.ToLower().StartsWith("http://"))
{
bool forceDownload = false;
if (m_SaveFilePath == null)
{
// TODO: hack, need to get the correct cache directory
m_SaveFilePath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Cache\\PictureBoxImages\\temp";
forceDownload = true;
}
System.IO.FileInfo saveFile = new System.IO.FileInfo(m_SaveFilePath);
if (saveFile.Exists)
{
try
{
Texture texture = ImageHelper.LoadTexture(m_SaveFilePath);
texture.Dispose();
}
catch
{
saveFile.Delete();
saveFile.Refresh();
}
}
if (forceDownload || !saveFile.Exists || (m_RefreshTime > 0 && saveFile.LastWriteTime.Subtract(System.DateTime.Now) > TimeSpan.FromSeconds(m_RefreshTime)))
{
//download it
try
{
WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(m_ImageUri);
webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified;
if (!saveFile.Directory.Exists)
saveFile.Directory.Create();
webDownload.DownloadFile(m_SaveFilePath);
}
catch { }
}
}
else
{
m_SaveFilePath = m_ImageUri;
}
if (m_ImageTexture != null && !m_ImageTexture.Disposed)
{
m_ImageTexture.Dispose();
m_ImageTexture = null;
}
if (!System.IO.File.Exists(m_SaveFilePath))
{
displayText = "Image Not Found";
return;
}
m_ImageTexture = ImageHelper.LoadTexture(m_SaveFilePath);
m_surfaceDescription = m_ImageTexture.GetLevelDescription(0);
int width = ClientSize.Width;
int height = ClientSize.Height;
if (ClientSize.Width == 0)
{
width = m_surfaceDescription.Width;
}
if (ClientSize.Height == 0)
{
height = m_surfaceDescription.Height;
}
if (ParentWidget is Widgets.Form && SizeParentToImage)
{
Widgets.Form parentForm = (Widgets.Form)ParentWidget;
parentForm.ClientSize = new System.Drawing.Size(width, height + parentForm.HeaderHeight);
}
else if(SizeParentToImage)
{
ParentWidget.ClientSize = new System.Drawing.Size(width, height);
}
ClientSize = new System.Drawing.Size(width, height);
m_currentImageUri = m_ImageUri;
IsLoaded = true;
//.........这里部分代码省略.........
示例5: TestFileArray
private string TestFileArray(ref bool noerrors, DateTime dtDB, string[] fileList)
{
//TimeSpan ts = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
StringBuilder sb = new StringBuilder();
foreach (string file in fileList)
{
if (System.IO.File.Exists(file))
{
System.IO.FileInfo fi = new System.IO.FileInfo(
file
);
fi.Refresh();
if (Math.Abs(fi.LastWriteTime.AddHours(_timeShift).Subtract(dtDB).Minutes) > 15)
{
sb.Append(string.Format("Файл БД\n {0}\n возможно старый!\n", file));
noerrors = noerrors & false;
}
}
else
{
noerrors = noerrors & false;
sb.Append(string.Format("Файл\n {0}\n отсутствует!\n", file));
}
}
return sb.ToString();
}
示例6: Open
/// <summary>
/// 指定されたファイルを開く
/// <para>開いた後は、メモリ上に全展開となる。</para>
/// <para>現時点ではデータ内にバイナリが入っているとエラーとなる。</para>
/// </summary>
/// <param name="fname">ファイル名</param>
public void Open(string fname)
{
if (System.IO.File.Exists(fname))
{
System.IO.FileInfo fi = new System.IO.FileInfo(fname); // ファイル情報を取得する
fi.Refresh();
long filesize = fi.Length; //ファイルのサイズを取得
this.fname = System.IO.Path.GetFileName(fname);
// ファイルを完全に読み込む
using (System.IO.StreamReader sr = new System.IO.StreamReader(fname))
{
List<string> txt = new List<string>(0);
while (sr.EndOfStream == false)
{
txt.Add(sr.ReadLine());
}
this.text = txt.ToArray();
}
}
return;
}
示例7: DumpBody
/// <summary>
/// Dumps the body of this entity into a file
/// </summary>
/// <param name="path">path of the destination folder</param>
/// <param name="name">name of the file</param>
/// <returns><see cref="System.IO.FileInfo" /> that represents the file where the body has been saved</returns>
public System.IO.FileInfo DumpBody(System.String path, System.String name)
{
System.IO.FileInfo file = null;
if (name != null)
{
name = System.IO.Path.GetFileName(name);
// Dump file contents
try
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path);
dir.Create();
try
{
file = new System.IO.FileInfo(System.IO.Path.Combine(path, name));
}
catch (System.ArgumentException exception)
{
file = null;
throw new Exception(
System.String.Concat("Filename [", System.IO.Path.Combine(path, name),"] is not allowed by the filesystem"), exception);
}
if (dir.Exists)
{
if (dir.FullName.Equals(new System.IO.DirectoryInfo(file.Directory.FullName).FullName))
{
if (!file.Exists)
{
System.IO.Stream stream;
try
{
stream = file.Create();
}
catch (System.Exception e)
{
throw new Exception(System.String.Concat("Error creating file [", file.FullName, "]"), e);
}
try
{
this.DumpBody(stream);
}
catch (Exception)
{
throw new Exception(System.String.Concat("Error writting file [", file.FullName, "] to disk"));
}
stream.Close();
// The file should be there
file.Refresh();
// Set file dates
if (this.Header.ContentDispositionParameters.ContainsKey("creation-date"))
file.CreationTime =
MimeTools.parseDate(this.Header.ContentDispositionParameters["creation-date"]);
if (this.Header.ContentDispositionParameters.ContainsKey("modification-date"))
file.LastWriteTime =
MimeTools.parseDate(this.Header.ContentDispositionParameters["modification-date"]);
if (this.Header.ContentDispositionParameters.ContainsKey("read-date"))
file.LastAccessTime =
MimeTools.parseDate(this.Header.ContentDispositionParameters["read-date"]);
}
else
{
System.Console.WriteLine("File already exists, skipping.");
}
}
}
}
catch (System.Exception)
{
if (file != null)
{
file.Refresh();
if (file.Exists)
file.Delete();
}
file = null;
}
}
return file;
}
示例8: OnTimerCallback
private void OnTimerCallback(object state)
{
if (this.InvokeRequired)
{
TimerCallback del = new TimerCallback(OnTimerCallback);
this.Invoke(del, state);
}
else
{
lock (locker)
{
try
{
updating = true;
System.IO.FileInfo fi = new System.IO.FileInfo(System.IO.Path.Combine(_startupPath, "TSDClient.ex_"));
fi.Refresh();
if (fi.Exists)
{
if (lastFileDate != fi.LastWriteTime)
{
this.listBox1.Items.Add("Файлы отличаются");
process.Refresh();
try
{
if (/*main_frm != null)//*/
process.Id != 0 &&
process.MainWindowHandle != IntPtr.Zero)
{
this.listBox1.Items.Add("Ожидание закрытия программы");
//main_frm.Close();
//process.CloseMainWindow();
process.Kill();
process.WaitForExit();
started = false;
RefreshFile();
lastFileDate = fi.LastWriteTime;
this.listBox1.Items.Add("Файл обновлен");
}
else
{
RefreshFile();
lastFileDate = fi.LastWriteTime;
this.listBox1.Items.Add("Файл обновлен");
}
}
catch (InvalidOperationException)
{
RefreshFile();
lastFileDate = fi.LastWriteTime;
this.listBox1.Items.Add("File changed");
}
}
}
}
finally
{
updating = false;
}
}
}
}
示例9: CheckForClear
public void CheckForClear()
{
try
{
lock (this)
{
if (System.IO.File.Exists(System.IO.Path.Combine(Program.StartupPath, "BTLog.txt")))
{
System.IO.FileInfo fi = new System.IO.FileInfo(System.IO.Path.Combine(Program.StartupPath, "BTLog.txt"));
fi.Refresh();
if (fi.Length > 1000000)
System.IO.File.Delete(System.IO.Path.Combine(Program.StartupPath, "BTLog.txt"));
}
}
}
catch
{ //не удалось удалить или получить информацию - ну фиг с ним
}
}