public async Task <ActionResult <FileItem> > EditShareFile(Guid uuid, [FromBody] EditFileSystemItemShareBody body)
        {
            try
            {
                await ValidateFileSystemItemShare(body);
            }
            catch (HttpResultException exc)
            {
                return(exc.Result);
            }

            if (await dbContext.ShareFiles.AnyAsync(f =>
                                                    f.Uuid != uuid && f.Name == body.Name && f.UserId == body.UserId))
            {
                return(BadRequest("File with this name is already shared"));
            }

            ShareFile shareFile = await dbContext.ShareFiles
                                  .Include(f => f.Permission)
                                  .FirstOrDefaultAsync(f => f.Uuid == uuid);

            if (shareFile == null)
            {
                return(NotFound("Share file not found"));
            }

            shareFile.Name     = body.Name;
            shareFile.IsListed = body.IsListed;
            shareFile.UserId   = string.IsNullOrWhiteSpace(body.UserId) ? null : body.UserId;

            await dbContext.SaveChangesAsync();

            return(shareFile.ToFileItem());
        }
        public void AddFileToDB(ShareFile file, User user, string ip)
        {
            string query = String.Format("INSERT INTO File VALUES(default,{0},'{1}',{2},{3},{4})", user.ID, file.fileName, file.t, file.n, file.ToReturn);

            this.runQueryNonReturn(query);
            this.FileUploadAudit(file, user, ip);
        }
        public async Task <ActionResult <FileItem> > AddShareFile([FromBody] AddFileShareBody body)
        {
            InternalFile file;

            try
            {
                file = await ValidateAddFileShare(body);
            }
            catch (HttpResultException exc)
            {
                return(exc.Result);
            }

            if (await dbContext.ShareFiles.AnyAsync(f => f.Name == body.Name && f.UserId == body.UserId))
            {
                return(BadRequest("File with this name is already shared"));
            }

            ShareFile shareFile = new ShareFile()
            {
                Name       = body.Name,
                Path       = file.PhysicalPath,
                IsListed   = body.IsListed,
                UserId     = string.IsNullOrWhiteSpace(body.UserId) ? null : body.UserId,
                Permission = Models.FileItemPermission.New(body.Permission),
            };

            await dbContext.ShareFiles.AddAsync(shareFile);

            await dbContext.SaveChangesAsync();

            return(shareFile.ToFileItem());
        }
示例#4
0
        public Task ShareFileAsync(string filePath)
        {
            var shareFile    = new ShareFile(filePath);
            var shareRequest = new ShareFileRequest(shareFile);

            return(Share.RequestAsync(shareRequest));
        }
        static void Main(string[] args)
        {
            User      u = Database.getDB().Login("0.0.0.0", "RyanMcb", "Pa$$w0rd");
            ShareFile f = new ShareFile(1);

            System.getSystem().downloadFile(u, f);
            // System.getSystem().uploadFile(f, u, "0.0.0.0");
            Console.WriteLine("Done");
            Console.ReadLine();
        }
示例#6
0
        public void TestShareFile()
        {
            String fileId = CreateTestBlob(filePath);
            var    ids    = ShareFile.DriveShareFile(fileId,
                                                     "*****@*****.**",
                                                     "test.appsdevtesting.com");

            Assert.AreNotEqual(0, ids.Count);
            DeleteFileOnCleanup(fileId);
        }
