コード例 #1
0
        private static void FindUpdateFileCallback(IAsyncResult ar)
        {
            ComObject state     = (ComObject)ar.AsyncState;
            Socket    handler   = state.WorkSocket;
            int       bytesRead = handler.EndReceive(ar);

            if (bytesRead > 0)
            {
                var receiveData = state.Buffer.Take(bytesRead).ToArray();
                var dataList    = PacketUtils.SplitBytes(receiveData, PacketUtils.ClientFindFileInfoTag());
                if (dataList != null && dataList.Any())
                {
                    var    request        = PacketUtils.GetData(PacketUtils.ClientFindFileInfoTag(), dataList.FirstOrDefault());
                    string str            = System.Text.Encoding.UTF8.GetString(request);
                    var    infos          = str.Split('_');
                    var    productName    = infos[0];
                    var    revitVersion   = infos[1];
                    var    currentVersion = infos[2];

                    var updatefile = ServerFileUtils.GetLatestFilePath(productName, revitVersion, currentVersion);
                    if (string.IsNullOrEmpty(updatefile) || !File.Exists(updatefile))
                    {
                        return;
                    }
                    _serverPath = updatefile;
                    FoundUpdateFileResponse(handler);
                }
            }
        }
コード例 #2
0
        private void FindUpdateFileInfo(Socket client, int packetNumber)
        {
            ComObject state = new ComObject {
                WorkSocket = client, PacketNumber = packetNumber
            };

            byte[] byteData = PacketUtils.PacketData(PacketUtils.ClientFindFileInfoTag(), Encoding.UTF8.GetBytes(_updateFileName));
            client.BeginSend(byteData, 0, byteData.Length, 0, FindUpdateFileCallback, state);
        }
コード例 #3
0
        private void ProcessReceiveFindFileRequest(SocketAsyncEventArgs e)
        {
            var bytesRead = e.BytesTransferred;

            if (bytesRead > 0 && e.SocketError == SocketError.Success)
            {
                var receiveData = e.Buffer.Skip(e.Offset).Take(bytesRead).ToArray();
                var dataList    = PacketUtils.SplitBytes(receiveData, PacketUtils.ClientFindFileInfoTag());
                if (dataList != null && dataList.Any())
                {
                    var    request        = PacketUtils.GetData(PacketUtils.ClientFindFileInfoTag(), dataList.FirstOrDefault());
                    string str            = System.Text.Encoding.UTF8.GetString(request);
                    var    infos          = str.Split('_');
                    var    productName    = infos[0];
                    var    revitVersion   = infos[1];
                    var    currentVersion = infos[2];

                    var mainFolder       = AppDomain.CurrentDomain.BaseDirectory.Replace("bin", "TestFile");
                    var serverFileFolder = Path.Combine(mainFolder, "Server");
                    var serverFileFiles  = new DirectoryInfo(serverFileFolder).GetFiles();

                    var updatefile = serverFileFiles.FirstOrDefault(x => x.Name.Contains(productName) && x.Name.Contains(revitVersion) && x.Name.Contains(currentVersion));
                    if (updatefile != null)
                    {
                        if (string.IsNullOrEmpty(updatefile.FullName) || !File.Exists(updatefile.FullName))
                        {
                            return;
                        }
                        _serverPath = updatefile.FullName;

                        //ready to send back to Client
                        byte[] foundUpdateFileData = PacketUtils.PacketData(PacketUtils.ServerFoundFileInfoTag(), null);

                        Array.Clear(e.Buffer, e.Offset, e.Count);
                        Array.Copy(foundUpdateFileData, 0, e.Buffer, e.Offset, foundUpdateFileData.Length);

                        e.Completed -= ProcessAccept_Completed;
                        e.Completed += ProcessReceiveFindFileRequest_Completed;

                        if (!e.AcceptSocket.SendAsync(e))
                        {
                            ProcessFilePosition(e);
                        }
                    }
                }
            }
        }
コード例 #4
0
        private static void FindUpdateFileCallback(IAsyncResult ar)
        {
            ComObject state     = (ComObject)ar.AsyncState;
            Socket    handler   = state.WorkSocket;
            int       bytesRead = handler.EndReceive(ar);

            if (bytesRead > 0)
            {
                var receiveData = state.Buffer.Take(bytesRead).ToArray();
                var dataList    = PacketUtils.SplitBytes(receiveData, PacketUtils.ClientFindFileInfoTag());
                if (dataList != null && dataList.Any())
                {
                    var    request        = PacketUtils.GetData(PacketUtils.ClientFindFileInfoTag(), dataList.FirstOrDefault());
                    string str            = System.Text.Encoding.UTF8.GetString(request);
                    var    infos          = str.Split('_');
                    var    productName    = infos[0];
                    var    revitVersion   = infos[1];
                    var    currentVersion = infos[2];

                    var mainFolder       = AppDomain.CurrentDomain.BaseDirectory.Replace("bin", "TestFile");
                    var serverFileFolder = Path.Combine(mainFolder, "Server");
                    var serverFileFiles  = new DirectoryInfo(serverFileFolder).GetFiles();

                    var updatefile = serverFileFiles.FirstOrDefault(x => x.Name.Contains(productName) && x.Name.Contains(revitVersion) && x.Name.Contains(currentVersion));
                    if (updatefile != null)
                    {
                        if (string.IsNullOrEmpty(updatefile.FullName) || !File.Exists(updatefile.FullName))
                        {
                            return;
                        }
                        _serverPath = updatefile.FullName;
                        FoundUpdateFileResponse(handler);
                    }
                }
            }
        }