Esempio n. 1
0
        public static void serializeXML <T>(string path, bool useCloud, bool usePath, T instance)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));

            if (useCloud)
            {
                MemoryStream memoryStream = new MemoryStream();
                XmlWriter    xmlWriter    = XmlWriter.Create(memoryStream, ReadWrite.XML_WRITER_SETTINGS);
                try
                {
                    xmlSerializer.Serialize(xmlWriter, instance, ReadWrite.XML_SERIALIZER_NAMESPACES);
                    ReadWrite.cloudFileWrite(path, memoryStream.GetBuffer(), (int)memoryStream.Length);
                }
                finally
                {
                    xmlWriter.Close();
                    memoryStream.Close();
                    memoryStream.Dispose();
                }
            }
            else
            {
                if (usePath)
                {
                    path = ReadWrite.PATH + path;
                }
                if (!Directory.Exists(Path.GetDirectoryName(path)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                }
                StreamWriter streamWriter = new StreamWriter(path);
                try
                {
                    xmlSerializer.Serialize(streamWriter, instance, ReadWrite.XML_SERIALIZER_NAMESPACES);
                }
                finally
                {
                    streamWriter.Close();
                    streamWriter.Dispose();
                }
            }
        }
Esempio n. 2
0
 public static void writeBytes(string path, bool useCloud, bool usePath, byte[] bytes, int size)
 {
     if (useCloud)
     {
         ReadWrite.cloudFileWrite(path, bytes, size);
     }
     else
     {
         if (usePath)
         {
             path = ReadWrite.PATH + path;
         }
         if (!Directory.Exists(Path.GetDirectoryName(path)))
         {
             Directory.CreateDirectory(Path.GetDirectoryName(path));
         }
         FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate);
         fileStream.Write(bytes, 0, size);
         fileStream.SetLength((long)size);
         fileStream.Flush();
         fileStream.Close();
         fileStream.Dispose();
     }
 }