Wednesday, May 29, 2013

HTML5+MVC Course, Day 4

Continued from day 1, day 2, day 3.

This lesson was mostly about writing Object Oriented in JavaScript.

 

Lets start by creating a basic model Customer, customer contains a first name, last name and full name that contains both:

function customer() {
    var _this = this;
    _this.firstName = 'Yair';
    _this.lastName = 'Siwek';
    _this.fullName = _this.firstName + ' ' + this.lastName;
}

Given that this is our body:

<body>
    <div>
        <span id="firstName"></span>
        --
        <span id="lastName"></span>
    </div>
    <div>
        <span id="fullName"></span>
    </div>
</body>

A basic use for the model will be:

<script src="Scripts/App/Customer_a.js"></script>
<script>
    $(function () {
        var cust = new customer();
        cust.firstName = "Moshe";

        $('#firstName').html(cust.firstName);
        $('#lastName').html(cust.lastName);
        $('#fullName').html(cust.fullName);
    });
</script>

This works.

But what if before using jQuery we would have changed firstName? then fullName would have still been Yair Siwek. In order for the right value for fullName to appear we need to change fullName to a method:

_this.fullName = function ()
{
    //if we wrote this then it's value would have been fullName, but _this is customer!
    return (_this.firstName + ' ' + _this.lastName);
};

TODO: _this

We also need to change our html:


$('#fullName').html(cust.fullName());

to use a method instead of a property.

 

We can now create another instance of customer:

var cust = new customer();
var cust1 = new customer();

But if we use a debugger we will see the method fullName is recreated for each instance of customer:

CustomerMethodDefinition

To fix that we will use a Prototype. A Prototype is common to all instances:

function customer() {
    var _this = this;
    _this.firstName = 'Yair';
    _this.lastName = 'Siwek';
}

customer.prototype = {
    fullName:  function ()
    {
        //_this does not exist here!
        return (this.firstName + ' ' + this.lastName);
    }
}

Note: We can’t use _this here because it doesn’t exist in the scope.

Now the instance doesn’t include the implementation (the Prototype has it).

CustomerPrototype

 

We could have also used an Anonymous Type:

<script>
    $(function () {
        var cust = {
            firstName: 'Joe',
            lastName: 'Sh',
            fullName: function () {
                return cust.firstName + ' ' + cust.lastName;
            }
        };

        $('#firstName').html(cust.firstName);
        $('#lastName').html(cust.lastName);
        $('#fullName').html(cust.fullName());
    });
</script>

Though we can’t use multiple instances the result is the same.

 

Book recommendation: Learning JavaScript Design Patterns by Addy Osmani (166 pages)

Shows how to create an empty object – 3 ways.

 

With the last example there was a problem: changing the values does not change the controls:

cust.firstName = "Moshe";

$('#firstName').html(cust.firstName);
$('#lastName').html(cust.lastName);
$('#fullName').html(cust.fullName());

cust.lastName = 'Blah';

Both last name and full name won’t contain “Blah”.

To solve that we will have to do a data binding with KnockOut.

var cust = new customer();
cust.firstName = "Moshe";

ko.applyBindings(cust,
                        //$('#divTop'));//doesn't work
                        //document.getElementById('divTop'));//works
                        $('#divTop')[0]);//work
cust.lastName = 'Blah';

model – the data

node - the element on which we want to the binding,

