예제 #1
0
        public void InitializeAccessoryPositions()
        {
            AccessoryPositions.Clear();

            var filePath = @"ftp://108.167.164.209/public_html/printahead.online/Library/Accessory/parts.cfg";

            if (!FTPHelper.IsFileExists(filePath))
            {
                return;
            }

            var request = (FtpWebRequest)FtpWebRequest.Create(filePath);

            request.Credentials = new NetworkCredential(FTPHelper.Login, FTPHelper.Password);
            request.Method      = WebRequestMethods.Ftp.DownloadFile;

            var ftpResponse = (FtpWebResponse)request.GetResponse();

            byte[] buffer = new byte[16 * 1024];
            using (var ftpStream = ftpResponse.GetResponseStream())
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    int read;
                    while ((read = ftpStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        ms.Write(buffer, 0, read);
                    }
                    ms.Position = 0;
                    ms.Flush();
                    using (var sr = new StreamReader(ms, Encoding.Default))
                    {
                        while (!sr.EndOfStream)
                        {
                            var path     = sr.ReadLine();
                            var position = sr.ReadLine();
                            var size     = sr.ReadLine();

                            if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(size) || string.IsNullOrEmpty(position))
                            {
                                continue;
                            }

                            AccessoryPositions.Add(Path.GetFileNameWithoutExtension(path.Remove(0, 1)), new Tuple <Vector3, float>(Vector3Ex.FromString(position.Split('=')[1]), StringConverter.ToFloat(size.Split('=')[1])));
                        }
                    }
                }
            }
        }