コード例 #1
0
            private async void AddAttachment(UITableView tableView)
            {
                // Get the image to upload.
                Stream imageStream = await GetImageStreamAsync();

                if (imageStream == null)
                {
                    return;
                }

                // Convert the image stream into a byte array.
                byte[] attachmentData = new byte[imageStream.Length];
                imageStream.Read(attachmentData, 0, attachmentData.Length);

                // Determine the file name.
                string filename = _filename ?? "iOS_image_1.jpg";

                // Add the attachment.
                // The contentType string is the MIME type for JPEG files, image/jpeg.
                await _selectedFeature.AddAttachmentAsync(filename, "image/jpeg", attachmentData);

                // Get a reference to the feature's service feature table.
                ServiceFeatureTable serviceTable = (ServiceFeatureTable)_selectedFeature.FeatureTable;

                // Apply the edits to the service feature table.
                await serviceTable.ApplyEditsAsync();

                // Update UI.
                _selectedFeature.Refresh();
                _attachments = await _selectedFeature.GetAttachmentsAsync();

                tableView.ReloadData();
                _viewController.ShowMessage("Successfully added attachment", "Success!");
            }
コード例 #2
0
        private async void UpdateUIForFeature()
        {
            // Select the feature.
            _damageLayer.SelectFeature(_selectedFeature);

            // Get the attachments.
            _featureAttachments = await _selectedFeature.GetAttachmentsAsync();

            // Limit to only feature attachments with an image/jpeg content type.
            _featureAttachments = _featureAttachments.Where(attachment => attachment.ContentType == "image/jpeg").ToList();

            // Configure array adapter.
            ArrayAdapter attachmentAdapter = new ArrayAdapter <string>(
                this,
                Android.Resource.Layout.SimpleListItem1,
                _featureAttachments.Select(attachment => attachment.Name).ToArray());

            // Populate the list.
            _attachmentsListView.Adapter = attachmentAdapter;
        }
コード例 #3
0
        private async void MapView_Tapped(object sender, GeoViewInputEventArgs e)
        {
            // Clear any existing selection.
            _damageLayer.ClearSelection();
            _selectedFeature = null;

            // Reset the UI.
            AttachmentsListBox.IsEnabled   = false;
            AttachmentsListBox.ItemsSource = null;
            AddAttachmentButton.IsEnabled  = false;

            try
            {
                // Perform an identify to determine if a user tapped on a feature.
                IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_damageLayer, e.Position, 2, false);

                // Do nothing if there are no results.
                if (!identifyResult.GeoElements.Any())
                {
                    return;
                }

                // Get the selected feature as an ArcGISFeature. It is assumed that all GeoElements in the result are of type ArcGISFeature.
                GeoElement    tappedElement = identifyResult.GeoElements.First();
                ArcGISFeature tappedFeature = (ArcGISFeature)tappedElement;

                // Select the feature in the UI and hold a reference to the tapped feature in a field.
                _damageLayer.SelectFeature(tappedFeature);
                _selectedFeature = tappedFeature;

                // Load the feature.
                await tappedFeature.LoadAsync();

                // Get the attachments.
                IReadOnlyList <Attachment> attachments = await tappedFeature.GetAttachmentsAsync();

                // Populate the UI with a list of attachments that have a content type of image/jpeg.
                AttachmentsListBox.ItemsSource = attachments.Where(attachment => attachment.ContentType == "image/jpeg");
                AttachmentsListBox.IsEnabled   = true;
                AddAttachmentButton.IsEnabled  = true;
            }
            catch (Exception ex)
            {
                await new MessageDialog2(ex.ToString(), "Error loading feature").ShowAsync();
            }
        }
コード例 #4
0
        private async void SetYTY()
        {
            await ArcGISFeature.LoadAsync();

            IReadOnlyList <Attachment> attachments = await ArcGISFeature.GetAttachmentsAsync();

            foreach (Attachment attachment in attachments)
            {
                if (attachment.Name.Equals(ArcGisService.YTY_FILE_NAME))
                {
                    Stream jsonStream = await attachment.GetDataAsync();

                    StreamReader streamReader = new StreamReader(jsonStream);
                    string       jsonString   = streamReader.ReadToEnd();

                    Binstance.YTYDatas.Clear();
                    Binstance.YTYDatas.AddRange((List <YTYData>)JsonConvert.DeserializeObject <IEnumerable <YTYData> >(jsonString));
                    break;
                }
            }
        }
