Esempio n. 1
0
        protected override void DoPullProperties()
        {
            DateTime start_time = ParseStartingDate(FileInfo);

            AddProperty(Beagle.Property.NewDate("fixme:starttime", start_time));

            // FIXME: We are dropping endtime in favor of performance
            // for the time being, until we can figure out how to get
            // it out of the log file more efficiently.
            //AddProperty (Beagle.Property.NewDate ("fixme:endtime", log.EndTime));

            AddProperty(Beagle.Property.NewUnsearched("fixme:client", "Pidgin"));

            string protocol = FileInfo.Directory.Parent.Parent.Name;

            AddProperty(Beagle.Property.NewUnsearched("fixme:protocol", protocol));

            // FIXME: Should the following properties use Property.NewKeyword and be searched?

            // Gaim likes to represent many characters in hex-escaped %xx form
            string speaking_to = StringFu.HexUnescape(FileInfo.Directory.Name);

            AddProperty(Beagle.Property.NewKeyword("fixme:speakingto", speaking_to));

            string identity = StringFu.HexUnescape(FileInfo.Directory.Parent.Name);

            AddProperty(Beagle.Property.NewUnsearched("fixme:identity", identity));
        }
Esempio n. 2
0
        public IMLog(Beagle.Hit hit, Beagle.Query query) : base(hit, query)
        {
            Group = TileGroup.Conversations;

            Subject.LabelProp = Catalog.GetString("IM Conversation");

            string alias = hit.GetFirstProperty("fixme:speakingto_alias");
            string name  = hit.GetFirstProperty("fixme:speakingto");

            if (alias != null && alias != "")
            {
                From.LabelProp = "<b>" + alias + "</b>";
            }
            else if (name != null && name != "")
            {
                From.LabelProp = "<b>" + name + "</b>";
            }
            else
            {
                From.LabelProp = "(unknown)";
            }

            try {
                string starttime = hit.GetFirstProperty("fixme:starttime");

                if (!String.IsNullOrEmpty(starttime))
                {
                    Timestamp = StringFu.StringToDateTime(starttime);
                }

                Date.LabelProp = Utils.NiceShortDate(Timestamp);
            } catch {}
        }
Esempio n. 3
0
        public MailMessage(Beagle.Hit hit, Beagle.Query query) : base(hit, query)
        {
            Group = TileGroup.Conversations;

            string title = Utils.GetFirstPropertyOfParent(hit, "dc:title");

            if (title == null || title == String.Empty)
            {
                title = Catalog.GetString("(untitled)");
            }
            Subject.LabelProp = Title = title;

            From.LabelProp = "<b>" + GetAddress(hit) + "</b>";
            try {
                Timestamp      = StringFu.StringToDateTime(Utils.GetFirstPropertyOfParent(hit, "fixme:date"));
                Date.LabelProp = Utils.NiceShortDate(Timestamp);
            } catch {}

            if (Utils.GetFirstPropertyOfParent(Hit, "fixme:client") == "evolution")
            {
                AddAction(new TileAction(Catalog.GetString("Send in Mail"), SendInMail));
            }
            if ((Utils.GetFirstPropertyOfParent(hit, "fixme:isSent") == null))
            {
                AddAction(new TileAction(Catalog.GetString("Find Messages From Sender"), Gtk.Stock.Find, FindAllFromSender));
            }
        }
        // FIXME: I don't really like this, the collection could be huge
        public ArrayList GetOlderThan(DateTime dt)
        {
            SqliteCommand    command;
            SqliteDataReader reader;

            lock (connection) {
                command             = new SqliteCommand();
                command.Connection  = connection;
                command.CommandText =
                    "SELECT uid FROM mapping WHERE last_seen < " +
                    StringFu.DateTimeToString(dt);

                reader = SqliteUtils.ExecuteReaderOrWait(command);

                ArrayList uids = new ArrayList();

                while (SqliteUtils.ReadOrWait(reader))
                {
                    uids.Add(reader.GetString(0));
                }

                reader.Close();
                command.Dispose();

                return(uids);
            }
        }
