Install IOS 8 Update without enough space

I tried to install my IOS8 updated on my iPad mini and iPhone and get the error that the must be 45Mb of free for installation to continue.

However I discovered while trying to install certificates on my iPad I could use the Apple Configurator to update the IOS8 and install my certificates with my Mac Book Pro.

Download the Apple Configurator from the App Store and then install it on your Mac.

When you install the Apple Configurator you can plug your iPad mini or iPhone Device in to the USB port.

You will need to go to Settings / iCloud / Find My iPhone and turn that off.

The Apple Configurator will then find the device.

Then you can go to the Prepare Icon on the top bar of the Apple Configurator as shown below:

Once you have plugged in the device you can press the Prepare button at the bottom of the Apple Configurator.

After that you can just wait until the IOS 8 version is downloaded and installed.

Parallels & Ubuntu

I am a very big supporter of both Apple Hardware as well as MAC OSX.
However I also use Parallels Desktop on the Apple Hardware to allow me to have the best of all worlds I have the opportunity to have virtual machines for Windows 7, 8.1, as well as Ubuntu Linux, Debian Linux and Chrome OS.
I just updated to Parallels Desktop 10.0 and I am really impressed with the update. The performance has improved and I really like to the UI improvements.
I have Ubuntu 14.04 working with the new version of Parallels Desktop 10.0 that I have and also have Parallels tools installed and working well. Today I got an update alert from Ubuntu that there were some updates. When completing my updates from Ubuntu it asked to reboot the system. To my surprise after the update I got nothing but a black screen once I logged in.
When you click on anything the box is a grey blob that is really messed up. I could not see anything resembling any graphics. I tried the CTRL & ALT & T (button combo) to open a Terminal (shortcut for Ubuntu). This caused not success but again a black screen.
I am thinking that this is an issue with the Ubuntu updates that I got so I began to investigate the fix. I found this knowledge base from Parallels http://kb.parallels.com/en/118776. I decided to try to this to remove my Parallels Tools and see if that could fix it. When following the process I found another choice that I tried and it worked without removing the Parallel Tools. I thought I would document it to help others.
The following is the steps I took to fix my issue and I am now successfully running with the new Ubuntu Updates and Parallels Tools.
1. After starting the Virtual Machine for Ubuntu and Logging In. I seen this screen:


1

2. Then I clicked on the Devices -> CD/DVD 1 -> Connect Image…
2a. This will show an Open Dialog box that you can then navigate to the following area: Applications-> Parallels Desktop.app->Contents->Resources->Tools->prl-tools-lin.iso you can double click or highlight and click Open button. (Notice the lin.iso there are several iso’s in the folder and you need the Linux one).

2

3. Clicking the open button will really make no change on the screen however you will mount the iso to the cdrom. You will need to then Press the CTRL & ALT & F2 (button combo) which will bring up the terminal window and you can log in.
4. You will need to now create mount point of the cdrom by typing in:
sudo mount /dev/cdrom /mnt

5. Change to the mnt point by doing typing:
cd /mnt

6. Now you need to start the install by typing:
sudo ./install

7. If you have done every thing correct you will see this screen:

3

8. You will need to press the next button however the mouse will not work so press the space bar. (press tab if the next is not highlighted)

9. I then saw this screen and I thought I will pick Upgrade and Next

4

10. You will then see this screen that will confirm the Upgrade by pressing Next.

5

11. After pressing Next I got this screen and I again pressed Next:

6

This will run through some updates and installs and after the process completes the you will see a Reboot button which will reboot you Ubuntu and then fixed all my issues on my display and all is working well.
Having this issue I thought I would document it for future reference and I hope this will help any one else having any issues with Parallels and Ubuntu on the Mac OSX.

True American “Hero’s”

America lets stop looking for our next sports “Hero” and instead realize that the Hero we seek is on our front line every day! Our Citizens and Military Personnel fighting for the freedom that gives me the right to develop this document.

