示例#1
0
        public int GetFileB()
        {
            PlayerListing pl     = new PlayerListing(_messages);
            Player        player = pl.GetPlayer(GetPlayerID);

            if (player.CurrentFile == "0")
            {
                return(GetCurrentPlayerFile());
            }
            else if (player.CurrentFile == "1")
            {
                return(GetPlayerPreviousFile());
            }
            else if (player.CurrentFile == "2")
            {
                DateTime endFile   = FormatTextDate(GetCurrentPlayerFile().ToString());
                DateTime startFile = FormatTextDate(GetCurrentPlayerFile().ToString()).AddDays(-7);

                Dictionary <Int32, string> files = GetAllFilesForPlayerFriendly();
                Int32 key = (from d in files
                             where DateTime.Parse(d.Value) >= startFile && DateTime.Parse(d.Value) <= endFile
                             select d.Key).FirstOrDefault();

                int file = (from g in GetAllFilesForPlayer()
                            where g.Key == key
                            select g.Value).FirstOrDefault();

                return(file);
            }
            else if (player.CurrentFile == "3")
            {
                DateTime endFile   = FormatTextDate(GetCurrentPlayerFile().ToString());
                DateTime startFile = FormatTextDate(GetCurrentPlayerFile().ToString()).AddDays(-14);

                Dictionary <Int32, string> files = GetAllFilesForPlayerFriendly();
                Int32 key = (from d in files
                             where DateTime.Parse(d.Value) >= startFile && DateTime.Parse(d.Value) <= endFile
                             select d.Key).FirstOrDefault();

                int file = (from g in GetAllFilesForPlayer()
                            where g.Key == key
                            select g.Value).FirstOrDefault();

                return(file);
            }
            else
            {
                Dictionary <Int32, string> files = GetAllFilesForPlayerFriendly();
                Int32 key = (from d in files
                             where DateTime.Parse(d.Value) == DateTime.Parse(player.CurrentFile.Insert(4, "-").Insert(7, "-"))
                             select d.Key).FirstOrDefault();

                int file = (from g in GetAllFilesForPlayer()
                            where g.Key == key
                            select g.Value).FirstOrDefault();

                return(file);
            }
        }
示例#2
0
        public void UploadToVBAddict(string filePath, string playerID, MessageQueue message)
        {
            try
            {
                FileInfo toUpload = new FileInfo(filePath);
                byte[]   data     = File.ReadAllBytes(filePath);

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.vbaddict.net/xxx.php");
                request.Proxy.Credentials = CredentialCache.DefaultCredentials;
                request.Method            = "PUT";
                request.ContentType       = "application/x-www-form-urlencoded";
                request.ContentLength     = data.Length;
                request.Headers.Clear();
                request.Referer   = toUpload.Name;
                request.UserAgent = "WOTStatistics 2.1.0.0";
                request.ServicePoint.Expect100Continue = false;

                using (Stream stream = request.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }

                var          response  = request.GetResponse();
                Stream       outStream = response.GetResponseStream();
                StreamReader reader    = new StreamReader(outStream);
                // Read the content.
                string responseFromServer = reader.ReadToEnd();

                if (responseFromServer.Contains("SUCCESS"))
                {
                    using (PlayerListing pl = new PlayerListing(new MessageQueue()))
                    {
                        if (pl.GetPlayer(playerID).OnlineURL == "#")
                        {
                            pl.SetPlayerOnlineURL(playerID, responseFromServer.Substring(responseFromServer.IndexOf("Link: ") + 6).Replace("SUCCESS", ""));
                            try
                            {
                                pl.Save();
                            }
                            catch
                            {
                            }
                        }
                    }
                }


                response.Close();
            }
            catch (Exception ex)
            {
                message.Add(ex.Message);
            }
        }