Пример #1
0
 public void SocketReceive()
 {
     if (InterlocutorIP == null && !string.IsNullOrEmpty(InterlocutorHostName))
     {
         try
         { InterlocutorIP = MiMFa_Net.GetInternalIPv4(InterlocutorHostName); }
         catch { }
     }
     if (InterlocutorIP != null)
     {
         TcpListener listener = new TcpListener(InterlocutorIP, Port);
         listener.Start();
         ConnectedToInterlocutor(InterlocutorIPEndPoint);
         while (Run)
         {
             Socket socket = listener.AcceptSocket();
             byte[] bytarr = new byte[BufferSize];
             StartDownloadData(null, InterlocutorIPEndPoint, 0);
             int  mi = socket.Receive(bytarr);
             bool b  = mi > 0;
             if (b && EndDownloadData != null)
             {
                 EndDownloadData(MiMFa_IOService.Deserialize(bytarr), InterlocutorIPEndPoint, mi);
             }
             socket.Close();
         }
         listener.Stop();
         StopDownloadData(null, InterlocutorIPEndPoint, 0);
     }
     else
     {
         throw new ArgumentException("Not set IP or HostName");
     }
 }
Пример #2
0
        public void Reciever_EndRecieveData(byte[] data, IPEndPoint ip, long length)
        {
            try
            {
                LastRecievePacket = (MiMFa_SimplePacket)MiMFa_IOService.Deserialize(data);
                MiMFa_SocketPacketSubject msps = LastRecievePacket.GetSubject();
                if (msps == MiMFa_SocketPacketSubject.Chat)
                {
                    var typ = LastRecievePacket.GetDataType();
                    switch (typ)
                    {
                    case MiMFa_SocketPacketDataType.None:
                        SetHTML(LastRecievePacket.GetData().ToString());
                        break;

                    case MiMFa_SocketPacketDataType.Text:
                        Recieve(LastRecievePacket.GetData());
                        break;

                    case MiMFa_SocketPacketDataType.Image:
                        Recieve(LastRecievePacket.GetData());
                        break;

                    default:
                        var mim = General.MiMFa_GetDetail.GetMimeObject(LastRecievePacket.Data).Split('/').First();
                        if (mim == "image")
                        {
                            Recieve(LastRecievePacket.GetData());
                        }
                        else
                        {
                            Recieve(LastRecievePacket.Data);
                        }
                        break;
                    }
                    RecievedPacket(LastRecievePacket, ip);
                }
                else if (msps == MiMFa_SocketPacketSubject.Error)
                {
                    try
                    { NotSendAlert((Exception)LastRecievePacket.GetData()); }
                    catch { }
                }
            }
            catch (Exception ex)
            {
                RecievedError(data, ip, length, ex);
                Reciever.Send(new MiMFa_SimplePacket(MiMFa_SocketPacketSubject.Error, ex, MiMFa_SocketPacketDataType.Text));
            }
        }