Esempio n. 5
0
    private static List <SnippetLine> GetSnippet(SnippetRequest request)
    {
        Queryable      queryable = QueryDriver.GetQueryable(request.Hit.Source);
        ISnippetReader snippet_reader;
        bool           full_text  = request.FullText;
        int            ctx_length = request.ContextLength;
        int            snp_length = request.SnippetLength;

        if (queryable == null)
        {
            Console.WriteLine("SnippetExecutor: No queryable object matches '{0}'", request.Hit.Source);
            snippet_reader = new SnippetReader(null, null, false, -1, -1);
            full_text      = false;
        }
        else
        {
            snippet_reader = queryable.GetSnippet(request.QueryTerms, request.Hit, full_text, ctx_length, snp_length);
        }

        List <SnippetLine> snippetlines = new List <SnippetLine> ();

        if (snippet_reader == null)
        {
            return(snippetlines);
        }

        if (!full_text)
        {
            foreach (SnippetLine snippet_line in snippet_reader.GetSnippet())
            {
                snippetlines.Add(snippet_line);
            }
        }
        else
        {
            SnippetLine snippet_line = new SnippetLine();
            snippet_line.Line = 1;

            Fragment fragment = new Fragment();
            fragment.QueryTermIndex = -1;
            StringBuilder sb = new StringBuilder();

            string line;
            // Read data from snippet_reader and write
            while ((line = snippet_reader.ReadLine()) != null)
            {
                sb.Append(StringFu.CleanupInvalidXmlCharacters(line));
                sb.Append("\n");
            }

            fragment.Text          = sb.ToString();
            snippet_line.Fragments = new ArrayList();
            snippet_line.Fragments.Add(fragment);
            snippetlines.Add(snippet_line);
        }

        snippet_reader.Close();

        return(snippetlines);
    }
Esempio n. 6
0
        private string GetPreview(ImLog log)
        {
            string preview = null;

            if (log.Utterances.Count == 0)
            {
                return(String.Empty);
            }

            foreach (ImLog.Utterance utt in log.Utterances)
            {
                string snippet    = utt.Text;
                int    word_count = StringFu.CountWords(snippet, 15);
                if (word_count > 3)
                {
                    preview = snippet;
                    break;
                }
            }

            if (preview == null)
            {
                preview = ((ImLog.Utterance)log.Utterances [0]).Text;
            }

            if (preview.Length > 50)
            {
                preview = preview.Substring(0, 50) + "...";
            }

            return(preview);
        }
Esempio n. 7
0
        // Returns the full directory path for this value, after stripping end '/' and expanding env variable
        private static string GetExcludeDirectory(string value)
        {
            if (String.IsNullOrEmpty(value))
            {
                return(null);
            }

            // Remove end '/'
            if (value != "/")
            {
                value = value.TrimEnd('/');
            }

            value = StringFu.ExpandEnvVariables(value);
            if (String.IsNullOrEmpty(value))
            {
                return(null);
            }

            value = Path.GetFullPath(value);
            if (Directory.Exists(value))
            {
                return(value);
            }

            return(null);
        }
Esempio n. 8
0
        private static string ReadKDEConfig(string kde_dir)
        {
            string kmailrc = kde_dir;

            kmailrc = Path.Combine(kmailrc, "share");
            kmailrc = Path.Combine(kmailrc, "config");
            kmailrc = Path.Combine(kmailrc, "kmailrc");

            if (!File.Exists(kmailrc))
            {
                return(null);
            }

            using (StreamReader reader = new StreamReader(kmailrc)) {
                string section = "";
                string line;

                while ((line = reader.ReadLine()) != null)
                {
                    if (line.StartsWith("[") && line.EndsWith("]"))
                    {
                        section = line;
                    }
                    if (section == "[General]")
                    {
                        if (line.StartsWith("folders=") && line.Length > 8)
                        {
                            return(StringFu.ExpandEnvVariables(line.Substring(8)));
                        }
                    }
                }
            }

            return(null);
        }
Esempio n. 9
0
        /////////////////////////////////////////////////////////////

        // Load data from configuration. Intersect deltas to the currently active excludes and
        // implement any changes upon notification.

        private void LoadConfiguration()
        {
            Config config = Conf.Get(Conf.Names.FilesQueryableConfig);

            List <string[]> values = config.GetListOptionValues(Conf.Names.ExcludeSubdirectory);

            if (values != null)
            {
                foreach (string[] value in values)
                {
                    AddExcludeDir(GetExcludeDirectory(value [0]));
                }
            }

            values = config.GetListOptionValues(Conf.Names.ExcludePattern);
            if (values != null)
            {
                foreach (string[] exclude in values)
                {
                    // RemoveQuotes from beginning and end
                    AddExcludePattern(exclude [0]);
                }
            }

            exclude_regex = StringFu.GetPatternRegex(exclude_patterns);

            Conf.WatchForUpdates();
            Conf.Subscribe(Conf.Names.FilesQueryableConfig, OnConfigurationChanged);
        }
