Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection();

            string hostname;

            if (args.Length > 0)
            {
                hostname = args[0];
            }
            else
            {
                hostname = "10.0.2.2";
            }

            Console.WriteLine("Connect to " + hostname);

            try
            {
                con.Connect(hostname, 102);

                Console.WriteLine("Files in server root directory:");
                List <string> serverDirectory = con.GetServerDirectory(true);

                foreach (string entry in serverDirectory)
                {
                    Console.WriteLine(entry);
                }

                Console.WriteLine();

                Console.WriteLine("File directory tree at server:");
                printFiles(con, "", "");
                Console.WriteLine();

                string filename = "IEDSERVER.BIN";

                Console.WriteLine("Download file " + filename);

                /* Download file from server and write it to a new local file */
                FileStream   fs = new FileStream(filename, FileMode.Create);
                BinaryWriter w  = new BinaryWriter(fs);

                con.GetFile(filename, new IedConnection.GetFileHandler(getFileHandler), w);

                fs.Close();

                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }

            // release all resources - do NOT use the object after this call!!
            con.Dispose();
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection ();

            string hostname;

            if (args.Length > 0)
                hostname = args[0];
            else
                hostname = "10.0.2.2";

            Console.WriteLine("Connect to " + hostname);

            try
            {
                con.Connect(hostname, 102);

                Console.WriteLine ("Files in server root directory:");
                List<string> serverDirectory = con.GetServerDirectory(true);

                foreach (string entry in serverDirectory) {
                    Console.WriteLine(entry);
                }

                Console.WriteLine();

                Console.WriteLine ("File directory tree at server:");
                printFiles(con, "", "");
                Console.WriteLine();

                string filename = "IEDSERVER.BIN";

                Console.WriteLine("Download file " + filename);

                /* Download file from server and write it to a new local file */
                FileStream fs = new FileStream(filename, FileMode.Create);
                BinaryWriter w = new BinaryWriter(fs);

                con.GetFile(filename, new IedConnection.GetFileHandler(getFileHandler), w);

                fs.Close();

                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Download each file in the download list.
        /// </summary>
        /// <param name="iedConnection"></param>
        /// <param name="device"></param>
        /// <param name="downloadableFileList"></param>
        private static void DownloadComtradeFiles(IedConnection iedConnection, Device device, IEnumerable <IEDFile> downloadableFileList)
        {
            foreach (var iedFile in downloadableFileList)
            {
                Logger.Info($"{device} - Downloading file: {iedFile.FileName} ({iedFile.FileSize})");
                //TODO: Check if the GetTemporaryDownloadPath works on both IEDs: 670, 615;
                //var destinationFilename = PathService.GetTemporaryDownloadPath(device, FileName.ReplaceAltDirectorySeparator().CleanFileName());
                var destinationFilename = PathHelper.GetTemporaryDownloadPath(device, iedFile.FileName.GetDestinationFilename());

                using (var fs = new FileStream(destinationFilename, FileMode.Create, FileAccess.ReadWrite))
                    using (var w = new BinaryWriter(fs))
                    {
                        iedConnection.GetFile(iedFile.FileName, GetFileHandler, w);
                    }
            }
        }
Ejemplo n.º 4
0
        public void UpdateComtradeFiles()
        {
            IedConnect();
            List <string> serverDirectory = _conn.GetServerDirectory(true);

            foreach (string entry in serverDirectory)
            {
                string tmp = entry.Replace("/", "\\");
                if (!fileList.Contains(entry))
                {
                    string filename = $"{AppDomain.CurrentDomain.BaseDirectory}{tmp}";
                    Console.WriteLine($"Download file {entry}");
                    FileStream   fs = new FileStream(filename, FileMode.Create);
                    BinaryWriter w  = new BinaryWriter(fs);
                    fileList.Add(entry);
                    _conn.GetFile(entry, new IedConnection.GetFileHandler(getFileHandler), w);
                    //fs.Close();
                }
            }
            _conn.Abort();
        }