Beispiel #1
0
        public void Execute(Attachment file, ImageMeta meta, NameValueCollection Parameters, Driver driver, string savedName, AttachmentUploadHandler handler)
        {
            this.handler = handler;
            this.driver  = driver;


            file.file_size       = file.RawData.Count;
            file.modify_time     = DateTime.UtcNow;
            file.url             = "/v2/attachments/view/?object_id=" + file.object_id;
            file.saved_file_name = savedName;

            BeforeSaveAttachment(file, Parameters, meta);
            new FileStorage(driver).SaveFile(savedName, file.RawData);
            SaveAttachmentInfoToDB(file, meta, savedName);

            AttachmentEventArgs aEvtArgs = new AttachmentEventArgs
            {
                Attachment = file,
                Driver     = driver
            };

            ImageAttachmentEventArgs evtArgs = new ImageAttachmentEventArgs
            {
                Attachment       = file,
                Meta             = meta,
                UserApiKey       = Parameters["apikey"],
                UserSessionToken = Parameters["session_token"],
                Driver           = driver
            };

            handler.OnAttachmentSaved(aEvtArgs);
            handler.OnImageAttachmentSaved(evtArgs);

            HttpHelper.RespondSuccess(handler.Response, ObjectUploadResponse.CreateSuccess(file.object_id));

            handler.OnImageAttachmentCompleted(evtArgs);
        }
Beispiel #2
0
        public void Execute(Attachment file, ImageMeta meta, NameValueCollection Parameters, Driver driver, string savedName, AttachmentUploadHandler handler)
        {
            file.file_size       = file.RawData.Count;
            file.modify_time     = DateTime.UtcNow;
            file.url             = "/v2/attachments/view/?object_id=" + file.object_id;
            file.saved_file_name = savedName;

            file.Upload(meta, Parameters["apikey"], Parameters["session_token"]);
            new FileStorage(driver).SaveAttachment(file);



            BsonDocument dbDoc    = CreateDbDocument(file, meta, savedName);
            BsonDocument existDoc = AttachmentCollection.Instance.FindOneAs <BsonDocument>(
                new QueryDocument("_id", file.object_id));

            if (existDoc != null)
            {
                existDoc.DeepMerge(dbDoc);
                AttachmentCollection.Instance.Save(existDoc);
            }
            else
            {
                AttachmentCollection.Instance.Save(dbDoc);
            }

            AttachmentEventArgs aEvtArgs = new AttachmentEventArgs
            {
                Attachment = file,
                Driver     = driver
            };

            handler.OnAttachmentSaved(aEvtArgs);
            HttpHelper.RespondSuccess(handler.Response, ObjectUploadResponse.CreateSuccess(file.object_id));
        }