<commit_before>// [WriteFile Name=GenerateGeodatabase, Category=Features]
// [Legal]
// Copyright 2016 Esri.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [Legal]

import QtQuick 2.6
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtGraphicalEffects 1.0
import Esri.ArcGISRuntime 100.0
import Esri.ArcGISExtras 1.1

Rectangle {
    width: 800
    height: 600

    property real scaleFactor: System.displayScaleFactor
    property string dataPath: System.userHomePath + "/ArcGIS/Runtime/Data/"
    property string featureServiceUrl: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Sync/WildfireSync/FeatureServer"
    property Envelope generateExtent: null
    property string statusText: ""

    // Map view UI presentation at top
    MapView {
        id: mapView
        anchors.fill: parent

        Map {
            id: map
            Basemap {
                ArcGISTiledLayer {
                    tileCache: TileCache {
                        path: dataPath + "tpk/SanFrancisco.tpk"
                    }
                }
            }

            // add the initial online feature service layers
            FeatureLayer {
                ServiceFeatureTable { url: featureServiceUrl + "/0" }
            }

            FeatureLayer {
                ServiceFeatureTable { url: featureServiceUrl + "/1" }
            }

            FeatureLayer {
                ServiceFeatureTable { url: featureServiceUrl + "/2" }
            }
        }
    }

    // create the GeodatabaseSyncTask to generate the local geodatabase
    GeodatabaseSyncTask {
        id: geodatabaseSyncTask
        url: featureServiceUrl

        function executeGenerate() {
            // execute the asynchronous task and obtain the job
            var generateJob = generateGeodatabase(generateParameters, dataPath + "Wildfire.geodatabase");

            // show the generate window
            generateWindow.visible = true;

            // connect to the job's status changed signal to know once it is done
            generateJob.jobStatusChanged.connect(function() {
                switch(generateJob.jobStatus) {
                case Enums.JobStatusFailed:
                    statusText = "Generate failed";
                    generateWindow.hideWindow(5000);
                    break;
                case Enums.JobStatusNotStarted:
                    statusText = "Job not started";
                    break;
                case Enums.JobStatusPaused:
                    statusText = "Job paused";
                    break;
                case Enums.JobStatusStarted:
                    statusText = "In progress...";
                    break;
                case Enums.JobStatusSucceeded:
                    statusText = "Complete";
                    generateWindow.hideWindow(1500);
                    displayLayersFromGeodatabase(generateJob.geodatabase);
                    break;
                default:
                    break;
                }
            });

            // start the job
            generateJob.start();
        }

        function displayLayersFromGeodatabase(geodatabase) {
            // remove the original online feature layers
            map.operationalLayers.clear();

            // load the geodatabase to access the feature tables
            geodatabase.loadStatusChanged.connect(function() {
                if (geodatabase.loadStatus === Enums.LoadStatusLoaded) {
                    // create a feature layer from each feature table, and add to the map
                    for (var i = 0; i < geodatabase.geodatabaseFeatureTables.length; i++) {
                        var featureTable = geodatabase.geodatabaseFeatureTables[i];
                        var featureLayer = ArcGISRuntimeEnvironment.createObject("FeatureLayer");
                        featureLayer.featureTable = featureTable;
                        map.operationalLayers.append(featureLayer);
                    }

                    // unregister geodatabase since there will be no edits uploaded
                    geodatabaseSyncTask.unregisterGeodatabase(geodatabase);

                    // hide the extent rectangle and download button
                    extentRectangle.visible = false;
                    downloadButton.visible = false;
                }
            });
            geodatabase.load();
        }
    }

    // create the generate geodatabase parameters
    GenerateGeodatabaseParameters {
        id: generateParameters
        extent: generateExtent
        layerOptions: [
            GenerateLayerOption { layerId: "0"},
            GenerateLayerOption { layerId: "1"},
            GenerateLayerOption { layerId: "2"}
        ]
        outSpatialReference: SpatialReference.createWebMercator()
        returnAttachments: false
    }   

    // create an extent rectangle for the output geodatabase
    Rectangle {
        id: extentRectangle
        anchors.centerIn: parent
        width: parent.width - (50 * scaleFactor)
        height: parent.height - (125 * scaleFactor)
        color: "transparent"
        border {
            color: "red"
            width: 3 * scaleFactor
        }
    }

    // Create the download button to generate geodatabase
    Rectangle {
        id: downloadButton
        property bool pressed: false
        anchors {
            horizontalCenter: parent.horizontalCenter
            bottom: parent.bottom
            bottomMargin: 10 * scaleFactor
        }

        width: 200 * scaleFactor
        height: 35 * scaleFactor
        color: pressed ? "#959595" : "#D6D6D6"
        radius: 8
        border {
            color: "#585858"
            width: 1 * scaleFactor
        }

        Row {
            anchors.fill: parent
            spacing: 5
            Image {
                width: 38 * scaleFactor
                height: width
                source: "qrc:/Samples/Features/GenerateGeodatabase/download.png"
            }

            Text {
                anchors.verticalCenter: parent.verticalCenter
                text: "Generate Geodatabase"
                font.pixelSize: 14 * scaleFactor
                color: "#474747"
            }
        }

        MouseArea {
            anchors.fill: parent
            onPressed: downloadButton.pressed = true
            onReleased: downloadButton.pressed = false
            onClicked: {
                getRectangleEnvelope();
                geodatabaseSyncTask.executeGenerate();
            }

            function getRectangleEnvelope() {
                var corner1 = mapView.screenToLocation(extentRectangle.x, extentRectangle.y);
                var corner2 = mapView.screenToLocation((extentRectangle.x + extentRectangle.width), (extentRectangle.y + extentRectangle.height));
                var envBuilder = ArcGISRuntimeEnvironment.createObject("EnvelopeBuilder");
                envBuilder.setCorners(corner1, corner2);
                generateExtent = GeometryEngine.project(envBuilder.geometry, SpatialReference.createWebMercator());
            }
        }
    }

    // Create a window to display the generate window
    Rectangle {
        id: generateWindow
        anchors.fill: parent
        color: "transparent"
        visible: false
        clip: true

        GaussianBlur {
            anchors.fill: generateWindow
            source: mapView
            radius: 40
            samples: 20
            rotation: 180
        }

        MouseArea {
            anchors.fill: parent
            onClicked: mouse.accepted = true
            onWheel: wheel.accepted = true
        }

        Rectangle {
            anchors.centerIn: parent
            width: 125 * scaleFactor
            height: 100 * scaleFactor
            color: "lightgrey"
            opacity: 0.8
            radius: 5
            border {
                color: "#4D4D4D"
                width: 1 * scaleFactor
            }

            Column {
                anchors {
                    fill: parent
                    margins: 10 * scaleFactor
                }
                spacing: 10

                BusyIndicator {
                    anchors.horizontalCenter: parent.horizontalCenter
                }

                Text {
                    anchors.horizontalCenter: parent.horizontalCenter
                    text: statusText
                    font.pixelSize: 16 * scaleFactor
                }
            }
        }

        Timer {
            id: hideWindowTimer

            onTriggered: generateWindow.visible = false;
        }

        function hideWindow(time) {
            hideWindowTimer.interval = time;
            hideWindowTimer.restart();
        }
    }

    FileFolder {
        path: dataPath

        // create the data path if it does not yet exist
        Component.onCompleted: {
            if (!exists) {
                makePath(dataPath);
            }
        }
    }

    // Neatline rectangle
    Rectangle {
        anchors.fill: parent
        color: "transparent"
        border {
            width: 0.5 * scaleFactor
            color: "black"
        }
    }
}
<commit_msg>Update GenerateGeodatabase.qml<commit_after>// [WriteFile Name=GenerateGeodatabase, Category=Features]
// [Legal]
// Copyright 2016 Esri.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [Legal]

