// POST /repository
        public async Task<HttpResponseMessage> Post()
        {
            if (!this.Request.Content.IsMimeMultipartContent("form-data"))
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            
            List<FileDescriptor> ret = new List<FileDescriptor>();

            using (var tmp = new TempDir())
            {
                MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(tmp.Path);

                var bodypart = await this.Request.Content.ReadAsMultipartAsync(provider);

                foreach (var fileName in provider.FileData)
                {
                    var fi = new FileInfo(fileName.LocalFileName);
                    try
                    {
                        var fd = FileDescriptor.Load(fi);

                        File.Copy(
                            fi.FullName,
                            Path.Combine(AppConfig.RepositoryPath, fi.Name));

                        ret.Add(fd);
                    }
                    catch (Exception ex)
                    {
                        // log
                        TraceSources.RepositoryControllerSource.TraceError(
                            "An exception of type {2} occured while processing '{0}': {1}",
                            fileName,
                            ex.ToString(),
                            ex.GetType().Name);
                        return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
                    }
                }

            }
            string reason = ret.Aggregate(
                                          new StringBuilder(),
                                          (builder, descriptor) =>
                                          (builder.Length == 0
                                               ? builder
                                               : builder.Append(", "))
                                              .AppendFormat(
                                                            "{{A:{0}, V:{1}}}",
                                                            descriptor.Assembly,
                                                            descriptor.Version),
                                          builder => builder.ToString());

            if (ret.Count > 0)
                ContentManager.Instance.QueueRebuild("Added assemblies: " + reason);

            return Request.CreateResponse(HttpStatusCode.Accepted, ret.AsEnumerable());

        }
        public ActionResult Upload(HttpPostedFileBase file)
        {
            string filename = Path.GetFileName(file.FileName);

            LostDocFileInfo fileInfo;
            using (TempDir tempDir = new TempDir(AppConfig.TempPath))
            {
                string tempLocation = Path.Combine(tempDir.Path, filename);
                file.SaveAs(tempLocation);

                fileInfo = new LostDocFileInfo(tempLocation);

                string targetFile = string.Format("{0}_{1}.ldoc", 
                                                  fileInfo.PrimaryAssembly.Filename, 
                                                  fileInfo.PrimaryAssembly.AssetId.Version);

                if (System.IO.File.Exists(Path.Combine(AppConfig.RepositoryPath, targetFile)))
                {
                    string message = string.Format("Unable to add file '{0}' as it already exists.", targetFile);
                    this.Notifications.Add(Severity.Error, 
                                                   Lifetime.Page, 
                                                   Scope.User, 
                                                   this.User, 
                                                   "Failed to upload file", 
                                                   message);
                }
                else
                {
                    System.IO.File.Move(tempLocation, Path.Combine(AppConfig.RepositoryPath, targetFile));

                    string message = string.Format("Successfully added file '{0}' (as '{1}') to repository.", filename, targetFile);
                    this.Notifications.Add(
                        Severity.Information, 
                        Lifetime.Page, 
                        Scope.User, 
                        this.User, 
                        "File uploaded", 
                        message);
                }
            }

            return this.RedirectToAction("Index");
        }