Friday, August 12, 2016

Difference between PropertyMetadata vs FrameworkPropertyMetadata in .NET

Be The First To Comment

Databind between View and ViewModel for PasswordBox WPF

Be The First To Comment
"When you try to databind the password property of a PasswordBox you will recognize that you cannot do data binding on it. The reason for this is, that the password property is not backed by a DependencyProperty.

The reason is databinding passwords is not a good design for security reasons and should be avoided. But sometimes this security is not necessary, then it's only cumbersome that you cannot bind to the password property. In this special cases you can take advantage of the following PasswortBoxHelper.

The PasswordHelper is attached to the password box by calling the PasswordHelper.Attach property. The attached property PasswordHelper.Password provides a bindable copy of the original password property of the PasswordBox control."

Published on -


PasswordHelper.cs
1:  public static class PasswordHelper  
2:  {  
3:    public static readonly DependencyProperty PasswordProperty =  
4:      DependencyProperty.RegisterAttached("Password",  
5:      typeof(string), typeof(PasswordHelper),  
6:      new FrameworkPropertyMetadata(string.Empty, OnPasswordPropertyChanged));  
7:     
8:    public static readonly DependencyProperty AttachProperty =  
9:      DependencyProperty.RegisterAttached("Attach",  
10:      typeof(bool), typeof(PasswordHelper), new PropertyMetadata(false, Attach));  
11:     
12:    private static readonly DependencyProperty IsUpdatingProperty =  
13:      DependencyProperty.RegisterAttached("IsUpdating", typeof(bool),   
14:      typeof(PasswordHelper));  
15:     
16:     
17:    public static void SetAttach(DependencyObject dp, bool value)  
18:    {  
19:      dp.SetValue(AttachProperty, value);  
20:    }  
21:     
22:    public static bool GetAttach(DependencyObject dp)  
23:    {  
24:      return (bool)dp.GetValue(AttachProperty);  
25:    }  
26:     
27:    public static string GetPassword(DependencyObject dp)  
28:    {  
29:      return (string)dp.GetValue(PasswordProperty);  
30:    }  
31:     

Tuesday, June 28, 2016

Interactive KML Placemarks using HTML/JavaScript

Be The First To Comment
My colleague stopped by this morning and asked me to see if there is any way to  implement combo box / drop-down list in KML file for dynamically selecting the Placemarks' information. Few hour of googling come up with a quick and dirty KML (adding custom data) using HTML/JavaScript in <ExtendedData> tag with combo box selection and pasted it here for our future reference. It may helps others as well. If there are any alternatives feel free to chime in.

 <?xml version="1.0" encoding="UTF-8"?>  
 <kml xmlns="http://www.opengis.net/kml/2.2">  
      <Document>  
         
      <Style id="MyBalloonStyle">  
           <BalloonStyle>  
                <text> <![CDATA[  
                <b>Example extended data template</b>  
   
                <div style="width:350px;" id="tree"></div>  
   
                <table id="table" border="1" >  
                     <tr><td>Company Name</td></tr>  
                     <tr><td><i>$[Company_Name]</i></td></tr>  
                     <tr><td>  
                          <select id = "treeListSelection" onchange = 'treeListChanged(value)'>  
                           <option>--Select--</option>  
                           <option value="tree 1">'Tree 1'</option>  
                           <option value="tree 2">'Tree 2'</option>   
                          </select>  
                     </td></tr>  
                </table>    
   
                <script type="text/javascript">   
                 function treeListChanged(value){  
                     document.getElementById('tree').innerHTML = value ;        
                 }  
                </script>  
   
                ]]></text>  
                <bgColor>ffffffbb</bgColor>  
           </BalloonStyle>  
           <IconStyle> <color>ffffffff</color> <scale>1</scale>  
                <Icon><href>http://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png</href>  
                </Icon>  
           </IconStyle>  
           <LabelStyle>   
                <scale>0</scale>   
           </LabelStyle>  
      </Style>  

Monday, June 27, 2016

[SOLUTION] Vagrant - Remote connection disconnect. Retrying ...

Be The First To Comment
Here is error from guest machine, complaining about remote connection

 ==> default: Attempting graceful shutdown of VM...  
 ==> default: Clearing any previously set forwarded ports...  
 ==> default: Clearing any previously set network interfaces...  
 ==> default: Preparing network interfaces based on configuration...  
   default: Adapter 1: nat  
   default: Adapter 2: hostonly  
 ==> default: Forwarding ports...  
   default: 80 (guest) => 8080 (host) (adapter 1)  
   default: 3000 (guest) => 3000 (host) (adapter 1)  
   default: 22 (guest) => 2222 (host) (adapter 1)  
 ==> default: Running 'pre-boot' VM customizations...  
 ==> default: Booting VM...  
 ==> default: Waiting for machine to boot. This may take a few minutes...  
   default: SSH address: 127.0.0.1:2222  
   default: SSH username: vagrant  
   default: SSH auth method: private key  
   default: Warning: Remote connection disconnect. Retrying...  
   default: Warning: Remote connection disconnect. Retrying...  
   default: Warning: Remote connection disconnect. Retrying...  
   default: Warning: Remote connection disconnect. Retrying...  
   default: Warning: Remote connection disconnect. Retrying...  
   default: Warning: Remote connection disconnect. Retrying...  
   default: Warning: Remote connection disconnect. Retrying...  
   default: Warning: Remote connection disconnect. Retrying...  
   default: Warning: Remote connection disconnect. Retrying...  
   default: Warning: Remote connection disconnect. Retrying...  
   default: Warning: Remote connection disconnect. Retrying...  
   default: Warning: Remote connection disconnect. Retrying...  

[SOLUTION] Vagrant box authentication failure after packaging box

2 Comments
ERROR IN NEWLY PACKAGED BOX AFTER - vagrant up


 Bringing machine 'default' up with 'virtualbox' provider...  
   ==> default: Clearing any previously set forwarded ports...  
   ==> default: Clearing any previously set network interfaces...  
   ==> default: Preparing network interfaces based on configuration...  
     default: Adapter 1: nat  
     default: Adapter 2: hostonly  
   ==> default: Forwarding ports...  
     default: 22 => 2222 (adapter 1)  
   ==> default: Running 'pre-boot' VM customizations...  
   ==> default: Booting VM...  
   ==> default: Waiting for machine to boot. This may take a few minutes...  
     default: SSH address: 127.0.0.1:2222  
     default: SSH username: vagrant  
     default: SSH auth method: private key  
     default: Warning: Connection timeout. Retrying...  
     default: Warning: Authentication failure. Retrying...  
     default: Warning: Authentication failure. Retrying...  
     default: Warning: Authentication failure. Retrying...  
     default: Warning: Authentication failure. Retrying...  
     default: Warning: Authentication failure. Retrying...  
     default: Warning: Authentication failure. Retrying...  
     default: Warning: Authentication failure. Retrying...  

SOLUTION

1. Press CTRL + Z to break the 'default: Warning: Authentication failure. Retrying... or wait for few more minutes

2. Login into your guest machine - vagrant ssh , which should prompt you for password, vagrant , the default password for vagrant

3. Then go to - /home/vagrant/.ssh  and remote all the contents inside it, if the path not existed create the directory - mkdir -p /home/vagrant/.ssh

Tuesday, May 31, 2016

Code Snippet: Set default database schema in Nhibernate SessionFactory

Be The First To Comment
1:  //Setup oracle database connection and connection pool  
2:    public class OracleConnectionManager  
3:    {  
4:      private static string _userName;  
5:      private static string _password;  
6:    
7:      public OracleConnectionManager(string userName, string password)  
8:      {  
9:        _userName = userName;  
10:        _password = password;  
11:      }  
12:    
13:      private static ISessionFactory _sessionFactory;  
14:      private static ISessionFactory SessionFactory { get  
15:        {  
16:          if(_sessionFactory == null)  
17:          {  
18:            var connectionString = DatabaseConnections.GetOracleConnectionsString(_userName,_password);  
19:              
20:            //Nhibernate Oracle database configuration  
21:            var configuration = new Configuration();  
22:            configuration.DataBaseIntegration(db =>  
23:            {  
24:              db.ConnectionProvider<NHibernate.Connection.DriverConnectionProvider>();  
25:              db.Dialect<NHibernate.Dialect.Oracle10gDialect>();  
26:              db.Driver<NHibernate.Driver.OracleDataClientDriver>();  
27:              db.ConnectionString = connectionString;  
28:             });  
29:    
30:            // Setup default schema  
31:            configuration.SetProperty(Environment.DefaultSchema, "DB_SCHEMA_NAME");  

Monday, May 30, 2016

Open Source Cloud GIS System Setup with Amazon EC2 and Geoserver

Be The First To Comment
Follow these steps to set up the open source cloud based GIS mapping system.

1. Create an Amazon Web Services (AWS) account. You can find instructions for this step in the EC2 Getting Started Guide.

3. Create an Amazon EC2 instance. Instructions are also in the EC2 Getting Started Guide. When choosing an AMI make sure you choose a Windows server with IIS (and ASP.NET) already installed.

4. Connect to your Windows EC2 instance and install GeoServer. You can download GeoServer here. There are multiple setups available. Use the Windows installer. The instructions for the install are here.

5. Copy GIS data and configure map layers. The GeoServer user's manual will guide you through the steps of configuring GeoServer.

6. Start GeoServer on the EC2 instance server.

7. Seed the layers in GeoWebCache on the server. Instructions for this are here. Note that jpeg tiles are smaller than png and the default for base layers. Also png are better quality and will always be used for overlays because they can be transparent and overlays need to support transparency. Seed all layers for zoom levels 0 to 10 for EPSG:4326. If it is a base layer, seed it with jpeg files. If it is an overlay layer, seed it with png files.

Thursday, May 26, 2016

Setting up automatic product or build version increment using JENKINS for .NET projects

Be The First To Comment
Steps for setting up automatic product or build version increment using JENKINS Continious Integration server and Visual Studio for .NET projects

Part A - Configure Visual Studio Solution

1. Copy the "AssemblyInfo.cs" from your project solutions and rename into "AssemblyInfo.cs.template"



2. Add a file called "AssemblyInfo.cs.template" and replace with these two lines:
             [assembly: AssemblyVersion("#VERSION_NUMBER#")]
             [assembly: AssemblyFileVersion("#VERSION_NUMBER#")]

3. In project properties, insert this pre-build command:
     "$(SolutionDir)builder-scripts\templates\pre-build\Stamper.exe" "$(ProjectDir)\"



4. Put the "builder-scripts" folder into your solution folder. Builder scripts source


Code snippet: Unzip the zip file in C# using DotNetZip

Be The First To Comment
DotNetZip is a FAST, FREE class library and toolset for manipulating zip files. Use VB, C# or any .NET language to easily create, extract, or update zip files.

1:  public static void DeCompressFile(string zipFilePath, string extractPath)  
2:      {  
3:        string zipToUnpack = zipFilePath;  
4:        string unpackDirectory = extractPath;  
5:        using (ZipFile zipfiles = ZipFile.Read(zipToUnpack))  
6:        {  
7:          // Here, we extract every entry, but we could extract conditionally based on entry name, size, date, checkbox status, etc.   
8:          foreach (ZipEntry e in zipfiles)  
9:          {  
10:            e.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);  
11:          }  
12:        }  
13:    
14:        Console.WriteLine("Status: Done extracting the zipped Archive");  
15:      }   

Code snippet: Read data from Access Database in C#

Be The First To Comment
Read data from Access Database in C#

1:  private static void ReadFromAccess(string accessDbPath)  
2:      {  
3:        string connection = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= {0}",accessDbPath);  
4:        using (OleDbConnection con = new OleDbConnection(connection))  
5:        {  
6:          try  
7:          {  con.Open();  
8:            OleDbCommand cmd = new OleDbCommand("SELECT * FROM Table_NAME", con);  
9:            OleDbDataReader reader = cmd.ExecuteReader();  
10:    
11:            while (reader.Read())  
12:            {  
13:              Console.WriteLine(reader.GetString(0));  
14:            }  
15:    
16:          }catch(Exception ex)  
17:          {  
18:            Console.WriteLine(ex.Message);  
19:          }finally  
20:          {  
21:            con.Close();  
22:          }  
23:        }  
24:      }  
 

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

About Me