After the issues of the past few weeks with the NFL and past incidents with sports stars showing us that they may not fit our “Hero Status”. Don’t get me wrong I am not perfect either. However I feel that we need to begin to set our standards for “Hero Status” to a new level. We have Military Men and Women risking their lives every minute for us to live the amazing life we have and enjoy. They are on the frontlines not asking, “Who the Hero is I am risking my life for”!! In their heart they know they are risking their lives for their loved ones and you and I.

My father was taken from this Earth at an early age from complications of Medical that is by no doubt from his military service. I have no regrets from this at all because he is and will always be the “Hero Status” in my heart. I know many great men and women that are continuing to serve in this Great Nation to fight for our Freedom. To them I say “Thank You” and they are and should be our new “Hero Status” we should all set our standard to.

Every one that knows me will know that I use my freedom daily, as I am “somewhat opinionated”. So for me I will begin to have a new standard for “Hero Status”. That new standard will be the Great Men and Women that allow me to have the Freedom to be “somewhat opinionated”.

To our entire new hero standard Men and Women that are risking their lives for America I again say, “Thank you for being our true Hero”.

I hope some day all your dreams come true.

Internet of Things / Machine 2 Machine Revolution

The Internet of Things (IOT) and Machine 2 Machine (M2M) communication is coming fast upon us and is creating a connected world with Services that will bring communication and automation to devices surrounding our every day lives. Development of Mongo DB, Express.js, Angular.js and Node.js are causing a development that can be replicated on Operating System Independent devices, with a very small footprint. JavaScript is coming on full speed in the world of development as a First Class Citizen that will allow for the ability to pass a function as a variable that will be executed later. Developers have been reluctant to embrace JavaScript because of the issues it has been blamed for in the Browser Wars. However with Node.js running on the Google V8 engine the JavaScript is a known, reproducible development platform that is very stable as well as fast. Many large corporations are making great strides to develop and/or embrace the IOT/M2M technology.

The connection of devices in our homes, vehicles and even on ourselves are beginning to evolve at an enormous rate. Development of devices like Raspberry Pi, Arduino and embedded devices are allowing people to develop and invent new products every day. The world as we know it will be very interesting in the next century when we all become connected to the Internet of Things.

With the push of IOT and M2M new technologies and emerging development are showing up at an alarming rate. This is not a complete list of the technologies by far but some I have been investigating to discover solutions to development I have been working on.

Some prominent and evolving technologies that are helping to drive the IOT/M2M revolution:

  • Katana – (OWIN implementation based on Microsoft Technology) -https://katanaproject.codeplex.com/documentation
  • AngularJS – Open Source web application maintained by Google
  • NodeJS – Open Source web application built on Google Chromes V8 JavaScript Engine
  • Wind River Linux – Open Source Linux OS wholly owned by Intel.

With the onset of the Internet of Things and the Machine 2 Machine push the development and capability of the Wireless Spectrum will need to have a huge impact on the speed and success of this technology. There are articles that are being produced that are showing the push of the Wireless Spectrum. Such as the following I have read lately:

http://entertainment.verizon.com/news/read/category/Technology/article/bgr-forget_5g_10gbps_wifi_is_coming_next_year-newscred

http://www.forbes.com/sites/timworstall/2013/03/23/the-beginning-of-the-death-of-wired-broadband/ 

This is of course a technology in its infancy that will be very interesting in the future revolution of our Connected World. This is a very exciting time to be in technology with the dramatic changes that are happening!!

Searching for an answer has become clear with http://www.pluralsight-training.net

Several years ago I had a question that I asked countless times with really no answer or solution. I wanted to know “What does it take to change from a mid level developer to a senior level developer?” I was really wanting to discover this answer because I felt I was still really not a senior level developer. And I wanted to take that step to begin my career as a senior level developer. I am still not sure I have made this step to become a senior level developer. However I am on a “Journey to become a better developer!” I do however feel that I may have the answer to the question “How do you move from a mid level developer to a senior level developer.”  The answer is “http://www.pluralsight-training.net!” I feel that this training is very solid and really great to developing your skill-set. Software development really is the continuous strive to improve both your skill set and understand of just writing and developing code. I have taken several training classes from many places but this is by far the best I have ever had. With that being said I have been working on an MVC3 project and have been trying to develop a webgrid filter that is a linkbutton functionality. With the help with pluralsight-training, Dan Wahlin, Scott Allen I have been working on a solution for a couple of days now. I have been watching Dan Wahlin and jQuery, Scott Allen and MVC3 to get this webfilter developed.

