Tuesday, September 3, 2019

[Code snippet] INotifyPropertyChanged in the model and subscribed the PropertyChanged event of the model in ViewModel

Be The First To Comment
internal class Model:INotifyPropertyChanged
        public Model()

        string _FirstName = "Shahir";
        public string FirstName
            get { return _FirstName; }
                _FirstName = value;

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged([CallerMemberName] string propertyName = "")
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

internal class MyViewModel:INotifyPropertyChanged
        private Model myModel;

        public MyViewModel(Model model)
            this.myModel = model;
            myModel.PropertyChanged += myModel_PropertyChanged;

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged([CallerMemberName] string propertyName = "")
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

        string _FirstName;
        public string MyFirstName
            get { return myModel.FirstName; }
                _FirstName = value;

        private void myModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
            if (e.PropertyName == "FirstName")
                MyFirstName = myModel.FirstName;

REFERECE - https://www.codeproject.com/Questions/1055820/How-the-Model-changes-could-be-notified-to-ViewMod

Tuesday, August 20, 2019

Code snippet: ArcGIS Runtime 100.x Geodatabase Delta Sync

Be The First To Comment
ESRI namespaces

using Esri.ArcGISRuntime.Tasks.Offline;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Tasks;
using Esri.ArcGISRuntime.Http;

Code snippet

string localGeodatabaseName = @"C:\Data\test.geodatabase";

string deltaGeodatabaseName = @"C:\Deltas\_ags_data{52DwertD40459D02EC197E5EC12C}.geodatabase";

Task<IReadOnlyList<SyncLayerResult>> syncTaskResult = GeodatabaseSyncTask.ImportGeodatabaseDeltaAsync(localGeodatabaseName , deltaGeodatabaseName );

Code snippet: HTTP call to ArcGIS server from ArcGIS Runtime Enviroment 100.x

Be The First To Comment
Required namespaces - 

using System.Net.Http;
using Esri.ArcGISRuntime.Http;

using Newtonsoft.Json; //To parse the response

Code snippet - 

Uri requestUri = new Uri(serviceUrl +"?f=pjson");

//Default HttpClient handler which also handles the ArcGIS server Identity
ArcGISHttpClientHandler handler = new ArcGISHttpClientHandler() 
                                                                  { UseDefaultCredentials = true };

HttpClient client = new HttpClient(handler);

string serverResponseJsonString = await client.GetStringAsync(requestUri);

Console.WriteLine(serverResponseJsonString );  

//Convert respones string to JSON Object, optional
ArcGisServerResponse  serverResponseJson = JsonConvert.DeserializeObject<ArcGisServerResponse>(serverResponseJsonString);

Saturday, June 15, 2019

Flavours of .NET implementation

Be The First To Comment

 OSOpen SourcePurpose
.NET FrameworkWindowsNoUsed for building Windows desktop applications and ASP.NET Web apps running on IIS.
.NET CoreWindows, Linux, macOSYesUsed for building cross-platform console apps and ASP.NET Core Web apps and cloud services.
XamariniOS, Android, macOSYesUsed for building mobile applications for iOS and Android, as well as desktop apps for macOS.
.NET StandardN/AYesUsed for building libraries that can be referenced from all .NET implementations, such as .NET Framework, .NET Core and Xamarin.

Sunday, May 19, 2019

Code Snippet: ESRI JS API 4.11 get Latittude Longitude on mouse hover

Be The First To Comment
ESRI JS API 4.11 get Latittude Longitude on mouse hover

//print point on mouse hover on map

mapView.on("pointer-move", function(event){
let mapPoint = mapView.toMap({x: event.x, y: event.y});

//print point on mouse click on map

mapView.on("click", function(event){
let mapPoint = event.mapPoint;

Both console statement will return the identical object as below which has latitude and longitude

  1. {__accessor__: b}
    1. cache(...)
    2. extent(...)
    3. hasM(...)
    4. hasZ(...)
    5. latitude(...)
    6. longitude(...)
    7. m(...)
    8. spatialReference(...)
    9. type(...)
    10. x(...)
    11. y(...)
    12. z(...)
    13. constructed(...)
    14. destroyed(...)
    15. initialized(...)

Friday, April 12, 2019

Code Snippet : Windows NTLM POST using Node JS

Be The First To Comment
let ntlm = require('request-ntlm-lite');

let postData = 'user=test';   //anything

let headers = {'Content-Type': 'application/x-www-form-urlencoded'};

let ntlmOptions = {                 
url: 'postUrl',
username: 'username',
password: 'password',
rejectUnauthorized: false, //disable ssl certificate error
ntlm_domain: 'domain_name',
json: true,

ntlm.post(ntlmOptions, postData, function(error, response, body){

Database Configuration to connect with named instance SQL Server with mssql for node.js

Be The First To Comment
After some frustration, it found that Node JS mssql (5.0.5) doesn't like instance name in config file to make mssql.ConnectionPool(config)-


    dbConfig: {
        "user": "user",
        "password": "pass",
        "server": "myserver",  //  Without instance name 
        "database": "dbname",
        "driver": "tedious",
        "options": {
            "trustedConnection": true

Doesn't Work

Thursday, March 28, 2019

ESRI JS API 4.8 makes default call to unsupported API to generate token.

Be The First To Comment
ESRI Identity Manager, ESRI JS API 4.8 makes default call to unsupported API to generate token.
ID calls to portal/sharing  in stead of portal/sharing/rest/ for token.

Friday, March 22, 2019

Generate ArcGIS Token By URL Request From ArcGIS Portal, Federated Environment , ESRI JS API and Angular snippets

Be The First To Comment

In my custom angular web application, I had to pull the data from different ArcGIS server environments, say Dev ArcGIS server and Test ArcGIS server environment, some of my items are directly referred from ArcGIS server services and some of them are from Enterprise portal referring the WebMapId and PortalId from both environment (Dev, Test). Servers are in federated environment.

To pull the data from different ArcGIS server environment, user must login in each environment. In addition, user must login to get inside the custom application and Enterprise AD Group was set to authenticate users on the custom web application and ArcGIS server environments. So, there will be 3 login attempts (1 –application itself, 2- Dev server/portal, 3- Test server/portal) to use the application, which doesn’t provide good user experience.

To improve the better application workflow, I decided to reduce the number of logins required in the application and use AD Username and Password captured during application login to generate token for each ArcGIS server environment. Here are some reference snippets to generate token from ArcGIS server and use tokens request parameter in ESRI JS API and Angular.

Step 1: Generate token and store tokens in session 

 devServerLogin(username, password){
     let portalTokenUrl = ....+'/portal/sharing/rest/generateToken'; //Federated evn.,  use Portal  to generate user token.

    if(username && password){
      this.httpClient.post(tokenUrl, this.getCredentials(username, password), this.getHttpOptions()).subscribe(esriResponse =>{
        sessionStorage.setItem('dev_access_token', esriResponse['token']);
        sessionStorage.setItem('dev_access_token_expires', esriResponse['expires']);

  private getCredentials(username, password){
    let expiration = 720; //1440 -> 60 minute * 24 = 1 day token , 720 ->  12hrs token 
let urlReferer = 'https://'+window.location.host+'/';     
 let tokenCredentials =  'username='+username+'&password='+password+'&f=json&expiration='+expiration+'&client=referer&referer='+urlReferer;

    return tokenCredentials;

  private getHttpOptions(){
    let httpOptions = {
      headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded', }),
      withCredentials: true,            
    return httpOptions;

Wednesday, November 21, 2018

ArcGIS Server SOI - HandleRESTRequest Parameter limitations

Be The First To Comment
The SOI Rest request handler method -

public byte[] HandleRESTRequest(string Capabilities, string resourceName, string operationName,
            string operationInput, string outputFormat, string requestProperties, out string responseProperties)

HandleRESTRequest paramater provides following information inside the method

capabilities Map,Query,Data
 resourceName layers/0
operationName query, 
operationInput {"returnZ":false,"returnIdsOnly":false,
"spatialRel":"esriSpatialRelIntersects","geometryType":"esriGeometryEnvelope"}, outputFormat json, 
requestProperties {"computeETag":true,"ETag":"\"c429a59c\""}, 
responseProperties {"Content-Type":"text/plain"}

But it has no way of telling service name and layer name ...other than using layer index from resourceName if you want to perform layer specific operation in layers.


© 2011 GIS and Remote Sensing Tools, Tips and more .. ToS | Privacy Policy | Sitemap

About Me