воскресенье, 27 июля 2014 г.

Manco Shapefile Editor - Integration with Telerik RadMap control for WPF


The projects are created in the Manco Shapefile Editor can be easily loaded into the Telerik RadMap control with just few lines of code.

You may ask why this is necessary. The Telerik RadMap control can load ESRI shape files and KML files. The Manco Shapefile Editor can export shapes into these formats. So at the first glance we need not this extra functionality. But think about following:
  1. The figures in the ESRI shape file format are represented by polylines and polygons. So every curve (ellipse, arc, Bezier curve and so on) created in the editor should be interpolated using polygons. It increases significantly number of the points are used to represent every shape and, as result, increase initial loading time, slowdown zooming in the RadMap, and makes curves look like polygon after some zoom level. In contrast any figures in the Manco Shapefile Editor project can be represented directly using correspondent map shapes in the Telerik RadMap control. So no interpolation is needed to represent shapes. It makes curves look absolutely same way as they were designed in the editor.
  2. Using this feature you can not only load the shapes, but open correspondent map provider and load background images (when necessary) automatically
So this feature significantly simplifies process of the creation applications using Telerik RadMap control and makes resulting picture much better.

To do it:

  1. Create new WPF application.
  2. Add references for the RadMap control:
  3. Add RadBusyIndicator, RadMap control and button to load project into your XAML. Setup bindings for the map properties:<Window x:Class="TestWpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        Title="MainWindow"
        Height="520" Width="650">
        <telerik:RadBusyIndicator Name="busyIndicator">
           <Grid>
              <Grid.ColumnDefinitions>
                 <ColumnDefinition Width="*" />
                 <ColumnDefinition Width="Auto" />
              </Grid.ColumnDefinitions>
              <telerik:RadMap Name="radMap"
                 Provider="{Binding Provider}"
                 Center="{Binding Center, Mode=TwoWay}"
                 ZoomLevel="{Binding ZoomLevel, Mode=TwoWay}"
                 MouseClickMode="SelectItem"
                 MouseSelectionMode="RaiseEvent" />
              <Button Grid.Column="1"
                 Click="OnButtonClick"
                 VerticalAlignment="Top"
                 HorizontalAlignment="Stretch">
                 <TextBlock Margin="4,2,4,2" Text="Load project" />
              </Button>
           </Grid>
        </telerik:RadBusyIndicator>
    </Window>
  4. Add reference to the Manco.MapShapeData.Load.dll.
  5. If you are using newer version of the Telerik RadControls for WPF than it was used to build Manco.MapShapeData.Load .dll then redirect assembly versions for Telerik assemblies as it is described here.
  6. Add code which load project file and bind it to the RadMap control:
C#

private async void OnButtonClick(object sender, RoutedEventArgs e)
{
   OpenFileDialog openProjectDialog = new OpenFileDialog();
   openProjectDialog.Filter = "ShapeFileEditor Project Files|*.shprj";
   openProjectDialog.Multiselect = false;

   bool? open = openProjectDialog.ShowDialog();
   if (open == true && !string.IsNullOrEmpty(openProjectDialog.FileName))
   {
      await this.LoadProject(
         new Uri(openProjectDialog.FileName, UriKind.RelativeOrAbsolute));
   }
}

private async Task LoadProject(Uri projectUri)
{
   this.busyIndicator.IsIndeterminate = true;
   this.busyIndicator.IsBusy = true;

   ProjectInfo info = await ProjectReader.Read(projectUri, this.Dispatcher);
   this.BindProject(info);

   this.busyIndicator.IsBusy = false;
}

private void BindProject(ProjectInfo info)
{
   if (info != null)
   {
      if (info.Errors.Count == 0)
      {
         ProjectReader.CreateLayers(
            this.radMap,
            info,
            this.Resources["PointDataTemplate"] as DataTemplate,
            null);
         this.radMap.DataContext = info;
      }
   }
}


VB.NET


Private Sub OnButtonClick(sender As Object, e As RoutedEventArgs)
    Dim openProjectDialog As New OpenFileDialog()
    openProjectDialog.Filter = "ShapeFileEditor Project Files|*.shprj"
    openProjectDialog.Multiselect = False

    Dim open As System.Nullable(Of Boolean) = openProjectDialog.ShowDialog()

    If open = True AndAlso Not String.IsNullOrEmpty(openProjectDialog.FileName) Then
        Await Me.LoadProject(New Uri(openProjectDialog.FileName, UriKind.RelativeOrAbsolute))
    End If
