Esempio n. 1
0
 public string GetFullPath(DocItem item)
 {
     if (item.LocalCopy || (!Operations.IsUriLocal(item.Uri)))
     {
         return Path.Combine(BasePath, item.DocItemId.ToString(), item.FileName);
     }
     else
     {
         return item.Uri;
     }
 }
Esempio n. 2
0
        public void OpenFile(DocItem item)
        {
            try
            {
                string fileName = GetFullPath(item);
                System.Diagnostics.Process.Start(fileName);
            }
            catch
            {

            }
        }
Esempio n. 3
0
        public static void AddItem(NewItem param, ReportProgress progressReport)
        {
            // 0%
            ReportProgress(progressReport, 0);

            string[] sc = {";", " ", ","};

            string[] tags = param.Tags.Split(sc, StringSplitOptions.RemoveEmptyEntries);

            // check uri
            bool isUriLocal = IsUriLocal(param.Uri);

            /*
             * Local URI
             *  [keep local] store to database
             *  [not keep] only link
             *
             * Web file
             *  [keep local] store to database
             *  [not keep] only link
            */

            var item = new DocItem()
            {
                Uri = param.Uri,
                Name = param.Name,
                Rating = 3
            };

            // Download file
            // 90%
            if (isUriLocal)
            {
                // local filesystem

                item.FileName = Path.GetFileName(param.Uri);
                item.HashCode = HashCalc.GetHash(param.Uri);
            }
            else
            {
                var download = new WebDownload(param.Uri, (int p, string d) =>
                {
                    int percentage = p * 90;
                    percentage /= 100;
                    ReportProgress(progressReport, percentage);
                });

                item.FileName = download.FileName;
                item.HashCode = HashCalc.GetHash(download.Content);
            }
            ReportProgress(progressReport, 90);

            // add DB record
            // 100%
            using (var db = new AppDataBase())
            using(var transaction = db.Database.BeginTransaction())
            {
                // try to select existing tags
                //var registeredTags = db.Tags.Select(x => x.Name).Intersect(tags, StringComparer.InvariantCultureIgnoreCase).ToArray();

                var registeredTags = from i in db.Tags
                                     where tags.Contains(i.Name.ToLower())
                                     select i;

                // save new tags
                var newTags = tags.Except(registeredTags.Select(x => x.Name), StringComparer.InvariantCultureIgnoreCase);

                item.Tags = new List<Tag>();

                // add link to existing tags
                foreach(var i in registeredTags)
                {
                    item.Tags.Add(i);
                }

                // add new tags and link with document
                foreach(var i in newTags)
                {
                    var newTagRecord = db.Tags.Add(new Tag()
                    {
                        Name = i
                    });

                    item.Tags.Add(newTagRecord);
                }

                // save tags
                db.SaveChanges();

                // add item
                db.Items.Add(item);

                // save item
                db.SaveChanges();

                transaction.Commit();
            }
        }
Esempio n. 4
0
        private void ProcessSingleFile(string fileName)
        {
            var hash = HashCalc.GetHash(fileName);

            using(var db = new AppDataBase())
            {
                var isFileNotRegistered = (from i in db.Items
                                where i.HashCode == hash
                                select i).Count() == 0;

                if (isFileNotRegistered)
                {
                    // file not registered

                    var file = Path.GetFileNameWithoutExtension(fileName);

                    var item = new DocItem()
                    {
                        Uri = string.Format(@"file://{0}", fileName),
                        FileName = file,
                        Name = file,
                        HashCode = hash,
                        LocalCopy = false,
                        Rating = 3,
                    };

                    lock(NewItems)
                    {
                        NewItems.Add(item);
                    }
                }
            }
        }
Esempio n. 5
0
 public bool IsFileExist(DocItem item)
 {
     string fileName = GetFullPath(item);
     return System.IO.File.Exists(fileName);
 }
Esempio n. 6
0
 public void DeleteFile(DocItem item)
 {
     string fileName = GetFullPath(item);
     File.Delete(fileName);
 }