示例#1
0
 private void SendBaseOptions(MossRequest request)
 {
     this.SendOption(AppSettings.UserIdOption, this._userId);
     this.SendOption(AppSettings.DirectoryModeOption, request.IsDirectoryMode);
     this.SendOption(AppSettings.ExperimentalOption, request.IsExperimental);
     this.SendOption(AppSettings.MaximumMatchesOption, request.MaximumMatches);
     this.SendOption(AppSettings.MaximumFilesToShowOption, request.MaximumFilesToShow);
 }
示例#2
0
        private string SendFinalOptions(MossRequest request)
        {
            var result = new byte[512];

            this.SendOption(AppSettings.QueryOption, request.Comments);
            this._socket.Receive(result);
            this.SendOption(AppSettings.EndOption, string.Empty);

            return(Encoding.UTF8.GetString(result));
        }
示例#3
0
        private void SendFiles(MossRequest request)
        {
            foreach (var file in request.BaseFileNames)
            {
                this.SendFile(request.Language, file, 0);
            }

            var submittedFilesCount = request.FileNames.Count();

            for (int i = 0; i < submittedFilesCount; i++)
            {
                this.SendFile(request.Language, request.FileNames.ElementAt(i), i + 1);
            }
        }
示例#4
0
        public MossResponse SendRequest(MossRequest request)
        {
            var endpoint = GetEndPoint();

            using (this._socket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
            {
                try
                {
                    this._socket.Connect(endpoint);

                    this.SendBaseOptions(request);
                    this.SendFiles(request);

                    var resultUrl = this.SendFinalOptions(request);

                    if (Uri.TryCreate(resultUrl, UriKind.Absolute, out Uri url))
                    {
                        return(new MossResponse
                        {
                            ResultUrl = url.ToString(),
                            IsValid = true
                        });
                    }

                    return(new MossResponse
                    {
                        IsValid = false
                    });
                }
                catch (Exception ex)
                {
                    //TODO Log this
                }
            }

            return(new MossResponse
            {
                IsValid = false
            });
        }