Ejemplo n.º 1
0
        private void CopyResource(INetDriveService netdrive, string basePath, string targetFile)
        {
            var orgPath = Server.MapPath(targetFile);
            var file    = System.IO.Path.Combine(basePath, System.IO.Path.GetFileName(targetFile));

            if (System.IO.File.Exists(orgPath) && !System.IO.File.Exists(file))
            {
                System.IO.File.Copy(orgPath, file);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add attachment files.
        /// </summary>
        /// <param name="files">The http file collection.</param>
        /// <param name="service">The INetDriveService object.</param>
        public void AttachFiles(HttpFileCollectionBase files, INetDriveService service)
        {
            if (files.Count == 0)
            {
                return;
            }
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            var attchUri = Parent.AttachmentsPath;

            if (!service.Exists(attchUri))
            {
                service.CreatePath(attchUri);
            }

            var itemUri = new Uri(attchUri.ToString() + "/" + this.ID.ToString());

            if (!service.Exists(itemUri))
            {
                service.CreatePath(itemUri);
            }

            var itemPath = service.MapPath(itemUri);

            for (int i = 0; i < files.Count; i++)
            {
                var file = files[i];
                if (file.ContentLength > 0)
                {
                    var fileName = System.IO.Path.GetFileName(file.FileName);
                    file.SaveAs(itemPath + (!itemPath.EndsWith("\\") ? "\\" : "") + fileName);
                    var webFile = new WebResourceInfo(itemUri.ToString() + (!itemPath.EndsWith("\\") ? "\\" : "") + fileName);
                    var attach  = new ContentAttachment()
                    {
                        ContentType = webFile.ContentType,
                        Extension   = webFile.Extension,
                        ItemID      = this.ID,
                        Size        = file.ContentLength,
                        Name        = fileName,
                        Uri         = webFile.Url.ToString()
                    };
                    Context.Add(attach);
                }
            }
            Context.SaveChanges();

            Model.TotalAttachments = Context.Count <ContentAttachment>(c => c.ItemID.Equals(this.ID));
            this.TotalAttachments  = Model.TotalAttachments;

            Context.SaveChanges();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Remove the attachement files by specified attachment ids.
        /// </summary>
        /// <param name="attachmentIDs">The attachment id array.</param>
        /// <param name="service">The INetDriveService object.</param>
        public void DetachFiles(int[] attachmentIDs, INetDriveService service)
        {
            if (attachmentIDs == null)
            {
                throw new ArgumentNullException("attachmentIDs");
            }

            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            var attachs = Context.Where <ContentAttachment>(c => attachmentIDs.Contains(c.ID));

            foreach (var attach in attachs)
            {
                service.Delete(new Uri(attach.Uri));
                Context.Delete(attach);
            }

            Context.SaveChanges();
        }
Ejemplo n.º 4
0
 public WebFilesController(INetDriveService svc)
 {
     service = svc;
 }
Ejemplo n.º 5
0
 public static void Trigger(this INetDriveService netdrive, string eventName, object eventArg = null)
 {
     App.Trigger(eventName, netdrive, eventArg);
 }
Ejemplo n.º 6
0
        private void CopyResource(INetDriveService netdrive, string basePath, string targetFile)
        {
            var orgPath = Server.MapPath(targetFile);
            var file = System.IO.Path.Combine(basePath, System.IO.Path.GetFileName(targetFile));

            if (System.IO.File.Exists(orgPath) && !System.IO.File.Exists(file))
                System.IO.File.Copy(orgPath, file);
        }