private int AddPath(string filteredPath)
 {
     if (filteredPath == null)
     {
         return(-1);
     }
     if (filteredPath == string.Empty)
     {
         return(-1);
     }
     try
     {
         string sql = String.Format("select * from tblFolderPath where strPath like '{0}'", filteredPath);
         using (SqlCommand cmd = _connection.CreateCommand())
         {
             cmd.CommandType = CommandType.Text;
             cmd.CommandText = sql;
             using (SqlDataReader reader = cmd.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     int id = (int)reader["idPath"];
                     reader.Close();
                     return(id);
                 }
                 else
                 {
                     reader.Close();
                     sql = String.Format("insert into tblFolderPath ( strPath) values (  '{0}' )", filteredPath);
                     return(SqlServerUtility.InsertRecord(_connection, sql));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex);
     }
     return(-1);
 }
        public void AddFolderSetting(string path, string key, Type type, object Value)
        {
            if (path == null)
            {
                return;
            }
            if (path == string.Empty)
            {
                return;
            }
            if (key == null)
            {
                return;
            }
            if (key == string.Empty)
            {
                return;
            }

            try
            {
                string pathFiltered = Utils.RemoveTrailingSlash(path);
                string keyFiltered  = key;
                DatabaseUtility.RemoveInvalidChars(ref pathFiltered);
                DatabaseUtility.RemoveInvalidChars(ref keyFiltered);

                int idPath = AddPath(pathFiltered);
                if (idPath < 0)
                {
                    return;
                }

                DeleteFolderSetting(path, key);


                XmlSerializer serializer = new XmlSerializer(type);
                //serialize...
                using (MemoryStream strm = new MemoryStream())
                {
                    using (TextWriter w = new StreamWriter(strm))
                    {
                        serializer.Serialize(w, Value);
                        w.Flush();
                        strm.Seek(0, SeekOrigin.Begin);

                        using (TextReader reader = new StreamReader(strm))
                        {
                            string valueText     = reader.ReadToEnd();
                            string valueFiltered = valueText;
                            DatabaseUtility.RemoveInvalidChars(ref valueFiltered);

                            string sql =
                                String.Format("insert into tblFolderSetting (idPath, tagName,tagValue) values( {0}, '{1}', '{2}') ",
                                              idPath, keyFiltered, valueFiltered);
                            SqlServerUtility.InsertRecord(_connection, sql);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
예제 #3
0
        public int AddPicture(string strPicture, int iRotation)
        {
            // Continue only if it's a picture files
            if (!Util.Utils.IsPicture(strPicture))
            {
                return(-1);
            }

            if (strPicture == null)
            {
                return(-1);
            }
            if (strPicture.Length == 0)
            {
                return(-1);
            }
            lock (typeof(PictureDatabase))
            {
                string strSQL = "";
                try
                {
                    string strPic = strPicture;
                    DatabaseUtility.RemoveInvalidChars(ref strPic);

                    strSQL = String.Format("select * from tblPicture where strFile like '{0}'", strPic);
                    using (SqlCommand cmd = _connection.CreateCommand())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = strSQL;
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                int id = (int)reader["idPicture"];
                                reader.Close();
                                return(id);
                            }
                            reader.Close();
                        }
                    }

                    //Changed mbuzina
                    DateTime dateTaken = DateTime.Now;
                    using (ExifMetadata extractor = new ExifMetadata())
                    {
                        ExifMetadata.Metadata metaData = extractor.GetExifMetadata(strPic);
                        try
                        {
                            DateTimeFormatInfo dateTimeFormat = new DateTimeFormatInfo();
                            dateTimeFormat.ShortDatePattern = "yyyy:MM:dd HH:mm:ss";

                            dateTaken = DateTime.ParseExact(metaData.DatePictureTaken.DisplayValue, "d", dateTimeFormat);
                        }
                        catch (Exception) {}
                        // Smirnoff: Query the orientation information
                        //						if(iRotation == -1)
                        iRotation = EXIFOrientationToRotation(Convert.ToInt32(metaData.Orientation.Hex));
                    }
                    strSQL = String.Format("insert into tblPicture (strFile, iRotation, strDateTaken) values('{0}',{1},'{2}')",
                                           strPic, iRotation, dateTaken);
                    return(SqlServerUtility.InsertRecord(_connection, strSQL));
                }
                catch (Exception ex)
                {
                    Log.Error("MediaPortal.Picture.Database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
                }
                return(-1);
            }
        }