Exemplo n.º 1
0
        public override void Download(String dirPath)
        {
            String downloadFolder = String.Format("{0}//{1}", dirPath, Name);

            if (!Directory.Exists(downloadFolder))
            {
                Directory.CreateDirectory(downloadFolder);
            }
            IDictionary <String, String> elements = CloudWorker.GetChildElements(ID);

            foreach (KeyValuePair <String, String> keys in elements)
            {
                if (CloudWorker.IsFile(keys.Key))
                {
                    File file = new File()
                    {
                        ID = keys.Key, CloudWorker = CloudWorker, Name = keys.Value
                    };
                    file.Download(downloadFolder);
                }
                //DownloadFile(keys.Key, downloadFolder);
                else
                {
                    Folder folder = new Folder()
                    {
                        ID = keys.Key, CloudWorker = CloudWorker, Name = keys.Value
                    };
                    folder.Download(downloadFolder);
                    //DownloadFolder(keys.Key, downloadFolder, keys.Value);
                }
            }
        }
Exemplo n.º 2
0
        public override void Download(String dirPath)
        {
            String       originalFileName = null;
            String       type             = null;
            MemoryStream stream           = CloudWorker.DownloadFile(ID, downloadProgress, ref originalFileName, ref type);
            FileStream   fileStream       = null;

            try
            {
                string fileName = String.Format("{0}{1}{2}", dirPath, System.IO.Path.DirectorySeparatorChar, originalFileName);
                fileStream = new FileStream(fileName, FileMode.Create);
                stream.WriteTo(fileStream);
                stream.Close();
                fileStream.Close();
            }

            catch (Exception ex)
            {
                //todo show message to user
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                }
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }
Exemplo n.º 3
0
        private async void bReg_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (tbLogin.Text.Length > 0 && tbName.Text.Length > 0 && tbEmail.Text.Length > 0 && pbPassword.Password.Length > 0)
                {// Reg code
                    bool result = false;

                    bReg.IsEnabled = false;

                    if (CloudWorker.Register(new WcfClassesLib.User {
                        Login = tbLogin.Text, Email = tbEmail.Text, Name = tbName.Text, Password = pbPassword.Password
                    }) == true)
                    {
                        result = true;
                    }


                    if (result == true)
                    {
                        MessageBox.Show("Successful registration!", "DropBox", MessageBoxButton.OK, MessageBoxImage.Information);

                        MainWindow mw = new MainWindow();
                        mw.Show();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Some errors occured.\nMaybe, this login is already busy?", "DropBox", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
                else
                {
                    MessageBox.Show("You should fill all fields!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            bReg.IsEnabled = true;
        }
Exemplo n.º 4
0
        private void bSearch_Click(object sender, RoutedEventArgs e)
        {
            var collection = CloudWorker.getFoldersByName(tbSearch.Text, login);

            foreach (var el in collection)
            {
                var sp = new StackPanel {
                    Orientation = Orientation.Horizontal
                };
                sp.Children.Add(new PackIcon {
                    Kind = PackIconKind.Folder, Foreground = new SolidColorBrush(Colors.Orange), Width = 30, Height = 30
                });
                sp.Children.Add(new TextBlock {
                    Text = el.Name, FontSize = 12
                });

                var b = new Button {
                    Content = sp, Tag = el.Hash
                };
                b.Click += B_Click;

                lbRes.Items.Add(b);
            }
        }
Exemplo n.º 5
0
        private Popup CreateRightClickPopup()
        {
            Popup popup = new Popup()
            {
                Margin = new Thickness(10, 0, 0, 13),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                Width     = 150,
                Height    = 150,
                IsOpen    = false,
                Placement = PlacementMode.Center
            };
            var point = Mouse.GetPosition(Application.Current.MainWindow);

            popup.HorizontalOffset = point.X;
            popup.VerticalOffset   = point.Y;
            Grid    grid     = new Grid();
            TextBox textBox  = new TextBox();
            Button  download = new Button()
            {
                Content = "Download"
            };

            //todo after actions update the grid
            download.Click += ((Object sender, RoutedEventArgs e) =>
            {
                popup.IsOpen = false;
                Element element = null;
                Button actualButton = sender as Button;
                using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
                {
                    System.Windows.Forms.DialogResult result = dialog.ShowDialog();
                    String id = CloudsWorker.GetId(lastRightClickedButton);
                    element = !CloudWorker.IsFile(id) ?
                              element = new Folder()
                    {
                        ID = id, CloudWorker = this.CloudWorker, Name = lastRightClickedButton.Content as String
                    } :
                    element = new File()
                    {
                        ID = id, CloudWorker = this.CloudWorker, Name = lastRightClickedButton.Content as String
                    };
                    element.Download(dialog.SelectedPath);
                }
            });
            Button moveToOtherCloud = new Button()
            {
                Content = "Move to another cloud"
            };

            moveToOtherCloud.Click += ((Object sender, RoutedEventArgs e) =>
            {
                popup.IsOpen = false;
            });
            Button share = new Button()
            {
                Content = "Share"
            };

            share.Click += ((Object sender, RoutedEventArgs e) =>
            {
                popup.IsOpen = false;
            });
            Button rename = new Button()
            {
                Content = "Rename"
            };

            rename.Click += ((Object sender, RoutedEventArgs e) =>
            {
                popup.IsOpen = false;
            });
            Button delete = new Button()
            {
                Content = "Delete"
            };

            delete.Click += ((Object sender, RoutedEventArgs e) =>
            {
                popup.IsOpen = false;
                Element element = null;
                Button actualButton = sender as Button;
                String id = CloudsWorker.GetId(lastRightClickedButton);
                element = !CloudWorker.IsFile(id) ?
                          element = new Folder()
                {
                    ID = id, CloudWorker = this.CloudWorker, Name = lastRightClickedButton.Content as String
                } :
                element = new File()
                {
                    ID = id, CloudWorker = this.CloudWorker, Name = lastRightClickedButton.Content as String
                };
                element.Remove();
            });
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid.Children.Add(textBox);
            grid.Children.Add(download);
            grid.Children.Add(moveToOtherCloud);
            grid.Children.Add(delete);
            Grid.SetRow(textBox, 0);
            Grid.SetRow(download, 1);//mainWindow.GRID_CLOUD_CONTENT.RowDefinitions.Count - 1
            Grid.SetRow(moveToOtherCloud, 2);
            Grid.SetRow(delete, 3);
            Grid.SetColumn(textBox, 0);
            Grid.SetColumn(download, 0);
            Grid.SetColumn(moveToOtherCloud, 0);
            Grid.SetColumn(delete, 0);
            popup.Child = grid;
            return(popup);
        }
Exemplo n.º 6
0
 public override void Upload(String parentID)
 {
     CloudWorker.UploadDirectory(Name, Name, parentID, Name);
 }
Exemplo n.º 7
0
 public override void Remove()
 {
     CloudWorker.DeleteFolder(ID);
 }
Exemplo n.º 8
0
 private void B_Click(object sender, RoutedEventArgs e)
 {
     CloudWorker.MoveElement(hash, ((Button)sender).Tag.ToString());
 }
Exemplo n.º 9
0
 public override void Upload(String parentID)
 {
     CloudWorker.UploadFile(Name, parentID);
 }
Exemplo n.º 10
0
 public override void Remove()
 {
     CloudWorker.DeleteFile(ID);
 }