Esempio n. 10
0
        static protected double HalfLifeMultiplierFromProperty(Hit hit,
                                                               double default_multiplier,
                                                               params object [] properties)
        {
            double best_m = -1.0;

            foreach (object obj in properties)
            {
                string key = obj as string;
                string val = hit [key];
                if (val != null)
                {
                    DateTime dt = StringFu.StringToDateTime(val);
                    double   this_m;
                    this_m = HalfLifeMultiplier(dt, 182);                       /* 182 days == six months */
                    if (this_m > best_m)
                    {
                        best_m = this_m;
                    }
                }
            }

            if (best_m < 0)
            {
                best_m = default_multiplier;
            }
            return(best_m);
        }
Esempio n. 11
0
        public void GotSnippet(string text)
        {
            snippet.Markup = text;

            string tip = text.Replace("<b>", String.Empty).Replace("</b>", String.Empty);

            snippet_tip.SetTip(snippet, StringFu.ConvertSpecialEntities(tip), null);
        }
Esempio n. 12
0
        private static ResponseMessage AddRemovableIndex(string path, string mnt_dir)
        {
            DirectoryInfo index_dir = new DirectoryInfo(StringFu.SanitizePath(path));

            if (!index_dir.Exists)
            {
                ErrorResponse msg;
                msg = new ErrorResponse();
                msg.ErrorMessage = "Adding removable index failed";
                msg.Details      = String.Format("'{0}' does not exist.", path);
                return(msg);
            }

            // Allow late loading of mount dir ?
            mnt_dir = StringFu.SanitizePath(mnt_dir);
            if (!Directory.Exists(mnt_dir))
            {
                ErrorResponse msg;
                msg = new ErrorResponse();
                msg.ErrorMessage = "Adding removable index failed";
                msg.Details      = String.Format("Mount directory '{0}' does not exist.", mnt_dir);
                return(msg);
            }

            if (removable_queryables.ContainsKey(path))
            {
                ErrorResponse msg;
                msg = new ErrorResponse();
                msg.ErrorMessage = "Adding removable index failed";
                msg.Details      = String.Format("'{0}' already added.", path);
                return(msg);
            }

            Queryable removable_queryable = null;

            try {
                iqueryable_lock.AcquireWriterLock(System.Threading.Timeout.Infinite);
                removable_queryable = StaticQueryable.LoadRemovableQueryable(index_dir, mnt_dir);
            } finally {
                iqueryable_lock.ReleaseWriterLock();
            }

            if (removable_queryable == null)
            {
                return(new ErrorResponse("Adding removable index failed"));
            }

            iqueryable_to_queryable [removable_queryable.IQueryable] = removable_queryable;
            removable_queryables [path] = removable_queryable;

            RemovableIndexResponse resp = new RemovableIndexResponse();

            resp.Source = removable_queryable.Name;
            Log.Info("Adding removable index '{0}' from {1}", resp.Source, path);
            return(resp);
        }