示例#7
0
        public MainWindow(String mid, LoginWindow lw)
        {
            InitializeComponent();
            parent        = lw;
            this.selfId   = mid;
            this.Closing += dialogCloseEvent;
            String localurl = (String)AppDomain.CurrentDomain.BaseDirectory + "Images\\i_male.gif";

            male     = ShareFile.Read(localurl);
            localurl = (String)AppDomain.CurrentDomain.BaseDirectory + "Images\\i_female.gif";
            female   = ShareFile.Read(localurl);
        }
        private void btnUpload_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            Nullable <bool> result             = dlg.ShowDialog();

            if (result == true)
            {
                string    filename = dlg.FileName;
                string    content  = File.ReadAllText(filename);
                ShareFile share    = new ShareFile(this.ToByte(content), filename, int.Parse(txtSharesTotal.Text), int.Parse(txtRequired.Text), int.Parse(txtReturn.Text));
                Controller.getController().service.UploadFile(share, Controller.getController().user, Controller.getController().getIPAddress());
            }
        }
        public async Task <ActionResult <ShareItem> > GetShareFile(Guid uuid)
        {
            ShareFile shareFile = await dbContext.ShareFiles
                                  .Include(f => f.Permission)
                                  .FirstOrDefaultAsync(f => f.Uuid == uuid);

            if (shareFile == null)
            {
                return(NotFound("Share file not found"));
            }

            return(shareFile.ToShareItem());
        }
        public async Task <ActionResult> DeleteShareFile(Guid uuid)
        {
            ShareFile shareFile = await dbContext.ShareFiles
                                  .Include(f => f.Permission)
                                  .FirstOrDefaultAsync(f => f.Uuid == uuid);

            if (shareFile == null)
            {
                return(NotFound("Share file not found"));
            }

            dbContext.ShareFiles.Remove(shareFile);
            await dbContext.SaveChangesAsync();

            return(Ok());
        }
        public static void Main(String[] args)
        {
            User      u = new User(1, "RyanMcB", "Pa$$w0rd", "Ryan", "Mcb");
            ShareFile f = new ShareFile(1);

            Console.WriteLine("File: " + Storage.getService().downloadShares(f, 1));
            Console.WriteLine("Done");
            Console.ReadLine();

            /***
             * byte[] b = File.ReadAllBytes("C:\\Users\\Ryan McBroom\\Desktop\\File.txt");
             * ShareFile f = new ShareFile(b, "File.txt", 50, 20, 20);
             * f.shares = CreateShares(f);
             *  Console.WriteLine("Done");
             * Console.ReadLine();
             ***/
        }
        protected byte[] sendShares(ShareFile file, User user)
        {
            int pos = 0;
            //ToReturn
            List <Share> toReturn = new List <Share>();

            if (file.ToReturn > 0)
            {
                while (pos < file.ToReturn)
                {
                    toReturn.Add((Share)file.shares.ElementAt(pos));
                    pos++;
                }
            }
            foreach (StorageConnector connector in this.connectors)
            {
                List <Share> shares = new List <Share>();
                while (pos <= file.shares.Count)
                {
                    shares.Add((Share)file.shares.ElementAt(pos));
                }
                ShareFile f       = new ShareFile(file.ID, file.fileName, file.UserID, file.n, file.t);
                byte[]    bShares = this.shareToByte(shares);
                connector.UploadShares(f, user, bShares);
            }
            if (pos < file.shares.Count)
            {
                List <Share> shares = new List <Share>();
                while (pos <= file.shares.Count)
                {
                    shares.Add((Share)file.shares.ElementAt(pos));
                }
                ShareFile f       = new ShareFile(file.ID, file.fileName, file.UserID, file.n, file.t);
                byte[]    bShares = this.shareToByte(shares);
                Random    rnd     = new Random();
                int       con     = rnd.Next(connectors.Count);
                connectors[con].UploadShares(f, user, bShares);
            }
            //Return Shares
            return(this.shareToByte(toReturn));
        }
示例#13
0
        public async Task <string> ShareFile([FromBody] ShareFile sf)
        {
            if (VerifyTheToken(sf._id))
            {
                ShareFileNoRev shareNoRev = new ShareFileNoRev(sf);

                // check if toUser exist
                var response = await CouchDBConnect.PostToDB(shareNoRev, "shares");

                // create the same file with diffrenet id
                string json = JsonConvert.SerializeObject(shareNoRev);
                await client.PublishAsync(json);

                Console.WriteLine(response);
                return("Image shared to " + sf.toUser + " successfully");
            }
            else
            {
                return("Please login first!");
            }
        }
