public HttpResponseMessage GetOrDownload(HttpRequestMessage request, string route) { string origin = request.RequestUri.Scheme + "://" + request.RequestUri.Host; if (!request.RequestUri.IsDefaultPort) { origin += ":" + request.RequestUri.Port; } IEnumerable <KeyValuePair <string, string> > queryNameValuePairs = request.GetQueryNameValuePairs(); FileSystemObject fileSystemObject = new DriveRepository().Query(origin, route, queryNameValuePairs); if (fileSystemObject is FileObject) { string download = queryNameValuePairs.GetValue("download"); if (!string.IsNullOrWhiteSpace(download)) { if (download == "download" || download == "Download") { if (!fileSystemObject.Exists) { throw new FileNotFoundException(fileSystemObject.Path); } return(Download(fileSystemObject as FileObject)); } } } string accept = request.GetAccept(); if (accept == "xml") { XElement element = fileSystemObject.ToElement(); return(new HttpResponseMessage() { Content = new ObjectContent <XElement>(element, new XmlMediaTypeFormatter(), "application/xml") }); } else { return(new HttpResponseMessage() { Content = new ObjectContent <FileSystemObject>(fileSystemObject, new JsonMediaTypeFormatter(), "application/json") }); } }
private Application(string keyFile, string wotGameDirectory) { driveRepository = new DriveRepository(keyFile); store = new Store(".store\\settings.json"); this.wotGameDirectory = wotGameDirectory; }