Esempio n. 13
0
        protected override void PopulateTemplate()
        {
            base.PopulateTemplate();

            Template["nice_duration"] = "(" +
                                        StringFu.DurationToPrettyString(
                StringFu.StringToDateTime(Hit ["fixme:endtime"]),
                StringFu.StringToDateTime(Hit ["fixme:starttime"])) + ")";
            if (Template ["nice_duration"] == "()")
            {
                Template ["nice_duration"] = "";
            }

            if (email != null)
            {
                Template ["SendMailAction"] = Catalog.GetString("Send Mail");
            }

            // FIXME: This is a temporary hack until gaim supports other protocols than AIM via gaim-remote
            if (Hit ["fixme:protocol"] == "aim")
            {
                Template ["SendIMAction"] = Catalog.GetString("Send IM");
            }

            speaking_alias = (Hit ["fixme:speakingto_alias"] != null) ? Hit ["fixme:speakingto_alias"] : Hit ["fixme:speakingto"];

            // FIXME: Hack to figure out if the conversation is taken place in a chat room
            if (Hit["fixme:speakingto"].EndsWith(".chat"))
            {
                Template["title"] = String.Format(Catalog.GetString("Conversation in {0}"), speaking_alias.Replace(".chat", ""));
            }
            else
            {
                Template["title"] = String.Format(Catalog.GetString("Conversation with {0}"), speaking_alias);
            }

            if (Hit ["fixme:speakingto_icon"] != null && File.Exists(Hit ["fixme:speakingto_icon"]))
            {
                Template["Icon"] = StringFu.PathToQuotedFileUri(Hit ["fixme:speakingto_icon"]);
            }
            else
            {
                Template["Icon"] = Images.GetHtmlSource("gnome-gaim.png", "image/png");
            }

#if ENABLE_GALAGO
            if (Hit ["fixme:protocol"] == "aim")
            {
                string status = GalagoTools.GetPresence(Hit ["fixme:protocol"], Hit["fixme:speakingto"]);
                if (status != null && status != "")
                {
                    Template ["Presence"] = status;
                }
            }
#endif
        }
Esempio n. 14
0
        protected override void PopulateTemplate()
        {
            base.PopulateTemplate();

            string photo_filename = Hit["beagle:Photo"];

            if (photo_filename != null)
            {
                System.Console.WriteLine("photo: {0}", photo_filename);
                string height = "";

                try {
                    // bad hack to scale the image
                    Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(photo_filename);
                    if (pixbuf.Width > pixbuf.Height)
                    {
                        if (pixbuf.Width > 80)
                        {
                            height = "width=\"80\"";
                        }
                    }
                    else
                    {
                        if (pixbuf.Height > 80)
                        {
                            height = "height=\"80\"";
                        }
                    }
                } catch {
                }

                Template["size_adjustment"] = height;
                Template["Icon"]            = StringFu.PathToQuotedFileUri(photo_filename);
            }
            else
            {
                Template["size_adjustment"] = "";
                Template["Icon"]            = default_contact_icon_data;
            }

            if (Hit["fixme:ImAim"] != null)
            {
                Template["CanSendIm"] = "";
            }

#if ENABLE_GALAGO
            if (Hit ["fixme:ImAim"] != null)
            {
                string status = GalagoTools.GetPresence("aim", Hit ["fixme:ImAim"]);
                if (status != null && status != "")
                {
                    Template ["Presence"] = status;
                }
            }
#endif
        }
Esempio n. 15
0
        public PidginLog(FileInfo file, TextReader reader) : base("Pidgin", file, reader)
        {
            string filename = file.Name;

            // Parse what we can from the file path
            try {
                string str;

                // Character at position 17 will be either a dot, indicating the beginning
                // of the extension for old gaim logs, or a plus or minus indicating a
                // timezone offset for new gaim logs.
                if (filename [17] == '+' || filename [17] == '-')
                {
                    // New gaim 2.0.0 format, including timezone.
                    //
                    // Ugly hack time: DateTime's format specifiers only know how to
                    // deal with timezones in the format "+HH:mm" and not "+HHmm",
                    // which is how UNIX traditionally encodes them.  I have no idea
                    // why; it would make RFC 822/1123 parsing a hell of a lot easier.
                    // Anyway, in this case, we're going to insert a colon in there so
                    // that DateTime.ParseExact can understand it.
                    //
                    // 2006-02-21-160424-0500EST.html
                    //                     ^
                    //                     offset 20

                    str       = filename.Substring(0, 20) + ':' + filename.Substring(20, 2);
                    StartTime = DateTime.ParseExact(str, "yyyy-MM-dd.HHmmsszzz", null);
                }
                else if (filename [17] == '.')
                {
                    // Older gaim format.
                    //
                    // 2006-02-21-160424.html

                    str       = Path.GetFileNameWithoutExtension(filename);
                    StartTime = DateTime.ParseExact(str, "yyyy-MM-dd.HHmmss", null);
                }
                else
                {
                    throw new FormatException();
                }
            } catch {
                Logger.Log.Warn("Could not parse date/time from filename '{0}'", file.Name);
                StartTime = DateTime.Now;
            }

            // Gaim likes to represent many characters in hex-escaped %xx form
            SpeakingTo = StringFu.HexUnescape(file.Directory.Name);
            Identity   = StringFu.HexUnescape(file.Directory.Parent.Name);

            Protocol = file.Directory.Parent.Parent.Name;

            Load();
        }
 public void Update(string uid, uint flags)
 {
     lock (connection) {
         SqliteUtils.DoNonQuery(connection,
                                "INSERT OR REPLACE INTO mapping " +
                                "  (uid, flags, last_seen) " +
                                "  VALUES (@uid, @flags, @last_seen)",
                                new string [] { "@uid", "@flags", "@last_seen" },
                                new object [] { uid, flags, StringFu.DateTimeToString(DateTime.UtcNow) });
     }
 }
