Common.cs 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783
  1. // **********************************************************************************
  2. // CassiniDev - http://cassinidev.codeplex.com
  3. //
  4. // Copyright (c) 2010 Sky Sanders. All rights reserved.
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. //
  7. // This source code is subject to terms and conditions of the Microsoft Public
  8. // License (Ms-PL). A copy of the license can be found in the license.txt file
  9. // included in this distribution.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // **********************************************************************************
  14. #region
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Data;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Reflection;
  21. using System.Runtime.InteropServices;
  22. using System.Text;
  23. using System.Web.UI;
  24. #endregion
  25. namespace CassiniDev
  26. {
  27. internal static class CommonExtensions
  28. {
  29. public static string ConvertToHexView(this byte[] value, int numBytesPerRow)
  30. {
  31. if (value == null) return null;
  32. List<string> hexSplit = BitConverter.ToString(value)
  33. .Replace('-', ' ')
  34. .Trim()
  35. .SplitIntoChunks(numBytesPerRow*3)
  36. .ToList();
  37. int byteAddress = 0;
  38. StringBuilder sb = new StringBuilder();
  39. for (int i = 0; i < hexSplit.Count; i++)
  40. {
  41. sb.AppendLine(byteAddress.ToString("X4") + ":\t" + hexSplit[i]);
  42. byteAddress += numBytesPerRow;
  43. }
  44. return sb.ToString();
  45. }
  46. public static string GetAspVersion()
  47. {
  48. string version = null;
  49. try
  50. {
  51. Type type = typeof (Page);
  52. Assembly assembly = Assembly.GetAssembly(type);
  53. object[] customAttributes = assembly.GetCustomAttributes(typeof (AssemblyFileVersionAttribute), true);
  54. if ((customAttributes != null) && (customAttributes.GetLength(0) > 0))
  55. {
  56. version = ((AssemblyFileVersionAttribute) customAttributes[0]).Version;
  57. }
  58. else
  59. {
  60. version = assembly.GetName().Version.ToString();
  61. }
  62. }
  63. // ReSharper disable EmptyGeneralCatchClause
  64. catch
  65. // ReSharper restore EmptyGeneralCatchClause
  66. {
  67. }
  68. return version;
  69. }
  70. /// <summary>
  71. /// CassiniDev FIX: #12506
  72. /// </summary>
  73. /// <param name="fileName"></param>
  74. /// <returns></returns>
  75. public static string GetContentType(string fileName)
  76. {
  77. if (!File.Exists(fileName))
  78. {
  79. return null;
  80. }
  81. string contentType;
  82. FileInfo info = new FileInfo(fileName);
  83. string extension = info.Extension.ToLowerInvariant();
  84. switch (extension)
  85. {
  86. //NOTE: these are fallbacks - and should be refined as needed
  87. // Only if the request does not already know
  88. // the content-type will this switch be hit - meaning that
  89. // served content-types for extensions listed here may not match
  90. // as this method may not be polled.
  91. case ".svgz":
  92. contentType = "image/svg+xml";
  93. break;
  94. // from registry - last resort - verified mappings follow
  95. case ".3g2":
  96. contentType = "video/3gpp2";
  97. break;
  98. case ".3gp":
  99. contentType = "video/3gpp";
  100. break;
  101. case ".3gp2":
  102. contentType = "video/3gpp2";
  103. break;
  104. case ".3gpp":
  105. contentType = "video/3gpp";
  106. break;
  107. case ".adt":
  108. contentType = "audio/vnd.dlna.adts";
  109. break;
  110. case ".amr":
  111. contentType = "audio/AMR";
  112. break;
  113. case ".addin":
  114. contentType = "text/xml";
  115. break;
  116. case ".evr":
  117. contentType = "audio/evrc-qcp";
  118. break;
  119. case ".evrc":
  120. contentType = "audio/evrc-qcp";
  121. break;
  122. case ".ssisdeploymentmanifest":
  123. contentType = "text/xml";
  124. break;
  125. case ".xoml":
  126. contentType = "text/plain";
  127. break;
  128. case ".aac":
  129. contentType = "audio/aac";
  130. break;
  131. case ".ac3":
  132. contentType = "audio/ac3";
  133. break;
  134. case ".accda":
  135. contentType = "application/msaccess";
  136. break;
  137. case ".accdb":
  138. contentType = "application/msaccess";
  139. break;
  140. case ".accdc":
  141. contentType = "application/msaccess";
  142. break;
  143. case ".accde":
  144. contentType = "application/msaccess";
  145. break;
  146. case ".accdr":
  147. contentType = "application/msaccess";
  148. break;
  149. case ".accdt":
  150. contentType = "application/msaccess";
  151. break;
  152. case ".acrobatsecuritysettings":
  153. contentType = "application/vnd.adobe.acrobat-security-settings";
  154. break;
  155. case ".ad":
  156. contentType = "text/plain";
  157. break;
  158. case ".ade":
  159. contentType = "application/msaccess";
  160. break;
  161. case ".adobebridge":
  162. contentType = "application/x-bridge-url";
  163. break;
  164. case ".adp":
  165. contentType = "application/msaccess";
  166. break;
  167. case ".adts":
  168. contentType = "audio/vnd.dlna.adts";
  169. break;
  170. case ".amc":
  171. contentType = "application/x-mpeg";
  172. break;
  173. case ".application":
  174. contentType = "application/x-ms-application";
  175. break;
  176. case ".asa":
  177. contentType = "application/xml";
  178. break;
  179. case ".asax":
  180. contentType = "application/xml";
  181. break;
  182. case ".ascx":
  183. contentType = "application/xml";
  184. break;
  185. case ".ashx":
  186. contentType = "application/xml";
  187. break;
  188. case ".asm":
  189. contentType = "text/plain";
  190. break;
  191. case ".asmx":
  192. contentType = "application/xml";
  193. break;
  194. case ".aspx":
  195. contentType = "application/xml";
  196. break;
  197. case ".awf":
  198. contentType = "application/vnd.adobe.workflow";
  199. break;
  200. case ".biz":
  201. contentType = "text/xml";
  202. break;
  203. case ".c2r":
  204. contentType = "text/vnd-ms.click2record+xml";
  205. break;
  206. case ".caf":
  207. contentType = "audio/x-caf";
  208. break;
  209. case ".cc":
  210. contentType = "text/plain";
  211. break;
  212. case ".cd":
  213. contentType = "text/plain";
  214. break;
  215. case ".cdda":
  216. contentType = "audio/aiff";
  217. break;
  218. case ".config":
  219. contentType = "application/xml";
  220. break;
  221. case ".contact":
  222. contentType = "text/x-ms-contact";
  223. break;
  224. case ".coverage":
  225. contentType = "application/xml";
  226. break;
  227. case ".cpp":
  228. contentType = "text/plain";
  229. break;
  230. case ".cs":
  231. contentType = "text/plain";
  232. break;
  233. case ".csdproj":
  234. contentType = "text/plain";
  235. break;
  236. case ".csproj":
  237. contentType = "text/plain";
  238. break;
  239. case ".csv":
  240. contentType = "application/vnd.ms-excel";
  241. break;
  242. case ".cur":
  243. contentType = "text/plain";
  244. break;
  245. case ".cxx":
  246. contentType = "text/plain";
  247. break;
  248. case ".datasource":
  249. contentType = "application/xml";
  250. break;
  251. case ".dbproj":
  252. contentType = "text/plain";
  253. break;
  254. case ".dcd":
  255. contentType = "text/xml";
  256. break;
  257. case ".dd":
  258. contentType = "text/plain";
  259. break;
  260. case ".def":
  261. contentType = "text/plain";
  262. break;
  263. case ".design":
  264. contentType = "image/design";
  265. break;
  266. case ".dgml":
  267. contentType = "application/xml";
  268. break;
  269. case ".dib":
  270. contentType = "image/bmp";
  271. break;
  272. case ".dif":
  273. contentType = "video/x-dv";
  274. break;
  275. case ".docm":
  276. contentType = "application/vnd.ms-word.document.macroEnabled.12";
  277. break;
  278. case ".docx":
  279. contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
  280. break;
  281. case ".dotm":
  282. contentType = "application/vnd.ms-word.template.macroEnabled.12";
  283. break;
  284. case ".dotx":
  285. contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.template";
  286. break;
  287. case ".dsp":
  288. contentType = "text/plain";
  289. break;
  290. case ".dsprototype":
  291. contentType = "text/plain";
  292. break;
  293. case ".dsw":
  294. contentType = "text/plain";
  295. break;
  296. case ".dtd":
  297. contentType = "application/xml-dtd";
  298. break;
  299. case ".dtsconfig":
  300. contentType = "text/xml";
  301. break;
  302. case ".dv":
  303. contentType = "video/x-dv";
  304. break;
  305. case ".dwfx":
  306. contentType = "model/vnd.dwfx+xps";
  307. break;
  308. case ".easmx":
  309. contentType = "model/vnd.easmx+xps";
  310. break;
  311. case ".edrwx":
  312. contentType = "model/vnd.edrwx+xps";
  313. break;
  314. case ".eprtx":
  315. contentType = "model/vnd.eprtx+xps";
  316. break;
  317. case ".fdf":
  318. contentType = "application/vnd.fdf";
  319. break;
  320. case ".filters":
  321. contentType = "Application/xml";
  322. break;
  323. case ".flc":
  324. contentType = "video/flc";
  325. break;
  326. case ".fo":
  327. contentType = "text/xml";
  328. break;
  329. case ".fsscript":
  330. contentType = "application/fsharp-script";
  331. break;
  332. case ".fsx":
  333. contentType = "application/fsharp-script";
  334. break;
  335. case ".generictest":
  336. contentType = "application/xml";
  337. break;
  338. case ".group":
  339. contentType = "text/x-ms-group";
  340. break;
  341. case ".gsm":
  342. contentType = "audio/x-gsm";
  343. break;
  344. case ".hpp":
  345. contentType = "text/plain";
  346. break;
  347. case ".hxa":
  348. contentType = "application/xml";
  349. break;
  350. case ".hxc":
  351. contentType = "application/xml";
  352. break;
  353. case ".hxd":
  354. contentType = "application/octet-stream";
  355. break;
  356. case ".hxe":
  357. contentType = "application/xml";
  358. break;
  359. case ".hxf":
  360. contentType = "application/xml";
  361. break;
  362. case ".hxh":
  363. contentType = "application/octet-stream";
  364. break;
  365. case ".hxi":
  366. contentType = "application/octet-stream";
  367. break;
  368. case ".hxk":
  369. contentType = "application/xml";
  370. break;
  371. case ".hxq":
  372. contentType = "application/octet-stream";
  373. break;
  374. case ".hxr":
  375. contentType = "application/octet-stream";
  376. break;
  377. case ".hxs":
  378. contentType = "application/octet-stream";
  379. break;
  380. case ".hxt":
  381. contentType = "application/xml";
  382. break;
  383. case ".hxv":
  384. contentType = "application/xml";
  385. break;
  386. case ".hxw":
  387. contentType = "application/octet-stream";
  388. break;
  389. case ".hxx":
  390. contentType = "text/plain";
  391. break;
  392. case ".i":
  393. contentType = "text/plain";
  394. break;
  395. case ".idl":
  396. contentType = "text/plain";
  397. break;
  398. case ".inc":
  399. contentType = "text/plain";
  400. break;
  401. case ".inl":
  402. contentType = "text/plain";
  403. break;
  404. case ".ipproj":
  405. contentType = "text/plain";
  406. break;
  407. case ".iqy":
  408. contentType = "text/x-ms-iqy";
  409. break;
  410. case ".ismv":
  411. contentType = "video/ismv";
  412. break;
  413. case ".jsx":
  414. contentType = "text/plain";
  415. break;
  416. case ".jsxbin":
  417. contentType = "text/plain";
  418. break;
  419. case ".jtx":
  420. contentType = "application/x-jtx+xps";
  421. break;
  422. case ".ldd":
  423. contentType = "text/plain";
  424. break;
  425. case ".library-ms":
  426. contentType = "application/windows-library+xml";
  427. break;
  428. case ".loadtest":
  429. contentType = "application/xml";
  430. break;
  431. case ".lsaprototype":
  432. contentType = "text/plain";
  433. break;
  434. case ".lst":
  435. contentType = "text/plain";
  436. break;
  437. case ".m1v":
  438. contentType = "video/mpeg";
  439. break;
  440. case ".m2t":
  441. contentType = "video/vnd.dlna.mpeg-tts";
  442. break;
  443. case ".m2ts":
  444. contentType = "video/vnd.dlna.mpeg-tts";
  445. break;
  446. case ".m2v":
  447. contentType = "video/mpeg";
  448. break;
  449. case ".m4a":
  450. contentType = "audio/mp4";
  451. break;
  452. case ".m4b":
  453. contentType = "audio/x-m4b";
  454. break;
  455. case ".m4p":
  456. contentType = "audio/x-m4p";
  457. break;
  458. case ".m4v":
  459. contentType = "video/x-m4v";
  460. break;
  461. case ".mac":
  462. contentType = "image/x-macpaint";
  463. break;
  464. case ".mak":
  465. contentType = "text/plain";
  466. break;
  467. case ".map":
  468. contentType = "text/plain";
  469. break;
  470. case ".master":
  471. contentType = "application/xml";
  472. break;
  473. case ".mda":
  474. contentType = "application/msaccess";
  475. break;
  476. case ".mde":
  477. contentType = "application/msaccess";
  478. break;
  479. case ".mdp":
  480. contentType = "text/plain";
  481. break;
  482. case ".mfp":
  483. contentType = "application/x-shockwave-flash";
  484. break;
  485. case ".mk":
  486. contentType = "text/plain";
  487. break;
  488. case ".mod":
  489. contentType = "video/mpeg";
  490. break;
  491. case ".mp2v":
  492. contentType = "video/mpeg";
  493. break;
  494. case ".mp4":
  495. contentType = "video/mp4";
  496. break;
  497. case ".mp4v":
  498. contentType = "video/mp4";
  499. break;
  500. case ".mpf":
  501. contentType = "application/vnd.ms-mediapackage";
  502. break;
  503. case ".mqv":
  504. contentType = "video/quicktime";
  505. break;
  506. case ".mts":
  507. contentType = "video/vnd.dlna.mpeg-tts";
  508. break;
  509. case ".mtx":
  510. contentType = "application/xml";
  511. break;
  512. case ".mxp":
  513. contentType = "application/x-mmxp";
  514. break;
  515. case ".nix":
  516. contentType = "application/x-mix-transfer";
  517. break;
  518. case ".odc":
  519. contentType = "text/x-ms-odc";
  520. break;
  521. case ".odh":
  522. contentType = "text/plain";
  523. break;
  524. case ".odl":
  525. contentType = "text/plain";
  526. break;
  527. case ".odp":
  528. contentType = "application/vnd.oasis.opendocument.presentation";
  529. break;
  530. case ".ods":
  531. contentType = "application/vnd.oasis.opendocument.spreadsheet";
  532. break;
  533. case ".odt":
  534. contentType = "application/vnd.oasis.opendocument.text";
  535. break;
  536. case ".orderedtest":
  537. contentType = "application/xml";
  538. break;
  539. case ".osdx":
  540. contentType = "application/opensearchdescription+xml";
  541. break;
  542. case ".pct":
  543. contentType = "image/pict";
  544. break;
  545. case ".pcx":
  546. contentType = "image/x-pcx";
  547. break;
  548. case ".pdfxml":
  549. contentType = "application/vnd.adobe.pdfxml";
  550. break;
  551. case ".pdx":
  552. contentType = "application/vnd.adobe.pdx";
  553. break;
  554. case ".pic":
  555. contentType = "image/pict";
  556. break;
  557. case ".pict":
  558. contentType = "image/pict";
  559. break;
  560. case ".pkgdef":
  561. contentType = "text/plain";
  562. break;
  563. case ".pkgundef":
  564. contentType = "text/plain";
  565. break;
  566. case ".png":
  567. contentType = "image/png";
  568. break;
  569. case ".pnt":
  570. contentType = "image/x-macpaint";
  571. break;
  572. case ".pntg":
  573. contentType = "image/x-macpaint";
  574. break;
  575. case ".potm":
  576. contentType = "application/vnd.ms-powerpoint.template.macroEnabled.12";
  577. break;
  578. case ".potx":
  579. contentType = "application/vnd.openxmlformats-officedocument.presentationml.template";
  580. break;
  581. case ".ppa":
  582. contentType = "application/vnd.ms-powerpoint";
  583. break;
  584. case ".ppam":
  585. contentType = "application/vnd.ms-powerpoint.addin.macroEnabled.12";
  586. break;
  587. case ".ppsm":
  588. contentType = "application/vnd.ms-powerpoint.slideshow.macroEnabled.12";
  589. break;
  590. case ".ppsx":
  591. contentType = "application/vnd.openxmlformats-officedocument.presentationml.slideshow";
  592. break;
  593. case ".pptm":
  594. contentType = "application/vnd.ms-powerpoint.presentation.macroEnabled.12";
  595. break;
  596. case ".pptx":
  597. contentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
  598. break;
  599. case ".psc1":
  600. contentType = "application/PowerShell";
  601. break;
  602. case ".psess":
  603. contentType = "application/xml";
  604. break;
  605. case ".pwz":
  606. contentType = "application/vnd.ms-powerpoint";
  607. break;
  608. case ".pxr":
  609. contentType = "image/pxr";
  610. break;
  611. case ".qcp":
  612. contentType = "audio/vnd.qcelp";
  613. break;
  614. case ".qht":
  615. contentType = "text/x-html-insertion";
  616. break;
  617. case ".qhtm":
  618. contentType = "text/x-html-insertion";
  619. break;
  620. case ".qti":
  621. contentType = "image/x-quicktime";
  622. break;
  623. case ".qtif":
  624. contentType = "image/x-quicktime";
  625. break;
  626. case ".qtl":
  627. contentType = "application/x-quicktimeplayer";
  628. break;
  629. case ".rat":
  630. contentType = "application/rat-file";
  631. break;
  632. case ".raw":
  633. contentType = "application/octet-stream";
  634. break;
  635. case ".rc":
  636. contentType = "text/plain";
  637. break;
  638. case ".rc2":
  639. contentType = "text/plain";
  640. break;
  641. case ".rct":
  642. contentType = "text/plain";
  643. break;
  644. case ".rdf":
  645. contentType = "text/xml";
  646. break;
  647. case ".rdlc":
  648. contentType = "application/xml";
  649. break;
  650. case ".rels":
  651. contentType = "application/vnd.ms-package.relationships+xml";
  652. break;
  653. case ".resx":
  654. contentType = "application/xml";
  655. break;
  656. case ".rgs":
  657. contentType = "text/plain";
  658. break;
  659. case ".rjt":
  660. contentType = "application/vnd.rn-realsystem-rjt";
  661. break;
  662. case ".rm":
  663. contentType = "application/vnd.rn-realmedia";
  664. break;
  665. case ".rmf":
  666. contentType = "application/vnd.adobe.rmf";
  667. break;
  668. case ".rmj":
  669. contentType = "application/vnd.rn-realsystem-rmj";
  670. break;
  671. case ".rmm":
  672. contentType = "audio/x-pn-realaudio";
  673. break;
  674. case ".rmp":
  675. contentType = "application/vnd.rn-rn_music_package";
  676. break;
  677. case ".rms":
  678. contentType = "application/vnd.rn-realaudio-secure";
  679. break;
  680. case ".rmvb":
  681. contentType = "application/vnd.rn-realmedia-vbr";
  682. break;
  683. case ".rmx":
  684. contentType = "application/vnd.rn-realsystem-rmx";
  685. break;
  686. case ".rnx":
  687. contentType = "application/vnd.rn-realplayer";
  688. break;
  689. case ".rp":
  690. contentType = "image/vnd.rn-realpix";
  691. break;
  692. case ".rpm":
  693. contentType = "audio/x-pn-realaudio-plugin";
  694. break;
  695. case ".rqy":
  696. contentType = "text/x-ms-rqy";
  697. break;
  698. case ".rsml":
  699. contentType = "application/vnd.rn-rsml";
  700. break;
  701. case ".rt":
  702. contentType = "text/vnd.rn-realtext";
  703. break;
  704. case ".rtsp":
  705. contentType = "application/x-rtsp";
  706. break;
  707. case ".ruleset":
  708. contentType = "application/xml";
  709. break;
  710. case ".rv":
  711. contentType = "video/vnd.rn-realvideo";
  712. break;
  713. case ".s":
  714. contentType = "text/plain";
  715. break;
  716. case ".sd":
  717. contentType = "text/plain";
  718. break;
  719. case ".sd2":
  720. contentType = "audio/x-sd2";
  721. break;
  722. case ".sdm":
  723. contentType = "text/plain";
  724. break;
  725. case ".sdmdocument":
  726. contentType = "text/plain";
  727. break;
  728. case ".sdp":
  729. contentType = "application/sdp";
  730. break;
  731. case ".sdv":
  732. contentType = "video/sd-video";
  733. break;
  734. case ".searchConnector-ms":
  735. contentType = "application/windows-search-connector+xml";
  736. break;
  737. case ".settings":
  738. contentType = "application/xml";
  739. break;
  740. case ".sgi":
  741. contentType = "image/x-sgi";
  742. break;
  743. case ".shtml":
  744. contentType = "text/html";
  745. break;
  746. case ".sitemap":
  747. contentType = "application/xml";
  748. break;
  749. case ".skin":
  750. contentType = "application/xml";
  751. break;
  752. case ".sldm":
  753. contentType = "application/vnd.ms-powerpoint.slide.macroEnabled.12";
  754. break;
  755. case ".sldx":
  756. contentType = "application/vnd.openxmlformats-officedocument.presentationml.slide";
  757. break;
  758. case ".slk":
  759. contentType = "application/vnd.ms-excel";
  760. break;
  761. case ".sln":
  762. contentType = "text/plain";
  763. break;
  764. case ".slupkg-ms":
  765. contentType = "application/x-ms-license";
  766. break;
  767. case ".smi":
  768. contentType = "application/smil";
  769. break;
  770. case ".smil":
  771. contentType = "application/smil";
  772. break;
  773. case ".snippet":
  774. contentType = "application/xml";
  775. break;
  776. case ".sol":
  777. contentType = "text/plain";
  778. break;
  779. case ".sor":
  780. contentType = "text/plain";
  781. break;
  782. case ".srf":
  783. contentType = "text/plain";
  784. break;
  785. case ".svc":
  786. contentType = "application/xml";
  787. break;
  788. case ".tga":
  789. contentType = "image/x-targa";
  790. break;
  791. case ".targa":
  792. contentType = "image/x-targa";
  793. break;
  794. case ".testrunconfig":
  795. contentType = "application/xml";
  796. break;
  797. case ".testsettings":
  798. contentType = "application/xml";
  799. break;
  800. case ".thmx":
  801. contentType = "application/vnd.ms-officetheme";
  802. break;
  803. case ".tlh":
  804. contentType = "text/plain";
  805. break;
  806. case ".tli":
  807. contentType = "text/plain";
  808. break;
  809. case ".trx":
  810. contentType = "application/xml";
  811. break;
  812. case ".ts":
  813. contentType = "video/vnd.dlna.mpeg-tts";
  814. break;
  815. case ".tts":
  816. contentType = "video/vnd.dlna.mpeg-tts";
  817. break;
  818. case ".user":
  819. contentType = "text/plain";
  820. break;
  821. case ".vb":
  822. contentType = "text/plain";
  823. break;
  824. case ".vbdproj":
  825. contentType = "text/plain";
  826. break;
  827. case ".vbproj":
  828. contentType = "text/plain";
  829. break;
  830. case ".vcproj":
  831. contentType = "Application/xml";
  832. break;
  833. case ".vcxproj":
  834. contentType = "Application/xml";
  835. break;
  836. case ".vddproj":
  837. contentType = "text/plain";
  838. break;
  839. case ".vdp":
  840. contentType = "text/plain";
  841. break;
  842. case ".vdproj":
  843. contentType = "text/plain";
  844. break;
  845. case ".vdx":
  846. contentType = "application/vnd.visio";
  847. break;
  848. case ".vscontent":
  849. contentType = "application/xml";
  850. break;
  851. case ".vsct":
  852. contentType = "text/xml";
  853. break;
  854. case ".vsd":
  855. contentType = "application/vnd.visio";
  856. break;
  857. case ".vsi":
  858. contentType = "application/ms-vsi";
  859. break;
  860. case ".vsix":
  861. contentType = "application/vsix";
  862. break;
  863. case ".vsixlangpack":
  864. contentType = "text/xml";
  865. break;
  866. case ".vsixmanifest":
  867. contentType = "text/xml";
  868. break;
  869. case ".vsl":
  870. contentType = "application/vnd.visio";
  871. break;
  872. case ".vsmdi":
  873. contentType = "application/xml";
  874. break;
  875. case ".vspscc":
  876. contentType = "text/plain";
  877. break;
  878. case ".vss":
  879. contentType = "application/vnd.visio";
  880. break;
  881. case ".vsscc":
  882. contentType = "text/plain";
  883. break;
  884. case ".vssettings":
  885. contentType = "text/xml";
  886. break;
  887. case ".vssscc":
  888. contentType = "text/plain";
  889. break;
  890. case ".vst":
  891. contentType = "application/vnd.visio";
  892. break;
  893. case ".vstemplate":
  894. contentType = "text/xml";
  895. break;
  896. case ".vsto":
  897. contentType = "application/x-ms-vsto";
  898. break;
  899. case ".vsu":
  900. contentType = "application/vnd.visio";
  901. break;
  902. case ".vsw":
  903. contentType = "application/vnd.visio";
  904. break;
  905. case ".vsx":
  906. contentType = "application/vnd.visio";
  907. break;
  908. case ".vtx":
  909. contentType = "application/vnd.visio";
  910. break;
  911. case ".wax":
  912. contentType = "audio/x-ms-wax";
  913. break;
  914. case ".wbk":
  915. contentType = "application/msword";
  916. break;
  917. case ".wdp":
  918. contentType = "image/vnd.ms-photo";
  919. break;
  920. case ".webtest":
  921. contentType = "application/xml";
  922. break;
  923. case ".wiq":
  924. contentType = "application/xml";
  925. break;
  926. case ".wiz":
  927. contentType = "application/msword";
  928. break;
  929. case ".wm":
  930. contentType = "video/x-ms-wm";
  931. break;
  932. case ".wma":
  933. contentType = "audio/x-ms-wma";
  934. break;
  935. case ".wmd":
  936. contentType = "application/x-ms-wmd";
  937. break;
  938. case ".wmv":
  939. contentType = "video/x-ms-wmv";
  940. break;
  941. case ".wmx":
  942. contentType = "video/x-ms-wmx";
  943. break;
  944. case ".wmz":
  945. contentType = "application/x-ms-wmz";
  946. break;
  947. case ".wpl":
  948. contentType = "application/vnd.ms-wpl";
  949. break;
  950. case ".wsc":
  951. contentType = "text/scriptlet";
  952. break;
  953. case ".wsdl":
  954. contentType = "application/xml";
  955. break;
  956. case ".wvx":
  957. contentType = "video/x-ms-wvx";
  958. break;
  959. case ".xaml":
  960. contentType = "application/xaml+xml";
  961. break;
  962. case ".xbap":
  963. contentType = "application/x-ms-xbap";
  964. break;
  965. case ".xbrl":
  966. contentType = "text/xml";
  967. break;
  968. case ".xdp":
  969. contentType = "application/vnd.adobe.xdp+xml";
  970. break;
  971. case ".xdr":
  972. contentType = "application/xml";
  973. break;
  974. case ".xej":
  975. contentType = "application/xej+xml";
  976. break;
  977. case ".xel":
  978. contentType = "application/xel+xml";
  979. break;
  980. case ".xesc":
  981. contentType = "application/x-ms-wmv";
  982. break;
  983. case ".xfd":
  984. contentType = "application/vnd.adobe.xfd+xml";
  985. break;
  986. case ".xfdf":
  987. contentType = "application/vnd.adobe.xfdf";
  988. break;
  989. case ".xht":
  990. contentType = "application/xhtml+xml";
  991. break;
  992. case ".xhtml":
  993. contentType = "application/xhtml+xml";
  994. break;
  995. case ".xlam":
  996. contentType = "application/vnd.ms-excel.addin.macroEnabled.12";
  997. break;
  998. case ".xlk":
  999. contentType = "application/vnd.ms-excel";
  1000. break;
  1001. case ".xll":
  1002. contentType = "application/vnd.ms-excel";
  1003. break;
  1004. case ".xlsb":
  1005. contentType = "application/vnd.ms-excel.sheet.binary.macroEnabled.12";
  1006. break;
  1007. case ".xlsm":
  1008. contentType = "application/vnd.ms-excel.sheet.macroEnabled.12";
  1009. break;
  1010. case ".xlsx":
  1011. contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  1012. break;
  1013. case ".xltm":
  1014. contentType = "application/vnd.ms-excel.template.macroEnabled.12";
  1015. break;
  1016. case ".xltx":
  1017. contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.template";
  1018. break;
  1019. case ".xml":
  1020. contentType = "application/xml";
  1021. break;
  1022. case ".xmta":
  1023. contentType = "application/xml";
  1024. break;
  1025. case ".xpr":
  1026. contentType = "image/xpr";
  1027. break;
  1028. case ".xps":
  1029. contentType = "application/vnd.ms-xpsdocument";
  1030. break;
  1031. case ".xrm-ms":
  1032. contentType = "text/xml";
  1033. break;
  1034. case ".xsc":
  1035. contentType = "application/xml";
  1036. break;
  1037. case ".xsd":
  1038. contentType = "application/xml";
  1039. break;
  1040. case ".xsl":
  1041. contentType = "text/xml";
  1042. break;
  1043. case ".xslt":
  1044. contentType = "application/xml";
  1045. break;
  1046. case ".xss":
  1047. contentType = "application/xml";
  1048. break;
  1049. // standard mappings from http://www.w3schools.com/media/media_mimeref.asp
  1050. case ".323":
  1051. contentType = "text/h323";
  1052. break;
  1053. case ".acx":
  1054. contentType = "application/internet-property-stream";
  1055. break;
  1056. case ".ai":
  1057. contentType = "application/postscript";
  1058. break;
  1059. case ".aif":
  1060. contentType = "audio/x-aiff";
  1061. break;
  1062. case ".aifc":
  1063. contentType = "audio/x-aiff";
  1064. break;
  1065. case ".aiff":
  1066. contentType = "audio/x-aiff";
  1067. break;
  1068. case ".asf":
  1069. contentType = "video/x-ms-asf";
  1070. break;
  1071. case ".asr":
  1072. contentType = "video/x-ms-asf";
  1073. break;
  1074. case ".asx":
  1075. contentType = "video/x-ms-asf";
  1076. break;
  1077. case ".au":
  1078. contentType = "audio/basic";
  1079. break;
  1080. case ".avi":
  1081. contentType = "video/x-msvideo";
  1082. break;
  1083. case ".axs":
  1084. contentType = "application/olescript";
  1085. break;
  1086. case ".bas":
  1087. contentType = "text/plain";
  1088. break;
  1089. case ".bcpio":
  1090. contentType = "application/x-bcpio";
  1091. break;
  1092. case ".bin":
  1093. contentType = "application/octet-stream";
  1094. break;
  1095. case ".bmp":
  1096. contentType = "image/bmp";
  1097. break;
  1098. case ".c":
  1099. contentType = "text/plain";
  1100. break;
  1101. case ".cat":
  1102. contentType = "application/vnd.ms-pkiseccat";
  1103. break;
  1104. case ".cdf":
  1105. contentType = "application/x-cdf";
  1106. break;
  1107. case ".cer":
  1108. contentType = "application/x-x509-ca-cert";
  1109. break;
  1110. case ".class":
  1111. contentType = "application/octet-stream";
  1112. break;
  1113. case ".clp":
  1114. contentType = "application/x-msclip";
  1115. break;
  1116. case ".cmx":
  1117. contentType = "image/x-cmx";
  1118. break;
  1119. case ".cod":
  1120. contentType = "image/cis-cod";
  1121. break;
  1122. case ".cpio":
  1123. contentType = "application/x-cpio";
  1124. break;
  1125. case ".crd":
  1126. contentType = "application/x-mscardfile";
  1127. break;
  1128. case ".crl":
  1129. contentType = "application/pkix-crl";
  1130. break;
  1131. case ".crt":
  1132. contentType = "application/x-x509-ca-cert";
  1133. break;
  1134. case ".csh":
  1135. contentType = "application/x-csh";
  1136. break;
  1137. case ".css":
  1138. contentType = "text/css";
  1139. break;
  1140. case ".dcr":
  1141. contentType = "application/x-director";
  1142. break;
  1143. case ".der":
  1144. contentType = "application/x-x509-ca-cert";
  1145. break;
  1146. case ".dir":
  1147. contentType = "application/x-director";
  1148. break;
  1149. case ".dll":
  1150. contentType = "application/x-msdownload";
  1151. break;
  1152. case ".dms":
  1153. contentType = "application/octet-stream";
  1154. break;
  1155. case ".doc":
  1156. contentType = "application/msword";
  1157. break;
  1158. case ".dot":
  1159. contentType = "application/msword";
  1160. break;
  1161. case ".dvi":
  1162. contentType = "application/x-dvi";
  1163. break;
  1164. case ".dxr":
  1165. contentType = "application/x-director";
  1166. break;
  1167. case ".eps":
  1168. contentType = "application/postscript";
  1169. break;
  1170. case ".etx":
  1171. contentType = "text/x-setext";
  1172. break;
  1173. case ".evy":
  1174. contentType = "application/envoy";
  1175. break;
  1176. case ".exe":
  1177. contentType = "application/octet-stream";
  1178. break;
  1179. case ".fif":
  1180. contentType = "application/fractals";
  1181. break;
  1182. case ".flr":
  1183. contentType = "x-world/x-vrml";
  1184. break;
  1185. case ".gif":
  1186. contentType = "image/gif";
  1187. break;
  1188. case ".gtar":
  1189. contentType = "application/x-gtar";
  1190. break;
  1191. case ".gz":
  1192. contentType = "application/x-gzip";
  1193. break;
  1194. case ".h":
  1195. contentType = "text/plain";
  1196. break;
  1197. case ".hdf":
  1198. contentType = "application/x-hdf";
  1199. break;
  1200. case ".hlp":
  1201. contentType = "application/winhlp";
  1202. break;
  1203. case ".hqx":
  1204. contentType = "application/mac-binhex40";
  1205. break;
  1206. case ".hta":
  1207. contentType = "application/hta";
  1208. break;
  1209. case ".htc":
  1210. contentType = "text/x-component";
  1211. break;
  1212. case ".htm":
  1213. contentType = "text/html";
  1214. break;
  1215. case ".html":
  1216. contentType = "text/html";
  1217. break;
  1218. case ".htt":
  1219. contentType = "text/webviewhtml";
  1220. break;
  1221. case ".ico":
  1222. contentType = "image/x-icon";
  1223. break;
  1224. case ".ief":
  1225. contentType = "image/ief";
  1226. break;
  1227. case ".iii":
  1228. contentType = "application/x-iphone";
  1229. break;
  1230. case ".ins":
  1231. contentType = "application/x-internet-signup";
  1232. break;
  1233. case ".isp":
  1234. contentType = "application/x-internet-signup";
  1235. break;
  1236. case ".jfif":
  1237. contentType = "image/pipeg";
  1238. break;
  1239. case ".jpe":
  1240. contentType = "image/jpeg";
  1241. break;
  1242. case ".jpeg":
  1243. contentType = "image/jpeg";
  1244. break;
  1245. case ".jpg":
  1246. contentType = "image/jpeg";
  1247. break;
  1248. case ".js":
  1249. contentType = "application/x-javascript";
  1250. break;
  1251. case ".latex":
  1252. contentType = "application/x-latex";
  1253. break;
  1254. case ".lha":
  1255. contentType = "application/octet-stream";
  1256. break;
  1257. case ".lsf":
  1258. contentType = "video/x-la-asf";
  1259. break;
  1260. case ".lsx":
  1261. contentType = "video/x-la-asf";
  1262. break;
  1263. case ".lzh":
  1264. contentType = "application/octet-stream";
  1265. break;
  1266. case ".m13":
  1267. contentType = "application/x-msmediaview";
  1268. break;
  1269. case ".m14":
  1270. contentType = "application/x-msmediaview";
  1271. break;
  1272. case ".m3u":
  1273. contentType = "audio/x-mpegurl";
  1274. break;
  1275. case ".man":
  1276. contentType = "application/x-troff-man";
  1277. break;
  1278. case ".mdb":
  1279. contentType = "application/x-msaccess";
  1280. break;
  1281. case ".me":
  1282. contentType = "application/x-troff-me";
  1283. break;
  1284. case ".mht":
  1285. contentType = "message/rfc822";
  1286. break;
  1287. case ".mhtml":
  1288. contentType = "message/rfc822";
  1289. break;
  1290. case ".mid":
  1291. contentType = "audio/mid";
  1292. break;
  1293. case ".mny":
  1294. contentType = "application/x-msmoney";
  1295. break;
  1296. case ".mov":
  1297. contentType = "video/quicktime";
  1298. break;
  1299. case ".movie":
  1300. contentType = "video/x-sgi-movie";
  1301. break;
  1302. case ".mp2":
  1303. contentType = "video/mpeg";
  1304. break;
  1305. case ".mp3":
  1306. contentType = "audio/mpeg";
  1307. break;
  1308. case ".mpa":
  1309. contentType = "video/mpeg";
  1310. break;
  1311. case ".mpe":
  1312. contentType = "video/mpeg";
  1313. break;
  1314. case ".mpeg":
  1315. contentType = "video/mpeg";
  1316. break;
  1317. case ".mpg":
  1318. contentType = "video/mpeg";
  1319. break;
  1320. case ".mpp":
  1321. contentType = "application/vnd.ms-project";
  1322. break;
  1323. case ".mpv2":
  1324. contentType = "video/mpeg";
  1325. break;
  1326. case ".ms":
  1327. contentType = "application/x-troff-ms";
  1328. break;
  1329. case ".msg":
  1330. contentType = "application/vnd.ms-outlook";
  1331. break;
  1332. case ".mvb":
  1333. contentType = "application/x-msmediaview";
  1334. break;
  1335. case ".nc":
  1336. contentType = "application/x-netcdf";
  1337. break;
  1338. case ".nws":
  1339. contentType = "message/rfc822";
  1340. break;
  1341. case ".oda":
  1342. contentType = "application/oda";
  1343. break;
  1344. case ".p10":
  1345. contentType = "application/pkcs10";
  1346. break;
  1347. case ".p12":
  1348. contentType = "application/x-pkcs12";
  1349. break;
  1350. case ".p7b":
  1351. contentType = "application/x-pkcs7-certificates";
  1352. break;
  1353. case ".p7c":
  1354. contentType = "application/x-pkcs7-mime";
  1355. break;
  1356. case ".p7m":
  1357. contentType = "application/x-pkcs7-mime";
  1358. break;
  1359. case ".p7r":
  1360. contentType = "application/x-pkcs7-certreqresp";
  1361. break;
  1362. case ".p7s":
  1363. contentType = "application/x-pkcs7-signature";
  1364. break;
  1365. case ".pbm":
  1366. contentType = "image/x-portable-bitmap";
  1367. break;
  1368. case ".pdf":
  1369. contentType = "application/pdf";
  1370. break;
  1371. case ".pfx":
  1372. contentType = "application/x-pkcs12";
  1373. break;
  1374. case ".pgm":
  1375. contentType = "image/x-portable-graymap";
  1376. break;
  1377. case ".pko":
  1378. contentType = "application/ynd.ms-pkipko";
  1379. break;
  1380. case ".pma":
  1381. contentType = "application/x-perfmon";
  1382. break;
  1383. case ".pmc":
  1384. contentType = "application/x-perfmon";
  1385. break;
  1386. case ".pml":
  1387. contentType = "application/x-perfmon";
  1388. break;
  1389. case ".pmr":
  1390. contentType = "application/x-perfmon";
  1391. break;
  1392. case ".pmw":
  1393. contentType = "application/x-perfmon";
  1394. break;
  1395. case ".pnm":
  1396. contentType = "image/x-portable-anymap";
  1397. break;
  1398. case ".pot":
  1399. contentType = "application/vnd.ms-powerpoint";
  1400. break;
  1401. case ".pot,":
  1402. contentType = "application/vnd.ms-powerpoint";
  1403. break;
  1404. case ".ppm":
  1405. contentType = "image/x-portable-pixmap";
  1406. break;
  1407. case ".pps":
  1408. contentType = "application/vnd.ms-powerpoint";
  1409. break;
  1410. case ".ppt":
  1411. contentType = "application/vnd.ms-powerpoint";
  1412. break;
  1413. case ".prf":
  1414. contentType = "application/pics-rules";
  1415. break;
  1416. case ".ps":
  1417. contentType = "application/postscript";
  1418. break;
  1419. case ".pub":
  1420. contentType = "application/x-mspublisher";
  1421. break;
  1422. case ".qt":
  1423. contentType = "video/quicktime";
  1424. break;
  1425. case ".ra":
  1426. contentType = "audio/x-pn-realaudio";
  1427. break;
  1428. case ".ram":
  1429. contentType = "audio/x-pn-realaudio";
  1430. break;
  1431. case ".ras":
  1432. contentType = "image/x-cmu-raster";
  1433. break;
  1434. case ".rgb":
  1435. contentType = "image/x-rgb";
  1436. break;
  1437. case ".rmi":
  1438. contentType = "audio/mid";
  1439. break;
  1440. case ".roff":
  1441. contentType = "application/x-troff";
  1442. break;
  1443. case ".rtf":
  1444. contentType = "application/rtf";
  1445. break;
  1446. case ".rtx":
  1447. contentType = "text/richtext";
  1448. break;
  1449. case ".scd":
  1450. contentType = "application/x-msschedule";
  1451. break;
  1452. case ".sct":
  1453. contentType = "text/scriptlet";
  1454. break;
  1455. case ".setpay":
  1456. contentType = "application/set-payment-initiation";
  1457. break;
  1458. case ".setreg":
  1459. contentType = "application/set-registration-initiation";
  1460. break;
  1461. case ".sh":
  1462. contentType = "application/x-sh";
  1463. break;
  1464. case ".shar":
  1465. contentType = "application/x-shar";
  1466. break;
  1467. case ".sit":
  1468. contentType = "application/x-stuffit";
  1469. break;
  1470. case ".snd":
  1471. contentType = "audio/basic";
  1472. break;
  1473. case ".spc":
  1474. contentType = "application/x-pkcs7-certificates";
  1475. break;
  1476. case ".spl":
  1477. contentType = "application/futuresplash";
  1478. break;
  1479. case ".src":
  1480. contentType = "application/x-wais-source";
  1481. break;
  1482. case ".sst":
  1483. contentType = "application/vnd.ms-pkicertstore";
  1484. break;
  1485. case ".stl":
  1486. contentType = "application/vnd.ms-pkistl";
  1487. break;
  1488. case ".stm":
  1489. contentType = "text/html";
  1490. break;
  1491. case ".sv4cpio":
  1492. contentType = "application/x-sv4cpio";
  1493. break;
  1494. case ".sv4crc":
  1495. contentType = "application/x-sv4crc";
  1496. break;
  1497. case ".svg":
  1498. contentType = "image/svg+xml";
  1499. break;
  1500. case ".swf":
  1501. contentType = "application/x-shockwave-flash";
  1502. break;
  1503. case ".t":
  1504. contentType = "application/x-troff";
  1505. break;
  1506. case ".tar":
  1507. contentType = "application/x-tar";
  1508. break;
  1509. case ".tcl":
  1510. contentType = "application/x-tcl";
  1511. break;
  1512. case ".tex":
  1513. contentType = "application/x-tex";
  1514. break;
  1515. case ".texi":
  1516. contentType = "application/x-texinfo";
  1517. break;
  1518. case ".texinfo":
  1519. contentType = "application/x-texinfo";
  1520. break;
  1521. case ".tgz":
  1522. contentType = "application/x-compressed";
  1523. break;
  1524. case ".tif":
  1525. contentType = "image/tiff";
  1526. break;
  1527. case ".tiff":
  1528. contentType = "image/tiff";
  1529. break;
  1530. case ".tr":
  1531. contentType = "application/x-troff";
  1532. break;
  1533. case ".trm":
  1534. contentType = "application/x-msterminal";
  1535. break;
  1536. case ".tsv":
  1537. contentType = "text/tab-separated-values";
  1538. break;
  1539. case ".txt":
  1540. contentType = "text/plain";
  1541. break;
  1542. case ".uls":
  1543. contentType = "text/iuls";
  1544. break;
  1545. case ".ustar":
  1546. contentType = "application/x-ustar";
  1547. break;
  1548. case ".vcf":
  1549. contentType = "text/x-vcard";
  1550. break;
  1551. case ".vrml":
  1552. contentType = "x-world/x-vrml";
  1553. break;
  1554. case ".wav":
  1555. contentType = "audio/x-wav";
  1556. break;
  1557. case ".wcm":
  1558. contentType = "application/vnd.ms-works";
  1559. break;
  1560. case ".wdb":
  1561. contentType = "application/vnd.ms-works";
  1562. break;
  1563. case ".wks":
  1564. contentType = "application/vnd.ms-works";
  1565. break;
  1566. case ".wmf":
  1567. contentType = "application/x-msmetafile";
  1568. break;
  1569. case ".wps":
  1570. contentType = "application/vnd.ms-works";
  1571. break;
  1572. case ".wri":
  1573. contentType = "application/x-mswrite";
  1574. break;
  1575. case ".wrl":
  1576. contentType = "x-world/x-vrml";
  1577. break;
  1578. case ".wrz":
  1579. contentType = "x-world/x-vrml";
  1580. break;
  1581. case ".xaf":
  1582. contentType = "x-world/x-vrml";
  1583. break;
  1584. case ".xbm":
  1585. contentType = "image/x-xbitmap";
  1586. break;
  1587. case ".xla":
  1588. contentType = "application/vnd.ms-excel";
  1589. break;
  1590. case ".xlc":
  1591. contentType = "application/vnd.ms-excel";
  1592. break;
  1593. case ".xlm":
  1594. contentType = "application/vnd.ms-excel";
  1595. break;
  1596. case ".xls":
  1597. contentType = "application/vnd.ms-excel";
  1598. break;
  1599. case ".xlt":
  1600. contentType = "application/vnd.ms-excel";
  1601. break;
  1602. case ".xlw":
  1603. contentType = "application/vnd.ms-excel";
  1604. break;
  1605. case ".xof":
  1606. contentType = "x-world/x-vrml";
  1607. break;
  1608. case ".xpm":
  1609. contentType = "image/x-xpixmap";
  1610. break;
  1611. case ".xwd":
  1612. contentType = "image/x-xwindowdump";
  1613. break;
  1614. case ".z":
  1615. contentType = "application/x-compress";
  1616. break;
  1617. case ".zip":
  1618. contentType = "application/zip";
  1619. break;
  1620. default:
  1621. // this should be used as a last resort only. i.e. svg files return text/xml
  1622. contentType = GetMimeFromFile(fileName);
  1623. break;
  1624. }
  1625. return contentType;
  1626. }
  1627. public static T GetValueOrDefault<T>(this IDataRecord row, string fieldName)
  1628. {
  1629. int ordinal = row.GetOrdinal(fieldName);
  1630. return row.GetValueOrDefault<T>(ordinal);
  1631. }
  1632. public static T GetValueOrDefault<T>(this IDataRecord row, int ordinal)
  1633. {
  1634. return (T) (row.IsDBNull(ordinal) ? default(T) : row.GetValue(ordinal));
  1635. }
  1636. public static byte[] StreamToBytes(this Stream input)
  1637. {
  1638. int capacity = input.CanSeek ? (int) input.Length : 0;
  1639. using (MemoryStream output = new MemoryStream(capacity))
  1640. {
  1641. int readLength;
  1642. byte[] buffer = new byte[4096];
  1643. do
  1644. {
  1645. readLength = input.Read(buffer, 0, buffer.Length);
  1646. output.Write(buffer, 0, readLength);
  1647. } while (readLength != 0);
  1648. return output.ToArray();
  1649. }
  1650. }
  1651. /// <summary>
  1652. /// CassiniDev FIX: #12506
  1653. /// </summary>
  1654. /// <param name="file"></param>
  1655. /// <returns></returns>
  1656. private static string GetMimeFromFile(string file)
  1657. {
  1658. IntPtr mimeout;
  1659. if (!File.Exists(file))
  1660. return null;
  1661. //throw new FileNotFoundException(file + " not found");
  1662. int maxContent = (int) new FileInfo(file).Length;
  1663. if (maxContent > 4096) maxContent = 4096;
  1664. FileStream fs = File.OpenRead(file);
  1665. byte[] buf = new byte[maxContent];
  1666. fs.Read(buf, 0, maxContent);
  1667. fs.Close();
  1668. int result = Interop.FindMimeFromData(IntPtr.Zero, file, buf, maxContent, null, 0, out mimeout, 0);
  1669. if (result != 0)
  1670. throw Marshal.GetExceptionForHR(result);
  1671. string mime = Marshal.PtrToStringUni(mimeout);
  1672. Marshal.FreeCoTaskMem(mimeout);
  1673. return mime;
  1674. }
  1675. private static IList<string> SplitIntoChunks(this string text, int chunkSize)
  1676. {
  1677. List<string> chunks = new List<string>();
  1678. int offset = 0;
  1679. while (offset < text.Length)
  1680. {
  1681. int size = Math.Min(chunkSize, text.Length - offset);
  1682. chunks.Add(text.Substring(offset, size));
  1683. offset += size;
  1684. }
  1685. return chunks;
  1686. }
  1687. }
  1688. public enum RunState
  1689. {
  1690. Idle = 0,
  1691. Running
  1692. }
  1693. public enum PortMode
  1694. {
  1695. FirstAvailable = 0,
  1696. Specific
  1697. }
  1698. public enum ErrorField
  1699. {
  1700. None,
  1701. ApplicationPath,
  1702. VirtualPath,
  1703. HostName,
  1704. IsAddHost,
  1705. IPAddress,
  1706. IPAddressAny,
  1707. IPAddressLoopBack,
  1708. Port,
  1709. PortRangeStart,
  1710. PortRangeEnd,
  1711. PortRange
  1712. }
  1713. public enum IPMode
  1714. {
  1715. Loopback = 0,
  1716. Any,
  1717. Specific
  1718. }
  1719. public enum RunMode
  1720. {
  1721. Server,
  1722. Hostsfile
  1723. }
  1724. internal class CassiniException : Exception
  1725. {
  1726. public CassiniException(string message, ErrorField field, Exception innerException)
  1727. : base(message, innerException)
  1728. {
  1729. Field = field;
  1730. }
  1731. public CassiniException(string message, ErrorField field)
  1732. : this(message, field, null)
  1733. {
  1734. }
  1735. public ErrorField Field { get; set; }
  1736. }
  1737. }