End Sub

Private Function LoadProject(projectUri As Uri) As Task
    Me.busyIndicator.IsIndeterminate = True
    Me.busyIndicator.IsBusy = True

    Dim info As ProjectInfo = Await ProjectReader.Read(projectUri, Me.Dispatcher)
    Me.BindProject(info)

    Me.busyIndicator.IsBusy = False
End Function

Private Sub BindProject(info As ProjectInfo)
    If info IsNot Nothing Then
        If info.Errors.Count = 0 Then
            ProjectReader.CreateLayers(Me.radMap, _
               info, _
               TryCast(Me.Resources("PointDataTemplate"), DataTemplate), Nothing)
            Me.radMap.DataContext = info
        End If
    End If
End Sub


You can find sample solution which implements this approach on our official site at the http://www.mancosoftware.com/ShapeFileEditor/download.htm
 

четверг, 19 июня 2014 г.

Version 3.0 of the Manco Shapefile Editor has been released

Manco Shapefile Editor version 3.0 is available now. You can get 30-days trial version at the http://www.mancosoftware.com/ShapeFileEditor/download.htm

List of the most significant changes made in the new version:
1. Brand new UI with a lot of improvements and enhancements:



















2. Predefined shape libraries. For your convenience the shapes which can be placed over the map are organized into the libraries. You can use existing libraries of the shapes or create your own for particular tasks. For example, you can create shape library for floor plan which will include typical elements like doors, windows, tables, chairs and so on.

3. Deep integration with Telerik RadMap control. Projects created with Manco Shapefile Editor can be easily loaded into the RadMap control in your application.

пятница, 14 февраля 2014 г.

How to use the evaluation Unlock Key

In the past we had several discussions with our customers about how they control distribution of the evaluation license on “1 customer – 1 evaluation license” basis. Most common licensing schema supposes that evaluation license is included into the product distribution. But in this case when somebody wants to evaluate the product it is not enough to simple download and run it. Client should contact with developer and obtain evaluation license.

It was possible with previous versions of the Manco .NET Licensing System product but it required distribution of the license file. This method made some additional problems with subsequent distribution of the retail license, especially when “Unlock Key with Activation” licensing schema is used.

We significantly simplified this process in the version 8.1 of the Manco .NET Licensing System by introducing so-called “Evaluation Unlock Key”. Using this new feature you can distribute license file with your application just as it is for “Unlock Key” or “Unlock Key with Activation” licensing schemas. When customer ask for the evaluation license you send an Evaluation Unlock Key which can be bound to the PC hardware (activated) the same way as it works with “Unlock Key with Activation” licensing schema. When customer asks for Retail license you simple send another Unlock Key which replace evaluation one.

In this article I’ll describe how the “Evaluation Unlock Key” licensing schema can be implemented. I suppose that you have read “Quick Start” and “Using of the online product activation” sections in our documentation, because this document describes differences for this approach.

First of all you should add {T} format string into the Unlock Key format:


The {T} format indicates that type of the Unlock Key (Evaluation or Retail), type of the evaluation rule (“Expiration Days”, “Expiration Date” or “Expiration Runs”), value of the expiration rule, and value of the “Override ID” rule will be included to the Unlock Key (will be encrypted).

Now you should create License Type that will allow your application operate as you desire: application will request Unlock Key on start. Depends on the Unlock Key type (Evaluation or Retail) application will run on evaluation or fully functional mode.

This is good known license type which we call “Unlock Key”. To create new license type click expand button on the “Add License Type” toolbar button. You will see list of the predefined license types:



Select “Unlock Key with Activation + Evaluation Unlock Key” license type. New license type will be created. It includes following rules:



Activation Key – indicates that activation key created using PC system info and unlock key (ether in automatic or manual mode) should be entered to get product fully functional.

AWS Allow Deactivation – AWS check whether this rule is included to the license type when     customer’s application calls "DeactivateProduct" web-method. If it is so, then Deactivate method works.

Expiration Days – set number of days during which your product will work in evaluation mode. This license rule can be used to create evaluation. When someone attempts use licensed product after given number of days it will give “Your license has been expired” exception.

Is Evaluation – indicates, that license is in evaluation mode. Allows you limit some functionality in your product using evaluation status of license.

