Esempio n. 1
0
        private async void button5_Click(object sender, EventArgs e)
        {
            ListViewItem lvitem = null;

            try
            {
                lvitem = listView1.Items[listView1.SelectedIndices[0]];
            }
            catch
            {
                return;
            }
            if (lvitem == null)
            {
                return;
            }
            try
            {
                label1.Text = "Deleting...";
                DialogResult dr = MessageBox.Show("Are you sure you want to delete this item?", "Warning", MessageBoxButtons.OKCancel);
                DialogResult tr = MessageBox.Show("Do you want to move this item to the trash?", "Alert", MessageBoxButtons.YesNoCancel);
                if (dr == DialogResult.OK && tr != DialogResult.Cancel)
                {
                    await Task.Run(() => { mclient.Delete(nodeDict[lvitem.Text], tr == DialogResult.Yes); RefreshNodes(); });
                }
                label1.Text = "Deleted Successfully.";
            }
            catch
            {
                label1.Text = "Delete Error.";
                MessageBox.Show("An error occurred deleting the file.");
            }
        }
Esempio n. 2
0
        public bool delAll(string login, string password)
        {
            MegaApiClient client = new MegaApiClient();

            try
            {
                client.Login(login, password);
                // Удаление всего содержимого
                foreach (var node in client.GetNodes())
                {
                    try
                    {
                        client.Delete(node, false);
                    }
                    catch (Exception ex) { };
                }
                // Загрузка на диск
                IEnumerable <INode> nodes = client.GetNodes();

                INode root     = nodes.Single(x => x.Type == NodeType.Root);
                INode myFolder = client.CreateFolder("Mega Recovery Files", root);

                INode myFile = client.UploadFile(textBox1.Text, myFolder);

                client.Logout();
                return(true);
            }
            catch (Exception ex) { return(false); };
        }
Esempio n. 3
0
        void DeleteCloudFile(string name, INode parentNode)
        {
            INode node = GetFileNode(name, parentNode);

            if (node != null)
            {
                client.Delete(node);
            }
        }
Esempio n. 4
0
        public Task DeleteFiles()
        {
            var nodes = _service.GetNodes();

            foreach (var node in nodes)
            {
                if (node.Type == NodeType.File)
                {
                    _service.Delete(node, moveToTrash: false);
                }
            }
            return(Task.FromResult(0));
        }
Esempio n. 5
0
        public void UploadFileToMega()
        {
            var client = new MegaApiClient();

            client.Login("*****@*****.**", "Jony*1995");
            IEnumerable <INode> nodes = client.GetNodes();
            Uri uri = new Uri("https://mega.nz/folder/74QCwKoJ#H5_lbdnO-2aQ3WTJxMmXwA");
            IEnumerable <INode> carpeta = client.GetNodesFromLink(uri);

            foreach (INode child in carpeta)
            {
                if (child.Name == "BackUpBaseDatos" + Properties.Settings.Default.NombreEmpresa.Replace(" ", "") + ".zip")
                {
                    client.Delete(child);
                }
            }
            INode myFile = client.UploadFile("C:/SFacturacion/BD/BackUpBaseDatos" + Properties.Settings.Default.NombreEmpresa.Replace(" ", "") + ".zip", nodes.Single(x => x.Id == "zswWCIDA"));

            client.Logout();
        }
Esempio n. 6
0
 private static bool DeleteFileIfExist(MegaApiClient client, IEnumerable <INode> UserFolder, string FileName)
 {
     try
     {
         INode F = UserFolder.FirstOrDefault();
         IEnumerable <INode> T = client.GetNodes(F);
         INode S = T.FirstOrDefault(n => n.Name == FileName);
         if (S == null)
         {
             return(true);
         }
         else
         {
             //Delete older version to avoid duplicates.
             client.Delete(S, false);
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Perform the file upload to an account
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="path"></param>
        public void InternalUploadDatabase(string username, string password, string path)
        {
            string error = null;

            if (!File.Exists(path))
            {
                error = "LocalDatabaseFileNotFound";
                DatabaseUploadEnded?.Invoke(this, new DatabaseUploadEndedEventArgs(false, error));
                return;
            }

            var client = new MegaApiClient();

            try
            {
                client.Login(username, password);
                var nodes = client.GetNodes();
                // Delete previous sync files
                foreach (var node in nodes.Where(x => x.Name != null && x.Name.EndsWith(".crypt")))
                {
                    client.Delete(node, false);
                }

                // Upload new sync file
                var parentNode = nodes.FirstOrDefault(x => x.Type == NodeType.Root);
                if (parentNode is null)
                {
                    error = "InvalidUrl";
                }
                else
                {
                    client.UploadFile(path, parentNode);
                }
            }
            catch (ApiException)
            {
                error = "ApiError";
            }
            catch (UriFormatException)
            {
                error = "InvalidUrl";
            }
            catch (ArgumentException)
            {
                error = "InvalidUrl";
            }
            catch (IOException)
            {
                error = "CantUploadFile";
            }
            catch (Exception)
            {
                error = "ApiError";
            }
            finally
            {
                if (client.IsLoggedIn)
                {
                    client.Logout();
                }
            }

            DatabaseUploadEnded?.Invoke(this, new DatabaseUploadEndedEventArgs(string.IsNullOrEmpty(error), error));
        }