Thursday, December 2, 2021

Instruct GIT not to track a specific file

Be The First To Comment

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>

Friday, November 19, 2021

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

Be The First To Comment

 

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"

Thursday, January 28, 2021

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

Be The First To Comment

 


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

Wednesday, December 16, 2020

[Code Snippet] : Connect to Sql Server from ArcObject

Be The First To Comment

 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");

      propertySet.SetProperty("INSTANCE", "sde:sqlserver:servername");

      propertySet.SetProperty("AUTHENTICATION_MODE", "DBMS");

    // propertySet.SetProperty("AUTHENTICATION_MODE", "OSA");

      propertySet.SetProperty("DATABASE", "test1");

      propertySet.SetProperty("USER", "username");

      propertySet.SetProperty("PASSWORD", "password");

      propertySet.SetProperty("VERSION", "sde.DEFAULT");


      IWorkspaceFactory workspaceFactory = new SDCWorkspaceFactory();

      IWorkspace workspace = workspaceFactory.Open(propertySet, 0);

    }

  }

}


Friday, December 11, 2020

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

Be The First To Comment

 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

});

}

Monday, May 11, 2020

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

Be The First To Comment
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("_isInitialized",  BindingFlags.NonPublic |       BindingFlags.Instance);

          field.SetValue(_testService , true);

         }
}

Wednesday, April 22, 2020

[Code Snippet] Assert Exception in private methods using PrivateObject

1 Comment
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());
       
}


Tuesday, September 24, 2019

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

Be The First To Comment
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);
        }

        static void Main(string[] args)
        {
            Method1(DoubleTheValue);

            Method2(DoubleTheValue);
        }

Example #2  Delegate and Action side by side

static void DisplayOnConsole(int x)
        {
            Console.WriteLine(x.ToString());
        }

        // delegate type should match the function signature  - DisplayOnConsole
        public delegate void functionDelegateType (int x);
        static void Method1(functionDelegateType func)
        {
            func(5);
        }

     
        static void Method2(Action<int> func) // easier syntax
        {
            func(5);
        }

     
        static void Main(string[] args)
        {
            Method1(DisplayOnConsole);
            Method2(DisplayOnConsole);
        }

Reference:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/a1ac99ed-0801-4773-a866-4223d42422cf/how-to-pass-function-as-an-argument-to-another-function-in-c?forum=csharpgeneral

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; }
            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 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; }
            set
            {
                _FirstName = value;
                OnPropertyChanged();
            }
        }

        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 );

 

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

About Me