Beispiel #1
0
        public string WriteSharedObject(string directory, string sharedFileName, string extension, string objectId, string readFileName, BinaryXmlTypeMap typeMap, IBinaryXmlElement obj)
        {
            string file = readFileName;

            if (file == null)
            {
                int    count = 1;
                string name  = sharedFileName + "_" + Util.GetStringHashCode(objectId).ToString("x");
                file = Path.Combine(directory, name + extension);

                while (Exists(file))
                {
                    count++;
                    file = Path.Combine(directory, name + "_" + count + extension);
                }
            }

            using (Stream s = Create(file)) {
                BinaryXmlWriter writer = new BinaryXmlWriter(s, typeMap);
                writer.WriteBeginElement("File");
                writer.WriteValue("id", objectId);
                writer.WriteValue("data", obj);
                writer.WriteEndElement();
            }
            return(file);
        }
Beispiel #2
0
        object ReadSharedObject(string directory, string sharedFileName, string extension, string objectId, BinaryXmlTypeMap typeMap, bool checkOnly, out string fileName)
        {
            string name = sharedFileName + "_" + Util.GetStringHashCode(objectId).ToString("x");
            string file = Path.Combine(directory, name + extension);

            object result;

            if (OpenFileForPath(file, objectId, typeMap, checkOnly, out result))
            {
                fileName = file;
                return(result);
            }

            // The file is not the one we expected. There has been a name colision

            foreach (string f in GetDirectoryFiles(directory, name + "*" + extension))
            {
                if (f != file && OpenFileForPath(f, objectId, typeMap, checkOnly, out result))
                {
                    fileName = f;
                    return(result);
                }
            }

            // File not found
            fileName = null;
            return(null);
        }
Beispiel #3
0
        string GetFileKey(string directory, string sharedFileName, string objectId)
        {
            int    avlen = System.Math.Max(240 - directory.Length, 10);
            string name  = sharedFileName + "_" + Util.GetStringHashCode(objectId).ToString("x");

            if (name.Length > avlen)
            {
                return(name.Substring(name.Length - avlen));
            }
            else
            {
                return(name);
            }
        }
Beispiel #4
0
        string GetFileKey(string directory, string sharedFileName, string objectId)
        {
            // We have two magic numbers here. 240 is a "room to spare" number based on 255,
            // the Windows MAX_PATH length for the full path of a file on disk. Then 130 is
            // a "room to spare" number based on 143-"ish", the maximum filename length for
            // files stored on eCryptFS on Linux. 240 relates to the complete path
            // (including the directory structure), and 130 is just the filename, so we pick
            // whichever is the smaller of those two numbers when truncating.
            int    avlen = System.Math.Min(System.Math.Max(240 - directory.Length, 10), 130);
            string name  = sharedFileName + "_" + Util.GetStringHashCode(objectId).ToString("x");

            if (name.Length > avlen)
            {
                return(name.Substring(name.Length - avlen));
            }
            else
            {
                return(name);
            }
        }