Esempio n. 17
0
        static public Property NewDate(string key, DateTime dt)
        {
            Property p = new Property();

            p.type        = PropertyType.Date;
            p.Key         = key;
            p.Value       = StringFu.DateTimeToString(dt);
            p.is_searched = true;
            p.is_stored   = true;
            return(p);
        }
Esempio n. 18
0
        public static string NiceShortTime(string timestamp)
        {
            DateTime dt;

            try {
                dt = StringFu.StringToDateTime(timestamp);
            } catch {
                return("");
            }

            return(NiceShortTime(dt));
        }
Esempio n. 19
0
        protected override void PopulateTemplate()
        {
            base.PopulateTemplate();

            if (Hit.FileInfo == null)
            {
                Console.WriteLine("FileInfo is null");
                return;
            }

            string quoted_uri = StringFu.PathToQuotedFileUri(Hit.Uri.LocalPath);
            string thumbnail  = Thumbnail.PathForUri(quoted_uri, ThumbnailSize.Normal);

            if (File.Exists(thumbnail))
            {
                Template ["Icon"] = Images.GetHtmlSource(thumbnail, Hit.MimeType);
            }
            else
            {
                Pixbuf   pix = thumb_factory.GenerateThumbnail(quoted_uri, Hit.MimeType);
                FileInfo fi  = new FileInfo(Hit.Uri.LocalPath);
                if (pix == null)
                {
                    thumb_factory.CreateFailedThumbnail(quoted_uri, fi.LastWriteTime);

                    string path = GnomeFu.GetMimeIconPath(Hit.MimeType);
                    string icon = Images.GetHtmlSource(path, Hit.MimeType);

                    if (icon != null)
                    {
                        Template ["Icon"] = icon;
                    }
                    else
                    {
                        Template ["Icon"] = Images.GetHtmlSource("document", "image/png");
                    }
                }
                else
                {
                    thumb_factory.SaveThumbnail(pix, quoted_uri, DateTime.Now);
                    Template ["Icon"] = Images.GetHtmlSource(thumbnail, Hit.MimeType);
                }
            }

            Template["Title"] = Hit ["dc:title"];

            if (Template["Title"] == null)
            {
                Template["Title"] = Template["FileName"];
            }
        }
Esempio n. 20
0
        ///////////////////////////////////////////////////////////

        static public DirectoryModel NewRoot(object big_lock, string path, FileAttributes attr)
        {
            path = StringFu.SanitizePath(path);

            DirectoryModel root;

            root = new DirectoryModel(attr);

            root.big_lock  = big_lock;
            root.rooted_to = FileSystem.GetDirectoryNameRootOk(path);
            root.name      = Path.GetFileName(path);

            return(root);
        }
Esempio n. 21
0
        static Uri PathToUri(string fullpath)
        {
            if (!arg_removable)
            {
                return(UriFu.PathToFileUri(fullpath));
            }

            fullpath = PathInIndex(fullpath);

            return(new Uri(String.Format("removable{0}{1}{2}",
                                         Uri.SchemeDelimiter,
                                         volume_label,
                                         StringFu.HexEscape(fullpath)), true));
        }
Esempio n. 22
0
        public void AddMatchFragment(int query_term_index, string text)
        {
            text = StringFu.CleanupInvalidXmlCharacters(text);
            if (String.IsNullOrEmpty(text))
            {
                return;
            }

            if (Fragments == null)
            {
                Fragments = new ArrayList(3);                  // mostly will be 3 fragments
            }
            // Before we send a snippet over the wire, clean up any
            // characters that would be invalid in XML.
            Fragments.Add(new Fragment(query_term_index, text));
        }
