Esempio n. 1
0
        public void ArchiveClick(List <IEntity> elements)
        {
            using (ZipFile zip = new ZipFile())
            {
                foreach (IEntity el in elements)
                {
                    zip.AddItem(el.GetFullName());
                }

                int n = 0;
                while (EntityFunctions.Exists(curDirectory.GetFullName() + "\\Archive(" + n + ").zip"))
                {
                    n++;
                }
                zip.Save(curDirectory.GetFullName() + "\\Archive(" + n + ").zip");
            }
        }
        public void RenameItemClick(KeyValuePair <IEntity, string> renameData)
        {
            if (EntityFunctions.Exists(curDirectory.GetFullName() + @"\" + renameData.Value))
            {
                MessageBox.Show("This file or directory is already exists!");
                return;
            }

            if (renameData.Key.GetType() == EntityType.DIRECTORY || renameData.Key.GetType() == EntityType.FILE || renameData.Key.GetType() == EntityType.ZIP)
            {
                renameData.Key.Rename(curDirectory.GetFullName() + @"\" + renameData.Value);
            }
            else
            {
                renameData.Key.Rename(renameData.Value);
            }
        }
Esempio n. 3
0
        public async void LoadFilesClick(string[] names)
        {
            if (curDirectory == null)
            {
                return;
            }

            var  cts  = new CancellationTokenSource();
            Wait wait = new Wait(cts);

            wait.Show();

            Dictionary <string, Task <string> > books = new Dictionary <string, Task <string> >();

            try
            {
                foreach (string name in names)
                {
                    string          fileName = "";
                    HttpWebResponse fwr      = null;
                    if (!makeFileRequest(name, ref fwr, ref fileName))
                    {
                        wait.Close();
                        return;
                    }
                    books.Add(fileName, readFileAsync(fwr, cts.Token));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error! " + ex.Message);
                wait.Close();
                return;
            }

            var progressIndicator = new Progress <int>(wait.ChangeProgress);
            int count = 0, totalCount = books.Count;

            try
            {
                foreach (var book in books)
                {
                    if (EntityFunctions.Exists(curDirectory.GetFullName() + "\\" + book.Key))
                    {
                        MessageBox.Show("This file is already exists!");
                        return;
                    }

                    EntityFileStream fstream = new EntityFileStream(curDirectory.GetFullName() + "\\" + book.Key);
                    string           str     = await book.Value;
                    ((IProgress <int>)progressIndicator).Report(count * 100 / totalCount);
                    byte[] array = Encoding.Default.GetBytes(str);
                    fstream.Write(array, 0, array.Length);
                    count++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error! " + ex.Message);
                wait.Close();
                return;
            }

            wait.Close();
        }