Пример #3
0
        public List <Report> GetReportList(DataTable dt)
        {
            List <Report> lr = new List <Report>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                try
                {
                    Report newReport = new Report();
                    try { newReport.ID = double.Parse(dt.Rows[i]["ID"].ToString()); } catch { }
                    try { newReport.Name = dt.Rows[i]["Name"].ToString(); } catch { }
                    try { newReport.Address = dt.Rows[i]["Address"].ToString(); } catch { }
                    try { newReport.HTML = dt.Rows[i]["HTML"].ToString(); } catch { }
                    try { newReport.RSID = double.Parse(dt.Rows[i]["RSID"].ToString()); } catch { }
                    try { newReport.Style = (ReportStyle)MiMFa_IOService.Deserialize((byte[])dt.Rows[i]["Style"]); } catch { }
                    try { newReport.Type = (Type)MiMFa_IOService.Deserialize((byte[])dt.Rows[i]["Type"]); } catch { }
                    try { newReport.ObjectArray = (object[])MiMFa_IOService.Deserialize((byte[])dt.Rows[i]["ObjectArray"]); } catch { }
                    try { newReport.CreatorName = dt.Rows[i]["CreatorName"].ToString(); } catch { }
                    try { newReport.CreateDate = (MiMFa_Date)MiMFa_IOService.Deserialize((byte[])dt.Rows[i]["CreateDate"]); } catch { }
                    try { newReport.CreateTime = (MiMFa_Time)MiMFa_IOService.Deserialize((byte[])dt.Rows[i]["CreateTime"]); } catch { }
                    try { newReport.Accessablity = (MiMFa_Accessibility)MiMFa_IOService.Deserialize((byte[])dt.Rows[i]["Accessablity"]); } catch { }
                    try { newReport.AccessDate = (MiMFa_Date)MiMFa_IOService.Deserialize((byte[])dt.Rows[i]["AccessDate"]); } catch { }
                    try { newReport.AccessTime = (MiMFa_Time)MiMFa_IOService.Deserialize((byte[])dt.Rows[i]["AccessTime"]); } catch { }
                    try { newReport.Extra = MiMFa_IOService.Deserialize((byte[])dt.Rows[i]["Extra"]); } catch { }
                    //object[] itemArray = dt.Rows[i].ItemArray;
                    //newReport.ID = double.Parse(itemArray[0].ToString());
                    //newReport.Name = itemArray[1].ToString();
                    //newReport.Address = itemArray[2].ToString();
                    //newReport.HTML = itemArray[3].ToString();
                    //newReport.RSID = double.Parse(itemArray[4].ToString());
                    //newReport.Style = (ReportStyle)itemArray[5];
                    //newReport.Type = (Type)itemArray[6];
                    //newReport.ObjectArray = (object[])itemArray[7];
                    //newReport.CreatorName = itemArray[8].ToString();
                    //newReport.CreateDate = (MiMFa_Date)itemArray[9];
                    //newReport.CreateTime = (MiMFa_Time)itemArray[10];
                    //newReport.Accessablity = (MiMFa_Accessablity)itemArray[11];
                    //newReport.AccessDate = (MiMFa_Date)itemArray[12];
                    //newReport.AccessTime = (MiMFa_Time)itemArray[13];
                    //newReport.Extra = itemArray[14];
                    lr.Add(newReport);
                }
                catch { }
            }
            return(lr);
        }
Пример #4
0
 private bool Start(params object[] po)
 {
     timer.Enabled = !_stop;
     if (_new || ipaddress == null || reciever == null || sender == null)
     {
         if (_password)
         {
             string[] stra = po[0].ToString().Split(',');
             setpassword("", stra.Last().Trim());
             if (stra.Length > 1)
             {
                 po[0] = MiMFa_CollectionService.GetAllItems(MiMFa_CollectionService.GetPart(stra, 0, stra.Length - 1), ",", 0);
             }
             else
             {
                 po[0] = "";
             }
         }
         ipaddress = IPAddress.Any;
         if (_all)
         {
             ipaddress = IPAddress.Any;
         }
         else
         {
             try
             {
                 ipaddress = IPAddress.Parse(MCL.Parse(po[0] + ""));
             }
             catch { }
         }
         reciever                 = new MiMFa_Receiver();
         sender                   = new MiMFa_Sender();
         sender.Port              = reciever.Port = port;
         sender.BufferSize        = reciever.BufferSize = buffer;
         reciever.EndReceiveData += (b, ip, i) =>
         {
             object o = MiMFa_IOService.Deserialize(b);
             if (string.IsNullOrEmpty(password))
             {
                 content = o;
             }
             else if (!MiMFa_CollectionService.ExistIn(remotedic, ip.Address))
             {
                 remotedic.Add(ip.Address, crypt.GetHashString(o.ToString()));
             }
             else if (remotedic[ip.Address] == password)
             {
                 content = o;
             }
             else
             {
                 remotedic[ip.Address] = crypt.GetHashString(o.ToString());
             }
         };
         reciever.SendCallBackData += (o, ip, i) =>
         {
             contentcallback = o;
         };
         reciever.Start(ipaddress);
         if (ipaddress != IPAddress.Any)
         {
             sender.InterlocutorIP = ipaddress;
         }
         return(false);
     }
     if (ipaddress != IPAddress.Any)
     {
         sender.InterlocutorIP = ipaddress;
     }
     else if (sender.InterlocutorIP == null || _ip || i)
     {
         try
         {
             string[] stra = po[0].ToString().Split(',');
             ipaddress = sender.InterlocutorIP = IPAddress.Parse(stra.First().Trim());
             if (stra.Length > 1)
             {
                 po[0] = MiMFa_CollectionService.GetAllItems(stra, ",", 1);
             }
             else
             {
                 po[0] = "";
             }
         }
         catch { }
     }
     sender.Port       = reciever.Port = port;
     sender.BufferSize = reciever.BufferSize = buffer;
     sender.Run        = reciever.Run = !_stop;
     return(true);
 }