Exemplo n.º 1
0
 void ImportPOIData(string path)
 {
     try
     {
         int count = workspace.Import(path);
         DialogWindow.ShowMessage(this, $"Successfully imported {count} record(s) from: \n{path}", "Done");
     }
     catch (Exception ex)
     {
         DialogWindow.ShowMessage(this, "Cannot finish importing because an error occured: \n" + ex.Message, "Failed");
     }
 }
Exemplo n.º 2
0
        void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            bool debug = Debugger.IsAttached;

            // Process unhandled exception
            DialogWindow.ShowMessage(
                this.MainWindow,
                e.Exception.Message + "\nWe are sorry for the inconvenience :("
                + (debug ? "\nThe exception will NOT be checked in debug mode, press OK to continue." : "")
                , "Oops..");
            // + (debug?"\nThe exception will NOT be checked in debug mode, press OK to continue.":"")
            // Prevent default unhandled exception processing in Release ver.

            e.Handled = !debug;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Drop file on main window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ContentGrid_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

                int workspaceFileCount = 0;
                // Can have multiple files
                for (int i = 0; i < files.Length; i++)
                {
                    if (files[i].EndsWith(".clt"))
                    {
                        if (workspaceFileCount == 0)
                        {                                   // for the first .clt file
                            if (TryLoadWorkspace(files[i])) // success
                            {
                                WorkspacePath = files[i];
                            }
                        }
                        else
                        {
                            // Run another copy with path as argument
                            Process.Start(Environment.GetCommandLineArgs()[0], files[i]);
                        }
                        workspaceFileCount++;
                    }
                    else if (files[i].EndsWith(".txt") || files[i].EndsWith(".csv") || files[i].EndsWith(".xlsx"))
                    {
                        DialogWindow dialog = DialogWindow.CreateConfirmCancelDialog(this, $"Confirm importing POI data from '{files[i]}'?", "Continue?");
                        dialog.PasswordBoxVisibility = Visibility.Hidden;
                        dialog.TextBoxVisibility     = Visibility.Hidden;
                        if (dialog.ShowDialog() == true)
                        {
                            ImportPOIData(files[i]);
                        }
                    }
                    else
                    {
                        DialogWindow.ShowMessage(this, $"File format not supported. ({files[i].Substring(files[i].LastIndexOf('\\') + 1)})\n" +
                                                 "Supported format:\n" +
                                                 "* Charlotte Workspace:  .clt\n" +
                                                 "* Plain Text:   .txt .csv\n" +
                                                 "* Microsoft Excel:  .xlsx", "Input File Not Supported");
                    }
                }
            }
        }
Exemplo n.º 4
0
        bool TryLoadWorkspace(string path)
        {
            bool success = false;

            try
            {
                Workspace = Workspace.Load(path);
                success   = true;
            }
            catch (FailedWorkspaceFailException ex)
            {
                // If first attempt fail, the file may have been encrypted or corrupted
                // We ask the user for password if PasswordRequired is true
                if (ex.PasswordRequired)
                {
                    string passwordAttempt = AskPassword(path);
                    if (!String.IsNullOrEmpty(passwordAttempt))
                    {
                        try
                        {
                            Workspace = Workspace.Load(path, passwordAttempt);
                            success   = true;
                        }
                        catch (Exception ex2)
                        {
                            // If this fail again, the user shoud start over by clicking Open again
                            // There are only two attempts for solely one click so far
                            DialogWindow.ShowMessage(this, "Failed decrypting Workspace: wrong password or corrupted file.\n" +
                                                     "Error message: " + ex2.Message, "Failed Loading Workspace");
                        }
                    }
                }
                else
                {
                    DialogWindow.ShowMessage(this, "Failed loading Workspace:\n" + ex.Message);
                }
            }
            return(success);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Start a search thread
        /// </summary>
        public void SearchPoiAction()
        {
            CurrentList = DataList;

            // Stop previous fetching if Processing=true
            if (Processing)
            {
                Processing = false;
                return;
            }

            if (!Append)
            {
                DataList.Clear();
            }

            if (fetchThread != null && !fetchThread.IsAlive)
            {
                fetchThread.Abort();
            }

            fetchThread = new Thread(e =>
            {
                this.Processing = true;
                try
                {
                    if (!String.IsNullOrEmpty(Keyword))
                    {
                        SearchPoi(Keyword, City, int.Parse(Offset));
                    }
                }
                catch (Exception ex)
                {
                    App.Current.Dispatcher.Invoke((Action) delegate
                    {
                        DialogWindow.ShowMessage(null, "We encountered an error when fetching data:\n" + ex.Message, "Sorry");
                    });
                }
                finally
                {
                    this.Processing = false;
                }
            });

            fetchThread.Start();

            // Internal POI fetching method
            void SearchPoi(string keyword, string city, int recordPerPage = 50, int maxRecords = -1)
            {
                int totalRecord = 0;

                List <POI> resultList = SearchPOIRequest(keyword, city, recordPerPage, 1, out totalRecord);

                MaxProgressValue     = (int)Math.Ceiling((float)totalRecord / (float)recordPerPage);
                CurrentProgressValue = 1;

                Thread.Sleep(int.Parse(Interval));

                if (resultList.Count >= 0)
                {
                    if (totalRecord > recordPerPage)
                    {
                        for (int i = 2; i <= MaxProgressValue && Processing; i++)
                        {
                            List <POI> pendingList = SearchPOIRequest(keyword, city, recordPerPage, i, out totalRecord);
                            resultList.AddRange(pendingList);
                            CurrentProgressValue++;
                            Thread.Sleep(int.Parse(Interval));
                        }
                    }
                }

                resultList.ForEach((Action <POI>)(poi =>
                {
                    // Update displaylist in main thread
                    App.Current.Dispatcher.Invoke((Action) delegate
                    {
                        this.DataList.Add(poi);
                    });
                }));

                // Update displaylist in main thread
                App.Current.Dispatcher.Invoke((Action) delegate
                {
                    this.Processing = true;
                    //MaxPage = (int)Math.Ceiling((float)DataList.Count / (float)int.Parse(offset));
                    RecordPerPage = recordPerPage;
                    CurrentPage   = 1;
                    //RefreshDataPage();
                });
            }
        }