I am hoping this will help someone to be able to develop a solution for some one. I am not sure this is the best way to develop this solution for MVC3 so understand this my be the wrong way to implement this code. But here goes nothing…

I first created a controller with an [HttpGet] method that looks like this:

public ActionResult AllUsers()
{
//var u = new UsersDao();
var uc = Membership.GetAllUsers();
var lstUser = new List();
foreach (MembershipUser membershipUser in uc)
{
var u = new UsersDao
{
UserName = membershipUser.UserName,
Email = membershipUser.Email,
Comment = membershipUser.Comment,
CreationDate = membershipUser.CreationDate,
LastLoginDate = membershipUser.LastLoginDate,
LastActivityDate = membershipUser.LastActivityDate,
LastLockoutDate = membershipUser.LastLockoutDate,
IsApproved = membershipUser.IsApproved,
IsLockedOut = membershipUser.IsLockedOut,
IsOnline = membershipUser.IsOnline,

};
lstUser.Add(u);
}
return View(lstUser);
}

I then created a .cshtml page

@using ConcurrentDevelopment.MvcSubmitExtensions.Html
@using DocuTech.DataLayer
@model List
@{
ViewBag.Title = "AllUsers";
}

AllUsers

var btnA = $('#A')

@Html.ValidationSummary(true, "AddUser was successful. Press Next to set up the roles for the user.")
@using (Html.BeginForm())
{

@{
var grid = new WebGrid(Model, defaultSort: "UserName", rowsPerPage: 5);
}

Users Grid View

@{
var sList = new List
{
"All", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
"W", "X", "Y", "Z"
};
}

@foreach (string s in sList)
{
@Html.SubmitLink(s,new {id = s})
}

Filter Grid: @Html.TextBox("letter") @Html.SubmitLink("Submit")

@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("UserName"),
grid.Column("Email"),
grid.Column("Comment"),
grid.Column("CreationDate"),
grid.Column("LastLoginDate"),
grid.Column("LastActivityDate"),
grid.Column("LastLockoutDate"),
grid.Column("IsApproved"),
grid.Column("IsOnline"),
grid.Column("IsLockedOut")))

}

I used a program written by Concurrent Development Ltd. which was a development for creating a Linkbutton. This code can be found here:

http://www.concurrentdevelopment.co.uk/blog/index.php/2011/02/asp-net-mvc-linkbutton-with-htmlhelper-extensions/

I then created a JavaScript file that handled the jQuery functionality that would handle the click event on the link buttons that would place the value you click in the filter TextBox. I used the ID value to develop the filter.


/*
--------------------------------------------------
All Required functions for the AllUsers.cshtml Page.
--------------------------------------------------
*/
$(document).ready(function () {
$('#A').click(function () {
//alert($('#A').html());

});
});

/*
---------------------------------------------------
Link function click event
---------------------------------------------------
*/
$(function () {
$('#A').click(function () {
$('#letter').val($('#A').attr('id'));
event.preventDefault();

});
});

$(function () {
$('#B').click(function () {
$('#letter').val($('#B').attr('id'));
});
});

$(function () {
$('#S').click(function() {
$('#letter').val($('#S').attr('id'));
event.preventDefault();
});
});

$(function () {
$('#All').click(function () {
$('#letter').val("");
});
});

I finally created this [HttpPost] method like this:

[HttpPost]
public ActionResult AllUsers(string letter)
{
var uc = Membership.GetAllUsers();
var lstUser = (from MembershipUser membershipUser in uc
select new UsersDao
{
UserName = membershipUser.UserName,
Email = membershipUser.Email,
Comment = membershipUser.Comment,
CreationDate = membershipUser.CreationDate,
LastLoginDate = membershipUser.LastLoginDate,
LastActivityDate = membershipUser.LastActivityDate,
LastLockoutDate = membershipUser.LastLockoutDate,
IsApproved = membershipUser.IsApproved,
IsLockedOut = membershipUser.IsLockedOut,
IsOnline = membershipUser.IsOnline,
}).Where(lst => lst.UserName.StartsWith(letter,true,null)).ToList();

return View(lstUser);
}

