Monday, October 28, 2013

Log File not written during scheduled task execution in Python Script

I wrote a python script to perform a scheduled job. I was also logging few information in a simple text file. But for some reason, nothing was written in the log file.

After doing some research, I found that, when setting up the scheduled task, I must fill in the "Start In" folder location. Only when this value is set, the python script can write the log file correctly.

Hope this helps !

Happy Coding.

Wednesday, September 25, 2013

Intercept calls coming to a Web Application in IIS Server



It was required to intercept all the calls coming into a particular web application on the IIS Server and identify the contents in the request. We ended up writing a class derived from “IHttpModule" interface.
Here are some tips on how to create and install it on the IIS server.
  • Creating the class is a simple task. Just derive the class from the interface “IHttpModule". Implement the interface as shown below.

public class ServerIntercept : IHttpModule
{
      public void Dispose()
       {
       }
       public void Init(HttpApplication context)
       {
        context.BeginRequest += context_BeginRequest;
        }
        void context_BeginRequest(object sender, EventArgs e)
        {
            // Add all code here
        }
}

  • Make sure the DLL is signed with strong name key
  • Copy this DLL to the server and use GAC utility to register this on the server.  If it is .NET 2 framework it is a different utility and if it is .NET 4 framework it is a different utility. Use the correct utility to register.
  • Add the entries to the Web.Config file of the application. This file may be read-only. Make sure the entries are being saved properly. A sample is shown below.
<configuration>
<system.webServer>
<modules>
<add name="ScriptModule-4.0" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler,runtimeVersionv4.0" />
</modules>
</system.webServer>
</configuration>

 The type in the above example is the class name with namespace and the DLL file name. The public key token value can be obtained from the GAC utility.
  • Reset IIS. Then open the IIS manager. Go to the application and look into the “Modules” section. The newly installed module must be present and now the application is ready to intercept all the calls coming to it.

Happy coding!

Monday, August 26, 2013

Java heap space – ArcGIS Server Error


Recently when we were doing some spatial ArcGIS query using ArcGIS REST endpoint, we ran into some issues.
We turned on the server logs and started to monitor it. We found the following error entries in the log files.

Exception caught while processing request. Java heap space
Internal Server Error. Error handling service request : java.lang.OutOfMemoryError: Java heap space

com.esri.discovery.DiscoveryException: Error handling service request : java.lang.OutOfMemoryError: Java heap space

After several hours of debugging, we discovered one crucial problem.
In our published MXD file, we had few GIS Featureclass Layers from ArcSDE and also standalone ArcSDE tables.  There was a JOIN established between the GIS Featureclass Layer and standalone table. We realized that the GIS Featureclass layer was not versioned, but the ArcSDE standalone table was versioned. We removed the versioning from the standalone table and all started to work as expected.

It was surprising to see this kind of behavior. I am documenting this here so that it might help someone.
Cheers
Anand

Saturday, July 13, 2013

Storing and Retreiving Data from a Web Server using WCF Web Service


In one of my Silverlight projects, there was a need to store some data on the server and get it back as needed. I wrote a simple WCF Web Service to do this. This service will take in a string and write it on the server on a file called "AppSettings.xml".

The web service function "GetStoredDataFromServer()" will get the stored data in string format from the server.

The web service function "SaveDataOnServer(string datatoSave)" will store the data on the server.

When deploying this service on the IIS server, make sure to provide write permission for the IIS_IUSRS account to the file "AppSettings.xml". This is required because the anonymous user must be able to save the information on the file "AppSettings.xml".


 Here is the code.

 This code needs to go on the IService.cs.

    [ServiceContract]

    public interface IStoreService

    {

        [OperationContract]

        string GetStoredDataFromServer();

 

        [OperationContract]

        string SaveDataOnServer(string datatoSave);

    }


This code needs to go on the Service.svc.cs file.

   public class StoreDataService : IStoreService

    {

        public string GetStoredDataFromServer()

        {

            string togoMessage = "";

            string fileName = AppDomain.CurrentDomain.BaseDirectory + "AppSettings.xml" ;

            if (File.Exists(fileName) == false)

            {

                try

                {

                    StreamWriter sw = new StreamWriter(fileName);

                    sw.WriteLine("");

                    sw.Close();

                }

                catch (Exception ex)

                {

                    togoMessage = "Error : " + ex.ToString();

                    return togoMessage;

                }

            }

            else

            {

                StreamReader sr = new StreamReader(fileName);

                togoMessage = sr.ReadToEnd();

                sr.Close();

            }

            return togoMessage;

        }

 

        public string SaveDataOnServer(string datatoSave)

        {

            string togoMessage = "";

            string fileName = AppDomain.CurrentDomain.BaseDirectory + "AppSettings.xml";

            try

            {

                StreamWriter sw = new StreamWriter(fileName);

                sw.WriteLine(datatoSave);

                sw.Close();

            }

            catch (Exception ex)

            {

                togoMessage = "Error : " + ex.ToString();

                return togoMessage;

            }

            return togoMessage;

        }

    }

 Happy Coding !

Saturday, June 22, 2013

Pulsating Point Symbol for ArcGIS Silverlight Applications

There was a need to display a pulsating/flashing point symbol in one of my Silverlight Application.

Here is the code to do it. You can change the color and timing and make it look better.

Use this "AnimatedPointSymbol" in the code behind file.

Cheers
Anand

========= XAML File content ===========

<esri2009:MarkerSymbol x:Name="AnimatedPointSymbol" OffsetX="12" OffsetY="12">
<esri2009:MarkerSymbol.ControlTemplate>
<ControlTemplate xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="RootElement" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<ScaleTransform ScaleX="1" ScaleY="1" />
</Grid.RenderTransform>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation BeginTime="0:0:0" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" To="1.5" Duration="0:0:1" />
<DoubleAnimation BeginTime="0:0:0" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" To="1.5" Duration="0:0:1" />
<DoubleAnimation BeginTime="0:0:0" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.Opacity)" From="1" To="0.5" Duration="00:00:01" />
</Storyboard>
</VisualState>
<VisualState x:Name="MouseOver">
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"></VisualState>
<VisualState x:Name="Selected">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation BeginTime="0:0:0" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" To="1.5" Duration="0:0:1" />
<DoubleAnimation BeginTime="0:0:0" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" To="1.5" Duration="0:0:1" />
<DoubleAnimation BeginTime="0:0:0" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.Opacity)" From="1" To="0.5" Duration="00:00:01" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Ellipse x:Name="Ellipse" Width="24" Height="24">
<Ellipse.Fill>
<RadialGradientBrush GradientOrigin="0.5,0.5" Center="0.5,0.5" RadiusX="0.5" RadiusY="0.5">
<GradientStop Color="#EEFF0000" Offset="0.0" />
<GradientStop Color="#EEFFFF00" Offset="0.5" />
<GradientStop Color="#EEFF0000" Offset="1.0" />
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
</Grid>
</ControlTemplate>
</esri2009:MarkerSymbol.ControlTemplate>
</esri2009:MarkerSymbol>

All Blogs so far ...