NFe.Settings.Empresas.CreateLockFile C# (CSharp) Method

CreateLockFile() public static method

Cria os arquivos de lock para os diretórios de envio que esta instância vai atender. Se verdadeiro, irá excluir os arquivos existentes antes de recriar
public static CreateLockFile ( bool clearIfExist = false ) : void
clearIfExist bool
return void
        public static void CreateLockFile(bool clearIfExist = false)
        {
            if (Empresas.Configuracoes == null || Empresas.Configuracoes.Count == 0) return;

            if (clearIfExist) ClearLockFiles(false);

            IEnumerable<string> diretorios = (from d in Empresas.Configuracoes
                                              select d.PastaBase);

            foreach (string dir in diretorios)
            {
                if (!string.IsNullOrEmpty(dir) && Directory.Exists(dir))
                {
                    string file = String.Format("{0}\\{1}-{2}.lock", dir, Propriedade.NomeAplicacao, Environment.MachineName);
                    FileInfo fi = new FileInfo(file);

                    using (StreamWriter sw = new StreamWriter(file, false)
                    {
                        AutoFlush = true
                    })
                    {
                        sw.WriteLine("Iniciado em: {0:dd/MM/yyyy hh:mm:ss}", DateTime.Now);
                        sw.WriteLine("Estação: {0}", Environment.MachineName);
                        sw.WriteLine("IP: {0}", Functions.GetIPAddress());
                        sw.Flush();
                        sw.Close();
                    }
                }
            }
        }