Example #1
0
 internal bool IsSame(URIItem oTag)
 {
     if (oTag.Key != Key)
     {
         return(false);
     }
     if (oTag.Uri != Uri)
     {
         return(false);
     }
     if (oTag.Title != Title)
     {
         return(false);
     }
     //时间不参与比较,否则每次导入都需要有大量的更新,其实没有必要
     //if (oTag.CreateTime != CreateTime) return false;
     //if (oTag.AccessTime != AccessTime) return false;
     if (oTag.Tags.Count != Tags.Count)
     {
         return(false);
     }
     for (int i = 0; i < Tags.Count; i++)
     {
         if (oTag.Tags[i] != Tags[i])
         {
             return(false);
         }
     }
     return(true);
 }
Example #2
0
        public int Export(string exportFile)
        {
            List <URIItem> all = new List <URIItem>();

            using (System.IO.TextWriter w = new System.IO.StreamWriter(exportFile))
            {
                int max = search.MaxDoc;
                //w.WriteLine(@"IDX,F_ID,F_KEY,F_URI,DEL,TAGS");
                for (int i = 0; i < max; i++)
                {
                    if (reader.IsDeleted(i))
                    {
                        continue;
                    }
                    Document doc = search.Doc(i);
                    if (doc != null)
                    {
                        URIItem item = DocToURIItem(doc);
                        if (item != null && !string.IsNullOrEmpty(item.Key) && !string.IsNullOrEmpty(item.Uri))
                        {
                            all.Add(item);
                        }
                    }
                }

                all.Sort((x, y) => x.Key.CompareTo(y.Key));
                foreach (URIItem item in all)
                {
                    w.WriteLine(JsonConvert.SerializeObject(item));
                }
            }
            return(0);
        }
Example #3
0
        public URIItem GetInf(string Uri)
        {
            URIItem  ret = null;
            Document doc = GetDoc(Uri);

            if (doc != null)
            {
                ret = DocToURIItem(doc);
            }
            return(ret);
        }
Example #4
0
 private void AddUpdate(URIItem item)
 {
     if (string.IsNullOrEmpty(item.Title))
     {
         AddUris(new string[] { item.Uri }, item.Tags);
     }
     else
     {
         AddUriWithTitle(item.Uri, item.Tags, item.Title);
     }
 }
Example #5
0
        internal static URIItem MergeTag(URIItem iTag, URIItem oTag)
        {
            URIItem it = new URIItem();

            it.Key        = iTag.Key;
            it.Uri        = string.IsNullOrEmpty(iTag.Uri)?oTag.Uri:iTag.Uri;
            it.Title      = string.IsNullOrEmpty(iTag.Title) ? oTag.Title : iTag.Title;
            it.CreateTime = iTag.CreateTime > oTag.CreateTime ? iTag.CreateTime : oTag.CreateTime;
            it.AccessTime = iTag.AccessTime > oTag.AccessTime ? iTag.AccessTime : oTag.AccessTime;
            foreach (string s in iTag.Tags)
            {
                it.AddTag(s);
            }
            foreach (string s in oTag.Tags)
            {
                it.AddTag(s);
            }
            return(it);
        }
Example #6
0
        private URIItem DocToURIItem(Document doc)
        {
            URIItem item = new URIItem();

            item.Title = doc.GetField(URIItem.F_URI_TITLE)?.StringValue;
            item.Key   = doc.Get(URIItem.F_KEY);
            item.Uri   = doc.Get(URIItem.F_URI);
            item.Tags  = GetDocTags(doc);
            string createT = doc.Get(URIItem.F_CREATE_TIME);
            string accessT = doc.Get(URIItem.F_ACCESS_TIME);

            if (string.IsNullOrEmpty(createT))
            {
                item.CreateTime = DateTime.Now;
            }
            else
            {
                item.CreateTime = DateTime.ParseExact(createT, TIME_FMT, CultureInfo.InvariantCulture);
            }
            if (string.IsNullOrEmpty(accessT))
            {
                item.AccessTime = DateTime.Now;
            }
            else
            {
                item.AccessTime = DateTime.ParseExact(accessT, TIME_FMT, CultureInfo.InvariantCulture);
            }
            if (!string.IsNullOrEmpty(item.Key) || !string.IsNullOrEmpty(item.Uri))
            {
                if (string.IsNullOrEmpty(item.Key))
                {
                    item.Key = item.Uri.ToLower();
                }
                else if (string.IsNullOrEmpty(item.Uri))
                {
                    item.Uri = item.Key;
                }
                //all.Add(item);
            }
            return(item);
        }
Example #7
0
        public int Import(string importFile)
        {
            if (!System.IO.File.Exists(importFile))
            {
                return(0);
            }


            int newCnt = 0, uptCnt = 0;

            SuspendCommit = true;
            string[] lns = System.IO.File.ReadAllLines(importFile);
            foreach (string ln in lns)
            {
                URIItem importURI = JsonConvert.DeserializeObject <URIItem>(ln);
                if (importURI != null)
                {
                    URIItem myURI = GetInf(importURI.Key);
                    if (myURI == null)
                    {
                        AddUpdate(importURI);
                        newCnt++;
                    }
                    else if (!importURI.IsSame(myURI))
                    {
                        AddUpdate(URIItem.MergeTag(importURI, myURI));
                        uptCnt++;
                    }
                    else
                    {
                        //两边完全相同,不用处理
                    }
                }
            }
            SuspendCommit = false;
            Commit();
            DBChanged();
            return(0);
        }