Example #1
0
        public static void DownloadFileAsync(string fileLocation,
                                             DownloadProgressChangedEventHandler downloadHandler,
                                             AsyncCompletedEventHandler downloadCompletedHandler, string programid = null)
        {
            try
            {
                using (ByteGuardWebClient byteguardWebClient = new ByteGuardWebClient())
                {
                    byteguardWebClient.CookieJar = CookieContainer;

                    byteguardWebClient.DownloadProgressChanged += downloadHandler;
                    //byteguardWebClient.DownloadDataCompleted += downloadCompletedHandler;
                    byteguardWebClient.DownloadFileCompleted += downloadCompletedHandler;

                    Uri postUri =
                        new Uri(
                            String.Format("{0}process.php?act=dlprogram&pid={1}",
                                          Variables.ByteGuardHost, programid));

                    lock (LockObject)
                    {
                        byteguardWebClient.DownloadFileAsync(postUri, fileLocation);
                    }
                }
            }
            catch
            {
                Variables.Containers.Main.SetStatus("Failed to download program, please try again shortly.", 1);
            }
        }
Example #2
0
        /// <summary>
        /// Submits data to be processed that has parameters.
        /// </summary>
        /// <param name="submitAct">The act being processed. (Example: login, register)</param>
        /// <returns>The result of the query as a byte array.</returns>
        public static bool SubmitData(string submitAct)
        {
            try
            {
                //MessageBox.Show(submitAct);

                using (ByteGuardWebClient byteguardWebClient = new ByteGuardWebClient())
                {
                    NameValueCollection submitData = new NameValueCollection {
                        { "act", submitAct }
                    };

                    byteguardWebClient.CookieJar = CookieContainer;

                    lock (LockObject)
                    {
                        Variables.WebResponse = Encoding.ASCII.GetString(byteguardWebClient.UploadValues(String.Format("{0}process.php", Variables.ByteGuardHost), submitData));
                    }

                    //MessageBox.Show(ByteGuardInterface.Globals.Variables.WebResponse);
                    return(true);
                }
            }
            catch
            {
                Variables.Containers.Active.SetStatus("The server appears to be offline.", 1);

                if (Variables.Containers.Main != null)
                {
                    Variables.Containers.Main.SetStatus("The server appears to be offline.", 1);
                }
                return(false);
            }
        }
Example #3
0
        public static void UploadFileAsync(string fileLocation, string submitAct, UploadProgressChangedEventHandler uploadHandler, UploadFileCompletedEventHandler completedHandler, string programid = null)
        {
            try
            {
                using (ByteGuardWebClient byteguardWebClient = new ByteGuardWebClient())
                {
                    byteguardWebClient.Headers.Add("Content-Type", "binary/octet-stream");
                    byteguardWebClient.CookieJar = CookieContainer;

                    byteguardWebClient.UploadProgressChanged += uploadHandler;
                    byteguardWebClient.UploadFileCompleted   += completedHandler;

                    Uri postUri =
                        new Uri(
                            String.Format("{0}files/upload.php?type={1}&pid={2}",
                                          Variables.ByteGuardHost, submitAct, programid));

                    lock (LockObject)
                    {
                        byteguardWebClient.UploadFileAsync(postUri, "POST", fileLocation);
                    }
                }
            }
            catch
            {
                Variables.Containers.Main.SetStatus("Failed to upload program image, please try again shortly.", 1);
            }
        }
Example #4
0
        public static void DownloadFileAsync(string fileLocation,
                                             DownloadProgressChangedEventHandler downloadHandler,
                                             AsyncCompletedEventHandler downloadCompletedHandler, string fileName)
        {
            General.IsUpdating = true;

            try
            {
                using (ByteGuardWebClient byteguardWebClient = new ByteGuardWebClient())
                {
                    byteguardWebClient.CookieJar = CookieContainer;

                    byteguardWebClient.DownloadProgressChanged += downloadHandler;
                    byteguardWebClient.DownloadFileCompleted   += downloadCompletedHandler;

                    Uri postUri =
                        new Uri(
                            String.Format("{0}process.php?act=downloadupdate&filename={1}", General.ByteGuardHost, fileName));

                    lock (LockObject)
                    {
                        byteguardWebClient.DownloadFileAsync(postUri, fileLocation);
                    }
                }
            }
            catch
            {
                MessageBox.Show("Failed to download update, please try again shortly.", "Update Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
Example #5
0
        /// <summary>
        /// Submits data to be processed that has parameters.
        /// </summary>
        /// <param name="submitAct">The act being processed. (Example: login, register)</param>
        /// <returns>The result of the query as a byte array.</returns>
        public static bool SubmitData(string submitAct)
        {
            try
            {
                //MessageBox.Show(submitAct);

                using (ByteGuardWebClient byteguardWebClient = new ByteGuardWebClient())
                {
                    NameValueCollection submitData = new NameValueCollection {
                        { "act", submitAct }
                    };

                    byteguardWebClient.CookieJar = CookieContainer;

                    lock (LockObject)
                    {
                        General.WebResponse = Encoding.ASCII.GetString(byteguardWebClient.UploadValues(String.Format("{0}process.php", General.ByteGuardHost), submitData));
                    }

                    //MessageBox.Show(ByteGuardInterface.Globals.Variables.WebResponse);
                    return(true);
                }
            }
            catch
            {
                MessageBox.Show("The server appears to be offline.2", "Update Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="imageLocation"></param>
        public static void DownloadAvatarImage(string username, string imageLocation)
        {
            try
            {
                using (ByteGuardWebClient byteguardWebClient = new ByteGuardWebClient())
                {
                    byteguardWebClient.CookieJar = CookieContainer;

                    lock (LockObject)
                    {
                        byteguardWebClient.DownloadFile(String.Format("{0}process.php?act=getavatar&u={1}", Variables.ByteGuardHost, username), imageLocation);
                    }
                }
            }
            catch
            {
                Variables.Containers.Main.SetStatus("The server appears to be offline.", 1);
            }
        }
Example #7
0
        /// <summary>
        /// Uploads the specified file and stores it on the server.
        /// </summary>
        /// <param name="fileLocation">The file path to the file that is being uploaded.</param>
        /// <param name="submitAct"></param>
        public static void UploadFile(string fileLocation, string submitAct, string programid = null)
        {
            try
            {
                using (ByteGuardWebClient byteguardWebClient = new ByteGuardWebClient())
                {
                    byteguardWebClient.Headers.Add("Content-Type", "binary/octet-stream");
                    byteguardWebClient.CookieJar = CookieContainer;

                    lock (LockObject)
                    {
                        Variables.WebResponse = Encoding.ASCII.GetString(byteguardWebClient.UploadFile(String.Format("{0}files/upload.php?type={1}&pid={2}", Variables.ByteGuardHost, submitAct, programid), "POST", fileLocation));
                    }
                }
            }
            catch
            {
                Variables.Containers.Main.SetStatus("Failed to upload file, please try again shortly.", 1);
            }
        }