I think that this was a good experience in answering the question, “How do you move from a mid level to senior level developer.” I feel the only way to continue to improve the software development world is to continue to program a lot and new stuff that you dont know. I think that is accomplished is by watching awesome video’s by pluralsight-training by great people like Dan Wahlin, Scott Allen and all the other authors.

Creating a Visual Web Part in Visual Studio for SharePoint 2010

I started classes at SetFocus (http://www.setfocus.com/) several months back to continue improving my skill set as a developer. I am always trying to discover new innovative ways to develop and understand new development strategies. I wanted to share this one with everyone since I thought it was somewhat difficult to implement at first but very simple and elaborate when complete.

I started with a empty SharePoint project and then added a Visual Web Part to the project. One thing you have to have is a SharePoint on the machine that you are using the Visual Studio to view and use the SharePoint project software. However SharePoint 2010 and Visual Studio 2010  has come along ways compared to previous versions. The functionality and ability has increased and the simplicity for developers like me (must be simple for little brains like mine) is really awesome.

The first thing you need to do is open Visual Studio 2010 on the machine that you have the SharePoint installed on.

Then select File\New Project ==> Then Choose Empty SharePoint Project.

I named my Empty SharePoint Project: CreateSolutionSiteWebPart. Then add to that project a Visual Web Part.

By selecting the Empty SharePoint Project and right clicking and selecting Add ==> New Item you will get a add new item list box. Select the Visual Web Part.

Once the Visual Web Part is added to the SharePoint Project you will see it is really nothing more then a .ascx user control. So you can add a div tag on the source view of the .ascx page. This is an example of the code I added to that form.

<div>

    <asp:Label ID="lblSiteName" Text="Site Name: " runat="server" Width="100" />
    <asp:TextBox ID="txtSiteName" runat="server" />

    <asp:Label ID="lblSiteDescription" Text="Site Description: " runat="server" />
    <asp:TextBox ID="txtSiteDescription" runat="server" />

    <asp:Label ID="lblIntendedURL" Text="Intended URL: " runat="server" />
    <asp:TextBox ID="txtIntendedURL" runat="server" />

    <asp:Label ID="lblSiteTemplate" Text="Site Template: " runat="server" />
    <asp:DropDownList ID="ddlSiteTemplate" runat="server"
        onselectedindexchanged="ddlSiteTemplate_SelectedIndexChanged">
    </asp:DropDownList>

    <asp:CheckBox ID="chkUniquePermissions" Text="Unique Permissions " runat="server" />

    <asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click"
        Text="Submit" />

</div>

Next I created the code behind that is required for the application. That looks like this.

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Collections;
using System.Collections.Generic;

namespace CreateSolutionSiteWebPart.CreateSolutionSiteWP
{

    public partial class CreateSolutionSiteUC : UserControl
    {
        SPWebTemplateCollection wt;

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (txtSiteName.Text == string.Empty && txtIntendedURL.Text == string.Empty)
                return;

            using (SPSite site = new SPSite(@"http://URLName:PortNumber/sites/Solutions"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    try
                    {

                        SPSecurity.RunWithElevatedPrivileges(() => web.Webs.Add(
                            txtIntendedURL.Text,
                            txtSiteName.Text,
                            txtSiteDescription.Text,
                            1033,
                            ddlSiteTemplate.SelectedValue,
                            chkUniquePermissions.Checked,
                            false));

                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "alert('Success');", true);

                    }
                    catch (Exception ex)
                    {
                        string error = ex.Message;
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "alert('" + error + "');", true);

                    }
                    finally
                    {
                        txtSiteName.Text = string.Empty;
                        txtSiteDescription.Text = string.Empty;
                        txtIntendedURL.Text = string.Empty;
                    }
                }
            }

        }

        protected override void OnLoad(EventArgs e)
        {

            EnsureChildControls();

            if (!IsPostBack)
            {
                using (SPSite site = new SPSite(@"http://URLName:PortNumber/sites/Solutions"))
                {
                    using (SPWeb web = site.RootWeb)
                    {
                        try
                        {
                            wt = web.GetAvailableWebTemplates(1033);
                            foreach (SPWebTemplate template in wt)
                            {
                                ddlSiteTemplate.Items.Add(new ListItem(template.Title, template.Name));
                            }
                            ddlSiteTemplate.DataBind();

                        }
                        catch (Exception ex)
                        {
                            string error = ex.Message;
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "alert('" + error + "');", true);
                        }
                    }
                }
            }

        }

    }
}