コード例 #5
0
        private async void AddAttachment_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedFeature == null)
            {
                return;
            }

            // Adjust the UI.
            AddAttachmentButton.IsEnabled = false;
            ActivityIndicator.Visibility  = Visibility.Visible;

            // Get the file.
            string contentType = "image/jpeg";

            byte[] attachmentData;

            try
            {
                // Show a file picker.
                // Allow the user to specify a file path - create the picker.
                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.FileTypeFilter.Add(".jpg");

                // Show the picker.
                StorageFile file = await openPicker.PickSingleFileAsync();

                // Take action if the user selected a file.
                if (file == null)
                {
                    return;
                }

                // Read the file contents into memory.
                Stream dataStream = await file.OpenStreamForReadAsync();

                attachmentData = new byte[dataStream.Length];
                dataStream.Read(attachmentData, 0, attachmentData.Length);
                dataStream.Close();

                // Add the attachment.
                // The contentType string is the MIME type for JPEG files, image/jpeg.
                await _selectedFeature.AddAttachmentAsync(file.Name, contentType, attachmentData);

                // Get a reference to the feature's service feature table.
                ServiceFeatureTable serviceTable = (ServiceFeatureTable)_selectedFeature.FeatureTable;

                // Apply the edits to the service feature table.
                await serviceTable.ApplyEditsAsync();

                // Update UI.
                _selectedFeature.Refresh();
                AttachmentsListBox.ItemsSource = await _selectedFeature.GetAttachmentsAsync();

                await new MessageDialog2("Successfully added attachment", "Success!").ShowAsync();
            }
            catch (Exception exception)
            {
                await new MessageDialog2(exception.ToString(), "Error adding attachment").ShowAsync();
            }
            finally
            {
                // Adjust the UI.
                AddAttachmentButton.IsEnabled = true;
                ActivityIndicator.Visibility  = Visibility.Collapsed;
            }
        }
コード例 #6
0
        private async void AddAttachment_Click(object sender, EventArgs e)
        {
            if (_selectedFeature == null)
            {
                return;
            }

            // Adjust the UI.
            AddAttachmentButton.IsEnabled         = false;
            AttachmentActivityIndicator.IsVisible = true;

            // Get the file.
            string contentType = "image/jpeg";

            try
            {
                byte[] attachmentData;
                string filename;

                // Xamarin.Plugin.FilePicker shows the iCloud picker (not photo picker) on iOS.
                // This iOS code shows the photo picker.
#if __IOS__
                Stream imageStream = await GetImageStreamAsync();

                if (imageStream == null)
                {
                    return;
                }

                attachmentData = new byte[imageStream.Length];
                imageStream.Read(attachmentData, 0, attachmentData.Length);
                filename = _filename ?? "file1.jpeg";
#else
                // Show a file picker - this uses the Xamarin.Plugin.FilePicker NuGet package.
                FileData fileData = await CrossFilePicker.Current.PickFile(new[] { ".jpg", ".jpeg" });

                if (fileData == null)
                {
                    return;
                }

                if (!fileData.FileName.EndsWith(".jpg") && !fileData.FileName.EndsWith(".jpeg"))
                {
                    await Application.Current.MainPage.DisplayAlert("Try again!", "This sample only allows uploading jpg files.", "OK");

                    return;
                }

                attachmentData = fileData.DataArray;
                filename       = fileData.FileName;
#endif
                // Add the attachment.
                // The contentType string is the MIME type for JPEG files, image/jpeg.
                await _selectedFeature.AddAttachmentAsync(filename, contentType, attachmentData);

                // Get a reference to the feature's service feature table.
                ServiceFeatureTable serviceTable = (ServiceFeatureTable)_selectedFeature.FeatureTable;

                // Apply the edits to the service feature table.
                await serviceTable.ApplyEditsAsync();

                // Update UI.
                _selectedFeature.Refresh();
                AttachmentsListBox.ItemsSource = await _selectedFeature.GetAttachmentsAsync();

                await Application.Current.MainPage.DisplayAlert("Success!", "Successfully added attachment", "OK");
            }
            catch (Exception exception)
            {
                await Application.Current.MainPage.DisplayAlert("Error adding attachment", exception.ToString(), "OK");
            }
            finally
            {
                // Adjust the UI.
                AddAttachmentButton.IsEnabled         = true;
                AttachmentActivityIndicator.IsVisible = false;
            }
        }
