예제 #1
0
        public bool FileImport(string filePath)
        {
            try
            {
                if (String.IsNullOrEmpty(filePath))
                {
                    return(false);
                }
                if (filePath.ToLower().IndexOf("folder.jpg") >= 0)
                {
                    return(false);
                }
                string fName = System.IO.Path.GetFileName(filePath);
                if (fName.ToLower().StartsWith("albumart"))
                {
                    return(false);
                }
                string ext = System.IO.Path.GetExtension(filePath).ToLower();
                if (!_extensions.Contains(ext))
                {
                    return(false);
                }
                try
                {
                    Query           imageByFilename = new Query("contentURI", Operator.Same, filePath);
                    IList <IDbItem> result          = _pictureDatabase.Query(imageByFilename);
                    if (result.Count > 0)
                    {
                        return(false);
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
                IDbItem picture = GetExifFor(filePath);
                if (picture == null)
                {
                    return(false);
                }

                picture.Save();
                return(true);
            }
            catch (Exception ex)
            {
                ServiceScope.Get <ILogger>().Info("pictureimporter:error ImportFile:{0}", filePath);
                ServiceScope.Get <ILogger>().Error(ex);
                return(false);
            }
        }
예제 #2
0
 public void FileRenamed(string filePath, string oldFilePath)
 {
     try
     {
         // The rename may have been on a directory or a file
         FileInfo fi = new FileInfo(filePath);
         if (fi.Exists)
         {
             IList <IDbItem> result;
             try
             {
                 Query imageByFilename = new Query("contenturi", Operator.Same, oldFilePath);
                 result = _pictureDatabase.Query(imageByFilename);
                 if (result.Count > 0)
                 {
                     IDbItem picture = result[0];
                     picture["contenturi"] = filePath;
                     picture.Save();
                 }
             }
             catch (Exception)
             {
                 return;
             }
         }
         else
         {
             // Must be a directory, so let's change the path entries, containing the old
             // name with the new name
             DirectoryInfo di = new DirectoryInfo(filePath);
             if (di.Exists)
             {
                 IList <IDbItem> result;
                 try
                 {
                     Query imageByFilename = new Query("contenturi", Operator.Like, String.Format("{0}%", oldFilePath));
                     result = _pictureDatabase.Query(imageByFilename);
                     if (result.Count > 0)
                     {
                         // We might have changed a Top directory, so we get a lot of path entries returned
                         for (int i = 0; i < result.Count; i++)
                         {
                             IDbItem picture = result[i];
                             string  strPath = picture["contenturi"].ToString().Replace(oldFilePath, filePath);
                             picture["contenturi"] = strPath;
                             picture.Save();
                         }
                     }
                 }
                 catch (Exception)
                 {
                     return;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ServiceScope.Get <ILogger>().Info("pictureimporter:error FileRenamed:{0}", filePath);
         ServiceScope.Get <ILogger>().Error(ex);
     }
 }