Exemplo n.º 1
0
        /// <summary>Loads informations about all RSS targets.</summary>
        /// <returns>Array of the RSS Informations.</returns>
        static public ArrayList Load()
        {
            if (!Directory.Exists(Anguista.Lib.Def.INFO_ROOT_DIR))
            {
                return(null);
            }

            XmlSerializer reader = new XmlSerializer(typeof(RssTargetEntry));

            ArrayList ret = new ArrayList();

            foreach (string folder in Directory.GetDirectories(Anguista.Lib.Def.INFO_ROOT_DIR))
            {
                string filePath = Path.Combine(folder, SETTINGS_FILE_NAME);
                using (StreamReader file = new StreamReader(filePath))
                {
                    try
                    {
                        RssTargetEntry info = (RssTargetEntry)reader.Deserialize(file);
                        info._dirTitle = _DecForPath(new DirectoryInfo(folder).Name);
                        ret.Add(info);
                    }
                    catch (Exception ex)
                    {
                        Log.AddError("  " + ex.Message + " : " + filePath + "\n" + ex.StackTrace);
                    }
                }
            }

            ret.Sort();

            return(ret);
        }
Exemplo n.º 2
0
        /// <summary>Saves information about this RSS target.</summary>
        /// <returns>true if succeeded, false otherwise.</returns>
        public bool Save()
        {
            if (!Directory.Exists(Anguista.Lib.Def.INFO_ROOT_DIR))
            {
                Directory.CreateDirectory(Anguista.Lib.Def.INFO_ROOT_DIR);
            }

            if (!_UpdateTitle())
            {
                return(false);
            }

            string infoPath = this.CurPath;

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

            XmlSerializer writer = new XmlSerializer(typeof(RssTargetEntry));

            using (StreamWriter file = new StreamWriter(Path.Combine(infoPath, SETTINGS_FILE_NAME)))
            {
                RssTargetEntry entry = this.dup();
                writer.Serialize(file, entry);
            }
            return(true);
        }
Exemplo n.º 3
0
        public static RssTargetEntry[] GetRssTargetsFromUrl(string baseUrl, bool isRegexp)
        {
            RssTargetEntry targetThetisRss = null;
            RssTargetEntry targetZeptDist  = null;

            ArrayList targetEntries = Anguista.Lib.RssTargetEntry.Load();

            if (targetEntries != null)
            {
                foreach (RssTargetEntry entry in targetEntries)
                {
                    if (entry.IsZeptDist)
                    {
                        targetZeptDist = entry;
                    }
                    else
                    {
                        if (entry.Url != null &&
                            entry.Match(baseUrl, isRegexp))
                        {
                            targetThetisRss = entry;
                        }
                    }
                }

                /*
                 * If Thetis RSS not found, retry to find it
                 * by Zeptair Distribution target information.
                 */
                if (targetThetisRss == null &&
                    targetZeptDist != null &&
                    targetZeptDist.Url != null &&
                    !targetZeptDist.Match(baseUrl, isRegexp))
                {
                    Match m = Regex.Match(targetZeptDist.Url, @"^(.+[/])feeds[/]");
                    if (m.Success)
                    {
                        baseUrl = m.Groups[1].Value;
                        foreach (RssTargetEntry entry in targetEntries)
                        {
                            if (!entry.IsZeptDist &&
                                entry.Url != null &&
                                entry.Url.StartsWith(baseUrl))
                            {
                                targetThetisRss = entry;
                                break;
                            }
                        }
                    }
                }
            }
            return(new RssTargetEntry[] {
                targetThetisRss,
                targetZeptDist
            });
        }
Exemplo n.º 4
0
 public int CompareTo(object obj)
 {
     if (obj is RssTargetEntry)
     {
         RssTargetEntry other = (RssTargetEntry)obj;
         return(this.Idx.CompareTo(other.Idx));
     }
     else
     {
         throw new ArgumentException("Object is not a RssInfo");
     }
 }
Exemplo n.º 5
0
        /// <summary>Duplicates self entry.</summary>
        /// <returns>Clone instance of RssTargetEntry.</returns>
        private RssTargetEntry dup()
        {
            RssTargetEntry entry = new RssTargetEntry();

            entry.Id              = this.Id;
            entry.Url             = this.Url;
            entry.Idx             = this.Idx;
            entry.Title           = this.Title;
            entry.UserName        = this.UserName;
            entry.EncPassword     = this.EncPassword;
            entry.PollingInterval = this.PollingInterval;
            entry.IsZeptDist      = this.IsZeptDist;
            return(entry);
        }
Exemplo n.º 6
0
        public static void SynchroTargets(string oldUrl, bool isRegexp, string newUrl, bool inheritSchemeIfExit, string userName, string password, bool synThetisRss, bool synZeptDist)
        {
            if (!newUrl.EndsWith(@"/"))
            {
                newUrl += @"/";
            }

            string rightPartFromHost = null;
            Match  m = Regex.Match(newUrl, @"^[ ]*[^:]+://(.+)");

            if (m.Success)
            {
                rightPartFromHost = m.Groups[1].Value;
            }

            RssTargetEntry[] entries         = RssTargetEntry.GetRssTargetsFromUrl(oldUrl, isRegexp);
            RssTargetEntry   targetThetisRss = entries[0];
            RssTargetEntry   targetZeptDist  = entries[1];

            if (synThetisRss)
            {
                if (targetThetisRss == null)
                {
                    targetThetisRss       = new RssTargetEntry();
                    targetThetisRss.Title = Anguista.Lib.Properties.Resources.THETIS_RSS;
                }
                else if (inheritSchemeIfExit)
                {
                    try
                    {
                        newUrl = String.Format(@"{0}://{1}", new Uri(targetThetisRss.Url).Scheme, rightPartFromHost);
                    }
                    catch (Exception) { }
                }
                targetThetisRss.Url = newUrl + @"feeds/index/";
                targetThetisRss.SetAuth(userName, password);

                targetThetisRss.Save();
            }
            if (synZeptDist)
            {
                if (targetZeptDist == null)
                {
                    targetZeptDist            = new RssTargetEntry();
                    targetZeptDist.Title      = Anguista.Lib.Properties.Resources.ZEPTAIR_DISTRIBUTION;
                    targetZeptDist.IsZeptDist = true;
                }
                else if (inheritSchemeIfExit)
                {
                    try
                    {
                        newUrl = String.Format(@"{0}://{1}", new Uri(targetZeptDist.Url).Scheme, rightPartFromHost);
                    }
                    catch (Exception) { }
                }
                targetZeptDist.Url = newUrl + @"feeds/zeptair_dist/";
                targetZeptDist.SetAuth(userName, password);

                targetZeptDist.Save();
            }
            if (synThetisRss || synZeptDist)
            {
                try
                {
                    Anguista.Lib.IIpcTaskService ipcTaskService = Anguista.Lib.IpcServiceAgent.GetTaskService();
                    if (ipcTaskService != null)
                    {
                        ipcTaskService.FireEventRssTargetInfosUpdated();
                    }
                }
                catch (Exception ex)
                {
                    Log.AddError(ex.Message + "\n" + ex.StackTrace);
                }
            }
        }