$(‘#Name’) returns an array, node needs a single element so we will have to pass the first element by adding [0].

 

Note: to add inteliscence to the JavaScript code we will drag and drop the KnockOut library to the top of the script, it will be converted to:

/// <reference path="../knockout-2.2.1.debug.js" />

And from now on you have inteliscence turned on (if you have Resharper then you can skip this step).

 

To make the model observable we will have to change each field to be an observable by:

_this.firstName = ko.observable('Yair');
_this.lastName = ko.observable('Siwek');

that will convert it to a method which is used by:

In HTML:

<input id="firstName" data-bind="value: firstName"/>

In JavaScript:

customer.prototype = {
    fullName:  function ()
    {
        return (this.firstName() + ' ' + this.lastName());
    }
}

When writing the data-bind from the HTML you can use either name() or name. But from JavaScript you must use name().

TODO:check why in JS

 

TODO: 18:06 not clear: when working with ko.computed +ko.observable than firstName() in the HTML data-bind doesn’t work. TODO: add code

TODO: There is difference between ko.computed and function(), computed is only called once?

 

Observable Array

When the array is simple (non object):

_this.grades = ko.observableArray([10, 11, 12]);

<ul data-bind="foreach: grades">
    <li>
        <span data-bind="text: $index" ></span>
        .
        <span data-bind="text: $data" ></span>
    </li>
</ul>

$index – the index of the item in the array.

$data – the item data

Output:

ObservableSimpleArray

 

When the array is of objects we can bind to the property names:

_this.grades = ko.observableArray([
    { subject: 'hist', mark: 90 },
    { subject: 'math', mark: 95 } ]);

<ul data-bind="foreach: grades">
    <li>
        <span data-bind="text: subject" ></span>
        -
        <span data-bind="text: mark" ></span>
    </li>
</ul>

Note: for intelliscence in KO you will have to install ASP.NET and Web Tools 2012.2.

 

KO Templates

HTML usage of a Template has at least 2 prameters:

name – the template name

data – the observable data

The template definition:

TODO: Add code

id – the name of the template

 

Adding templates to a page:

1. Using href:

TODO

Will cause the template to be downloaded to the client even when the template is not used.

2. Dynamically through JS code:

TODO

Tuesday, March 5, 2013

ArcObjects: Licensing

This post is the 7th post in my ArcObjects series.

ESRI has a very annoying licensing settings which I curse every time my license expires (once a year using EDN). Lets start by saying ESRI delivers the license in the form of ABC######: EFL123456, ESU123456, ECP123456, RUD123456 and each has a different set of instructions. I usually get an ECP license (ArcGis Server) and there is a guide for that.

Assuming you managed to pass the nightmare and tried to use ArcObjects in your code then you will get an Exception. In this case I just run this code:

IPoint point = new PointClass { X = x, Y = y, SpatialReference = CreateWgsSpatialReference() };

And got this exception:

System.Runtime.InteropServices.COMException : Retrieving the COM class factory for component with CLSID {00A5CB41-52DA-11D0-A8F2-00608C85EDE5} failed due to the following error: 80040111 ClassFactory cannot supply requested class (Exception from HRESULT: 0x80040111 (CLASS_E_CLASSNOTAVAILABLE)).

As you can see it is very descriptive. But basically it tells you that without initializing the license you won’t be able to use any ArcObjects (even IPoint). In version 9.3 the license was done using class RuntimeManager but in version 10 the IAoInitialize interface was added. I usually add them together like this:

private static bool Initialize(ProductCode product, esriLicenseProductCode esriLicenseProduct)
{
    if (RuntimeManager.Bind(product))
    {
        IAoInitialize aoInit = new AoInitializeClass();
        aoInit.Initialize(esriLicenseProduct);
        return true;
    }
    return false;
}

This method checks if the current machine has a license of ProductCode which is an enum with values like Server or Engine and if it does returns true. The usage looks like this:

private static bool _isStarted = false;

public static void Start()
{
    if (_isStarted)
        return;

    if (!Initialize(ProductCode.Server, esriLicenseProductCode.esriLicenseProductCodeArcServer))
    {
        if(!Initialize(ProductCode.Engine, esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB))
        {
            throw new ApplicationException(
                "Unable to bind to ArcGIS license Server nor to Engine. Please check your licenses.");
        }
    }
    _isStarted = true;
}

Since the production machines are usually ArcGis Server and the development machines are Engine we usually check if the machine has Server license and if it doesn’t then we go to the fallback of Engine. Now the creation of PointClass will work.

 

That’s it.

Monday, May 14, 2012

Silverlight: Binding Resource to DataGridTextColumn.Header

In the last two days, since it’s the end of our block I have decided to do some minor work (that way a check in won’t really effect the block). One of the changes I thought of was replacing all the free text in our Silverlight application with text from a resource file.

Everything worked like a charm except for the Header of DataGridTextColumn. My original Data Binding looked like this:

  1. <slData:DataGridTextColumn Header="{Binding Path=Type, Source={StaticResource StringsRes}}" Binding="{Binding Title}"/>

But the DataGrid columns in the application looked like this:

DataGrid-header-column-bug

In the end I found the solution here:

  1. <slData:DataGridTextColumn Binding="{Binding TypeString}" >
  2.     <sdk:DataGridTextColumn.HeaderStyle>
  3.         <Style TargetType="primitives:DataGridColumnHeader" >
  4.             <Setter Property="ContentTemplate">
  5.                 <Setter.Value>
  6.                     <DataTemplate>
  7.                         <TextBlock Text="{Binding Path=Type, Source={StaticResource StringsRes}}"/>
  8.                     </DataTemplate>
  9.                 </Setter.Value>
  10.             </Setter>
  11.         </Style>
  12.     </sdk:DataGridTextColumn.HeaderStyle>
  13. </slData:DataGridTextColumn>

Though I am still searching for a generic solution and not something I have to copy paste for each DataGrid Column…

 

//TODO: Check if this was fixed in SL5. If so post the elegant solution

IceRocket Tags:

Tuesday, May 1, 2012

Polyline wrong coordinates

We have been developing for a long time on a single oracle DB Server (Development stage) and recently added a new integration server. Because of time constraints we decided to just copy the data from the Dev server using SQL (out DBA did that part), and since we moved to SDO_GEOMETRY the data can be transferred without the use of ArcDesktop utilities.

So the data was moved correctly and the registration went without a glitch. But when we tried to create a new line in the layer its coordinates moved from (35.5, 32.7) (in x,y) to (–324.4, 32.7). The first thing I checked was my code but there were no changes done and in the old environment everything worked fine.

Looking at the Layers table in the SDE schema that table looked like:

EFLAGS

LAYER_MASK

GSIZE1

GSIZE2

GSIZE3

MINX

MINY

MAXX

MAXY

LAYER_CONFIG

138674317

128

-2

0 0

-400

-400

471.3916

471.3916

SDO_GEOMETRY

My first thought was that the –400 somehow affected the data being inserted but the same values were in the old DB and they worked.

After many actions of unregister and register of that layer the problem was solved.

 

TODO: Add table border, it looks bad in the site

Tuesday, March 6, 2012

Notes: Order of posts to complete – 6/3/2012

As I said before this is not my real blog just a place holder for the drafts for my real blog. Subscribers should note that the blog posts are being updated on the fly, so use a feed reader that can handle this (Google Reader will not mark the post differently for updated posts).

I am sure some of you are wondering why I don’t post some of the more complete posts and for those posts I simply would like to post them in a certain order. It’s like writing a story I can’t really post on FluentMigrator before I write about the SDE or ArcObjects (since extending FluentMigrator is all about using ArcObjects to deploy the SDE).

Since at this point in time I have 55 draft posts I decided to add categories to the posts:

  • ????? – haven’t reviewed the post
  • Title Draft – only has a title and lots of TODOs
  • Draft – has some text but the text is rough
  • Beta – almost ready: spelling, ordering, checking the grammar…
  • Post In Wait – waiting for another post before posting

I have also decided to post the exceptions/error solving posts without waiting for background posts (if they are ready). Since they are mostly posts I am not going to edit.

I have decided to write here the order of the Notes’ drafts I am going to work on:

  1. Unit Tests: What to Test?  - Draft: code, go over all the cases, add my Resharper template, TODOs 
  2. Unit Test Code Coverage – Title Draft: even the TODOs are rough…
  3. To Rhino or not to Rhino? – Draft: code, font, the explanations are too short
  4. Tracking down a simple bug - Draft: code, font, draw the examples
  5. TODO: ArcObjects: WorkspaceUtils
  6. File GeoDatabase: Getting the Workspace – Draft: might need to split to 2 posts
  7. Multithreading with ArcObjects – Draft: font, code, TODOs
  8. Refactoring ESRI: Making the Examples Readable, Part 1 – Draft: continue the example, maybe remove the first refactor result ( just keep the number of lines), to many text strings in the end code – move to consts
  9. Mocking ESRI (testing wise) – Title Draft: even the TODOs are rough… Though the title is just right!
  10. TODO: SQL
  11. TODO: SQL Server
  12. ArcSDE–Connection to the Geodatabase – Draft: write how to get the service number, images in old style, remove del tags
  13. TODO: ArcSDE: Different DB types
  14. SDE – A look at the layer table structure – Draft: images, font, write about deleting features and triggers
  15. Reading SDE queries – Draft: images, font, weird characters, SQL, del tags, grammer
  16. Deleting SDE left over tables – Draft: images, font, SQL, rewrite query
  17. TODO: WorkspaceProvider
  18. TODO: WorkspaceUtils
  19. Working with CAD files in ArcObjects – Draft: code, links, font
  20. Upgrading the code base from ArcGIS 9.3.1 to 10 – Beta: images, code, del tags
  21. Rename Polyline layer – Beta: code, font
  22. ArcSDE–Adding domains from code – Beta: refactor the code
  23. Simplify and the ArcEngine license – Draft: code, font, images, name should be different
  24. ESRI License error – Draft: code, font, images, name should be different
  25. TODO: ArcGIS Server Introduction
  26. TODO: ArcGIS Server Publish mxd
  27. ArcGIS Server layer problem (DB is down) – Beta: font, images, post clearing cache first, del tags ***
  28. Restart ArcGIS Server service – Beta: font, images, del tags ***
  29. Calling ArcGIS Server service model - Beta: font, images, del tags ***
  30. Address Locator Style: Introduction – Draft: finish a working style before posting this
  31. Address Locator Style: Customizing Guide – Draft: finish a working style before posting this
  32. Address Locator Style: Testing – Draft: finish a working style before posting this
  33. FluentMigrator: Understanding the Framework Code – Draft: TODOs
  34. FluentMigrator: Extending the Framework – Draft: not finished
  35. ArcSDE/SQL Server Tables–What is Sde’s and what is Regular – Beta: SQL query, del tags, post after FM
  36. Stuck Database – the JOY! – Beta: font, images, maybe add a conclusion, post after intro to FM
  37. VS2010: “The project type is not supported by this... – Beta: cut the post (won’t continue to work on it), images, font ***
  38. Silverlight Memory Leak, Part 3 – ?????
  39. Silverlight Memory Leak, Part 4 – ?????

I have some more posts to which I haven’t decided the order:

  1. Coded UI testing for Silverlight application – Draft: really rough, font, images
  2. Silverlight ESRI App - IIS is dead–Error 5011 – Draft: TODOs, wrong date, del tags
  3. IntelliTrace: – Draft: still rough
  4. TODO: Using DotTrace
  5. Silverlight error connecting to WCF – ?????
  6. Rebuild All failed without any errors (Silverlight), Part 2 – ?????
  7. TODO: Probability, Why do I need it?
  8. Linq2Sql: Changing the Database Schema at Runtime (without XMLs) – Draft: still waiting for a solution
  9. Silverlight: Adding Google Streets View, part 2 – ?????
  10. LINQ and WCF – ?????
  11. Game Programming with XNA – ????
  12. HTTP Error 503. The service is unavailable. – ?????
  13. Combining WMV Videos – ????

Posts that I might not post:

  1. Writing a Windows Live Writer Plugin – Draft: didn’t write one…, images, del tags, ice tags
  2. Windows Live Writer: Tag providers, Part 2 – need to go over all the tag providers and need to get a response from some of them so it might take some time, Technorati is still giving me hard times.
  3. Offline Blog Writing Applications - Draft
  4. The Library example – Haven’t decided on posting this or not might change it to sheep and shepherds…
  5. Python – Introduction – Draft: just not written well
  6. Silverlight 4 – more for me…

I think that’s enough for now…

Refactoring ESRI: Making the Examples Readable, Part 1

This is the refactor for ESRI example for creating an Address Locator in a Personal GeoDatabase:

  1. public void AddressLocatorPersonalGDBViaArcObjects()
  2. {
  3.     // Open the default local locator workspace to get the locator style.
  4.     System.Object obj = Activator.CreateInstance(Type.GetTypeFromProgID(
  5.         "esriLocation.LocatorManager"));
  6.     ILocatorManager2 locatorManager2 = obj as ILocatorManager2;
  7.     ILocatorWorkspace locatorWorkspace = locatorManager2.GetLocatorWorkspaceFromPath
  8.         ("");
  9.  
  10.     // Get the locator style to base the new locator.
  11.     ILocatorStyle locatorStyle = locatorWorkspace.GetLocatorStyle(
  12.         "US Address - Dual Ranges");
  13.  
  14.     // Open the feature class to use as reference data.
  15.     IWorkspaceFactory2 workspaceFactory2 = new AccessWorkspaceFactoryClass();
  16.     IWorkspace workspace = workspaceFactory2.OpenFromFile(
  17.         @"D:\workspace\arcobjects\location\redlands.mdb",
  18.         0);
  19.     IFeatureWorkspace featureWorkspace = (IFeatureWorkspace) workspace;
  20.     IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("Streets");
  21.  
  22.     // Set the feature class as the primary reference data table for the locator.
  23.     IDataset dataset = (IDataset) featureClass;
  24.  
  25.     IReferenceDataTables referenceDataTables = (IReferenceDataTables) locatorStyle;
  26.     IEnumReferenceDataTable enumReferenceDataTable = referenceDataTables.Tables;
  27.     enumReferenceDataTable.Reset();
  28.  
  29.     IReferenceDataTable referenceDataTable = enumReferenceDataTable.Next();
  30.     IReferenceDataTableEdit referenceDataTableEdit = (IReferenceDataTableEdit)
  31.                                                      referenceDataTable;
  32.     IName name = dataset.FullName;
  33.     referenceDataTableEdit.Name_2 = (ITableName) name;
  34.  
  35.     // Store the new locator in the same workspace as the reference data.
  36.     if (referenceDataTables.HasEnoughInfo)
  37.     {
  38.         locatorWorkspace = locatorManager2.GetLocatorWorkspaceFromPath(
  39.             @"D:\workspace\arcobjects\location\redlands.mdb");
  40.         ILocator locator = locatorWorkspace.AddLocator("New Redlands Locator",
  41.                                                        (ILocator) locatorStyle, "", null);
  42.     }
  43. }

The first order of business is refactoring this method.

The first thing to go was this:

  1. IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("Streets");
  2.  
  3. // Set the feature class as the primary reference data table for the locator.
  4. IDataset dataset = (IDataset) featureClass;

To:

  1. IDataset dataset = (IDataset)featureWorkspace.OpenFeatureClass("Streets");

There was a few other things like: referenceDataTable->referenceDataTableEdit,

The end result was:

  1. public void AddressLocatorPersonalGDBViaArcObjects()
  2. {
  3.     // Open the default local locator workspace to get the locator style.
  4.     System.Object obj = Activator.CreateInstance(Type.GetTypeFromProgID(
  5.         "esriLocation.LocatorManager"));
  6.     var locatorManager2 = obj as ILocatorManager2;
  7.     var locatorWorkspace = locatorManager2.GetLocatorWorkspaceFromPath
  8.         ("");
  9.  
  10.     // Get the locator style to base the new locator.
  11.     var locatorStyle = locatorWorkspace.GetLocatorStyle(
  12.         "US Address - Dual Ranges");
  13.     // Open the feature class to use as reference data.
  14.     IWorkspaceFactory2 workspaceFactory2 = new AccessWorkspaceFactoryClass();
  15.     var featureWorkspace = (IFeatureWorkspace)workspaceFactory2.OpenFromFile(
  16.         @"D:\workspace\arcobjects\location\redlands.mdb",
  17.         0);
  18.  
  19.     // Set the feature class as the primary reference data table for the locator.
  20.     var dataset = (IDataset)featureWorkspace.OpenFeatureClass("Streets");
  21.     
  22.     var referenceDataTables = (IReferenceDataTables)locatorStyle;
  23.  
  24.     var enumReferenceDataTable = referenceDataTables.Tables;
  25.     enumReferenceDataTable.Reset();
  26.  
  27.     var referenceDataTableEdit = (IReferenceDataTableEdit) enumReferenceDataTable.Next();
  28.     
  29.     referenceDataTableEdit.Name_2 = (ITableName)dataset.FullName;
  30.  
  31.     // Store the new locator in the same workspace as the reference data.
  32.     if (referenceDataTables.HasEnoughInfo)
  33.     {
  34.         locatorWorkspace = locatorManager2.GetLocatorWorkspaceFromPath(
  35.             @"D:\workspace\arcobjects\location\redlands.mdb");
  36.         locatorWorkspace.AddLocator("New Redlands Locator",
  37.                                                        (ILocator) locatorStyle, "", null);
  38.     }
  39. }

39 lines without any loss of readability, not that it says much – it still not readable!

The next thing to look at is creating the ILocatorManager2, I don’t know about you but I prefer getting an exception about converting than about Null reference:

  1. (ILocatorManager2)Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"));

(that also solved the problem of the ‘obj’ variable naming)

The next part is creating a Utils class for LocatorWorkspace:

  1. public class LocatorWorkspaceUtils
  2. {
  3.     private readonly ILocatorManager2 _locatorManager;
  4.  
  5.     #region Singleton
  6.  
  7.     private static readonly LocatorWorkspaceUtils instance = new LocatorWorkspaceUtils();
  8.  
  9.     // Explicit static constructor to tell C# compiler
  10.     // not to mark type as beforefieldinit
  11.     static LocatorWorkspaceUtils()
  12.     {
  13.     }
  14.  
  15.     private LocatorWorkspaceUtils()
  16.     {
  17.         _locatorManager =
  18.             (ILocatorManager2)Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"));
  19.     }
  20.  
  21.     public static LocatorWorkspaceUtils Instance
  22.     {
  23.         get { return instance; }
  24.     }
  25.  
  26.     #endregion

It’s singleton with ILocatorManager already set, now the only thing we use it for is:

  1. private ILocatorWorkspace GetLocatorWorkspace(string fileLocation)
  2. {
  3.     return _locatorManager.GetLocatorWorkspaceFromPath(fileLocation);
  4. }

Getting the style:

  1. public ILocatorStyle GetLocatorStyle(string styleName)
  2. {
  3.     return GetLocatorStyle(styleName, "");
  4. }
  5.  
  6. public ILocatorStyle GetLocatorStyle(string styleName, string fileLocation)
  7. {
  8.     var locatorWorkspace = GetLocatorWorkspace(fileLocation);
  9.  
  10.     // Get the locator style to base the new locator.
  11.     return locatorWorkspace.GetLocatorStyle(styleName);
  12. }

Adding the locator style:

  1. public void AddLocatorStyle(string styleName, string fileLocation, ILocator locatorStyle)
  2. {
  3.     var locatorWorkspace = GetLocatorWorkspace(fileLocation);
  4.     locatorWorkspace.AddLocator(styleName, locatorStyle, "", null);
  5. }

Setting the dataset name in the locator:

  1. public void SetLocatorDatasetName(IName datasetName, ILocatorStyle locatorStyle)
  2. {
  3.     var referenceDataTables = (IReferenceDataTables)locatorStyle;
  4.  
  5.     var enumReferenceDataTable = referenceDataTables.Tables;
  6.     enumReferenceDataTable.Reset();
  7.  
  8.     var referenceDataTableEdit = (IReferenceDataTableEdit)enumReferenceDataTable.Next();
  9.  
  10.     //var name = new TableNameClass {Name = datasetName};
  11.  
  12.     referenceDataTableEdit.Name_2 = (ITableName)datasetName;
  13. }

Checking if the locator is good to be saved:

  1. public bool IsLocatorValidForSave(ILocatorStyle locatorStyle)
  2. {
  3.     return ((IReferenceDataTables)locatorStyle).HasEnoughInfo;
  4. }

Now the code looks like:

  1. public void AddressLocatorPersonalGDBViaArcObjects()
  2. {
  3.     // Get the locator style to base the new locator.
  4.     var locatorStyle = LocatorWorkspaceUtils.Instance.GetLocatorStyle("US Address - Dual Ranges");
  5.  
  6.     // Open the feature class to use as reference data.
  7.     IWorkspaceFactory2 workspaceFactory2 = new AccessWorkspaceFactoryClass();
  8.     var featureWorkspace = (IFeatureWorkspace)workspaceFactory2.OpenFromFile(
  9.         @"D:\workspace\arcobjects\location\redlands.mdb",
  10.         0);
  11.  
  12.     // Set the feature class as the primary reference data table for the locator.
  13.     var dataset = (IDataset)featureWorkspace.OpenFeatureClass("Streets");
  14.     LocatorWorkspaceUtils.Instance.SetLocatorDatasetName(dataset.FullName, locatorStyle);
  15.  
  16.     if (LocatorWorkspaceUtils.Instance.IsLocatorValidForSave(locatorStyle))
  17.     {
  18.         LocatorWorkspaceUtils.Instance.AddLocatorStyle("New Redlands Locator",
  19.             @"D:\workspace\arcobjects\location\redlands.mdb",
  20.             (ILocator)locatorStyle);
  21.     }
  22. }

Now something seems a bit off here, the only reason we open the workspace for the MDB file is to get the dataset FullName, WTF?!? Why not just pass the name as a… wait for it… string?

TODO: continue this

 

Keywords: ESRI, ArcObjects, refactor

IceRocket Tags: ,,

Bug: Using TimeStamp with Time Zone in (Oracle) Entity Framework

For the past week I have been working on the problem of correctly saving TimeStamp with Time Zone in (Oracle) Entity Framework. The problem is both DateTime and OffsetDateTime when saved in that field in the DB are missing a critical info – the location offset given to them. They always save the field with the offset of the client, in my case +02:00.

In the beginning I was sure it was something that will be easily fixed, simply because I came through this StackOverFlow question/answer which talked about changing the numeric data type so that bool is number(1,0). So I was sure it was a generic interface, well its not!

Looking into Oracle’s EFOracleProviderServices decompiled source (using JetBrains’s dotPeek) I tried looking for config values but instead found the bug in Oracle:

  1. new OracleParameter(name, (object) ((DateTimeOffset) value).DateTime))

Meaning that although you might have gone into the trouble of creating a DateTimeOffset (with no trouble at all), Oracle just knows what’s best and will convert it to DateTime (plus enable a boolean that will later convert it back to offset).

I have tried using Open Source Providers but so far no luck (had problem finding the provider or it wasn’t in .net 4.0), I will try again tomorrow.

http://eforacleodpprovider.codeplex.com

http://archive.msdn.microsoft.com/EFOracleProvider/Release/ProjectReleases.aspx?ReleaseId=1395

//TODO: Continue this

 

Resources:

StackOverFlow: Where do I put Oracle EntityFramework Mapping settings for LinqPad?