Exemple #1
0
        public T Read(string fileFullName = "")
        {
            if (fileFullName == "")
            {
                fileFullName = Path.Combine(DirectoryPath, FileName);
            }
            if (Format == SerializeFormat.Binary)
            {
                BinaryFormatter bf    = new BinaryFormatter();
                byte[]          bytes = new TFile(fileFullName).ReadBytes();
                using (MemoryStream ms = new MemoryStream(bytes))
                {
                    object obj = bf.Deserialize(ms);
                    return((T)obj);
                }
            }
            else// if (Format == SerializeFormat.Xml)
            {
                XmlSerializer xs  = new XmlSerializer(typeof(T));
                string        xml = new TFile(fileFullName).ReadText();
                using (StringReader rd = new StringReader(xml))
                {
                    return((T)xs.Deserialize(rd));
                }
            }

            /*else //JSON
             * {
             *  string json = new TFile(fileFullName).ReadText();
             *  return JsonSerializer.Deserialize<T>(json);
             * }*/
        }
Exemple #2
0
        public void Write(params string[] messages)
        {
            if (Directory.Exists(DirectoryPath) && CurrentLog == null)
            {
                CurrentLog = Directory.GetFiles(DirectoryPath).Max();
                if (CurrentLog != null)
                {
                    CurrentLog = new FileInfo(CurrentLog).Name;
                }
            }

            if (CurrentLog == null)
            {
                CurrentLog = GenerateLogName();
            }

            if (Term != LoggerTerm.Last)
            {
                string     logName    = GenerateLogName();
                LoggerTerm comparison = CompareLogNames(logName, CurrentLog);
                if (Term < comparison)
                {
                    CurrentLog = GenerateLogName();
                }
            }
            LogFile = new TFile(CurrentLog, DirectoryPath);
            for (int i = 0; i < messages.Length; i++)
            {
                string prefix = DateTime.Now.ToString("dd/MM HH:mm:ss > ");
                messages[i] = prefix + messages[i];
            }
            LogFile.WriteAllLines(messages);
        }
Exemple #3
0
        public bool MoveTo(string directoryPath, string renamedFileName = "", bool overwrite = false)
        {
            if (renamedFileName == "")
            {
                renamedFileName = Info.Name;
            }
            try
            {
                File.Move(Info.FullName, String.Concat(directoryPath, renamedFileName));//, overwrite);
            }
            catch
            {
            }
            TFile copy = new TFile(renamedFileName, directoryPath);

            return(copy.Exists);
        }