/// <inheritdoc />
        public void StoreDecision(DecisionModel decision)
        {
            this.RemoveAllOccurences(decision);

            string titre = decision.EstSupprimée ? RemovedIndicator + decision.Titre : decision.Titre;
            var    item  = new RssItem
            {
                title       = titre,
                pubDate     = decision.Date.ToString("ddd, dd MMM yyyy HH:mm:ss"),
                description = decision.Description,
                link        = decision.Lien?.ToString(),
                guid        = new Guid {
                    isPermaLink = false, Value = decision.GetHashCode().ToString()
                }
            };

            foreach (Domaine decisionDomaine in decision.Domaines)
            {
                RssChannel channel = this.OpenOrCreateChannelForDomaine(decisionDomaine);
                channel.Add(item);

                var rss = new Rss {
                    channel = new [] { channel }
                };
                var serializer = new XmlSerializer(typeof(Rss));

                IFile file = this._feedsStorageDirectory.CreateOrReturn(FileNameForDomaine(decisionDomaine));

                using (StreamWriter writer = file.CreateWriter())
                    serializer.Serialize(writer, rss);
            }
        }
Ejemplo n.º 2
0
        private static void UpdaterComplete(object sender, RunWorkerCompletedEventArgs e)
        {
            if (_setting.UseRSS)
            {
                RssChannel channel = File.Exists(_setting.RSSFileName.Trim())
                                         ? new RssChannel(File.ReadAllText(_setting.RSSFileName.Trim(),
                                                                           Encoding.GetEncoding(1251)))
                                         : new RssChannel();
                foreach (Author author in Authors)
                {
                    channel.Add(author);
                }
                File.WriteAllText(_setting.RSSFileName.Trim(), channel.GenerateRss(_setting.RSSCount), Encoding.GetEncoding(1251));
            }

            if (!e.Cancelled)
            {
                string baloonInfo = (string)e.Result;
                if (baloonInfo != "")
                {
                    MainWindow.ShowTrayInfo(baloonInfo.Trim().Trim(new[] { ';' }));
                }
            }
            try
            {
                if (_setting.BeforeUpdater.Trim() != "")
                {
                    Process.Start(_setting.BeforeUpdater.Trim(), _setting.BeforeUpdaterParam.Trim());
                    _logger.Add(string.Format("'{0}' запущен.", Path.GetFileName(_setting.BeforeUpdater.Trim())), false);
                }
            }
            catch (Exception ex)
            {
                _logger.Add(ex.StackTrace, false, true);
                _logger.Add(ex.Message, false, true);
                _logger.Add(string.Format("Ошибка при запуске '{0}'.", _setting.BeforeUpdater.Trim()), false, true);
            }

            UpdateIntervalAndStart();
            Save();

            string[] args = Environment.GetCommandLineArgs();
            for (int i = 1; i < args.Length; i++)
            {
                if (args[i].ToLowerInvariant() == "autoclose")
                {
                    Application.Current.MainWindow.Close();
                }
            }
        }