DateTimeToUnixTimestamp() public static method

Convert DateTime to unix timestamp.
public static DateTimeToUnixTimestamp ( System.DateTime dateTime ) : long
dateTime System.DateTime /// DateTime ///
return long
示例#1
0
        /// <summary>
        /// Update or insert a new entry for the file into the database
        /// </summary>
        /// <returns>
        /// Flase if there was a problem during the update
        /// </returns>
        /// <param name='user'></param>
        /// <param name='thisFile'></param>
        public bool UpdateFile(ServerUser user, MyFile thisFile)
        {
            // TODO: use OwnCloud API calls if possible perhaps: http://owncloud.org/dev/apps/database/

            string   path    = "/" + user.id + "/files/" + thisFile.name;
            string   absPath = GetDataDir(user) + thisFile.name; //Server.baseDataDir + path;
            FileInfo f       = new FileInfo(absPath);
            long     mtime   = Common.DateTimeToUnixTimestamp(f.LastWriteTimeUtc);

            DbCommand command_checkExists = dbConnection.CreateCommand();

            command_checkExists.CommandText = "SELECT count(id) FROM oc_fscache WHERE path='" + path + "'";

            int checkFound = Convert.ToInt32(command_checkExists.ExecuteScalar());

            DbCommand command = dbConnection.CreateCommand();

            if (checkFound > 0)
            {
                command.CommandText = "UPDATE oc_fscache SET mtime='" + mtime + "' WHERE path='" + path + "'";
            }
            else
            {
                // if the entry does not exist, insert it instead of updating it

                long ctime = Common.DateTimeToUnixTimestamp(f.CreationTimeUtc);

                DbCommand command_getParent = dbConnection.CreateCommand();
                command_getParent.CommandText = "SELECT id FROM oc_fscache WHERE path_hash='"
                                                + Common.Md5Hash(path.Substring(0, path.LastIndexOf('/'))) + "'";

                int parentId = Convert.ToInt32(command_getParent.ExecuteScalar());

                string mimetype = MIMEAssistant.GetMIMEType(f.Name);
                string mimepart = mimetype.Substring(0, mimetype.LastIndexOf('/'));

                bool writable  = true;  //!f.IsReadOnly;
                bool encrypted = false; // ?
                bool versioned = false; // ?

                command.CommandText = String.Format("INSERT INTO oc_fscache (parent, name, path, path_hash, size, mtime, ctime, mimetype, mimepart,`user`,writable,encrypted,versioned) "
                                                    + "VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}')",
                                                    parentId, f.Name, path, Common.Md5Hash(path), f.Length, mtime, ctime, mimetype, mimepart, user.id, writable, encrypted, versioned);
            }

            return(command.ExecuteNonQuery() == 1);
        }