Friday, August 27, 2010

iPhone Development - Day 7 Review

Another book bites the dust. Code doesn't fit, words, words, words, anyone ever heard of video teaching?

Wednesday, August 25, 2010

iPhone Development - Day 5 Review

I got through another two chapters. Starting to get muddy around here. I went to use the provided code for the book, and I can't because the code is in iPhone 3 SDK, which is not supported under the newest Xcode version...great. So the only thing I can do with the code is copy and paste it in to mine and see if there's works with my code, and go from there. Not so happy with that. There is only one book out there so far that I have found that uses iOS 4. That is iPhone and iPad Development for Absolute Beginners from APRESS.

I have reached some errors in my last two projects that I have done through the book. Both errors are not in my code, so I have yet to find a way to work through those errors.

Thursday, August 19, 2010

iPhone Development - Day 2 Review

So here we are with Day 2 complete. Once again, Deitel did not fail, well, almost. I had a little complication with understanding delegates. However... voila! ... I checked out this website and got a great understand by comparing the code that Deitel had to this, and the explanation that this blog provided was nothing less than understandable.

I am still taking the positive attitude that it is possible for me to be an iPhone developer! This book is providing me with much more understanding and better tutorials as to what I am doing. It is also providing great examples to build off of for later projects.

Once again, the book that I am using is iPhone for Programmers: An-App Driven Approach.

Tuesday, August 17, 2010

iPhone Development - Day 1 Review

Hooray!

For the first time in my iPhone Dev. adventures I have come across a helpful book. As expected Deitel provided a no assumption approach to explaining what they were doing in their tutorials. I have completed the first two apps and already see a big difference in explanations of why I am doing what I am doing in the code. I am also seeing a better lead in from simple to complex. Each chapter is laid out in a fashion that is like a meeting (i.e., agenda, goal, discussion, code explanation, conclusion). Thumbs up as of right now.

Monday, August 16, 2010

iPhone Development Start

I can't say that it was really started right now. I am re-engaging this problem. I started out trying to learn iPhone development right at the time when Apple was switching over to iOS 4, so it made it difficult to utilize source code from any book that was out at the time. None of them worked since they were for different versions of the OS. I dived into Learn Cocoa on the Mac (terrible first step), then I went to Beginning iPhone 3 Development (not bad, but could have been better), I finally came to More iPhone 3 Development (same as last one). None of these helped me understand technically why I was doing what I was doing. My background is C#, so that might have something to do with it all, but I find it as just a higher hurdle to jump then just going from C# to Java. This is also my first time of getting involved into MVC style programming, and my experience is in Domain Model. All this colliding together made for a first attempt bad experience. So here I am now renewing my vows to the iPod Touch, iPhone, and, hopefully, iPad.

My first step is trying a new book for teaching. I am going with a Deitel production, "iPhone For Developers: An App-Driven Approach". Deitel & Deitel is a well known college book author. I used the Java and C++ one in school, so hopefully this is a good first start. My first application, simple, a picture and label on the screen. That couldn't be easier.

Tuesday, July 20, 2010

PHP: Check to see if you have a postback.

I looked all over for a simple answer to find out how you check to see if the page is a postback. It was simple, but yet out of all the web pages I trolled through nothing had come up.

The situation is that if you submit a form and the action is set to blank, then how do you do some work if there is postback data and do other work if there is no postback data? This a common occurrence that I came across all the time while doing development in the .NET world, but there was a simple boolean variable to check in C#. How do you do that in PHP?

if ($_POST) {

}

It IS that simple (well, at least for me it was). It just checks to see if the $_POST array has been set. I don't know why no one else can answer that simple question just like that.

Monday, May 10, 2010

SharePoint HttpHandler Example

This past week I needed a solution to do customized server-side work from the EditControlBlock menu in a list. I had to lace together a few solutions that I found when googling the net.


1) Creating a CustomAction as a feature to install on the SharePoint server.
2) Creating a custom WebControl for the CustomAction.
3) Utilize jQuery and a Generic Handler to perform server side code.

For the CustomAction it was pretty easy. You need to place the following XML in the elements.xml file for your feature.


elements.xml
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="Unique Id Here"
Title="Action Name in Menu"
Description="Description of Action"
RegistrationType="List"
RegistrationId="101"
Location="EditControlBlock"
Sequence="1000"
ControlAssembly="[Fully Qualified Assembly Name]"
ControlClass="ImportXML.Import">
<UrlAction Url="javascript:ExecuteAJAXCall();"/>
</CustomAction>
</Elements>

This will create a CustomAction for the Edit Control Block menu. The Edit Control Block menu is the pop down menu that appears for List Items. RegistrationId can change based on the type of list you want to attach this CustomAction to.

The second part is creating a generic handler to handle the server side functionality.
HandlerRequest.ashx
<%@ Assembly Name="[Fully Qualified Assembly Name]" %>
<%@ WebHandler Language="C#" CodeBehind="HandlerRequest.ashx.cs" Class="HttpHandler.HandlerRequest" %>
HandlerRequest.ashx.cs
namespace HttpHandler
{
public class HandlerRequest : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
string webUrl = context.Request.Form["thisWebUrl"];
string listName = context.Request.Form["thisListName"];
string stringListId = context.Request.Form["thisListItemId"];

int itemId = Convert.ToInt32(stringListId);

List<string> response = new List<string>();

try
{
using (SPSite site = new SPSite(webUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[listName];

SPListItem item = list.Items[itemId];


response.Add("1");
response.Add(item.ID.ToString());
response.Add(item.Title);
}
}
}
catch(Exception ex)
{
response.Add("0");
response.Add("Operations failed.");
response.Add(ex.Message);
response.Add(ex.StackTrace);
}

JavaScriptSerializer JSSerializer = new JavaScriptSerializer();
context.Response.ContentType = "text/plain";
context.Response.Write(JSSerializer.Serialize(response));
}

public bool IsReusable
{
get
{
return false;
}
}
}
}


Finally I am using javascript in the default.master to compose the ExecuteAJAXCall() method. I utilized SharePoint Designer to access default.master.
Javascript
<script type='text/javascript' src='jquery.js' ></script>
<script>
function ExecuteAJAXCall() {
var userResponse = confirm("Are you sure you want to import this data?");

if (userResponse) {
$.post("/_layouts/ImportXML/ImportRequest.ashx",
{thisWebUrl:ctx.HttpRoot,thisListName:ctx.ListTitle,thisListItemId:currentItemID},
function(data, status, request){
Callback_AJAXCall(data, status, request);
},
'json'
);
}
};

function Callback_AJAXCall(data, status, request) {
if (data[0] == "1") {
alert(data[1]);
} else {
alert(data[1] + "\r\n\r\nError Message:" + data[2] + "\r\n\r\nStack Trace:" + data[3]);
}
};
</script>


After the creation of all these files you are ready to start putting it all together for the server.

1) The generic handler needs to be placed in the "12\TEMPLATE\LAYOUTS" folder.
2) The .dll file from the handler code needs to be placed in "InetPub\wwwroot\wss\VirtualDirectories\80\bin"
3) Last step is to install the feature through stsadm.exe command line utility and you are set!

Hope that helps out someone.