Пример #1
0
        public void Deserialize(string fileName, byte[] file)
        {
            TLVUtil tlvParser = new TLVUtil();

            int curPos = 0;

            string name, data;

            while (curPos < file.Length)
            {
                //Чтение имени
                curPos = tlvParser.ReadKnownTag(file, curPos, Entry.ENTRY_NAME_TAG);
                if (tlvParser.TagData[1] != 0)
                    name = Encoding.GetEncoding(1251).GetString(file, curPos, tlvParser.TagData[1]);
                else
                    name = "";

                curPos += tlvParser.TagData[1];

                //Чтение тела файла
                curPos = tlvParser.ReadKnownTag(file, curPos, Entry.ENTRY_DATA_TAG);
                if (tlvParser.TagData[1] != 0)
                    data = Encoding.GetEncoding(1251).GetString(file, curPos, tlvParser.TagData[1]);
                else
                    data = "";

                curPos += tlvParser.TagData[1];

                Entry entry = new Entry(this, name, data, fileName);
                Blocks.Add(entry);

                if (ItemsChangedEvent != null)
                    ItemsChangedEvent(this, new ItemsChangedEventArgs(entry));
            }
        }
Пример #2
0
 public EntryBlock(StackPanel parent, Entry entry)
 {
     InitializeComponent();
     Source = entry;
     lblName.Content = entry.Name;
     tbData.Text = entry.Data;
     isModified = false;
     this.parent = parent;
 }
Пример #3
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            IFileTransfer proxy = new FileTransferClient();
            RemoteFileInfo uploadRequestInfo = new RemoteFileInfo();

            Entry entry = new Entry(entrys, "Name", "", "");
            byte[] bEntry = entry.Serialize();

            string path = proxy.AddNewFile(currentUser.UserName, bEntry);
            if (path == null || path == "")
            {
                return;
            }

            entrys.Deserialize(path, bEntry);
            byte[] encrypted = CryptoLibrary.encrypt28147cfb(currentUser.MasterKey, entry.Serialize());

            using (MemoryStream stream = new MemoryStream(encrypted))
            {
                uploadRequestInfo.FileName = path;
                uploadRequestInfo.Length = encrypted.Length;
                uploadRequestInfo.FileByteStream = stream;
                proxy.UploadFile(uploadRequestInfo);
            }
        }