示例#14
0
        public static async Task <InternalFile> GetFileItem(string virtualPath, AppDbContext dbContext, string userId,
                                                            ControllerBase controller)
        {
            string[] parts = Utils.SplitPath(virtualPath);
            if (!Guid.TryParse(parts[0], out Guid uuid))
            {
                throw (HttpResultException)controller.BadRequest("Can't parse uuid");
            }

            if (parts.Length == 1)
            {
                ShareFile shareFile = await dbContext.ShareFiles
                                      .Include(f => f.Permission)
                                      .FirstOrDefaultAsync(f => f.Uuid == uuid);

                if (shareFile == null || (shareFile.UserId != null && shareFile.UserId != userId))
                {
                    throw (HttpResultException)controller.NotFound("Share file not found.");
                }

                return(new InternalFile()
                {
                    PhysicalPath = shareFile.Path,
                    VirtualPath = virtualPath,
                    Name = shareFile.Name,
                    SharedId = shareFile.Uuid,
                    Permission = shareFile.Permission.ToFileItemPermission(),
                });
            }

            ShareFolder folder = await dbContext.ShareFolders
                                 .Include(f => f.Permission)
                                 .FirstOrDefaultAsync(f => f.Uuid == uuid);

            if (folder == null || (folder.UserId != null && folder.UserId != userId))
            {
                throw (HttpResultException)controller.NotFound("Share folder not found.");
            }

            IEnumerable <string> allPhysicalPathParts = new string[] { folder?.Path }.Concat(parts[1..]);
示例#15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="file"></param>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public List <byte[]> downloadShares(ShareFile file, int UserID)
        {
            //Local
            string content = "";
            string saveLoc = String.Format("{0}\\Storage\\{1}\\{2}.share", Environment.CurrentDirectory, UserID, file.ID);

            using (StreamReader reader = new StreamReader(@saveLoc))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();
                    if (line != "")
                    {
                        content = content + reader.ReadLine();
                    }
                }
            }

            List <byte[]> bShares = (List <byte[]>)JsonConvert.DeserializeObject(content);

            if (bShares == null)
            {
                //Azure
                List <byte[]>      shares    = new List <byte[]>();
                CloudBlobContainer container = this.getUsersContainer(UserID);
                CloudBlockBlob     blob      = container.GetBlockBlobReference(file.ID.ToString());
                long   arraySize             = blob.Properties.Length;
                byte[] data = new byte[50];
                blob.DownloadToByteArray(data, 0);
                shares.Add(data);
                return(shares);
            }
            foreach (byte[] b in bShares)
            {
                //Local
                bShares.Add(b);
            }
            return(bShares);
        }
示例#16
0
        public void CreateFile(string sharename, string filename, string accessToken, Action <string> urlCallback)
        {
            Console.WriteLine("CreateFile(sharename={0},filename={1},accessToken={2})", sharename, filename, accessToken);

            string jsonPayload = "{\"filename\": \"" + Path.GetFileName(filename).ToLower() + "\"}";

            _post <ShareFile>(string.Format("{0}/files/{1}/create?accesstoken={2}", API_URL, sharename, accessToken), jsonPayload, (success) => {
                Console.WriteLine("File sucessfully created: {0}", success);

                ShareFile sf = (success as ShareFile);

                if (urlCallback != null)
                {
                    urlCallback(sf.GetUrl);
                }

                PushFile(sf.Upload.PutUrl, new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read, 4 * 1024, false));
            }, (error) => {
                Console.WriteLine("Failed to create file: {0}", error);
            }
                              );
        }
        public ShareFile downloadFile(User user, ShareFile file)
        {
            ShareFile               share            = Database.getDB().FileDetails(user, file.ID);
            List <Share>            shares           = new List <Share>();
            int                     timeout          = 0;
            List <SharesThread>     threads          = new List <SharesThread>();
            List <StorageConnector> activeConnectors = new List <StorageConnector>();

            foreach (StorageConnector connector in this.connectors)
            {
                SharesThread st = new SharesThread(connector, file, user);
                threads.Add(st);
                Thread t = new Thread(new ThreadStart(st.ThreadRun));
                t.Start();
                t.Join();
            }
            while (shares.Count < file.t)
            {
                foreach (SharesThread st in threads)
                {
                    if (st.found == true)
                    {
                        timeout = 0;
                        foreach (byte[] b in st.shares)
                        {
                            shares.AddRange(this.byteToShare(b));
                        }
                    }
                }
            }
            //Convert.
            Facade f = new Facade(file.n, file.t, RandomSources.SHA1, Encryptors.AESGCM, Algorithms.CSS);

            file.file = f.join(shares.ToArray());
            return(file);
        }
示例#18
0
 public ShareFileRequest(ShareFile file)
 => File = file;
 public byte[] uploadFile(ShareFile file, User user, string ip)
 {
     Database.getDB().AddFileToDB(file, user, ip);
     file.shares = this.createShares(file);
     return(this.sendShares(file, user));
 }
