Ejemplo n.º 1
0
        public FeedFileData GetFeedFileByStore(Store store, string secondFileName = null, string extension = null)
        {
            if (store == null)
            {
                return(null);
            }

            string dirTemp  = FileSystemHelper.TempDir();
            string ext      = extension ?? BaseSettings.ExportFormat;
            string dir      = Path.Combine(HttpRuntime.AppDomainAppPath, "Content\\files\\exportimport");
            string fileName = "{0}_{1}".FormatWith(store.Id, BaseSettings.StaticFileName);
            string logName  = Path.GetFileNameWithoutExtension(fileName) + ".txt";

            if (ext.HasValue())
            {
                fileName = Path.GetFileNameWithoutExtension(fileName) + (ext.StartsWith(".") ? "" : ".") + ext;
            }

            string url = "{0}content/files/exportimport/".FormatWith(store.Url.EnsureEndsWith("/"));

            if (!(url.StartsWith("http://") || url.StartsWith("https://")))
            {
                url = "http://" + url;
            }

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            var feedFile = new FeedFileData
            {
                StoreId      = store.Id,
                StoreName    = store.Name,
                FileTempPath = Path.Combine(dirTemp, fileName),
                FilePath     = Path.Combine(dir, fileName),
                FileUrl      = url + fileName,
                LogPath      = Path.Combine(dir, logName),
                LogUrl       = url + logName
            };

            try
            {
                feedFile.LastWriteTime = File.GetLastWriteTimeUtc(feedFile.FilePath).RelativeFormat(true, null);
            }
            catch (Exception)
            {
                feedFile.LastWriteTime = feedFile.LastWriteTime.NaIfEmpty();
            }

            if (secondFileName.HasValue())
            {
                string fname2 = store.Id + "_" + secondFileName;
                feedFile.CustomProperties.Add("SecondFileTempPath", Path.Combine(dirTemp, fname2));
                feedFile.CustomProperties.Add("SecondFilePath", Path.Combine(dir, fname2));
                feedFile.CustomProperties.Add("SecondFileUrl", url + fname2);
            }
            return(feedFile);
        }
Ejemplo n.º 2
0
        public FeedFileData GetFeedFileByStore(Store store, string secondFileName = null, string extension = null)
        {
            if (store == null)
                return null;

            string dirTemp = FileSystemHelper.TempDir();
            string ext = extension ?? BaseSettings.ExportFormat;
            string dir = Path.Combine(HttpRuntime.AppDomainAppPath, "Content\\files\\exportimport");
            string fileName = "{0}_{1}".FormatWith(store.Id, BaseSettings.StaticFileName);
            string logName = Path.GetFileNameWithoutExtension(fileName) + ".txt";

            if (ext.HasValue())
                fileName = Path.GetFileNameWithoutExtension(fileName) + (ext.StartsWith(".") ? "" : ".") + ext;

            string url = "{0}content/files/exportimport/".FormatWith(store.Url.EnsureEndsWith("/"));

            if (!(url.StartsWith("http://") || url.StartsWith("https://")))
                url = "http://" + url;

            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            var feedFile = new FeedFileData
            {
                StoreId = store.Id,
                StoreName = store.Name,
                FileTempPath = Path.Combine(dirTemp, fileName),
                FilePath = Path.Combine(dir, fileName),
                FileUrl = url + fileName,
                LogPath = Path.Combine(dir, logName),
                LogUrl = url + logName
            };

            try
            {
                feedFile.LastWriteTime = File.GetLastWriteTimeUtc(feedFile.FilePath).RelativeFormat(true, null);
            }
            catch (Exception)
            {
                feedFile.LastWriteTime = feedFile.LastWriteTime.NaIfEmpty();
            }

            if (secondFileName.HasValue())
            {
                string fname2 = store.Id + "_" + secondFileName;
                feedFile.CustomProperties.Add("SecondFileTempPath", Path.Combine(dirTemp, fname2));
                feedFile.CustomProperties.Add("SecondFilePath", Path.Combine(dir, fname2));
                feedFile.CustomProperties.Add("SecondFileUrl", url + fname2);
            }
            return feedFile;
        }