public bool Open(string path) { if (!string.IsNullOrEmpty(path)) { if (MiMFa_GetDetail.IsAbsoluteURL(path)) { Browse(path); return(true); } else { string mime = ""; try { mime = General.MiMFa_GetDetail.GetMimeFile(path).Split('/')[0].Trim().ToLower(); } catch { } if (mime == "image") { ShowBrowser(MiMFa_IOService.TryDeserialize(File.ReadAllBytes(path)), true); } else if (mime == "text") { ShowBrowser(MiMFa_StringService.ToHTML(MiMFa_IOService.FileToString(path))); } else if (mime == "") { Clear(); } else { bool b = General.MiMFa_GetDetail.IsBinaryFile(path); if (b) { string ext = System.IO.Path.GetExtension(path).ToLower(); if (ext == ".pdf" || ext.StartsWith(".doc") || ext.StartsWith(".xls") ) { OpenBrowser(path); } else { OpenMediaPlayer(path); } } else { ShowBrowser(MiMFa_IOService.FileToString(path)); } return(true); } } } else { Clear(); } return(false); }
public void Send(object data, MiMFa_SocketPacketDataType dt) { try { try { Send(new MiMFa_SimplePacket(MiMFa_SocketPacketSubject.Chat, data, dt)); SendData(data, Sender.InterlocutorIPEndPoint, 0); string detail = "<div class='DETAIL'>" + Configuration.Default.Time + "</div>"; string shtml = "<div style='text-align:right;'><div class='SEND'>"; string ehtml = "</div></div>"; if (data == null) { SetHTML(shtml + Display.Done(data) + detail + ehtml); } else if (data is byte[]) { switch (dt) { case MiMFa_SocketPacketDataType.None: break; case MiMFa_SocketPacketDataType.Image: SetHTML(shtml + Display.Done(MiMFa_IOService.TryDeserialize((byte[])data)) + detail + ehtml); break; case MiMFa_SocketPacketDataType.Text: SetHTML(shtml + Display.Done(data) + detail + ehtml); break; default: var mim = General.MiMFa_GetDetail.GetMimeObject(data).Split('/').First(); if (mim == "image") { SetHTML(shtml + Display.Done(General.MiMFa_Convert.ToImage((byte[])data)) + detail + ehtml); } else { SetHTML(shtml + Display.Done(data) + detail + ehtml); } break; } } else { SetHTML(shtml + Display.Done(data) + detail + ehtml); } } finally { InputClear(); } } catch (Exception ex) { SendError(RTB.Text, Sender.InterlocutorIPEndPoint, 0, ex); NotSendAlert(ex); } }
public object GetAttach() { if (Attach != null && Attach is byte[]) { return(MiMFa_IOService.TryDeserialize((byte[])Attach)); } else { return(Attach); } }
public object GetData() { if (GetDataType() == MiMFa_SocketPacketDataType.Image && Data != null && Data is byte[]) { return(General.MiMFa_Convert.ToImage((byte[])Data)); } else if (Data != null && Data is byte[]) { return(MiMFa_IOService.TryDeserialize((byte[])Data)); } else { return(Data); } }
private void Receiver_EndReceiveData(byte[] data, IPEndPoint ip, long length) { try { string str = MiMFa_IOService.TryDeserialize(data); if (File.Exists(str)) { AddressReceive(str); return; } else { throw new Exception("Is not address"); } } catch { DataReceive(data, ip, length); } }
public static string GetMimeObject(object obj) { if (obj == null) { return("null"); } try { if (obj is byte[]) { var o = MiMFa_IOService.TryDeserialize((byte[])obj); if (o is byte[]) { throw new Exception("unknown"); } else { return(GetMimeObject(o)); } } else { try { string typ = obj.GetType().Name.ToLower(); switch (typ) { case "string": case "int": case "uint": case "long": case "float": case "double": case "intptr": case "decimal": case "single": return("text/txt"); case "bitmap": return("image/png"); case "image": return("image/jpg"); case "icon": return("image/ico"); default: return(typ + "/data"); } } catch { string filename = Config.TempDirectory + "\\mimecheck"; MiMFa_IOService.SaveSerializeFile(filename, obj); return(GetMimeFile(filename)); } } } catch (Exception e) { return("unknown/unknown"); } }