Unlock Key – including of this validation rule to the base license file allows you using of the “Unlock Key” schema to activate product.  It informs protection library that Unlock Key provided by customer should be validated.

Use evaluation key – indicates whether the protection library must check availability of the Unlock Key and test it state (Evaluation or Retail).

Write Key To File – indicates whether the “Unlock Key” should be written to the protected storage after validation. If you don’t use this rule, then customer will be asked for Unlock Key every time when your application starts.

As usual now you should create license file. Pay attention, with this approach license doesn’t operate as evaluation license, but just contains set of the rules which handle behavior of the protection library. Here it is screenshot of the sale window for the license file:



Pay attention, the “Is Evaluation” checkbox must be unchecked, and “Expiration Days” and “Unlock Key” fields must be empty.

The code for this licensing schema isn’t different much from one is used for the “Unlock Key with Activation” licensing schema. You just should keep in mind that old Unlock and Activation keys can be cleaned from the protected storage when new ones have been entered only:

C#


private bool RequestKeys()
{
       // Check if the current license is evaluation license or not valid
       if (!this.licenseState.IsValid || this.licenseState.IsEvaluation)
       {
             // This is evaluation or not valid license,
             // so we should show evaluation dialog
             EvaluationWindow evaluationWindow = new EvaluationWindow(this.license);
             evaluationWindow.Owner = this;
             if (evaluationWindow.ShowDialog() == true
                    && evaluationWindow.UnlockKey.Trim() != string.Empty
                    && evaluationWindow.ActivationKey.Trim() != string.Empty)
             {
                    // Check whether license REQUIRE the calling of the AWS
                    // and it has been called from the license form.
                    if (evaluationWindow.IsAwsCalled
                    || !this.licenseProperties.DoForceValidation)
                    {
                           // License information have been entered.
                           // Pass it to the license object for the
                           // following validation.
                           this.license.ClearUnlockKeys();
                           this.license.UnlockKey = evaluationWindow.UnlockKey;
                           this.license.ActivationKey = evaluationWindow.ActivationKey;
                    }
                    else
                    {
                           MessageBox.Show("You must click 'Activate' button on the evaluation form"
                                  + "to activate your copy of the product on this PC.");
                    }
             }
       } 

       return this.licenseState.IsValid
             && !(this.licenseState.IsEvaluation
&& this.licenseState.IsEvaluationExpired);
}


VB.NET


Private Function RequestKeys() As Boolean
       ' Check if the current license is evaluation license or not valid
If Not Me.licenseState.IsValid _
OrElse Me.licenseState.IsEvaluation Then
' This is evaluation or not valid license,
' so we should show evaluation dialog
Dim evaluationWindow As New EvaluationWindow(Me.license)
evaluationWindow.Owner = Me
If evaluationWindow.ShowDialog() = True _
AndAlso evaluationWindow.UnlockKey.Trim() <> String.Empty _
AndAlso evaluationWindow.ActivationKey.Trim() <> String.Empty Then
' Check whether license REQUIRE the calling of the AWS
' and it has been called from the license form.
If evaluationWindow.IsAwsCalled _
OrElse Not Me.licenseProperties.DoForceValidation Then
' License information have been entered.
' Pass it to the license object for the
' following validation.
Me.license.ClearUnlockKeys()
Me.license.UnlockKey = evaluationWindow.UnlockKey
Me.license.ActivationKey = evaluationWindow.ActivationKey
Else
MessageBox.Show("You must click 'Activate' button on the evaluation form" _
& "to activate your copy of the product on this PC.")
End If
End If
        End If 

        Return Me.licenseState.IsValid _
            AndAlso Not (Me.licenseState.IsEvaluation _
                         AndAlso Me.licenseState.IsEvaluationExpired)
End Function


Finally here are the screenshots of the sale records for the evaluation and retail Unlock Keys.

Evaluation



When customer asks you for the evaluation license you create new sale records, check “Is Evaluation” check box, set number of the expiration days and then generate Unlock Key. Send new key to the customer for activation. After activation customer will be able to evaluate your product during specified time frame. Pay attention, you must check “Is Evaluation” and set value for the “Expiration Days” field before Unlock Key generation.
Retail



Pay attention, for the retail license you must uncheck “Is Evaluation” checkbox and left “Expiration Days” field empty.

You can find sample solution which demonstrates using of the Evaluation Unlock Key on our official site at http://www.mancosoftware.com/licensing/download.htm