コード例 #7
0
        private async void AddAttachment_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedFeature == null)
            {
                return;
            }

            // Adjust the UI.
            AddAttachmentButton.IsEnabled = false;
            ActivityIndicator.Visibility  = Visibility.Visible;

            try
            {
                // Show a file dialog.
                // Allow the user to specify a file path - create the dialog.
                OpenFileDialog dlg = new OpenFileDialog
                {
                    DefaultExt       = ".jpg",
                    Filter           = "Image Files(*.JPG;*.JPEG)|*.JPG;*.JPEG",
                    InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
                };

                // Show the dialog and get the results.
                bool?result = dlg.ShowDialog();

                // Take action if the user selected a file.
                if (result != true)
                {
                    return;
                }

                // Get the name of the file from the full path (dlg.FileName is the full path).
                string filename = Path.GetFileName(dlg.FileName);

                // Create a stream for reading the file.
                FileStream fs = new FileStream(dlg.FileName,
                                               FileMode.Open,
                                               FileAccess.Read);

                // Create a binary reader from the stream.
                BinaryReader br = new BinaryReader(fs);

                // Populate the attachment data with the binary content.
                long   numBytes       = new FileInfo(dlg.FileName).Length;
                byte[] attachmentData = br.ReadBytes((int)numBytes);

                // Close the stream.
                fs.Close();

                // Add the attachment.
                // The contentType string is the MIME type for JPEG files, image/jpeg.
                await _selectedFeature.AddAttachmentAsync(filename, "image/jpeg", attachmentData);

                // Get a reference to the feature's service feature table.
                ServiceFeatureTable serviceTable = (ServiceFeatureTable)_selectedFeature.FeatureTable;

                // Apply the edits to the service feature table.
                await serviceTable.ApplyEditsAsync();

                // Update UI.
                _selectedFeature.Refresh();
                AttachmentsListBox.ItemsSource = await _selectedFeature.GetAttachmentsAsync();

                MessageBox.Show("Successfully added attachment", "Success!");
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString(), "Error adding attachment");
            }
            finally
            {
                // Adjust the UI.
                AddAttachmentButton.IsEnabled = true;
                ActivityIndicator.Visibility  = Visibility.Collapsed;
            }
        }