Esempio n. 23
0
        static public ICollection GetMatchingHammers(string pattern)
        {
            ArrayList matches;

            matches = new ArrayList();

            foreach (Pair pair in all_pairs)
            {
                if (StringFu.GlobMatch(pattern, pair.Attribute.Name))
                {
                    matches.Add(pair.CreateInstance());
                }
            }

            return(matches);
        }
Esempio n. 24
0
        /// <summary>
        /// Standard properties for files
        /// Used by FileSystem backend and filters which produce file child-indexables
        /// </summary>
        /// <param name="name">
        /// A <see cref="System.String"/>
        /// </param>
        /// <param name="mutable">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <returns>
        /// A <see cref="IEnumerable"/>
        /// </returns>
        public static IEnumerable StandardFileProperties(string name, bool mutable)
        {
            StringBuilder sb;

            sb = new StringBuilder();

            string no_ext, ext, no_punct;

            no_ext = Path.GetFileNameWithoutExtension(name);
            ext    = Path.GetExtension(name).ToLower();

            sb.Append(no_ext);
            for (int i = 0; i < sb.Length; ++i)
            {
                if (!Char.IsLetterOrDigit(sb [i]))
                {
                    sb [i] = ' ';
                }
            }
            no_punct = sb.ToString();


            Property prop;

            prop           = Property.NewKeyword(ExactFilenamePropKey, name);
            prop.IsMutable = mutable;
            yield return(prop);

            prop           = Property.New(TextFilenamePropKey, no_ext);
            prop.IsMutable = mutable;
            yield return(prop);

            prop           = Property.New(NoPunctFilenamePropKey, no_punct);
            prop.IsMutable = mutable;
            yield return(prop);

            prop           = Property.NewUnsearched(FilenameExtensionPropKey, ext);
            prop.IsMutable = mutable;
            yield return(prop);

            string str;

            str            = StringFu.FuzzyDivide(no_ext);
            prop           = Property.New(SplitFilenamePropKey, str);
            prop.IsMutable = mutable;
            yield return(prop);
        }
