Exemple #1
0
        private string GetFilename(SerializedData data)
        {
            string path = Path.Combine(m_storeDirectory, data.StoreID.ToString());

            path = Path.Combine(path, data.Section);

            string extension = m_simian.ContentTypeToExtension(data.ContentType);

            if (!String.IsNullOrEmpty(extension))
            {
                extension = '.' + extension;
            }

            string filename;

            if (data.Version > 1)
            {
                filename = String.Format("{0}-v{1:00}{2}", data.Name, data.Version, extension);
            }
            else
            {
                filename = String.Format("{0}{1}", data.Name, extension);
            }

            return(Path.Combine(path, filename));
        }
Exemple #2
0
        public SerializedData DeserializeOne(UUID storeID, string section)
        {
            string[]       files      = null;
            SerializedData latestData = null;

            string dir = GetDirectory(storeID, section);

            if (Directory.Exists(dir))
            {
                try { files = Directory.GetFiles(dir); }
                catch { }
            }

            if (files != null)
            {
                for (int i = 0; i < files.Length; i++)
                {
                    SerializedData data = CreateFromFile(files[i]);

                    if (data != null)
                    {
                        if (latestData == null || data.Version > latestData.Version)
                        {
                            latestData = data;
                        }
                    }
                }
            }

            return(latestData);
        }
Exemple #3
0
        public IList <SerializedData> Deserialize(UUID storeID, string section)
        {
            string[] files             = null;
            List <SerializedData> list = null;

            string dir = GetDirectory(storeID, section);

            if (Directory.Exists(dir))
            {
                try { files = Directory.GetFiles(dir); }
                catch { }
            }

            if (files != null)
            {
                list = new List <SerializedData>(files.Length);

                for (int i = 0; i < files.Length; i++)
                {
                    SerializedData data = CreateFromFile(files[i]);

                    if (data != null)
                    {
                        list.Add(data);
                    }
                }
            }
            else
            {
                list = new List <SerializedData>(0);
            }

            return(list);
        }
Exemple #4
0
        private void SerializeHandler(SerializedData data)
        {
            string filename = GetFilename(data);

            if (data.Data != null)
            {
                AddOrUpdate(filename, data.Data);
                m_log.Debug("Serialized " + data.Data.Length + " bytes to " + filename);
            }
            else if (Remove(filename))
            {
                m_log.Debug("Removed serialized data file " + filename);
            }
            else
            {
                //m_log.Debug("Attempted to remove missing serialized data file " + filename);
            }
        }
Exemple #5
0
        private SerializedData CreateFromFile(string filename)
        {
            try
            {
                SerializedData data = new SerializedData();

                DirectoryInfo dirInfo    = new DirectoryInfo(Path.GetDirectoryName(filename));
                DirectoryInfo parentInfo = dirInfo.Parent;
                if (UUID.TryParse(parentInfo.Name, out data.StoreID))
                {
                    string shortFilename = Path.GetFileNameWithoutExtension(filename);

                    data.Section     = dirInfo.Name;
                    data.ContentType = m_simian.ExtensionToContentType(Path.GetExtension(filename));
                    data.Version     = 1;

                    int i = shortFilename.LastIndexOf("-v");
                    if (i > -1)
                    {
                        Int32.TryParse(shortFilename.Substring(i + 2), out data.Version);
                        data.Name = shortFilename.Substring(0, i);
                    }
                    else
                    {
                        data.Name = shortFilename;
                    }

                    data.Data = File.ReadAllBytes(filename);
                }

                return(data);
            }
            catch (Exception ex)
            {
                m_log.Error("Failed to deserialize " + filename + ": " + ex.Message);
                return(null);
            }
        }
Exemple #6
0
 public void BeginSerialize(SerializedData item)
 {
     //m_log.Debug("Queuing serialization for " + GetFilename(item));
     m_pendingSerialization.Add(item.StoreID + item.Section + item.Name, item);
 }
Exemple #7
0
 public void BeginSerialize(SerializedData item)
 {
     //m_log.Debug("Queuing serialization for " + GetFilename(item));
     m_pendingSerialization.Add(item.StoreID + item.Section + item.Name, item);
 }
Exemple #8
0
 private void SerializeHandler(SerializedData data)
 {
     string filename = GetFilename(data);
     if (data.Data != null)
     {
         AddOrUpdate(filename, data.Data);
         m_log.Debug("Serialized " + data.Data.Length + " bytes to " + filename);
     }
     else if (Remove(filename))
     {
         m_log.Debug("Removed serialized data file " + filename);
     }
     else
     {
         //m_log.Debug("Attempted to remove missing serialized data file " + filename);
     }
 }
Exemple #9
0
        private string GetFilename(SerializedData data)
        {
            string path = Path.Combine(m_storeDirectory, data.StoreID.ToString());
            path = Path.Combine(path, data.Section);

            string extension = m_simian.ContentTypeToExtension(data.ContentType);
            if (!String.IsNullOrEmpty(extension))
                extension = '.' + extension;

            string filename;

            if (data.Version > 1)
                filename = String.Format("{0}-v{1:00}{2}", data.Name, data.Version, extension);
            else
                filename = String.Format("{0}{1}", data.Name, extension);

            return Path.Combine(path, filename);
        }
Exemple #10
0
        private SerializedData CreateFromFile(string filename)
        {
            try
            {
                SerializedData data = new SerializedData();

                DirectoryInfo dirInfo = new DirectoryInfo(Path.GetDirectoryName(filename));
                DirectoryInfo parentInfo = dirInfo.Parent;
                if (UUID.TryParse(parentInfo.Name, out data.StoreID))
                {
                    string shortFilename = Path.GetFileNameWithoutExtension(filename);

                    data.Section = dirInfo.Name;
                    data.ContentType = m_simian.ExtensionToContentType(Path.GetExtension(filename));
                    data.Version = 1;

                    int i = shortFilename.LastIndexOf("-v");
                    if (i > -1)
                    {
                        Int32.TryParse(shortFilename.Substring(i + 2), out data.Version);
                        data.Name = shortFilename.Substring(0, i);
                    }
                    else
                    {
                        data.Name = shortFilename;
                    }

                    data.Data = File.ReadAllBytes(filename);
                }

                return data;
            }
            catch (Exception ex)
            {
                m_log.Error("Failed to deserialize " + filename + ": " + ex.Message);
                return null;
            }
        }