I removed the real URL and Port Number for security however all the other code is exact.

This code gives the ability to add a Visual Web Part to your SharePoint 2010 that will allow for a user with permissions to create a new site on the SharePoint Portal. This is really not that amazing but it does show the simplicity and power of what Visual Studio 2010 and SharePoint 2010 is capable of doing. I am very impressed with the functionality and collaboration that can be accomplished is a very small amount of time.

This is an example of the simple look and feel of the Visual Web Part on the web site.



    	
    	

Again thanks to Pluralsite video and the suggestion from Keith Brown of Pluralsite

After my last post Keith Brown had made the suggestion to:

“You might try factoring the test into a SPECIFICATION (google the specification pattern for more). Very simple refactoring but then you’ll be able to use your tests not just for validation, but also for selection and build-to-order objects. Glad you’re enjoying the library!”

Which I thought was a great suggestion, however I am not a real programmer… So I turned to Pluralsite to help me to become a real programmer. I am posting this but I am not sure of the validity of this yet.

Any constructive criticism is greatly appreciated.

I decided to try to re-factor my test into a specification pattern. Here is my attempt:

I first developed the Interface IValidation<TEntity>:

namespace BusinessRules
{
    public interface IValidation<TEntity>
    {
        bool IsSatisfiedBy(TEntity entity);
    }
}

I then created three concrete classes that implemented the above interface.

Those classes were the classes I thought would be my validation rules that needed to be checked which are:

using System;

namespace BusinessRules
{
    public class EmployeeNameIsValid : IValidation<Employee>
    {
        public bool IsSatisfiedBy(Employee employee)
        {
            if (employee != null)
            {
                if (!String.IsNullOrEmpty(employee.Name))
                {
                    return true;
                }
                return false;
            }
            return false;
        }
    }
}
namespace BusinessRules
{
    public class EmployeeIdIsValid : IValidation<Employee>
    {
        public bool IsSatisfiedBy(Employee employee)
        {
            if (employee != null)
            {
                if (employee.EmployeeID > 0)
                {
                    return true;
                }
                return false;
            }
            return false;
        }
    }
}
namespace BusinessRules
{
    public class EmployeeDepartmentIdIsValid : IValidation<Employee>
    {

        public bool IsSatisfiedBy(Employee employee)
        {
            if (employee != null)
            {
                if (employee.DepartmentID > 0)
                {
                    return true;
                }
                return false;
            }
            return false;
        }
    }
}

I then Thanks to Wikipedia discovered this explanation of the pattern.  http://en.wikipedia.org/wiki/Specification_pattern. So I used there example to develop a group of extension methods for testing the And, Or and Not validation chaining.

I created the chaining functionality by creating the And, Or and Not as an extension methods like this:

namespace BusinessRules
{
    public class AndValidation<TEntity> : IValidation<TEntity>
    {
        private IValidation<TEntity> _validation1;
        private IValidation<TEntity> _validation2;

        public AndValidation(IValidation<TEntity> v1, IValidation<TEntity> v2)
        {
             _validation1 = v1;
             _validation2 = v2;
        }

        public bool IsSatisfiedBy(TEntity entity)
        {
            return _validation1.IsSatisfiedBy(entity) && _validation2.IsSatisfiedBy(entity);
        }
    }
}
namespace BusinessRules
{
    public class OrValidation<TEntity> : IValidation<TEntity>
    {
        private IValidation<TEntity> _validation1;
        private IValidation<TEntity> _validation2;

        public OrValidation(IValidation<TEntity> v1, IValidation<TEntity> v2)
        {
            _validation1 = v1;
            _validation2 = v2;
        }

