private static void Require(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); NSJSString rawUri = arguments.Length > 0 ? arguments[0] as NSJSString : null; if (rawUri == null || rawUri.DateType != NSJSDataType.kString) { arguments.SetReturnValue(false); } else { NSJSVirtualMachine machine = arguments.VirtualMachine; NSJSObject global = machine.Global; string path = rawUri.Value; string source; if (string.IsNullOrEmpty(path)) { arguments.SetReturnValue(false); } else { int index = path.IndexOf('#'); if (index > -1) { path = path.Substring(0, index); } index = path.IndexOf('?'); if (index > -1) { path = path.Substring(0, index); } do { bool success = false; if (!FileAuxiliary.TryReadAllText(path, out source)) { if (!FileAuxiliary.TryReadAllText(Application.StartupPath + "/" + path, out source)) { arguments.SetReturnValue(false); break; } success = true; } if (!success) { if (!HttpAuxiliary.TryReadAllText(path, out source)) { arguments.SetReturnValue(false); break; } } if (File.Exists(path)) { path = Path.GetFullPath(path); } arguments.SetReturnValue(machine.Run(source, path)); } while (false); } } }
public static IEnumerable <string> GetAllSection(string path) { List <string> sections = new List <string>(); int len = FileAuxiliary.GetFileLength(path); if (len > 0) { char[] buffer = new char[len]; if ((len = GetPrivateProfileSectionNames(buffer, len, path)) > 0) { unsafe { fixed(char *str = buffer) { char *ptr = str; int index = 0, last = 0; while (index < len) { if (*ptr++ == '\0') { int size = index - last; char[] name = new char[size]; global::System.Array.Copy(buffer, last, name, 0, size); sections.Add(new string(name)); last = index + 1; } index++; } } } } } return(sections); }
private static void GetFileLength(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); string path = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null; arguments.SetReturnValue(FileAuxiliary.GetFileLength64(path)); }
private void SetContentLengthByFile(string path) { try { response.StatusCode = 500; if (File.Exists(path)) { response.StatusCode = 200; response.ContentLength = FileAuxiliary.GetFileLength(path); } } catch (Exception) { /*--A--*/ } }
public virtual string Run(FileInfo path, out NSJSException exception) { if (path == null) { throw new ArgumentNullException("path"); } if (!path.Exists) { throw new FileNotFoundException("path"); } byte[] source = File.ReadAllBytes(path.FullName); return(Run(FileAuxiliary.GetEncoding(source).GetString(source), path.FullName, out exception)); }
private unsafe void OpenFileViewAccessor(string path, Action <IntPtr, long, Action> callback) { if (callback == null || !File.Exists(path)) { response.StatusCode = 404; return; } MemoryMappedFile mmf = null; MemoryMappedViewAccessor mmva = null; Action closeMmf = () => { if (mmva != null) { mmva.Dispose(); mmva = null; } if (mmf != null) { mmf.Dispose(); mmf = null; } }; bool immediate_shutdown = false; try { mmf = MemoryMappedFile.CreateFromFile(path, FileMode.Open); long totalcount = FileAuxiliary.GetFileLength64(path); mmva = mmf.CreateViewAccessor(0, totalcount, MemoryMappedFileAccess.ReadWrite); SafeHandle handle = mmva.SafeMemoryMappedViewHandle; if (handle.IsInvalid) { immediate_shutdown = true; response.StatusCode = 503; } else { callback(handle.DangerousGetHandle(), totalcount, closeMmf); } } catch (Exception) { immediate_shutdown = true; response.StatusCode = 500; } if (immediate_shutdown) { closeMmf(); } }
public bool Handle() { int methodid = this.GetMethodId(); if (methodid != 1 && methodid != 3) { return(false); } string path = (application.Root + request.Url.LocalPath); if (string.IsNullOrEmpty(path)) { return(false); } path = Path.GetFullPath(path); if (!File.Exists(path)) { return(false); } string ext = Path.GetExtension(path); if (string.IsNullOrEmpty(ext)) { return(false); } try { response.ContentType = HttpContentTypeTable.Get(ext = ext.ToLower()); if (string.IsNullOrEmpty(response.ContentType)) { response.ContentType = "application/octet-stream"; } response.ContentEncoding = FileAuxiliary.GetEncoding(path); this.ProcessRequest(methodid, path); } catch (Exception) { return(false); } return(true); }
public static IEnumerable <KeyValuePair <string, string> > GetAllKeyValue(string path, string section) { List <KeyValuePair <string, string> > keyValues = new List <KeyValuePair <string, string> >(); int len = FileAuxiliary.GetFileLength(path); if (len > 0) { string buffer = new string('\0', len); if (GetPrivateProfileSection(section, ref buffer, len, path) > 0) { string[] items = buffer.Split('\0'); foreach (string str in items) { int i; if (str.Length > 0 && (i = str.IndexOf('=')) > -1) { keyValues.Add(new KeyValuePair <string, string>(str.Substring(0, i), str.Substring(i + 1))); } } } } return(keyValues); }