コード例 #1
0
        public void ImportAddressButtonClick()
        {
            try
            {
                string languageFilePath = view.OpenFileDialog(
                    fileExt: "html",
                    title: "Open Alba Language File");

                string addressFilePath = view.OpenFileDialog(
                    fileExt: "csv",
                    title: "Open Alba Address CSV File to Upload");

                if (string.IsNullOrWhiteSpace(languageFilePath) ||
                    string.IsNullOrWhiteSpace(addressFilePath))
                {
                    return;
                }

                new ImportAddress(AuthenticatedClient(), int.Parse(view.UploadDelayMs))
                .Upload(addressFilePath, languageFilePath);
            }
            catch (UserException e)
            {
                view.ShowMessageBox(e.Message);
            }
        }
コード例 #2
0
        public void Upload()
        {
            if (client.BasePath == null)
            {
                view.ShowMessageBox("You are not logged on to Alba.  Please Logon.");
                return;
            }

            string fileName = view.OpenFileDialog("kml");

            if (string.IsNullOrWhiteSpace(fileName))
            {
                return;
            }

            var kml         = new KmlGateway().Load(fileName);
            var territories = new KmlToTerritoryConverter()
                              .TerritoryListFrom(kml)
                              .Where(t => t.Border != null && t.Border.Vertices != null && t.Border.Vertices.Count > 0)
                              .ToList();

            view.AppendResultText("Uploading " + territories.Count + " territory borders...");

            foreach (var territory in territories)
            {
                int count = territory.Border.Vertices.Count;

                var url          = RelativeUrlBuilder.RequestToAddNew(territory);
                var resultString = client.DownloadString(url);

                view.AppendResultText("Territory: " + territory.Number);
                view.AppendResultText(count + " vertices where uploaded..." + Environment.NewLine);
                view.AppendResultText(resultString + Environment.NewLine + Environment.NewLine);
                Thread.Sleep(delay);
            }
        }