Esempio n. 25
0
        public void WriteXml(XmlWriter writer)
        {
            writer.WriteAttributeString("FullText", (FullText ? "true" : "false"));

            if (snippet_reader == null)
            {
                return;
            }

            if (FullText)
            {
                writer.WriteStartElement("SnippetLine");
                writer.WriteAttributeString("Line", "1");
                writer.WriteStartElement("Fragment");
                writer.WriteAttributeString("QueryTermIndex", "-1");

                string line;
                // Read data from snippet_reader and write
                while ((line = snippet_reader.ReadLine()) != null)
                {
                    writer.WriteString(StringFu.CleanupInvalidXmlCharacters(line));
                    writer.WriteString("\n");
                }

                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            else if (snippet_reader.GetSnippet() != null)
            {
                // If fulltext is false, read lines from snippet reader
                foreach (SnippetLine snippet_line in snippet_reader.GetSnippet())
                {
                    writer.WriteStartElement("SnippetLine");
                    writer.WriteAttributeString("Line", Convert.ToString(snippet_line.Line));
                    foreach (Fragment fragment in snippet_line.Fragments)
                    {
                        writer.WriteStartElement("Fragment");
                        writer.WriteAttributeString("QueryTermIndex", Convert.ToString(fragment.QueryTermIndex));
                        writer.WriteString(fragment.Text);
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }
            }
            snippet_reader.Close();
        }
        private FileAttributes GetFromReader(SqliteDataReader reader)
        {
            FileAttributes attr = new FileAttributes();

            attr.UniqueId      = GuidFu.FromShortString(reader.GetString(0));
            attr.Path          = System.IO.Path.Combine(reader.GetString(1), reader.GetString(2));
            attr.LastWriteTime = StringFu.StringToDateTime(reader.GetString(3));
            attr.LastAttrTime  = StringFu.StringToDateTime(reader.GetString(4));
            attr.FilterName    = reader.GetString(5);
            attr.FilterVersion = int.Parse(reader.GetString(6));

            if (attr.FilterName == "")
            {
                attr.FilterName = null;
            }

            return(attr);
        }
Esempio n. 27
0
        public bool IsMatch(Uri uri, string extension, string mime_type)
        {
            if (Uri != null && (uri == null || !StringFu.GlobMatch(Uri, uri.ToString())))
            {
                return(false);
            }

            if (Extension != null && (extension == null || !StringFu.GlobMatch(Extension, extension)))
            {
                return(false);
            }

            if (MimeType != null && (mime_type == null || !StringFu.GlobMatch(MimeType, mime_type)))
            {
                return(false);
            }

            return(true);
        }
        public bool Write(FileAttributes attr)
        {
            if (Disable)
            {
                return(false);
            }

            try {
                if (ExtendedAttribute.OldExists(attr.Path, "Fingerprint"))
                {
                    DropObsoleteAttributes(attr.Path);
                }

                string fingerprint = String.Format("{0:00} {1}", EA_VERSION, index_fingerprint);
                string uid         = GuidFu.ToShortString(attr.UniqueId);
                string mtime       = StringFu.DateTimeToString(attr.LastWriteTime);

                string filter = String.Empty;

                if (attr.HasFilterInfo)
                {
                    filter = String.Format("{0:000} {1}", attr.FilterVersion, attr.FilterName);
                }

                attr.LastAttrTime = DateTime.UtcNow;
                string attrtime = StringFu.DateTimeToString(attr.LastAttrTime);

                string [] csv = { fingerprint, uid, mtime, attrtime, filter };
                ExtendedAttribute.Set(attr.Path, String.Join(",", csv));

                return(true);
            } catch (IOException e) {
                // An IOException here probably means that we don't have the right
                // permissions to set the EAs.  We just fail silently and return false rather
                // than spewing a bunch of scary exceptions.
                //Logger.Log.Debug (e);
                return(false);
            } catch (Exception e) {
                //Logger.Log.Debug (e, "Caught exception writing EAs to {0}", attr.Path);
                // FIXME: Do something smarter with the exception.
                return(false);
            }
        }
        public FileAttributes Read(string path)
        {
            if (Disable)
            {
                return(null);
            }

            try {
                string tmp = ExtendedAttribute.Get(path);

                if (tmp == null)
                {
                    return(null);
                }

                string[] csv = tmp.Split(',');

                if (int.Parse(csv [0].Substring(0, 2)) != EA_VERSION ||
                    (index_fingerprint != null && csv [0].Substring(3) != index_fingerprint))
                {
                    return(null);
                }

                FileAttributes attr = new FileAttributes();
                attr.UniqueId      = GuidFu.FromShortString(csv [1]);
                attr.Path          = path;
                attr.LastWriteTime = StringFu.StringToDateTime(csv [2]);
                attr.LastAttrTime  = StringFu.StringToDateTime(csv [3]);

                if (!String.IsNullOrEmpty(csv [4]))
                {
                    attr.FilterVersion = int.Parse(csv [4].Substring(0, 3));
                    attr.FilterName    = csv [4].Substring(4);
                }

                return(attr);
            } catch (Exception e) {
                //Logger.Log.Debug ("Caught exception reading EAs from {0}", path);
                //Logger.Log.Debug (e);
                // FIXME: Do something smarter with the exception.
                return(null);
            }
        }
Esempio n. 30
0
        // Scans configuration for user-specified index paths
        // to load StaticQueryables from.
        static void LoadStaticQueryables()
        {
            int count = 0;

            if (UseQueryable("static"))
            {
                Logger.Log.Info("Loading user-configured static indexes.");
                List <string[]> values = Conf.Daemon.GetListOptionValues(Conf.Names.StaticQueryables);
                if (values != null)
                {
                    foreach (string[] path in values)
                    {
                        static_queryables.Add(path [0]);
                    }
                }
            }

            Queryable queryable;

            foreach (string path in static_queryables)
            {
                DirectoryInfo index_dir = new DirectoryInfo(StringFu.SanitizePath(path));

                if (!index_dir.Exists)
                {
                    continue;
                }

                // FIXME: QueryDomain might be other than local
                queryable = StaticQueryable.LoadStaticQueryable(index_dir, QueryDomain.Local);
                if (queryable != null)
                {
                    iqueryable_to_queryable [queryable.IQueryable] = queryable;
                    count++;
                }
            }

            Logger.Log.Info("Found {0} user-configured static indexes..", count);

            static_queryables = null;
        }