        public bool IsSatisfiedBy(TEntity entity)
        {
            return _validation1.IsSatisfiedBy(entity) || _validation2.IsSatisfiedBy(entity);
        }
    }
}
namespace BusinessRules
{
    public class NotValidation<TEntity> : IValidation<TEntity>
    {
        private IValidation<TEntity> _validation1;

        public NotValidation(IValidation<TEntity> v1)
        {
            _validation1 = v1;
        }

        public bool IsSatisfiedBy(TEntity entity)
        {
            return !_validation1.IsSatisfiedBy(entity);
        }
    }
}
namespace BusinessRules
{
    public static class ExtensionMethods
    {
        public static IValidation<TEntity> AndValidation<TEntity>(this IValidation<TEntity> v1, IValidation<TEntity> v2)
        {
            return new AndValidation<TEntity>(v1, v2);
        }

        public static IValidation<TEntity> OrValidation<TEntity>(this IValidation<TEntity> v1, IValidation<TEntity> v2)
        {
            return new OrValidation<TEntity>(v1, v2);
        }

        public static IValidation<TEntity> NotValidation<TEntity>(this IValidation<TEntity> v1)
        {
            return new NotValidation<TEntity>(v1);
        }
    }
}

From there is was trying to figure out how to put it all together to have the functionality of the previous post. I re-factored the program class that I originally developed to try to improve on that functionality like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessRules
{
    class Program
    {
        public static void Main(string[] args)
        {
            string error = EmployeeRules();
            Console.WriteLine(error);
            Console.ReadKey();
        }

        private static string EmployeeRules()
        {

            var employeeIdIsValid = new EmployeeIdIsValid();
            var employeeDepartmentIdIsValid = new EmployeeDepartmentIdIsValid();
            var employeeNameIsValid = new EmployeeNameIsValid();

            var rules = new List<Rule<Employee>>()
                            {

                                new Rule<Employee>()
                                    {
                                        Test = employeeNameIsValid.IsSatisfiedBy,
                                        Message = "name cannot be empty"
                                    },

                                new Rule<Employee>()
                                    {
                                        Test = employeeIdIsValid.IsSatisfiedBy,
                                        Message = "must have an employeeID"
                                    },

                                new Rule<Employee>()
                                    {
                                        Test = employeeDepartmentIdIsValid.IsSatisfiedBy,
                                        Message = "must have an assigned department"
                                    }

                            };

            StringBuilder stringBuilder = new StringBuilder();
            foreach (var employee in Employee.GetEmployee())
            {
                if (employee != null)
                {
                    var test = employeeNameIsValid.AndValidation(employeeIdIsValid).AndValidation(employeeDepartmentIdIsValid);
                    var isValid = test.IsSatisfiedBy(employee);

                    if (!isValid)
                    {
                        var failedRules = rules.Where(r => r.Test(employee) == false);

                        string errorMessage =
                            failedRules.Aggregate(new StringBuilder(),
                                                  (sb, r) => sb.AppendLine(r.Message),
                                                  sb => sb.ToString());
                        return stringBuilder.ToString() + Environment.NewLine + String.Format("Error: {0} is Invalid \r\n Employee {1}: {2} ", employee.Name, employee.Name, errorMessage);
                    }
                }

                if (employee != null) stringBuilder.Append(String.Format("Employee: {0} Is Valid \r\n", employee.Name));
            }
            return stringBuilder.ToString();
        }

    }
}

Again I am not sure of the validation of this code being a true “specification pattern”.

I want to thank Keith Brown for the suggestion and Wikipedia for the great example of the code to help me try to find the way to being a good developer!!

BusinessRules using LINQ

After watching the Pluralsite video on LINQ from Scott Allen. I wanted to implement a example that would help me understand some of the functionality that I saw. I was really impressed with the implementation of the Business Rules that Scott did with the LINQ aggregate function. So I developed a small console application that used some of this technology. I first developed a small Rules class like the video shows:

using System;

namespace BusinessRules
{
    public class Rule<T>
    {
        public Func<T, bool> Test { get; set; }
        public string Message { get; set; }
    }
}

