Posted by
Scott
on
17. August 2010 15:35
I have a website that gets thousands upon thousands of hits a day. And I use guids to identifiy everything. So I needed something to show Guids in the URLS. The best thing I found at that moment was Mads Kristensen’s Shorter URL Friendly Guid.
Mads basically converts the Guid to base 64. For a small website of sorts, this isn’t a bad idea. But overtime and larger websites there will be more and more Guids represented. After coming up with several errors in my site, I decided to investigate. When converting to Base64 with Guids, I started to notice some slight loss of the Guid. When I say slight, I mean one in every 2000 users had shown errors. To me this isn’t acceptable by any means. One user can destroy an entire website by talking slander so I was in need of a fix.
So I threw out Mads idea and went searching for something different. Its not uncommon to still use Guids in URL’s. With the Dashes and all. Microsoft, Flickr, Yahoo, Google, and some various other third party websites still use them in their URLs. But I didn’t want the dashes. I wanted just the numbers and letters. Dashes could some day cause a problem, but not just numbers and letters. So I decided to get rid of the dashes. So here is the final code to use Guids as Urls.
I have a Guid extension class in C#. One method is as follows:
public static string RemoveDashes(this Guid guid)
{
return guid.ToString().Replace("-","");
}
This method gets called when ever I convert a Guid to a URL. Whats nice about this, is the way I convert the Guid back with dashes. No real fiddling with strings. All that needs to be done is this:
Guid guid = new Guid("c9a646d39c614cb7bfcdee2522c8f633");
And that automatically puts the dashes back into the system.
If you liked this post, please be sure to subscribe to my
RSS Feed.
Comments:
0
Filed Under:
C#
Tags:
Posted by
Scott
on
9. August 2010 15:32
When developing WCF silverlight 4 services to contact data, I received the following error:
The contract name '’ could not be found in the list of contracts implemented by the service ‘’.
I wanted to just give a heads up to those wondering whats going on. Make sure when you add the endpoint, your contract points to the Interface instead of just the service it self. For example:
<services>
<service behaviorConfiguration="PortalSilverlight.Web.Services.ServicesBehavior" name="PortalSilverlight.Web.Services.Services">
<endpoint address="http://localhost:3454/Services/Services.svc" binding="wsHttpBinding" contract="PortalSilverlight.Web.Services.IServices" />
</service>
</services>
Notice in the contract attribute I am pointing towards the IService instead of just the Services.svc file. Took me a couple of hours to figure this out.
If you liked this post, please be sure to subscribe to my
RSS Feed.
Posted by
Scott
on
6. August 2010 15:42
All,
Along with my last few posts, I received an Error when trying to open shapefiles with Arcobjects. Thought I would post the problem incase someone else ran into it.
Here is the code to open shapefiles with Arcobjects.
IWorkspaceFactory workspaceFactoryShape = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass(); //creates a shape factory to pull the shape and create the feature class.
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactoryShape.OpenFromFile(System.IO.Path.GetDirectoryName(file), 0); //Opens the Shape file.
IFeatureLayer featureLayer = new FeatureLayerClass();
featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(file)); //opens the featurclass from the shapefile
Two things to point out.
- The openfromFile method will throw the error: HRESULT: 0x80040258 if you don’t get the directory in which the shape files are located. Its not looking for the actual .shp file. Its looking for where the shape files reside.
- The OpenFeatureclass method is where you give just the file name of the shape file. Don’t include the .shp extenstion nor the file path. Remember it already has the file path I stated in the first point.
Hope this helps someone out! I know I struggled with it for about 2 hours…
If you liked this post, please be sure to subscribe to my
RSS Feed.
Posted by
Scott
on
4. August 2010 15:32
The first example shows how to download a file synchronously and the second, asynchronously. Just a quick post. Thought it would help someone out that.
using System.Net;
WebClient webClient = new WebClient();
webClient.DownloadFile("http://yahoo.com/file.txt", @"c:\file.txt");
This one shows how to download a file in C# asynchronously.
private void btnDownload_Click(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileAsync(new Uri("http://mysite.com/myfile.txt"), @"c:\myfile.txt");
}
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar.Value = e.ProgressPercentage;
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Download completed!");
}
If you liked this post, please be sure to subscribe to my
RSS Feed.
Posted by
Scott
on
4. August 2010 12:02
So after tons of searching and bothersome problems, It took a while to find code, but none could be found. So I wanted to make sure the end example was easily findable on the internet next time. Hope this saves some time of another programmer out there!
This code will publish an .MXD map to the ArcGIS server. And turn it on to be used right away.
//The following C# code shows how to connect to the ArcGIS Server called " ",
//and use the IServerObjectConfiguration interface to set the properties of
//a new server object configuration. The new configuration is created and
// added to the server with the
//CreateConfiguration and AddConfiguration methods on IServerObjectAdmin.
/// <summary>
/// This publishes a Map to the ArcGIS Server
/// </summary>
/// <param name="serverMachineName">Servername</param>
/// <param name="serviceName">Service name in which you want to call it</param>
/// <param name="pathToMap">File Path to the .mxd map.</param>
/// <param name="format">Which format you would like. Look in code.</param>
public static void AddMapService(string serverMachineName, string serviceName, string pathToMap, int format)
{
// Initialize ESRI licenses
IAoInitialize aoInit = new AoInitializeClass();
aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);
//define paths for the onlineresource property in the extension properties
string resource = "http://" + serverMachineName + "/ArcGIS/services/" + serviceName + "/MapServer/WMSServer";
string resourceKML = "http://" + serverMachineName + "/ArcGIS/services/" + serviceName + "/MapServer/KMLServer";
string resourceWCS = "http://" + serverMachineName + "/ArcGIS/services/" + serviceName + "/MapServer/WCSServer";
string resourceWFS = "http://" + serverMachineName + "/ArcGIS/services/" + serviceName + "/MapServer/WFSServer";
// Connect to the ArcGIS server called serverMachineName (string) .
IGISServerConnection pGISServerConnection = new GISServerConnectionClass();
// example : pGISServerConnection.Connect("llv38-tasc65688");
pGISServerConnection.Connect(serverMachineName);
// create the new configuration
IServerObjectAdmin pServerObjectAdmin = pGISServerConnection.ServerObjectAdmin;
IServerObjectConfiguration pConfiguration = pServerObjectAdmin.CreateConfiguration();
IServerObjectConfiguration2 pConfiguration2 = (IServerObjectConfiguration2)pConfiguration;
IServerObjectConfiguration3 pConfiguration3 = (IServerObjectConfiguration3)pConfiguration;
// set the General Configuration Settings
pConfiguration.Name = serviceName; // the name of this configuration
pConfiguration.TypeName = "MapServer"; // the type of server object to be created
pConfiguration.IsPooled = true;
pConfiguration.MinInstances = 1;
pConfiguration.MaxInstances = 2;
pConfiguration.WaitTimeout = 60;
pConfiguration.UsageTimeout = 600;
pConfiguration.StartupType = esriStartupType.esriSTAutomatic;
pConfiguration.IsolationLevel = esriServerIsolationLevel.esriServerIsolationHigh;
// Set the configuration Properties of the MapServer Object
IPropertySet pProps = pConfiguration.Properties;
pProps.SetProperty("FilePath", pathToMap); // required property
pProps.SetProperty("OutputDir", "c:\\arcgisserver\\arcgisoutput");
string virtualOutDir = " http://" + serverMachineName + "/arcgisoutput";
pProps.SetProperty("VirtualOutputDir", virtualOutDir);
pProps.SetProperty("MaxImageHeight", "2048");
pProps.SetProperty("MaxRecordCount", "500");
pProps.SetProperty("MaxBufferCount", "100");
pProps.SetProperty("MaxImageWidth", "2048");
pConfiguration.Properties = pProps;
// Set the info segment of the MapServer Object properties
IPropertySet info = pConfiguration2.Info;
info.SetProperty("WebEnabled", "true");
info.SetProperty("WebCapabilities", "Map,Query,Data");
pConfiguration2.Info = info;
// Set the recycle properties of the MapSrver object
IPropertySet pProp = pConfiguration.RecycleProperties;
pProp.SetProperty("StartTime", "1:00 AM"); // start recycling at midnight
pProp.SetProperty("Interval", "86400"); // every 24 hours
pConfiguration.RecycleProperties = pProp;
bool enabled;
if (format == 1 || format == 15)
{ //Set WMS extension Properties
pConfiguration2.set_ExtensionEnabled("WmsServer", true);
IPropertySet pExtensionProps = pConfiguration2.get_ExtensionProperties("WmsServer");
pExtensionProps.SetProperty("OnlineResource", resource);
pExtensionProps.SetProperty("Name", "WMS");
pExtensionProps.SetProperty("Title", serviceName);
// pConfiguration2.set_ExtensionProperties("WmsServer", pExtensionProps);
IPropertySet pProp2 = pConfiguration2.get_ExtensionInfo("WmsServer");
pProp2.SetProperty("WebEnabled", "true");
pProp2.SetProperty("WebCapabilities", "Map,Query,Data");
pConfiguration2.set_ExtensionInfo("WmsServer", pProp2);
}
if (format == 2 || format == 15)
{ // Set KML extension properties
pConfiguration2.set_ExtensionEnabled("KMLServer", true);
IPropertySet pPropKML = pConfiguration2.get_ExtensionInfo("KMLServer");
pPropKML.SetProperty("WebEnabled", "true");
pPropKML.SetProperty("WebCapabilities", "SingleImage,SeparateImages,Vectors");
pConfiguration2.set_ExtensionInfo("KMLServer", pPropKML);
IPropertySet pExtensionPropKML = pConfiguration2.get_ExtensionProperties("KMLServer");
pExtensionPropKML.SetProperty("ImageSize", "1024");
pExtensionPropKML.SetProperty("FeatureLimit", "1000000");
pExtensionPropKML.SetProperty("Dpi", "96");
pExtensionPropKML.SetProperty("MinRefreshPeriod", "30");
pExtensionPropKML.SetProperty("UseDefaultSnippets", "false");
// pConfiguration2.set_ExtensionProperties("KMLServer", pExtensionPropKML);
}
if (format == 4 || format == 15)
{ //Set WCS extension Properties
pConfiguration2.set_ExtensionEnabled("WcsServer", true);
IPropertySet pExtensionPropsWCS = pConfiguration2.get_ExtensionProperties("WcsServer");
pExtensionPropsWCS.SetProperty("OnlineResource", resourceWCS);
pExtensionPropsWCS.SetProperty("Name", "WCS");
pExtensionPropsWCS.SetProperty("Title", serviceName);
// pConfiguration2.set_ExtensionProperties("WcsServer", pExtensionPropsWCS);
IPropertySet pPropWCS = pConfiguration2.get_ExtensionInfo("WcsServer");
pPropWCS.SetProperty("WebEnabled", "true");
pConfiguration2.set_ExtensionInfo("WcsServer", pPropWCS);
}
if (format == 8 || format == 15)
{ //Set WFS Extension Properties
pConfiguration2.set_ExtensionEnabled("WfsServer", true);
IPropertySet pExtensionPropsWFS = pConfiguration2.get_ExtensionProperties("WfsServer");
pExtensionPropsWFS.SetProperty("OnlineResource", resourceWFS);
pExtensionPropsWFS.SetProperty("Name", "WFS");
pExtensionPropsWFS.SetProperty("Title", serviceName);
pExtensionPropsWFS.SetProperty("AppSchemaURI", resourceWFS);
pExtensionPropsWFS.SetProperty("AppSchemaPrefix", serviceName);
// pConfiguration2.set_ExtensionProperties("WfsServer", pExtensionPropsWFS);
IPropertySet pPropWFS = pConfiguration2.get_ExtensionInfo("WfsServer");
pPropWFS.SetProperty("WebEnabled", "true");
pConfiguration2.set_ExtensionInfo("WfsServer", pPropWFS);
}
//' add the configuration to the server
pServerObjectAdmin.AddConfiguration(pConfiguration2);
pServerObjectAdmin.StartConfiguration(serviceName, "MapServer");
} // end method
If you liked this post, please be sure to subscribe to my
RSS Feed.
Comments:
0
Filed Under:
ESRI | C#
Tags:
Posted by
Scott
on
30. July 2010 11:38
I hate when I can't find things easily on the web. Things are soo buried on the ESRI website its ridiculous. So I am going to start posting simple solutions and complaints if I find any. So thank you ESRI for being so hard to code for.
Complaint Number 1 about ESRI's site - When giving examples or even Class Objects, you don't show the namespaces. That leaves us developers looking for where classes are buried in several different namespaces. This is a problem that needs to be fixed.
So on to the example:
using ESRI.ArcGIS.Geodatabase;
IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(location, 0);
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(shapefilename);
Console.WriteLine("There are {0} features in the {1} feature class", featureClass.FeatureCount(new QueryFilterClass()), featureClass.AliasName);
Make Note that the variable location is does NOT include the file name.
For example: "C:\Users\Desktop\Newfolder" and NOT "C:\Users\Desktop\Newfolder\blah.shp"
Thats it!
Hope this will help someone down the road. It took me about an hour to find it on the ESRI website.
If you liked this post, please be sure to subscribe to my
RSS Feed.
Posted by
Scott
on
31. March 2009 05:05
Training the un-wanting is just plain hard.
Can you teach me to program/code? I get this question a lot in my day to day life. I have fallen for it almost 100% of the time and in total, about 10 times in the past two years. Friends ask me if I can teach them how to program. Other Friends want to create nifty little applications and need to know how to start. Then there are those that wish they knew, but don't know where to start. Every time I tell people I am a full time developer, I tend to get the question. The problem here is not that I get the question, its that 99% of the time I say yes. I actually don't really remember the last time I said no.
The United States along with other countries such as South Korea, India, Parts of China, Australia and Parts of England are now fast becoming post industrial countries. They are losing their manufacturing expertise and moving to more of an intellectual work environment. In this work environment, most people sit on their butts all day in front of a computer and get something done. In a work where the computer rules the office space, people want to manipulate their computers more and more. They want to figure out how to change information and manipulate the way things work. So because of this post industrial revolution, people want to learn how to program. Take for example, MySpace. You have to know how to develop for the web in order for you to make your page more personal. Its becoming more and more mainstream to hack a bit at code. It used to be the things that nerds do and now every kid on myspace.com has coded a little bit.
I have one friend who wanted to create a small application for user management of their organization (I ended up doing most of their work). I have another friend who wanted to learn how to create online games for Myspace. I sat down with him for a couple of hours and banged out some code. For the next week, he experimented a lot. Then he just fell off and I no longer heard him talk about code. I just had another friend who knew a bit of C and C++ in which she asked me if I can teach her to code. I said yes for the plain fact that its hard to say no. I learned to say no a while back and people tend to confuse me with someone as selfish or self absorbed. I usually let it go as that for the short answer. The long answer for those closer to me is I almost always said yes to things and became overwhelmed with things to do. It happens to everyone that says yes too much, so I had to learn to be a bit more selfish or people would just step all over you.
So, how do I make sure that the people I teach are actually going to continue doing it? This is a question I ask my self a lot and still don't have an answer for. For every person I taught; I have tried to seduce them to being my partner in crime but it just doesn't seem to happen. I still don't know how to keep these people working on code. To keep developing, to keep moving and firing. The point is, I need to start saying no to these folks as well or I need to bind them to a contract that says we are going to build this together and this will be how you learn to code. By helping me build this application, I will teach you how to code.
Thanks for listening.
If you liked this post, please be sure to subscribe to my
RSS Feed.
Posted by
Scott
on
24. December 2008 22:34
At the time of writing this, I finally got my second real website out for customers and would like to publish my profile online. So at the time of writing this, I have completed two sites for customers. This list will grow with time with each new project I create.
- Lumber by Lance - 12/24/2008 – This site is for a customer that produces logs to lumber and then has a kiln to dry the lumber out.
- Indialantic Volunteer Fire Department - 6/20/2008 – This site is for a volunteer fire department out of Indialantic Beach, Fl. I was quite happy with this project because all the white space is completely updatable before I found out the concept of what a CMS is.
- DotNet Instant Messenger - 12/28/2008 - This site was designed by a friend without a website. I designed and created DotNet IM. Pretty proud of this one actually. First real engine I have put out on the internet.
- DrinkingFor -1/09/2008 - Been working on this site with my partner in crime. I knew asp.net and he knew only java. Since C# and Java go hand and hand, he wanted to jump onto a simple project. This is it. We are working on it to make sure it up to web 2.0 standards but it has been launched.
- UtopiaPimp -6/30/2009 - I started this site well over a year ago and gave it a break so I could work on DrinkingFor. I am back at this site and it is working well for me. The site is built for a Online game at Utopia.Swirve.com. It is a game that requires a bit of intellect and collaboration. The learning curve has said to be high, but it is still one of the best and if not oldest online games in the world. UtopiaPimp currently has over 13k users.
If you liked this post, please be sure to subscribe to my
RSS Feed.
Posted by
scott
on
26. May 2008 01:56
Visual C# 2008 Keyboard Reference Poster
Visual Basic 2005 Keyboard Shortcut Reference Poster
VERY Cool!
If you liked this post, please be sure to subscribe to my
RSS Feed.
Posted by
Scott
on
23. April 2008 19:34
Boy am I tired. I can literally say I am exhausted. Now here is why. Sessions today were AMAZING and today was a good day because yesterday I found a programmer just like me who is as young as I am who wants to start up his own company just like I do. I am not telling you his name, but I got his contact information and will be giving him a ring ding ding soon! Anyone else interested in helping me with my ideas? I am poor and don't pay until we actually produce something, but I am looking for some takers. I don't mind splitting 60-40 or even starting a small business with employees. It will NOT be a consulting business, too many of those floating around. I want to start a business with my own ideas and make them a reality. Any takers?
Sessions Attended:
Building Custom AJAX Controls:
Taught by Dan Wahlin. If you have ever met him, he is as tall as me and married. One question I asked him personally is how he gets so much done and his wife be okay with it, when I have a girlfriend of my own. He said she gets used to it. This guy is also pretty interesting and pretty informed on the subject of ASP.NET. I enjoyed this session, because the JavaScript he taught was pretty much down to my level of understanding. He hit the topics of web services and JavaScript debugging in Visual Studio. He hit on the things to do when your starting up a new JavaScript file and make sure it talks to ASP.NET. Cool session, but far too much to be explained here.
Building N-Tier Applications with LINQ:
Taught again by Dan Wahlin. Another great session about how to implement LINQ into your projects and showed the easy parts of LINQ which only gets easier from T-SQL. Thank you Dan for this great session. It is a lot to implement in this short session.
Can you tell I am getting tired?
PLINQ: LINQ but faster:
Taught by the one and only Stephen Toub. The same guy I met last night is now teaching a session. I didn't know much about what he was talking about last night, but when he hit on it today in the session, I WAS BLOWN AWAY. So, he has got this 24 CORE computer up in Washington that he ran demos for us on. If you don't know what LINQ is I should ask that you check it out. PLINQ is the next step up and which you can select and transfer data at tremendous speeds using the processors that a person has in their computer. He completed a select statement with one processor with 256mbs worth of data and took about 20 seconds. The second select statement was with PLINQ with the same amount of data and the select completed at .5 seconds. Amazing STUFF. This kind of data selects could be used for gaming and even the Folding@Home project where they use personal computers from all around the world to fold protein. Amazing things if they only had their hands on this.
.NET Rocks:
Live interview with Dan Wahlin. I screamed a few times and asked the first question. Great interview and good times thanks to Carl Franklin, Richard Campbell and Dan Wahlin.
Time to Go home. Thanks for reading. More to follow.
Side Note: I am required by my company to do a "What I learned" white paper. I will post it to this blog when done, because it will contain a lot of things that I thought would be too detailed to explain in these entries.
If you liked this post, please be sure to subscribe to my
RSS Feed.