コード例 #1
0
        public ActionResult DeleteXml()
        {
            try
            {
                string fileName = Request.Form["FileName"];
                if (string.IsNullOrEmpty(fileName))
                {
                    throw new Exception("Invalid file name.");
                }

                string   path = RssFeedHelper.GetFilePath(fileName);
                FileInfo info = new FileInfo(path);
                if (!info.Exists)
                {
                    throw new HttpException(404, string.Format(@"The file ""{0}"" does not exists.", fileName));
                }
                info.Delete();
                SuccessNotification(string.Format(@"The file ""{0}"" has been deleted successfully.", fileName));
            }
            catch (Exception e)
            {
                ErrorNotification(e);
            }

            return(RedirectToConfiguration());
        }
コード例 #2
0
        public ActionResult Configure(ConfigurationModel model)
        {
            DirectoryInfo info = new DirectoryInfo(RssFeedHelper.GetFilePath(""));

            Directory.CreateDirectory(info.FullName);
            model.Files = info.GetFiles("*.xml").OrderByDescending(p => p.CreationTime).ToArray();

            if (!ModelState.IsValid)
            {
                return(View("~/Plugins/AF.Nop.Plugins.RssFeed/Views/Configure.cshtml", model));
            }

            try
            {
                _rssFeedSettings.EnabledSchedule = model.EnabledSchedule;
                _rssFeedSettings.Locales.Clear();
                foreach (var m in model.Locales)
                {
                    _rssFeedSettings.Locales.Add(new RssFeedSettingLocale()
                    {
                        Title       = m.Title,
                        Link        = m.Link,
                        FileName    = m.FileName,
                        Description = m.Description,
                        LanguageId  = m.LanguageId
                    });
                }
                _rssFeedSettings.RebuildJson();

                _rssFeedSettings.EnabledSchedule = model.EnabledSchedule;
                _rssFeedSettings.TaskRunTime     = model.TaskRunTime;
                _rssFeedSettings.TaskCheckTime   = model.TaskCheckTime;

                var task = _scheduleTaskService.GetTaskById(_rssFeedSettings.TaskId);
                if (task == null)
                {
                    ErrorNotification("The schedualTaskId is corrupted. So, the plugin cannot be run in a schedule till this value is retrieved correctly.");
                }
                else
                {
                    task.Enabled = model.EnabledSchedule;
                    task.Seconds = model.TaskCheckTime;
                    _scheduleTaskService.UpdateTask(task);
                    _rssFeedSettings.TaskName = task.Name;
                }

                SuccessNotification(_localizationService.GetResource("Admin.Configuration.Updated"));
                _settingService.SaveSetting(_rssFeedSettings);
                _settingService.ClearCache();

                return(Configure());
            }
            catch (Exception ex)
            {
                ErrorNotification(ex);
                return(View("~/Plugins/AF.Nop.Plugins.RssFeed/Views/Configure.cshtml", model));
            }
        }
コード例 #3
0
ファイル: RssFeedService.cs プロジェクト: fatiheker/AF452
        public void GeneratRssFeedFiles(IList <ProductVariant> products)
        {
            try
            {
                var rssFeeds = CreateRssFeeds(products);

                var path = RssFeedHelper.GetFilePath("");
                Directory.CreateDirectory(path);

                var xmlSettings = new XmlWriterSettings();
                xmlSettings.Indent   = true;
                xmlSettings.Encoding = Encoding.UTF8;

                foreach (var local in _rssFeedSettings.Locales)
                {
                    var    fileName    = Path.Combine(path, local.FileName);
                    string fileNameAll = Path.Combine(path, Path.GetFileNameWithoutExtension(local.FileName) + "-all." + Path.GetExtension(local.FileName));

                    var tt1      = DateTime.Now.Ticks;
                    var feedsAll = rssFeeds[local.LanguageId];
                    var feedsWithoutCallForPrice = new Rss20()
                    {
                        Version = feedsAll.Version,
                        Channel = new Rss20Channel()
                        {
                            Title       = feedsAll.Channel.Title,
                            Link        = feedsAll.Channel.Link,
                            Description = feedsAll.Channel.Description,
                            Items       = feedsAll.Channel.Items.Where(x => x.CallForPrice == false).ToList(),
                        },
                    };

                    XmlSerializer serializer = new XmlSerializer(typeof(Rss20));
                    var           ns         = new XmlSerializerNamespaces();
                    ns.Add("g", RssFeedHelper.GoogleNamespce);

                    using (var stream = XmlWriter.Create(fileNameAll, xmlSettings))
                    {
                        serializer.Serialize(stream, feedsAll, ns);
                        stream.Close();
                        _logger.Information($"RssFeed: the file {fileNameAll} has been saved");
                    }
                    using (var stream = XmlWriter.Create(fileName, xmlSettings))
                    {
                        serializer.Serialize(stream, feedsWithoutCallForPrice, ns);
                        stream.Close();
                        _logger.Information($"RssFeed: the file {fileName} has been saved");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("RssFeed: error occured in generating XML files", ex);
                throw;
            }
        }
コード例 #4
0
        public ActionResult DownloadXml(string fileName)
        {
            try
            {
                string   path = RssFeedHelper.GetFilePath(fileName);
                FileInfo info = new FileInfo(path);
                if (!info.Exists)
                {
                    throw new HttpException(404, string.Format(@"The file ""{0}"" does not exists.", fileName));
                }

                return(File(path, "text/xml", fileName));
            }
            catch (Exception xp)
            {
                ErrorNotification(xp);
                return(RedirectToConfiguration());
            }
        }
コード例 #5
0
        public ActionResult Configure()
        {
            ConfigurationModel model = new ConfigurationModel();
            var defaultLanguage      = _languageService.GetAllLanguages().FirstOrDefault();

            model.TaskId          = _rssFeedSettings.TaskId;
            model.TaskName        = _rssFeedSettings.TaskName;
            model.TaskRunTime     = _rssFeedSettings.TaskRunTime;
            model.TaskCheckTime   = _rssFeedSettings.TaskCheckTime;
            model.LastRunTime     = _rssFeedSettings.LastRunTime;
            model.EnabledSchedule = _rssFeedSettings.EnabledSchedule;

            DirectoryInfo info = new DirectoryInfo(RssFeedHelper.GetFilePath(""));

            Directory.CreateDirectory(info.FullName);
            model.Files = info.GetFiles("*.xml").OrderByDescending(p => p.CreationTime).ToArray();

            _rssFeedSettings.RebuildList();
            AddLocales(_languageService, model.Locales);
            foreach (var m in model.Locales)
            {
                foreach (var s in _rssFeedSettings.Locales)
                {
                    if (m.LanguageId == s.LanguageId)
                    {
                        m.Link        = s.Link;
                        m.Title       = s.Title;
                        m.Description = s.Description;
                        m.FileName    = s.FileName;
                        break;
                    }
                }
            }

            return(View("~/Plugins/AF.Nop.Plugins.RssFeed/Views/Configure.cshtml", model));
        }