This is a small generic class that exposes two properties. This first property is a Func<T, TResult> delegate. Which MSDN states a Func<T, TResult>: Encapsulates a method that has one parameter and returns a value of the type specified by the TResult parameter. And the second property is the message that will be used for the validation.

I then created a small employee class that will be my data to test in the validation rules.

This is very simple class like this:

using System.Collections.Generic;
using System.Linq;

namespace BusinessRules
{
    public class Employee
    {
        #region Properties

        public int EmployeeID { get; set; }
        public string Name { get; set; }
        public int DepartmentID { get; set; }

        #endregion

        #region Constructor
        public Employee()
        {
            //Used for AutoImplementation
        }

        public static List<Employee> GetEmployee()
        {
           var employee =  new List<Employee>
                                {
                                    new Employee() { EmployeeID = 1, Name = "Allan", DepartmentID = 1 },
                                    new Employee() { EmployeeID = 2, Name = "Quincy", DepartmentID = 2},
                                    new Employee() { EmployeeID = 3, Name = "Bella", DepartmentID = 2},
                                    new Employee() { EmployeeID = 0, Name = "Rylee", DepartmentID = 3}
                                }.ToList();

            return employee;

        }
        #endregion

        #region Methods()
        public override string ToString()
        {
            return string.Format("Employee: EmployeeID = {0}, Name = {1}, DepartmentID = {2}", EmployeeID, Name,
                                 DepartmentID);
        }
        #endregion

    }
}

Finally I created a small EmployeeRules() method that would be used to validate the business rules.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessRules
{
    class Program
    {
        public static void Main(string[] args)
        {
            string error = EmployeeRules();
            Console.WriteLine(error);
            Console.ReadKey();
        }

        private static string EmployeeRules()
        {
            var rules = new List<Rule<Employee>>()
                            {
                                new Rule<Employee>(){ Test = e => !String.IsNullOrEmpty(e.Name),
                                    Message = "name cannot be empty"},

                                new Rule<Employee>() {Test = e => e.DepartmentID > 0,
                                    Message = "must have an assigned department"},

                                new Rule<Employee>() {Test = e => e.EmployeeID > 0,
                                    Message = "must have an employeeID"}
                            };

            StringBuilder stringBuilder = new StringBuilder();
            foreach (var employee in Employee.GetEmployee())
            {
                if (employee != null)
                {
                    bool isValid = rules.All(r => r.Test(employee));

                    if (!isValid)
                    {
                        var failedRules = rules.Where(r => r.Test(employee) == false);

                        string errorMessage =
                            failedRules.Aggregate(new StringBuilder(),
                                                  (sb, r) => sb.AppendLine(r.Message),
                                                  sb => sb.ToString());
                        return stringBuilder.ToString() + Environment.NewLine + String.Format("Error: {0} is Invalid \r\n Employee {1}: {2} ", employee.Name, employee.Name, errorMessage);
                    }
                }

                stringBuilder.Append(String.Format("Employee: {0} Is Valid \r\n", employee.Name));
                //return stringBuilder.ToString();
            }
            return stringBuilder.ToString();
        }

    }
}

This functionality seems to be very simple and straight forward to even me and I am not very smart. I was impressed by the simplicity that Scott Allen showed with his video and yet still showed the true power of LINQ in one example.

Thanks to Scott Allen and http://www.pluralsight-training.net for the examples and functionality.

NetTryx CRM is up and running!

NetTryx LLC. has now implemented a solution for a Customer Relations Management Software solution for Evaluation. I am really excited to announce that it is the SplendidCRM Community Edition. I am going to be developing some additional functionality as the weeks progress. This is a very cool ASP.net open source solution to SugarCRM. I may try to get that up and running for an evaluation soon. I have found a job in Omaha at Securities America. I am very excited about this opportunity.

I am in Gretna Nebraska

I am officially in Gretna Nebraska… Looking hard for a position in ASP.net as a developer. I am going to look at a house to rent today at 6:00 pm. I am hoping to get completely moved soon so I get to working on training videos for this Blog. Please keep checking for them to be released soon.

%d bloggers like this: