Example #1
0
        public MainViewModel(IMessagerSercive service, IPackageOut pkgOut, NetSource netSource, SynchronizationContext context)
        {
            _context             = context;
            IsLoading            = true;
            this.messagerService = service;
            _Stickies            = LoadAllSitcky();
            _handler             = SimpleIoc.Default.GetInstance <IPackageHandler[]>();
            _UserMessages        = new UserMessageCollection();
#if DEBUG
            _UserMessages = GetSampleGroup();
#endif
            _OnlineUsers     = new UserCollection();
            _ContentVistable = false;
            client           = netSource;
            client.Received += Client_Received;
            client.ReceiveAsync();
            client.Disconnected += Client_Disconnected;
            Out           = pkgOut;
            User.UserName = client.Config.UserName;
            Out.SendUserConnect();
            Task.Delay(2000).ContinueWith((task) =>
            {
                Out.SendGetAllUser();
            }).ContinueWith((t) => IsLoading = false);
        }
        public static void MissSourceSaveToFile(string WorkPath, string Url, string Attachname, string index = null, string filetype = ".jpg")
        {
            new Thread(() => {
                WebClient wb = new WebClient();
                string ext   = NetSource.GetTypeFromUrl(Url);
                if (ext == ".unknow")
                {
                    ext = filetype;
                }

                try
                {
                    if (!Directory.Exists(WorkPath))
                    {
                        Directory.CreateDirectory(WorkPath);
                    }

                    if (!string.IsNullOrWhiteSpace(Attachname))
                    {
                        wb.DownloadFile(Url, GetPath(WorkPath, (string.IsNullOrWhiteSpace(index) ? Attachname : Attachname + index) + ext));
                    }
                    else
                    {
                        wb.DownloadFile(Url, GetPath(WorkPath, (string.IsNullOrWhiteSpace(index) ? DateTime.Now.Ticks.ToString() : index) + ext));
                    }
                }
                catch (Exception e)
                {
                    LogHelper.Debug(string.Format(@"尝试获取遗失文件{4}时出错:写入文件[{0}\{1}{2}{5}]失败,{3}", WorkPath, Attachname, index, e.Message, Url, ext));
                }
            }).Start();
        }
Example #3
0
 public StartViewModel(IMessagerSercive navigationService, NetSource client)
 {
     this.client         = client;
     client.Connected   += Client_Connected;
     this.messageService = navigationService;
     Config = client.Config;
     //LoadConfigAsync();
     IsConnectable = _config != null && _config.ServerIP != null && _config.UserName != null;
 }
Example #4
0
 private void Client_Received(NetSource sender, NetSourceEventArgs e)
 {
     try
     {
         if (Handler?[e.Package.Code] != null)
         {
             _context.Post((o) => Handler[e.Package.Code].Handle(this, e.Package), this);
         }
     }
     catch (Exception ex)
     {
         messagerService.ShowError(ex, "Exception", "OK", null);
     }
 }
        private CustomResponseFilter GetData(IRequest request, IResponse response)
        {
            var  length = response.Headers["Content-Length"];
            long size   = -1;

            try
            {
                size = Convert.ToInt64(length);
            }
            catch (Exception errormsg)
            {
                LogHelper.Debug("无法转换的文件长度 : " + length + "    " + errormsg);
            }
            var imme = response.Headers["Content-Type"];

            if (imme != null && imme.IndexOf(";") > 0)
            {
                imme = imme.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)[0];
            }

            NetSource ms = null;

            if (!SourcesList.TryGetValue(request.Url, out ms))
            {
                ms = new NetSource
                {
                    Data = new MemoryStream(),
                    IMME = imme
                };
                SourcesList.Add(request.Url, ms);
            }
            else
            {
                //LogHelper.Debug("Url 已存在于缓存列表 " + request.Url);
            }

            return(new CustomResponseFilter(size, ms.Data));
        }
        public static void SaveMemoryToFile(NetSource ms, string WorkPath, string Url, string Attachname, string index = null)
        {
            if (ms.Data.Length > 0)
            {
                // if (!WorkPath.EndsWith("/")) WorkPath += "/";

                try
                {
                    if (!Directory.Exists(WorkPath))
                    {
                        Directory.CreateDirectory(WorkPath);
                    }

                    var ext = IMMEHelper.GetExtentionType(ms.IMME);
                    if (ext == null)
                    {
                        ext = NetSource.GetTypeFromUrl(Url);
                    }

                    if (!string.IsNullOrWhiteSpace(Attachname))
                    {
                        File.WriteAllBytes(GetPath(WorkPath, (string.IsNullOrWhiteSpace(index) ? Attachname : Attachname + index) + ext), ms.Data.ToArray());
                    }
                    else
                    {
                        File.WriteAllBytes(GetPath(WorkPath, (string.IsNullOrWhiteSpace(index) ? DateTime.Now.Ticks.ToString() : index) + ext), ms.Data.ToArray());
                    }
                    // LogHelper.Debug(string.Format("写入文件[{0}/{1}{2}{3}]成功",WorkPath,Attachname,index,ext));
                }catch (Exception e)
                {
                    LogHelper.Debug(string.Format("写入文件[{0}/{1}{2}]失败,{3}", WorkPath, Attachname, index, e.Message));
                }
            }
            else
            {
                LogHelper.Debug(string.Format("指定数据长度为0,文件写入[{0}/{1}]失败,index={2},data={3}", WorkPath, Attachname, index, Url));
            }
        }
Example #7
0
 private void Client_Disconnected(NetSource sender, NetSourceEventArgs e)
 {
     messagerService.ShowMessage("Disconnected", "Network Infomation");
     SimpleIoc.Default.Unregister <NetSource>();
     messagerService.GoBack();
 }
Example #8
0
 private void Client_Received(NetSource sender, NetSourceEventArgs e)
 {
     Console.WriteLine("Receicve Package: {0}, Legnth={1}", e.Package.Code, e.Package.Length);
     Server.Handlers[e.Package.Code]?.Handle(sender, e.Package);
 }
Example #9
0
 public void SendPacket(NetSource sock, NetBuffer data, NetConnection conn)
 {
     if (sock == NetSource.CLIENT)
     {
         client.SendMessage(data, NetChannel.Unreliable);
     }
     else
         server.SendMessage(data, conn, NetChannel.Unreliable);
 }
Example #10
0
 public void OutOfBandMessage(NetSource src, IPEndPoint dest, string data)
 {
     if (src == NetSource.CLIENT)
     {
         NetBuffer buf = client.CreateBuffer(data);
         client.SendOutOfBandMessage(buf, dest);
     }
     else if (src == NetSource.SERVER)
     {
         NetBuffer buf = server.CreateBuffer(data);
         server.SendOutOfBandMessage(buf, dest);
     }
 }
Example #11
0
 public netchan_t NetChan_Setup(NetSource source, IPEndPoint from, int qport)
 {
     netchan_t netchan = new netchan_t();
     netchan.remoteAddress = from;
     netchan.qport = qport;
     netchan.outgoingSequence = 1;
     netchan.sock = source;
     return netchan;
 }