예제 #1
0
        public static void File(string fileName)
        {
            //Import config variables
            Config.softwareConfig cfg = new Config.softwareConfig();

            FtpWebRequest request;
            try
            {
                string absoluteFileName = Path.GetFileName(MainWindow.workingDir + "\\Config\\" + fileName);

                request = WebRequest.Create(new Uri(string.Format(@"ftp://{0}/{1}/{2}", cfg.ftpjsonAddress , cfg.eventsLocation, fileName))) as FtpWebRequest;
                request.Method = WebRequestMethods.Ftp.UploadFile;
                request.UseBinary = true;
                request.UsePassive = true;
                request.KeepAlive = true;
                request.Credentials = new NetworkCredential(cfg.ftpjsonUser, cfg.ftpjsonPassword);
                request.ConnectionGroupName = "group";

                using (FileStream fs = System.IO.File.OpenRead(MainWindow.workingDir + "\\Config\\" + fileName))
                {
                    byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, buffer.Length);
                    fs.Close();
                    Stream requestStream = request.GetRequestStream();
                    requestStream.Write(buffer, 0, buffer.Length);
                    requestStream.Close();
                    requestStream.Flush();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #2
0
        public static void File(string fileName)
        {
            //Import config variables
            Config.softwareConfig cfg = new Config.softwareConfig();

            FtpWebRequest request;

            try
            {
                string absoluteFileName = Path.GetFileName(MainWindow.workingDir + "\\Config\\" + fileName);

                request                     = WebRequest.Create(new Uri(string.Format(@"ftp://{0}/{1}/{2}", cfg.ftpjsonAddress, cfg.eventsLocation, fileName))) as FtpWebRequest;
                request.Method              = WebRequestMethods.Ftp.UploadFile;
                request.UseBinary           = true;
                request.UsePassive          = true;
                request.KeepAlive           = true;
                request.Credentials         = new NetworkCredential(cfg.ftpjsonUser, cfg.ftpjsonPassword);
                request.ConnectionGroupName = "group";

                using (FileStream fs = System.IO.File.OpenRead(MainWindow.workingDir + "\\Config\\" + fileName))
                {
                    byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, buffer.Length);
                    fs.Close();
                    Stream requestStream = request.GetRequestStream();
                    requestStream.Write(buffer, 0, buffer.Length);
                    requestStream.Close();
                    requestStream.Flush();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #3
0
        public static void File(string fileName, eventVar _eventVar)
        {
            try
            {
                //Import config variables
                Config.softwareConfig cfg = new Config.softwareConfig();

                if (System.IO.File.Exists(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted"))
                {
                    System.IO.File.Delete(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");

                    using (FileStream fs = System.IO.File.Open(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted", FileMode.CreateNew))
                    using (StreamWriter sw = new StreamWriter(fs))
                    using (JsonWriter jw = new JsonTextWriter(sw))
                    {
                        jw.Formatting = Formatting.Indented;

                        JsonSerializer serializer = new JsonSerializer();
                        serializer.Serialize(jw, _eventVar);
                        jw.Close();
                        sw.Close();
                        fs.Close();
                    }

                    string json = System.IO.File.ReadAllText(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");
                    string encryptJson = CryptoService.Load.Encrypt(json, cfg.cipherKey);
                    System.IO.File.WriteAllText(MainWindow.workingDir + "\\Config\\" + fileName, encryptJson);
                    System.IO.File.Delete(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");
                }
                else
                {
                    using (FileStream fs = System.IO.File.Open(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted", FileMode.CreateNew))
                    using (StreamWriter sw = new StreamWriter(fs))
                    using (JsonWriter jw = new JsonTextWriter(sw))
                    {
                        jw.Formatting = Formatting.Indented;

                        JsonSerializer serializer = new JsonSerializer();
                        serializer.Serialize(jw, _eventVar);
                        jw.Close();
                        sw.Close();
                        fs.Close();

                        string json = System.IO.File.ReadAllText(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");
                        string encryptJson = CryptoService.Load.Encrypt(json, cfg.cipherKey);
                        System.IO.File.WriteAllText(MainWindow.workingDir + "\\Config\\" + fileName, encryptJson);
                        System.IO.File.Delete(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");
                    }

                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #4
0
        public static void File(string fileName, eventVar _eventVar)
        {
            try
            {
                //Import config variables
                Config.softwareConfig cfg = new Config.softwareConfig();

                if (System.IO.File.Exists(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted"))
                {
                    System.IO.File.Delete(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");

                    using (FileStream fs = System.IO.File.Open(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted", FileMode.CreateNew))
                        using (StreamWriter sw = new StreamWriter(fs))
                            using (JsonWriter jw = new JsonTextWriter(sw))
                            {
                                jw.Formatting = Formatting.Indented;

                                JsonSerializer serializer = new JsonSerializer();
                                serializer.Serialize(jw, _eventVar);
                                jw.Close();
                                sw.Close();
                                fs.Close();
                            }

                    string json        = System.IO.File.ReadAllText(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");
                    string encryptJson = CryptoService.Load.Encrypt(json, cfg.cipherKey);
                    System.IO.File.WriteAllText(MainWindow.workingDir + "\\Config\\" + fileName, encryptJson);
                    System.IO.File.Delete(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");
                }
                else
                {
                    using (FileStream fs = System.IO.File.Open(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted", FileMode.CreateNew))
                        using (StreamWriter sw = new StreamWriter(fs))
                            using (JsonWriter jw = new JsonTextWriter(sw))
                            {
                                jw.Formatting = Formatting.Indented;

                                JsonSerializer serializer = new JsonSerializer();
                                serializer.Serialize(jw, _eventVar);
                                jw.Close();
                                sw.Close();
                                fs.Close();

                                string json        = System.IO.File.ReadAllText(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");
                                string encryptJson = CryptoService.Load.Encrypt(json, cfg.cipherKey);
                                System.IO.File.WriteAllText(MainWindow.workingDir + "\\Config\\" + fileName, encryptJson);
                                System.IO.File.Delete(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");
                            }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #5
0
        public static void File()
        {
            try
            {
                //Import config variables
                Config.softwareConfig cfg = new Config.softwareConfig();

                if (System.IO.File.Exists(MainWindow.workingDir + "\\" + cfg.ftpjsonFileName))
                {
                    System.IO.File.Delete(MainWindow.workingDir + "\\" + cfg.ftpjsonFileName);

                    using (FileStream fs = System.IO.File.Open(MainWindow.workingDir + "\\" + cfg.ftpjsonFileName, FileMode.CreateNew))
                        using (StreamWriter sw = new StreamWriter(fs))
                            using (JsonWriter jw = new JsonTextWriter(sw))
                            {
                                jw.Formatting = Formatting.Indented;

                                JsonSerializer serializer = new JsonSerializer();
                                serializer.Serialize(jw, MainWindow.config);
                            }
                }
                else
                {
                    using (FileStream fs = System.IO.File.Open(MainWindow.workingDir + "\\" + cfg.ftpjsonFileName, FileMode.CreateNew))
                        using (StreamWriter sw = new StreamWriter(fs))
                            using (JsonWriter jw = new JsonTextWriter(sw))
                            {
                                jw.Formatting = Formatting.Indented;

                                JsonSerializer serializer = new JsonSerializer();
                                serializer.Serialize(jw, MainWindow.config);
                            }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #6
0
        public static void File()
        {
            try
            {
                //Import config variables
                Config.softwareConfig cfg = new Config.softwareConfig();

                if (System.IO.File.Exists(MainWindow.workingDir + "\\" + cfg.ftpjsonFileName))
                {
                    System.IO.File.Delete(MainWindow.workingDir + "\\" + cfg.ftpjsonFileName);

                    using (FileStream fs = System.IO.File.Open(MainWindow.workingDir + "\\" + cfg.ftpjsonFileName, FileMode.CreateNew))
                    using (StreamWriter sw = new StreamWriter(fs))
                    using (JsonWriter jw = new JsonTextWriter(sw))
                    {
                        jw.Formatting = Formatting.Indented;

                        JsonSerializer serializer = new JsonSerializer();
                        serializer.Serialize(jw, MainWindow.config);
                    }
                }
                else
                {
                    using (FileStream fs = System.IO.File.Open(MainWindow.workingDir + "\\" + cfg.ftpjsonFileName, FileMode.CreateNew))
                    using (StreamWriter sw = new StreamWriter(fs))
                    using (JsonWriter jw = new JsonTextWriter(sw))
                    {
                        jw.Formatting = Formatting.Indented;

                        JsonSerializer serializer = new JsonSerializer();
                        serializer.Serialize(jw, MainWindow.config);
                    }
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }