Posts

Instruct GIT not to track a specific file

In scenarios like you have a configuration file in  a remote repo for the production environment, and you don’t want to commit the changes to this configuration file made from local.  How do you instruct git to do not track the local changes? --skip-worktree is what you need. git update-index --skip-worktree <filepath/file_name> After index update git won't show you the file in working tree. If you want to track the changes update-index as  git update-index --no-skip-worktree <filepath/file_name>

Update WPF Interaction Triggers in from .Net Framework 4.8 to .Net 5

  When migrating the Visual Studio projects from .Net Framework 4.8 to .Net 5, you may encounter   in the following error regarding Interaction.Triggers .   Error      XDG0008             The name "Interaction" does not exist in the namespace "http://schemas.microsoft.com/xaml/behaviors".   The one solution to fix it is to install “ Microsoft.Xaml.Behaviors.Wpf ” from Nuget And update the namespace ( if needed) xmlns : i ="http://schemas.microsoft.com/expression/2010/interactivity" to              xmlns:i ="http://schemas.microsoft.com/xaml/behaviors"

[Snippet] Add/Remove an Assembly to/from the Global Assembly Cache using C#.Net

  Code snippets to add remove an assembly from GAC -  Add reference to - System.EnterpriseServices using System.EnterpriseServices.Internal; var path = "the absolute path of assembly";  Publish publish = new Publish();  publish.GacInstall(path);  publish.GacRemove(path); Reference: https://docs.microsoft.com/en-us/dotnet/framework/app-domains/install-assembly-into-gac#global-assembly-cache-tool https://docs.microsoft.com/en-us/dotnet/framework/app-domains/how-to-remove-an-assembly-from-the-gac

[Code Snippet] : Connect to Sql Server from ArcObject

 using System; using ESRI.ArcGIS.DataSourcesFile; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geodatabase; namespace MyNamespace {   class MyProgram   {     private static LicenseInitializer _licenseInitializer = new LicenseInitializer();     [STAThread()]     static void Main(string[] args)     {       _licenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB },                                                    new esriLicenseExtensionCode[] { });       Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SqlWorkspaceFactory");       IPropertySet propertySet = new PropertySetClass();       propertySet.SetProperty("SERVER", " servername ");       ...

[Code Snippet] Assert.Throws on Exception and Derived Type Nunit

 Code snippet for asserting throw in ArgumentException and its derived types(such as ArgumentNullException) in Nunit -  public void Test(){ Assert.Throws(Is.InstanceOf<ArgumentException>(), () =>{      //SUT code }); }

[Code snippet] How to set value of private variable in Unit Test Using Reflection ?

A sample example to set private variable to true from unit test class in C#.Net //TestService.cs public class TestService {         private bool _isInitialized = false; } //TestServiceUnitTest.cs using System.Reflection; public class TestServiceUnitTest {           private TestService _testService ;                    [TestInitalize]           private void testInitalize()          {             _testService = new TestService();          }                  [TestMethod]          Private void SetInitializeToTrue()          {                          FieldInfo field = typeof(TestService).GetField(" _isInitializ...

[Code Snippet] Assert Exception in private methods using PrivateObject

NON ASYNC Method Method.cs private MyMethod(object value1) {       if(value1 == null)       {            throw new ArgumentNullException(nameof(MyMethod));       } } Test.Cs [TestMethod] public void MyMethod_Throws_Verify() {          PrivateObject po = new PrivateObject(new Method()) TargetInvocationException exception = Assert.ThrowsException<TargetInvocationException>(() =>                     privateObject.Invoke("MyMethod", new object[] { null }));             Assert.AreEqual(typeof(ArgumentNullException), exception.InnerException.GetType());         }

[Code Snippet] Example of using Delegate, Func and Action side by side in C#

Quick and dirty example of using Delegate, Func and Action side by side in C# to show how to use function pointer  or callback in C# Example #1  Delegate and Func side by side      static int DoubleTheValue (int x)         {             return x * 2;         }         // delegate type should match the function signature  -  DoubleTheValue         public delegate int functionDelegateType (int x);               static void Method1 ( functionDelegateType func)         {             int doubleValue = func(5);         }         static void Method2 (Func<int, int> func) // easier syntax         {             int doubleValue = func(5);     ...

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

internal class Model:INotifyPropertyChanged { public Model() { } string _FirstName = " Shahir" ; public string FirstName { get { return _FirstName; } set { _FirstName = value ; OnPropertyChanged(); } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged([CallerMemberName] string propertyName = " " ) { if (PropertyChanged!= null ) { 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 Property...

Code snippet: ArcGIS Runtime 100.x Geodatabase Delta Sync

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

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.D...

Flavours of .NET implementation

  OS Open Source Purpose .NET Framework Windows No Used for building Windows desktop applications and ASP.NET Web apps running on IIS. .NET Core Windows, Linux, macOS Yes Used for building cross-platform console apps and ASP.NET Core Web apps and cloud services. Xamarin iOS, Android, macOS Yes Used for building mobile applications for iOS and Android, as well as desktop apps for macOS. .NET Standard N/A Yes Used for building libraries that can be referenced from all .NET implementations, such as .NET Framework, .NET Core and Xamarin. Ref -  https://msdn.microsoft.com/en-us/magazine/mt842506.aspx

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

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 }); console . log ( mapPoint ); }); //print point on mouse click on map mapView . on ( "click" , function ( event ){ let mapPoint = event . mapPoint ; console . log ( mapPoint ) }); Both console statement will return the identical object as below which has latitude and longitude { __accessor__ : b } cache :  (...) extent :  (...) hasM :  (...) hasZ :  (...) latitude :  (...) longitude :  (...) m :  (...) spatialReference :  (...) type :  (...) x :  (...) y :  (...) z :  (...) constructed :  (...) destroyed :  (...) initialized :  (...) __accessor__ :  b  { host :  {…} ,  _origin :  6 ,  cursors :  {…} ,...

Code Snippet : Windows NTLM POST using Node JS

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', workstation:'', rejectUnauthorized: false, //disable ssl certificate error ntlm_domain: 'domain_name', json: true, headers:headers }; ntlm.post(ntlmOptions, postData, function(error, response, body){ console.log(error); console.log(response);                      });

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

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)- Works     dbConfig: {         "user": "user",         "password": "pass",         "server": "myserver",  //  Without instance name          "database": "dbname",         "port":1433,         "driver": "tedious",         "options": {             "instance":"mylocaldevdatabase",             "trustedConnection": true           }         } Doesn't Work

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

Image
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.

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

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 du...

ArcGIS Server SOI - HandleRESTRequest Parameter limitations

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, "where":"","returnDistinctValues":false,"returnM":false,"returnCountOnly":false,"returnExtentsOnly":false, "returnTrueCurves":false,"returnGeometry":true, "spatialRel":"esriSpatialRelIntersects","geometryType":"esriGeometryEnvelope"}, outputFormat json,  requestProperties {"computeETag":true,"ETag":"\"c429a59c\""},  responseProperties {...

[Code snippet]: Planet API Image Download Url

from requests.auth import HTTPBasicAuth import os import requests item_id = "20161109_173041_0e0e" item_type = "PSScene3Band" os.environ['PLANET_API_KEY'] = '3b711bededf6485a0' #not a real id asset_type = "visual" item_url = 'https://api.planet.com/data/v1/item-types/{}/items/{}/assets'.format(item_type, item_id) # Request a new download URL result = requests.get(item_url, auth=HTTPBasicAuth(os.environ['PLANET_API_KEY'], '')) download_url = result.json()[asset_type]['location'] print(download_url)

Angular Async Patterns

Image
https://sean-olson-e.github.io/Angular-and-the-ArcGIS-API-for-JavaScript/#/17