示例#20
0
        private void SendPicButton_Click(object sender, RoutedEventArgs e)
        {
            RichTextBox stackrtb = new RichTextBox();

            stackrtb.SelectAll();
            stackrtb.Paste();
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = "Picture Files (*.bmp;*.jpg;*.jpeg;*.gif;*.png)|*.bmp;*.jpg;*.jpeg;*.gif;*.png";
            ofd.Multiselect = false;
            if (ofd.ShowDialog() == true)
            {
                String fname1 = "", fname2 = "";
                String url      = ofd.FileName;
                String fname    = ofd.SafeFileName;
                String localurl = (String)AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
                while (true)
                {
                    fname1 = "" + DateTime.Now;
                    for (int i = 0; i < fname1.Length; i++)
                    {
                        if (fname1.ElementAt(i).Equals('/') || fname1.ElementAt(i).Equals(' ') || fname1.ElementAt(i).Equals(':'))
                        {
                            fname1 = fname1.Substring(0, i) + "_" + fname1.Substring(i + 1, fname1.Length - i - 1);
                        }
                    }
                    Random rd   = new Random();
                    int    rand = rd.Next();
                    fname2 = rand.ToString();
                    if (!File.Exists(localurl + fname1 + fname2 + fname))
                    {
                        break;
                    }
                }
                try
                {
                    File.Copy(url, localurl + fname1 + fname2 + fname);
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.ToString());
                }
                url = localurl + fname1 + fname2 + fname;
                String tmp = ShareFile.Read(url);
                if (tmp.Length > 1000000)
                {
                    MessageBox.Show("图片太大,请以文件形式发送!");
                    stackrtb.SelectAll();
                    stackrtb.Copy();
                    return;
                }
                mw.SendMessage("sendimg", new string[] { key, tmp });
                SendPicButton.IsEnabled = false;

                Image       img  = new Image();
                BitmapImage bImg = new BitmapImage();
                img.IsEnabled = true;
                bImg.BeginInit();
                bImg.UriSource = new Uri(url, UriKind.Relative);
                bImg.EndInit();
                img.Source = bImg;

                RichTextBox rtb = msgRecRichTextBox;
                rtb.SelectAll();
                rtb.Copy();
                msgRecRichTextBox.SelectAll();
                msgRecRichTextBox.Paste();
                String      head = mw.NickName.Text + "  " + DateTime.Now;
                RichTextBox rtb2 = new RichTextBox();
                rtb2.AppendText(head);
                rtb2.SelectAll();
                rtb2.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.DarkGreen);
                rtb2.Copy();
                msgRecRichTextBox.Paste();
                new InlineUIContainer(img, msgRecRichTextBox.Selection.End); //插入图片到选定位置
                msgRecRichTextBox.AppendText("\r\n");
            }

            stackrtb.SelectAll();
            stackrtb.Copy();
        }
示例#21
0
 public ShareFileRequest(FileBase file)
 {
     ExperimentalFeatures.VerifyEnabled(ExperimentalFeatures.ShareFileRequest);
     File = new ShareFile(file);
 }
示例#22
0
 public ShareFileRequest(ShareFile file)
 {
     File = file;
 }
示例#23
0
 public ShareFileRequest(string title, ShareFile file)
 {
     Title = title;
     File  = file;
 }
 public static List <Share> CreateShares(ShareFile file)
 {
     sss.Facade f = new Facade(file.n, file.t, RandomSources.SHA1, Encryptors.AESGCM, Algorithms.CSS);
     return(f.split(file.file).ToList <Share>());
 }
 private void FileItem_ShareFile(object sender, EventArgs e)
 {
     ShareFile?.Invoke(sender, e);
 }
示例#26
0
 public ShareFileRequest(string title, ShareFile file)
 {
     ExperimentalFeatures.VerifyEnabled(ExperimentalFeatures.ShareFileRequest);
     Title = title;
     File  = file;
 }
示例#27
0
 public ShareFileRequest(string title, FileBase file)
 {
     Title = title;
     File  = new ShareFile(file);
 }
示例#28
0
 public ShareFileRequest(string title, FileBase file)
 {
     ExperimentalFeatures.VerifyEnabled(ExperimentalFeatures.ShareFileRequest);
     Title = title;
     File  = new ShareFile(file);
 }
示例#29
0
 public ShareFileRequest(FileBase file)
 {
     File = new ShareFile(file);
 }
示例#30
0
 public ShareFileRequest(ShareFile file)
 {
     ExperimentalFeatures.VerifyEnabled(ExperimentalFeatures.ShareFileRequest);
     File = file;
 }