public void SocketSend(object obj) { if (InterlocutorIP == null && !string.IsNullOrEmpty(InterlocutorHostName)) { try { InterlocutorIP = IPAddress.Parse(InterlocutorHostName); } catch { try { InterlocutorIP = MiMFa_Net.GetExternalIP(InterlocutorHostName); } catch { } } } if (InterlocutorIP != null) { TcpClient client = new TcpClient(); client.Connect(InterlocutorIP, Port); ConnectedToInterlocutor(InterlocutorIPEndPoint); Stream stream = client.GetStream(); StartUploadData(obj, InterlocutorIPEndPoint, 0); byte[] bytarr = (obj != null && obj is byte[]) ? (byte[])obj : MiMFa_IOService.Serialize(obj); stream.Write(bytarr, 0, bytarr.Length); client.Close(); EndUploadData(obj, InterlocutorIPEndPoint, bytarr.Length); } else { throw new ArgumentException("Not set IP or HostName"); } }
private SQLiteParameter[] GetReportParameter(Report report = null) { Report r; if (report == null) { r = new Report(); } else { r = report; } return(new SQLiteParameter[] { new SQLiteParameter("@ID", r.ID), new SQLiteParameter("@Name", r.Name), new SQLiteParameter("@Address", r.Address), new SQLiteParameter("@HTML", r.HTML), new SQLiteParameter("@RSID", r.RSID), new SQLiteParameter("@Style", MiMFa_IOService.Serialize(r.Style)), new SQLiteParameter("@Type", MiMFa_IOService.Serialize(r.Type)), new SQLiteParameter("@ObjectArray", MiMFa_IOService.Serialize(r.ObjectArray)), new SQLiteParameter("@CreatorName", r.CreatorName), new SQLiteParameter("@CreateDate", MiMFa_IOService.Serialize(r.CreateDate)), new SQLiteParameter("@CreateTime", MiMFa_IOService.Serialize(r.CreateTime)), new SQLiteParameter("@Accessablity", MiMFa_IOService.Serialize(r.Accessablity)), new SQLiteParameter("@AccessDate", MiMFa_IOService.Serialize(r.AccessDate)), new SQLiteParameter("@AccessTime", MiMFa_IOService.Serialize(r.AccessTime)), new SQLiteParameter("@Extra", MiMFa_IOService.Serialize(r.Extra)) }); }
public void Send(object obj) { Obj = obj; byte[] byteData = (obj != null && obj is byte[]) ? (byte[])obj : MiMFa_IOService.Serialize(obj); // Sends data asynchronously to a connected Socket Handler.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), Handler); }
private object DoneByMime(object arg) { string ext = MiMFa_GetDetail.GetMimeObject(arg).Split('/').First().Trim().ToLower(); try { switch (ext) { case "image": return(Done(Image.FromStream(new System.IO.MemoryStream(MiMFa_IOService.Serialize(arg))))); default: return(arg); } } catch { return(arg); } }
public void ShowMediaPlayer(object value) { Clear(); Value = value; //WMP.Visible = true; Path = TempDirectory + System.DateTime.Now.Ticks + ".mp4"; File.WriteAllBytes(Path, MiMFa_IOService.Serialize(Value)); MiMFa_ControlService.SetControlThreadSafe( WMP, new Action <object[]>((arg) => { WMP.settings.autoStart = AutoStart; WMP.URL = Path; WMP.Visible = true; }), new object[] { }); ValueChanged(this, EventArgs.Empty); }
private SQLiteParameter[] GetReportStyleParameter(ReportStyle reportStyle = null) { ReportStyle rs; if (reportStyle == null) { rs = new ReportStyle(); } else { rs = reportStyle; } return(new SQLiteParameter[] { new SQLiteParameter("@RSID", rs.RSID), new SQLiteParameter("@Style", MiMFa_IOService.Serialize(rs)) }); }
public void Start(object obj) { Thread th = new Thread(() => { try { if (InterlocutorIP == null && !string.IsNullOrEmpty(InterlocutorHostName)) { try { InterlocutorIP = MiMFa_Net.GetInternalIPv4(InterlocutorHostName); } catch { } } if (InterlocutorIP != null) { StartSendData(obj, InterlocutorIPEndPoint, 0); SocketPermission Permission; // Creates one SocketPermission object for access restrictions Permission = new SocketPermission( NetworkAccess.Accept, // Allowed to accept connections TransType, // Defines transport types "", // The IP addresses of local host SocketPermission.AllPorts // Specifies all ports ); // Listening Socket object SenderSock = null; // Ensures the code to have permission to access a Socket Permission.Demand(); // Create one Socket object to listen the incoming connection SenderSock = new Socket( InterlocutorIP.AddressFamily, SocketType.Stream, ProtocolType.Tcp ); // Associates a Socket with a local endpoint SenderSock.SendTimeout = Timeout; SenderSock.Connect(InterlocutorIPEndPoint); ConnectedToInterlocutor(InterlocutorIPEndPoint); // Places a Socket in a listening state and specifies the maximum // Length of the pending connections queue // Sending message byte[] data = (obj != null && obj is byte[]) ? (byte[])obj : MiMFa_IOService.Serialize(obj); // Sends data to a connected Socket. int bytesSend = SenderSock.Send(data); EndSendData(data, InterlocutorIPEndPoint, bytesSend); Receive(); } else { throw new ArgumentException("Not set IP or HostName"); } } catch (Exception ex) { ErrorSendData(obj, InterlocutorIPEndPoint, 0, ex); } }); th.IsBackground = true; th.Start(); }