Пример #1
0
        System.IO.Stream IItemStorage.Load(Guid itemID)
        {
            Guid      fsitemID = GetFSGuid(itemID);
            const int BUFFSIZE = 1024;

            if (!(this as IItemStorage).Exists(itemID))
            {
                string msg = string.Format("Nie istnieje element o id {0}", fsitemID);
                DataAccessLogEntry.Create(msg, false);
                throw new ArgumentException(msg);
            }
            MemoryStream ms = new MemoryStream();

            byte[]     buff      = new byte[BUFFSIZE];
            FileStream fs        = File.Open(BaseDirectory + fsitemID, FileMode.Open);
            int        bytesRead = 0;

            do
            {
                bytesRead = fs.Read(buff, 0, BUFFSIZE);
                ms.Write(buff, 0, bytesRead);
            }while(bytesRead > 0);
            fs.Close();
            return(ms);
        }
Пример #2
0
        Guid IItemStorage.Save(System.IO.Stream contentStream)
        {
            const int BUFFSIZE = 1024;
            Guid      itemId   = Guid.NewGuid();

            try
            {
                using (BinaryReader br = new BinaryReader(contentStream))
                {
                    byte[] buff = new byte[BUFFSIZE];

                    FileStream fs        = File.Create(BaseDirectory + itemId.ToString());
                    int        bytesRead = 0;
                    do
                    {
                        bytesRead = br.Read(buff, 0, BUFFSIZE);
                        fs.Write(buff, 0, bytesRead);
                    } while (bytesRead > 0);
                    fs.Close();
                    return(itemId);
                }
            }
            catch (Exception ex)
            {
                DataAccessLogEntry.Create(ex.Message, false);
                return(Guid.Empty);
            }
        }