コード例 #1
0
 public FileAppender(ILayout layout, IWritableObject file) : base(layout, file)
 {
     if (!(file is IWritableFile))
     {
         throw new ArgumentException("The given WritableObject MUST Implement IWritableFile!");
     }
 }
コード例 #2
0
ファイル: FileManager.cs プロジェクト: agSant01/se-assembler
        /// <summary>
        /// Writes to a file the given text
        /// </summary>
        /// <param name="writeable">Writable object to write to file</param>
        /// <param name="filePath">Complete path to save file into. (Without filename)</param>
        /// <returns></returns>
        public bool ToWriteFile(IWritableObject writeable, string filePath)
        {
            string fullFilePath = Path.Combine(filePath, writeable.FileName);

            try
            {
                if (string.IsNullOrEmpty(fullFilePath))
                {
                    return(false);
                }

                if (!fullFilePath.Contains("."))
                {
                    return(false);
                }

                if (writeable.GetLines() == null)
                {
                    return(false);
                }

                File.WriteAllLines(fullFilePath, writeable.GetLines());

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e);
                return(false);
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates appender
        /// </summary>
        /// <param name="appenderName">The class name of the appender. It should be in the provided namespace</param>
        /// <param name="layout">The layout in which the appender should append the given data</param>
        /// <param name="writableObject">The place where the appender will place the data</param>
        /// <returns></returns>
        public IAppender GetAppender(string appenderName, ILayout layout, IWritableObject writableObject)
        {
            var appenderType = Type.GetType(this.appendersNamespace.Length == 0 ? appenderName : $"{appendersNamespace}.{appenderName}");

            var appender = Activator.CreateInstance(appenderType, layout, writableObject) as IAppender;

            return(appender);
        }
コード例 #4
0
ファイル: FileManager.cs プロジェクト: agSant01/se-assembler
        public void ToWriteFileAsync(IWritableObject writeable, string filePath)
        {
            string fullFilePath = Path.Combine(filePath, writeable.FileName);

            try
            {
                if (string.IsNullOrEmpty(fullFilePath))
                {
                    return;
                }

                if (!fullFilePath.Contains("."))
                {
                    return;
                }

                if (writeable.GetLines() == null)
                {
                    return;
                }

                File.Create(fullFilePath).Close();

                return;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e);
            }

            Task task = new Task(delegate()
            {
                while (writeable.MoveNext())
                {
                    File.AppendText(filePath).WriteLine(writeable.Current);
                }
            });

            task.Start();
        }
コード例 #5
0
 public void WriteObject(string path, IWritableObject obj)
 {
     file = new FileInfo(Path.Combine(directory.FullName, path + ".txt"));
     file.CreateText().Close();
     obj.Write(path, this);
 }
コード例 #6
0
 public ConsoleAppender(ILayout layout, IWritableObject console) : base(layout, console)
 {
 }
コード例 #7
0
ファイル: SaveManager.cs プロジェクト: ArtSerov/Coursework
 public void WriteObject(IWritableObject obj)
 {
     obj.Write(this);
 }
コード例 #8
0
ファイル: Appender.cs プロジェクト: vv-b-s/SoftUni
 protected Appender(ILayout layout, IWritableObject writableObject)
 {
     this.layout         = layout;
     this.writableObject = writableObject;
 }