Exemplo n.º 1
0
        public static bool SaveToFile(XIMOutboundConfig config, string content)
        {
            if (config == null || content == null)
            {
                return(false);
            }

            try
            {
                string pathData  = ConfigHelper.GetFullPath(config.TargetPath + "\\" + DataFolder);
                string pathIndex = ConfigHelper.GetFullPath(config.TargetPath + "\\" + IndexFolder);
                if (!Directory.Exists(pathData))
                {
                    Directory.CreateDirectory(pathData);
                }
                if (!Directory.Exists(pathIndex))
                {
                    Directory.CreateDirectory(pathIndex);
                }

                string fileName = config.FileNamePrefix + DirectoryMonitor.GetRandomString();

                string fnData = pathData + "\\" + fileName + config.FileNameSuffix;
                Program.Log.Write("Write to file: " + fnData);
                using (StreamWriter sw = File.CreateText(fnData))
                {
                    sw.Write(content);
                }

                string fnIndex = pathIndex + "\\" + fileName + IndexFileExtension;
                Program.Log.Write("Write to file: " + fnIndex);
                using (StreamWriter sw = File.CreateText(fnIndex))
                {
                }

                return(true);
            }
            catch (Exception err)
            {
                Program.Log.Write(err);
                return(false);
            }
        }