コード例 #8
0
        public static async Task <ArcCrudEnum> EditBin(BinViewModel binViewModel)
        {
            IBinstance    bin           = binViewModel.Binstance;
            ArcGISFeature featureToEdit = binViewModel.ArcGISFeature;

            try
            {
                await featureToEdit.LoadAsync();

                featureToEdit.Attributes["identifier"]  = bin.Identifier;
                featureToEdit.Attributes["modified_by"] = binViewModel.EmpoyeeNumber;

                switch (bin.BinType)
                {
                case BinTypeEnum.RoundStorage:
                    featureToEdit.Attributes["bin_type"] = "round_storage";
                    break;

                case BinTypeEnum.GravityWagon:
                    featureToEdit.Attributes["bin_type"] = "gravity_wagon";
                    break;

                case BinTypeEnum.PolygonStructure:
                    featureToEdit.Attributes["bin_type"] = "polygon_structure";
                    break;

                case BinTypeEnum.FlatStructure:
                    featureToEdit.Attributes["bin_type"] = "flat_structure";
                    break;
                }

                featureToEdit.Attributes["year_collected"] = bin.YearCollected;


                if (bin.IsLeased.HasValue)
                {
                    featureToEdit.Attributes["owned_or_leased"] = bin.IsLeased.Value ? "leased" : "owned";
                }

                if (bin.HasDryingDevice.HasValue)
                {
                    featureToEdit.Attributes["drying_device"] = bin.HasDryingDevice.Value ? "true" : "false";
                }

                if (bin.HasGrainHeightIndicator.HasValue)
                {
                    featureToEdit.Attributes["bin_level_indicator_device"] = bin.HasGrainHeightIndicator.Value ? "true" : "false";
                }

                switch (bin.LadderType)
                {
                case Ladder.None:
                    featureToEdit.Attributes["ladder_type"] = "none";
                    break;

                case Ladder.Ladder:
                    featureToEdit.Attributes["ladder_type"] = "ladder";
                    break;

                case Ladder.Stairs:
                    featureToEdit.Attributes["ladder_type"] = "stairs";
                    break;
                }

                featureToEdit.Attributes["notes"] = bin.Notes;

                double dr;
                //double.TryParse(bin.BinVolume, out dr);
                //featureToEdit.Attributes["bin_volume"] = dr;

                //bin type specific logic below
                Type t = bin.GetType();
                if (bin.BinType == BinTypeEnum.FlatStructure)
                {
                    if (t.Equals(typeof(FlatBin)))
                    {
                        FlatBin flat = (FlatBin)bin;
                        featureToEdit.Attributes["crib_height"] = flat.CribLength;
                        featureToEdit.Attributes["crib_width"]  = flat.CribWidth;
                    }
                }
                else if (bin.BinType == BinTypeEnum.GravityWagon)
                {
                    if (t.Equals(typeof(GravityBin)))
                    {
                        GravityBin gravityBin = (GravityBin)bin;
                        featureToEdit.Attributes["chute_length"]     = gravityBin.ChuteLength;
                        featureToEdit.Attributes["hopper_height"]    = gravityBin.HopperHeight;
                        featureToEdit.Attributes["rectangle_height"] = gravityBin.RectangleHeight;
                        featureToEdit.Attributes["rectangle_length"] = gravityBin.RectangleLength;
                        featureToEdit.Attributes["rectangle_width"]  = gravityBin.RectangleWidth;
                    }
                }
                else if (bin.BinType == BinTypeEnum.PolygonStructure)
                {
                    if (t.Equals(typeof(PolygonBin)))
                    {
                        PolygonBin polygonBin = (PolygonBin)bin;
                        featureToEdit.Attributes["side_height"]     = polygonBin.SideHeight;
                        featureToEdit.Attributes["side_width"]      = polygonBin.SideWidth;
                        featureToEdit.Attributes["number_of_sides"] = polygonBin.NumberOfSides;
                    }
                }
                else if (bin.BinType == BinTypeEnum.RoundStorage)
                {
                    if (t.Equals(typeof(PolygonBin)))
                    {
                        RoundBin round = (RoundBin)bin;
                        if (round.HasHopper.HasValue)
                        {
                            featureToEdit.Attributes["has_hopper"] = round.HasHopper.Value ? "true" : "false";
                        }

                        featureToEdit.Attributes["radius"]        = round.Radius;
                        featureToEdit.Attributes["wall_height"]   = round.WallHeight;
                        featureToEdit.Attributes["roof_height"]   = round.RoofHeight;
                        featureToEdit.Attributes["hopper_height"] = round.HopperHeight;
                    }
                }


                // can't be null
                if (binViewModel.Binstance.YTYDatas == null)
                {
                    binViewModel.Binstance.YTYDatas = new List <YTYData>();
                }
                //use data in _binViewModel

                System.Diagnostics.Debug.Print("Feature can edit attachments" + (featureToEdit.CanEditAttachments ? "Yes" : "No"));
                //-------- Formatting --------
                //create json
                string jsonString = JsonConvert.SerializeObject(binViewModel.Binstance.YTYDatas);

                //System.Diagnostics.Debug.Print(jsonString);
                //System.Diagnostics.Debug.Print(((Binstance)(binViewModel.Binstance)).YTYDatasString());
                // convert json to byte array
                byte[] byteArray = Encoding.UTF8.GetBytes(jsonString);


                //-------- ARC Connection --------
                //remove old YTYData
                List <Attachment>          attachmentsToRemove = new List <Attachment>();
                IReadOnlyList <Attachment> attachments         = await featureToEdit.GetAttachmentsAsync();

                foreach (Attachment attachment in attachments)
                {
                    System.Diagnostics.Debug.Print(attachment.Name);
                    if (attachment.Name.Equals(YTY_FILE_NAME))
                    {
                        System.Diagnostics.Debug.Print("Found YTY attachment");
                        attachmentsToRemove.Add(attachment);
                    }
                }
                System.Diagnostics.Debug.Print("Attachments to remove:");
                foreach (Attachment attachment in attachments)
                {
                    System.Diagnostics.Debug.Print(attachment.Name);
                }

                if (attachmentsToRemove.Any())
                {
                    //update the json file
                    await featureToEdit.UpdateAttachmentAsync(attachmentsToRemove.First(), YTY_FILE_NAME, "application/json", byteArray);
                }

                _featureTable = (ServiceFeatureTable)featureToEdit.FeatureTable;

                // update feature after attachment added
                await _featureTable.UpdateFeatureAsync(featureToEdit); //agsFeature

                System.Diagnostics.Debug.Print("Feature table updated");

                // push to ArcGIS Online feature service
                IReadOnlyList <EditResult> editResults = await _featureTable.ApplyEditsAsync();

                System.Diagnostics.Debug.Print("Arc updated");

                foreach (var er in editResults)
                {
                    if (er.CompletedWithErrors)
                    {
                        // handle error (er.Error.Message)
                        return(ArcCrudEnum.Failure);
                    }
                }

                return(ArcCrudEnum.Success);
            }
            catch (ArcGISWebException)
            {
                return(ArcCrudEnum.Exception);
            }
        }