Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        public void OnAttachmentSaved(AttachmentEventArgs evt)
        {
            EventHandler <AttachmentEventArgs> handler = AttachmentSaved;

            if (handler != null)
            {
                handler(this, evt);
            }
        }
        public void HandleAttachmentSaved(object sender, AttachmentEventArgs evt)
        {
            if (evt.Attachment.saved_file_name == null)             // this attachment is a thumbnail
            {
                return;
            }

            // just for avoiding race condition, might cause bad performance
            lock (cs)
            {
                CloudStorage cloudstorage = CloudStorageCollection.Instance.FindOne(Query.EQ("Type", "dropbox"));
                if (cloudstorage != null)
                {
                    logger.DebugFormat("Trying to backup file {0} to Dropbox", evt.Attachment.saved_file_name);
                    new DropboxFileStorage(evt.Driver, cloudstorage).SaveAttachment(evt.Attachment);
                }
            }
        }
Ejemplo n.º 4
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);
        }