Пример #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //  MessageBox.Show(result[0].ToString());
            //   MessageBox.Show(filename[0]);
            //string filename = Directory.GetFiles(@appPath + "Update").Select(x => System.IO.Path.GetFileNameWithoutExtension(x));
            //MessageBox.Show(Y);

            // CurrentProject.GetDirrectory();
            //  MessageBox.Show(appPath + "Update");

            // string[] files1 = Directory.GetFiles(@"c:\0001");

            //MessageBox.Show(files1[0]);

            var ServiceUpdate = new Service.ServiceUpdateClient("BasicHttpBinding_IServiceUpdate");

            try
            {
                String[] list = ServiceUpdate.getFileinfo();



                string appPath = AppDomain.CurrentDomain.BaseDirectory;
                Directory.CreateDirectory(appPath + "Update");
                //string[] filename = Directory.GetFiles(appPath + "Update");

                List <string> result = new List <string>();
                for (int i = 0; i < list.Length; i++)
                {
                    result.Add(System.IO.Path.GetFileName(list[i]));
                }


                txtblock.Text = "";

                for (int i = 0; i < list.Length; i++)
                {
                    // MessageBox.Show(list[i]);
                    // int l = list[0].Length;

                    txtblock.Text += "-->>" + list[i] + "\n";
                    //  MessageBox.Show(list[i].Substring(0, 3) + "0001" + list[i].Substring(7, list[i].Length - 7 ));
                }



                for (int i = 0; i < list.Length; i++)
                {
                    int    lenght       = ServiceUpdate.LenghtFile(list[i]);
                    Stream file         = ServiceUpdate.getFile(list[i]);
                    byte[] bytes_file_w = new byte[lenght];
                    file.Read(bytes_file_w, 0, lenght);

                    //string path = @list[i].Substring(0, 3) + "0001" + list[i].Substring(7, list[i].Length - 7);
                    //string path = @"c:\0001\test.txt";
                    string     path   = @appPath + "Update\\" + result[i];
                    FileStream file_w = File.Open(path, FileMode.Create);
                    file_w.Write(bytes_file_w, 0, bytes_file_w.Length);

                    // File.WriteAllBytes(@"c:\\MyDownloadedBooks\\" + "test.txt", bytes_file_w);
                    file_w.Close();
                }
            }
            catch
            {
                MessageBox.Show("Сервис не отвечает:");
            }
            ServiceUpdate.Close();
        }
Пример #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            /*   if(MessageBox.Show("Есть обновления. Обновить?", "Обновление системы", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes){
             *     MessageBox.Show("ОТЛИЧО");
             * }*/

            //  MessageBox.Show(result[0].ToString());
            //   MessageBox.Show(filename[0]);
            //string filename = Directory.GetFiles(@appPath + "Update").Select(x => System.IO.Path.GetFileNameWithoutExtension(x));
            //MessageBox.Show(Y);

            // CurrentProject.GetDirrectory();
            //  MessageBox.Show(appPath + "Update");

            // string[] files1 = Directory.GetFiles(@"c:\0001");

            //MessageBox.Show(files1[0]);

            var ServiceUpdate = new Service.ServiceUpdateClient("BasicHttpBinding_IServiceUpdate");


            try
            {
                String[] list = ServiceUpdate.getFileinfo();



                string appPath = AppDomain.CurrentDomain.BaseDirectory;
                Directory.CreateDirectory(appPath + "Update");
                //string[] filename = Directory.GetFiles(appPath + "Update");

                List <string> result = new List <string>();
                for (int i = 0; i < list.Length; i++)
                {
                    result.Add(System.IO.Path.GetFileName(list[i]));
                }


                txtblock.Text = "";

                /* for (int i = 0; i < list.Length; i++)
                 * {
                 *   // MessageBox.Show(list[i]);
                 *   // int l = list[0].Length;
                 *
                 * //  txtblock.Text += "-->>" + list[i] + "\n";
                 *   //  MessageBox.Show(list[i].Substring(0, 3) + "0001" + list[i].Substring(7, list[i].Length - 7 ));
                 * }*/



                for (int i = 0; i < list.Length; i++)
                {
                    txtblock.Text += "\n-->>" + list[i];//Скачиваемый файл

                    int    lenght       = ServiceUpdate.LenghtFile(list[i]);
                    Stream file         = ServiceUpdate.getFile(list[i]);
                    byte[] bytes_file_w = new byte[lenght];

                    var offset     = 0;
                    var actualRead = 0;

                    string text = txtblock.Text;
                    do
                    {
                        actualRead    = file.Read(bytes_file_w, offset, lenght - offset);
                        offset       += actualRead;
                        txtblock.Text = text + " " + offset.ToString() + "/" + lenght.ToString();
                    } while (actualRead > 0);



                    //string path = @list[i].Substring(0, 3) + "0001" + list[i].Substring(7, list[i].Length - 7);
                    //string path = @"c:\0001\test.txt";
                    string way1 = System.IO.Path.GetDirectoryName(list[i]);
                    Directory.CreateDirectory(appPath + "Update\\" + way1);
                    string     path   = @appPath + "Update\\" + list[i];
                    FileStream file_w = File.Open(path, FileMode.Create);
                    file_w.Write(bytes_file_w, 0, bytes_file_w.Length);

                    // File.WriteAllBytes(@"c:\\MyDownloadedBooks\\" + "test.txt", bytes_file_w);
                    file_w.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Сработало исключение\n " + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                txtblock.Text = ex.Message;
            }
            ServiceUpdate.Close();
        }