示例#1
0
        public string SharePackage(string sender, string[] recipients, string packageCode, string[] tokens, string subject, string message)
        {
            Console.WriteLine("Sharing package from " + sender + " for package " + packageCode + " containing " + tokens.Length + " files");
            log.InfoFormat("Sharing package from \"{0}\"", sender);

            Package package = new Package() {
                Code = packageCode,
                SenderMail = sender,
                Message = subject + "\n" + message,
                Status = (char)PackageStatus.Open,
                Scanned = false,
                ExpiresAt = DateTime.UtcNow.AddDays(14),
                CreatedAt = DateTime.UtcNow
            };

            using (DataClassesDataContext db = new DataClassesDataContext()) {
                foreach (string fileHash in tokens) {
                    File f = new File() {
                        CreatedAt = DateTime.UtcNow,
                        FileHash = fileHash,
                        FileSize = 0/*Storage.GetFileSize(package.Code, fileHash)*/,
                        Package = package,
                    };
                    db.Files.InsertOnSubmit(f);
                }

                db.SubmitChanges();
            }

            string response = TransmitSettings.Instance.Setting.OutlookInjectedHtml ?? "Download: [TransmitUrl]/receive.aspx?h=[Package.Code]";
            response = response.Replace("[Package.Code]", packageCode);
            response = response.Replace("[TransmitUrl]", TransmitSettings.Instance.Setting.ExternalUrl);
            return response;
        }
示例#2
0
        protected void BtnShare_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request["Files[]"])) {
                ValidationError.Display(_("No files uploaded"));
            }

            if (!Page.IsValid) {
                (this.Master as SiteMasterPage).Flash(_("You did not provide files to share"));
                return;
            }

            string[] fileHashes = Request["Files[]"].Split(',');

            using (DataClassesDataContext db = new DataClassesDataContext()) {
                Package p = db.Packages.SingleOrDefault(pkg => pkg.Code == HfToken.Value);
                if (p == null) {
                    // FIXME: this "if" section should be removed once Flash code has been updated to files immediately as well
                    p = new Package() {
                        Code = HfToken.Value,
                        SenderMail = this.Invitation.RecipientMail,
                        Message = TbxMessage.Text,
                        Status = (char)PackageStatus.Open,
                        Scanned = false,
                        ExpiresAt = DateTime.Now.AddDays(14),
                        CreatedAt = DateTime.UtcNow
                    };

                    foreach (string fileHash in fileHashes) {
                        Commanigy.Transmit.Data.File f = new Commanigy.Transmit.Data.File() {
                            CreatedAt = DateTime.UtcNow,
                            FileHash = fileHash,
                            FileSize = Storage.GetFileSize(p.Code, fileHash),
                            Package = p,
                        };
                        db.Files.InsertOnSubmit(f);
                    }
                }
                else {
                    p.SenderMail = this.Invitation.RecipientMail;
                    p.Message = TbxMessage.Text;
                }

                db.SubmitChanges();
            }

            // get fresh copy of package
            Package package = Package.FindByCode(HfToken.Value);

            log.Debug("Packing files into ZIP archive for faster (initial) downloads by clients");
            new Thread(new ParameterizedThreadStart(delegate(object data) {
                Package uploadedPackage = data as Package;
                Storage.Pack(uploadedPackage.Code);
            })).Start(package);

            // generate unique token allowing recipient (requester) to download file
            string uniqueHash = package.Code;

            // look up user requesting files (this should always resolve to a user) unless that
            // user has been disabled before file has been uploaded
            AuthenticatedUser recipientUser = Locator.FindByMail(this.Invitation.SenderMail);

            Dictionary<string, string> tokens = new Dictionary<string, string>();
            tokens.Add("CompanyName", TransmitSettings.Instance.Setting.CompanyName);
            tokens.Add("Sender.Mail", this.Invitation.RecipientMail);
            tokens.Add("Sender.DisplayName", this.Invitation.RecipientDisplayName);
            tokens.Add("Recipient.Mail", this.Invitation.SenderMail);
            tokens.Add("Recipient.DisplayName", (recipientUser != null) ? recipientUser.DisplayName : this.Invitation.SenderDisplayName);
            tokens.Add("Mail.Message", TbxMessage.Text ?? string.Empty);
            tokens.Add("Package.Code", package.Code);
            tokens.Add("Package.Files", PackageHelper.FilesToMailHtml(package.Files.ToList()));
            tokens.Add("File.Location", string.Format("{0}/receive.aspx?h={1}", UserHelper.GetSiteUrl(recipientUser), uniqueHash));

            MailHelper.Send(TransmitSettings.Instance.Setting.UploadMailSubject, TransmitSettings.Instance.Setting.UploadMailBodyPlain, TransmitSettings.Instance.Setting.UploadMailBodyHtml, tokens);

            this.Response.Redirect("~/upload.success.aspx", true);
        }
示例#3
0
 partial void DeleteFile(File instance);
示例#4
0
 partial void UpdateFile(File instance);
示例#5
0
 partial void InsertFile(File instance);
示例#6
0
		private void detach_Files(File entity)
		{
			this.SendPropertyChanging();
			entity.Package = null;
		}
示例#7
0
		private void attach_Files(File entity)
		{
			this.SendPropertyChanging();
			entity.Package = this;
		}