예제 #1
0
파일: Form1.cs 프로젝트: DrZeil/nbn-csharp
 private void OpenDataFile()
 {
     try
     {
         blockInterface();
         inputDataFilename = Common.Dialog.Open(LearnByError.Internazional.Resource.Inst.Get("r165"),
                                                LearnByError.Internazional.Resource.Inst.Get("r166"), "dat");
         if (inputDataFilename == "")
         {
             return;
         }
         inputData = MatrixMB.Load(inputDataFilename);
         info      = LearnByError.Internazional.Resource.Inst.Get("r164") + inputDataFilename;
     }
     catch (Exception ex)
     {
         ex.ToLog();
         info = LearnByError.Internazional.Resource.Inst.Get("r163");
     }
     finally
     {
         unblockInterface();
     }
 }
예제 #2
0
파일: Form1.cs 프로젝트: DrZeil/nbn-csharp
        /// <summary>
        /// Load netowrk data for specified position
        /// </summary>
        /// <param name="url">String - web address of data file</param>
        private void loadSample(String url)
        {
            try
            {
                String filename = Common.Folder.Samples + "\\" + System.IO.Path.GetFileName(url);
                if (!System.IO.File.Exists(filename))
                {
                    status.Text      = Form1_Res.Pobieranie_pliku_z_sieci;
                    progress.Style   = ProgressBarStyle.Marquee;
                    progress.Visible = true;

                    var bw = new BackgroundWorker();
                    bw.DoWork += (a, b) =>
                    {
                        try
                        {
                            String address = (String)b.Argument;
                            var    request = WebRequest.Create(url);
                            request.Timeout = 60000;

                            using (var response = request.GetResponse())
                            {
                                using (var file = File.Create(filename))
                                {
                                    response.GetResponseStream().CopyTo(file);
                                }
                            }
                            b.Result = filename;
                        }
                        catch
                        {
                            b.Result = "";
                        }
                    };
                    bw.RunWorkerCompleted += (a, b) =>
                    {
                        try
                        {
                            inputDataFilename = (String)b.Result;
                            status.Text       = Form1_Res.Plik_został_pobrany;
                            try
                            {
                                inputData = MatrixMB.Load(inputDataFilename);
                                var tmp = String.Format(Form1_Res.Dane_z_pliku_0_zostały_wczytane, inputDataFilename);
                                info = tmp;
                                Common.Log.Write(tmp);
                            }
                            catch
                            {
                                var tmp = String.Format(Form1_Res.Dane_z_pliku_0_nie_zostały_wczytane, inputDataFilename);
                                info = tmp;
                                Common.Log.Write(tmp);
                            }
                        }
                        catch
                        {
                            status.Text = Form1_Res.Plik_nie_został_pobrany;
                        }
                        finally
                        {
                            progress.Visible = false;
                            unblockInterface();
                        }
                    };
                    blockInterface();
                    progress.Style   = ProgressBarStyle.Marquee;
                    progress.Visible = true;
                    progress.Enabled = true;
                    bw.RunWorkerAsync(url);
                }
                else
                {
                    try
                    {
                        inputDataFilename = filename;
                        inputData         = MatrixMB.Load(inputDataFilename);
                        var tmp = String.Format(Form1_Res.Dane_z_pliku_0_zostały_wczytane, inputDataFilename);
                        info = tmp;
                        Common.Log.Write(tmp);
                    }
                    catch (Exception ex)
                    {
                        var tmp = String.Format(Form1_Res.Dane_z_pliku_0_nie_zostały_wczytane, inputDataFilename);
                        info = tmp;
                        Common.Log.Write(tmp, ex);
                    }
                }
            }
            catch (Exception ex)
            {
                info = ex.ToLog().GetError();
            }
        }