import QtQuick 2.6
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtGraphicalEffects 1.0
import Esri.ArcGISRuntime 100.0
import Esri.ArcGISExtras 1.1

Rectangle {
    width: 800
    height: 600

    property real scaleFactor: System.displayScaleFactor
    property string dataPath: System.userHomePath + "/ArcGIS/Runtime/Data/"
    property string featureServiceUrl: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Sync/WildfireSync/FeatureServer"
    property Envelope generateExtent: null
    property string statusText: ""

    // Map view UI presentation at top
    MapView {
        id: mapView
        anchors.fill: parent

        Map {
            id: map
            Basemap {
                ArcGISTiledLayer {
                    tileCache: TileCache {
                        path: dataPath + "tpk/SanFrancisco.tpk"
                    }
                }
            }

            // add the initial online feature service layers
            FeatureLayer {
                ServiceFeatureTable { url: featureServiceUrl + "/0" }
            }

            FeatureLayer {
                ServiceFeatureTable { url: featureServiceUrl + "/1" }
            }

            FeatureLayer {
                ServiceFeatureTable { url: featureServiceUrl + "/2" }
            }
        }
    }

    // create the GeodatabaseSyncTask to generate the local geodatabase
    GeodatabaseSyncTask {
        id: geodatabaseSyncTask
        url: featureServiceUrl

        function executeGenerate() {
            // execute the asynchronous task and obtain the job
            var generateJob = generateGeodatabase(generateParameters, dataPath + "WildfireQml.geodatabase");

            // show the generate window
            generateWindow.visible = true;

            // connect to the job's status changed signal to know once it is done
            generateJob.jobStatusChanged.connect(function() {
                switch(generateJob.jobStatus) {
                case Enums.JobStatusFailed:
                    statusText = "Generate failed";
                    generateWindow.hideWindow(5000);
                    break;
                case Enums.JobStatusNotStarted:
                    statusText = "Job not started";
                    break;
                case Enums.JobStatusPaused:
                    statusText = "Job paused";
                    break;
                case Enums.JobStatusStarted:
                    statusText = "In progress...";
                    break;
                case Enums.JobStatusSucceeded:
                    statusText = "Complete";
                    generateWindow.hideWindow(1500);
                    displayLayersFromGeodatabase(generateJob.geodatabase);
                    break;
                default:
                    break;
                }
            });

            // start the job
            generateJob.start();
        }

        function displayLayersFromGeodatabase(geodatabase) {
            // remove the original online feature layers
            map.operationalLayers.clear();

            // load the geodatabase to access the feature tables
            geodatabase.loadStatusChanged.connect(function() {
                if (geodatabase.loadStatus === Enums.LoadStatusLoaded) {
                    // create a feature layer from each feature table, and add to the map
                    for (var i = 0; i < geodatabase.geodatabaseFeatureTables.length; i++) {
                        var featureTable = geodatabase.geodatabaseFeatureTables[i];
                        var featureLayer = ArcGISRuntimeEnvironment.createObject("FeatureLayer");
                        featureLayer.featureTable = featureTable;
                        map.operationalLayers.append(featureLayer);
                    }

                    // unregister geodatabase since there will be no edits uploaded
                    geodatabaseSyncTask.unregisterGeodatabase(geodatabase);

                    // hide the extent rectangle and download button
                    extentRectangle.visible = false;
                    downloadButton.visible = false;
                }
            });
            geodatabase.load();
        }
    }

    // create the generate geodatabase parameters
    GenerateGeodatabaseParameters {
        id: generateParameters
        extent: generateExtent
        layerOptions: [
            GenerateLayerOption { layerId: "0"},
            GenerateLayerOption { layerId: "1"},
            GenerateLayerOption { layerId: "2"}
        ]
        outSpatialReference: SpatialReference.createWebMercator()
        returnAttachments: false
    }   

    // create an extent rectangle for the output geodatabase
    Rectangle {
        id: extentRectangle
        anchors.centerIn: parent
        width: parent.width - (50 * scaleFactor)
        height: parent.height - (125 * scaleFactor)
        color: "transparent"
        border {
            color: "red"
            width: 3 * scaleFactor
        }
    }

    // Create the download button to generate geodatabase
    Rectangle {
        id: downloadButton
        property bool pressed: false
        anchors {
            horizontalCenter: parent.horizontalCenter
            bottom: parent.bottom
            bottomMargin: 10 * scaleFactor
        }

        width: 200 * scaleFactor
        height: 35 * scaleFactor
        color: pressed ? "#959595" : "#D6D6D6"
        radius: 8
        border {
            color: "#585858"
            width: 1 * scaleFactor
        }

        Row {
            anchors.fill: parent
            spacing: 5
            Image {
                width: 38 * scaleFactor
                height: width
                source: "qrc:/Samples/Features/GenerateGeodatabase/download.png"
            }

            Text {
                anchors.verticalCenter: parent.verticalCenter
                text: "Generate Geodatabase"
                font.pixelSize: 14 * scaleFactor
                color: "#474747"
            }
        }

        MouseArea {
            anchors.fill: parent
            onPressed: downloadButton.pressed = true
            onReleased: downloadButton.pressed = false
            onClicked: {
                getRectangleEnvelope();
                geodatabaseSyncTask.executeGenerate();
            }

            function getRectangleEnvelope() {
                var corner1 = mapView.screenToLocation(extentRectangle.x, extentRectangle.y);
                var corner2 = mapView.screenToLocation((extentRectangle.x + extentRectangle.width), (extentRectangle.y + extentRectangle.height));
                var envBuilder = ArcGISRuntimeEnvironment.createObject("EnvelopeBuilder");
                envBuilder.setCorners(corner1, corner2);
                generateExtent = GeometryEngine.project(envBuilder.geometry, SpatialReference.createWebMercator());
            }
        }
    }

    // Create a window to display the generate window
    Rectangle {
        id: generateWindow
        anchors.fill: parent
        color: "transparent"
        visible: false
        clip: true

        GaussianBlur {
            anchors.fill: generateWindow
            source: mapView
            radius: 40
            samples: 20
            rotation: 180
        }

        MouseArea {
            anchors.fill: parent
            onClicked: mouse.accepted = true
            onWheel: wheel.accepted = true
        }

        Rectangle {
            anchors.centerIn: parent
            width: 125 * scaleFactor
            height: 100 * scaleFactor
            color: "lightgrey"
            opacity: 0.8
            radius: 5
            border {
                color: "#4D4D4D"
                width: 1 * scaleFactor
            }

            Column {
                anchors {
                    fill: parent
                    margins: 10 * scaleFactor
                }
                spacing: 10

                BusyIndicator {
                    anchors.horizontalCenter: parent.horizontalCenter
                }

                Text {
                    anchors.horizontalCenter: parent.horizontalCenter
                    text: statusText
                    font.pixelSize: 16 * scaleFactor
                }
            }
        }

        Timer {
            id: hideWindowTimer

            onTriggered: generateWindow.visible = false;
        }

        function hideWindow(time) {
            hideWindowTimer.interval = time;
            hideWindowTimer.restart();
        }
    }

    FileFolder {
        path: dataPath

        // create the data path if it does not yet exist
        Component.onCompleted: {
            if (!exists) {
                makePath(dataPath);
            }
        }
    }

    // Neatline rectangle
    Rectangle {
        anchors.fill: parent
        color: "transparent"
        border {
            width: 0.5 * scaleFactor
            color: "black"
        }
    }
}

{'fraction_non_alphanumeric': 0.06948906622447922, 'fraction_numerical': 0.012125608871385635, 'mean_word_length': 1.50149060272197, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5939677', 'n_tokens_mistral': 4963, 'n_tokens_neox': 4544, 'n_words': 1207}