Sunday, February 10, 2013

Asus G75VW Boot Recovery. Formatting is not an option!!!!!

Hey guys,
I just got a new Asus G75VW with Windows 7 Ultimate loaded (in place of Home Premium). I do not have an Ultimate disk nor the Home Premium (except for the CD key in the bottom of the laptop). The current Windows was booting by EFI so this was going to be a special solution.

I completely f'd up my Asus G75VW laptop by messing with EasyBCD. In detail, I messed up by using EasyBCD 1.6, since adding a new entry has the ability to choose Generic x86 as the boot type or whatever. I needed this option because lots of hackintosh tutorials used this. Turns out, EasyBCD 1.6 is not supported by Win7. I loaded some defaults with EasyBCD, saved it, and restarted my computer. NOW YOU CAN POUND ME INTO A PANCAKE!!!!!

So when I boot, windows boot manager loads into an error screen that says something is wrong with the BCD. The location was either of the error was either (forgot which displayed first):

/EFI/Microsoft/Boot/BCD

or

/Boot/BCD


So, what are my options? A. Fix the boot for Windows Ultimate. B. Format the drive with Windows Home Premium. I opted for A: So what worked and what didn't?

- When doing a search, I found a lot of people suggest using the Repair disk in the Windows Install DVD. This DID NOT WORK....yet. Something about being EFI bootable will show an incompatibility error no matter which Windows disk I used.

Then I downloaded the Hiren Boot CD 15.2!!!!

- Then I used DiskGenius, which was part of the CD. This may work for some, but it totally f'd up my BCD. Refer to here:

http://www.sevenforums.com/installation-setup/228504-missing-boot-manager-4.html

Using it pretty much just made the whole drive unallocated, although the partitions were still there, but lost.

- Then I used Partition Recovery Wizard, another utility in the CD. I basically used this to find partitions and repair it. It successfully did.

- Now when I restarted the computer, it would say BootMgt is missing.

- So I popped in a Windows 7 disk. At the installation screen, I pressed shift+f10 to go to the command line and I ran all the bootrec commands. It successfully did.This also assigned a drive to the BCD. So you when you run bcdedit in command line, you see "partition=c:" instead of {unknown}

- I believe it still didn't boot then. So now I booted up the Windows 7 Ultimate DVD and hit the repair disk option. Finally!!! It passed the incompatibility error. Now all I did was choose the option to fire up the Startup Recovery.

- When I booted, now there are 2 options for this drive. To boot off the Windows Boot Manager or the drive itself. The boot manager, I believe, boots off the EFI partition. This will obviously create an error since I did not fix this. So if I boot off the hard drive itself, it will FINALLY LOAD INTO WINDOWS! YA!

Conclusion:

I know this was not a clean fix, since I converted from EFI to MBR boot (or is it GPT or MBR boot?). Anyways, I am not a claimed IT, hardware expert either. But I'm just glad this thing is finally working.

Tuesday, December 4, 2012

[.NET] I don't have time for this. POCO Generator, Function Imports, Returning None

1. Used POCO Generator to create Function Imports
2. Had a Function that returns none
3. POCO Generator does not generate Functions that return none.

WUDDDAAAPPPAAAACCCKKERRRR

Alright, this was such a headache, but thanks to Matt Johnson in this stack overflow link:
http://stackoverflow.com/questions/3797248/update-function-import-not-displaying-in-context-file

...problem was solved.

Here is the Function Import region of the .tt file:


region.Begin("Function Imports");

        foreach (EdmFunction edmFunction in container.FunctionImports)
        {
            var parameters = FunctionImportParameter.Create(edmFunction.Parameters, code, ef);
            string paramList = String.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray());
            string returnTypeElement = edmFunction.ReturnParameter == null
? null : code.Escape(ef.GetElementType(edmFunction.ReturnParameter.TypeUsage));

#>
    <#=Accessibility.ForMethod(edmFunction)#> <#= returnTypeElement == null ? "int" : ("ObjectResult<" + returnTypeElement + ">") #>  <#=code.Escape(edmFunction)#>(<#=paramList#>)
    {
<#
            foreach (var parameter in parameters)
            {
                if (!parameter.NeedsLocalVariable)
                {
                    continue;
                }
#>

        ObjectParameter <#=parameter.LocalVariableName#>;

        if (<#=parameter.IsNullableOfT ? parameter.FunctionParameterName + ".HasValue" : parameter.FunctionParameterName + " != null"#>)
        {
            <#=parameter.LocalVariableName#> = new ObjectParameter("<#=parameter.EsqlParameterName#>", <#=parameter.FunctionParameterName#>);
        }
        else
        {
            <#=parameter.LocalVariableName#> = new ObjectParameter("<#=parameter.EsqlParameterName#>", typeof(<#=parameter.RawClrTypeName#>));
        }
<#
            }
#>
        return base.ExecuteFunction<#= returnTypeElement == null ? "" : ("<" + returnTypeElement + ">")#>("<#=edmFunction.Name#>"<#=code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()))#>);
    }
<#
        }

        region.End();



Monday, November 19, 2012

[PHP/MySQL] Amazon EC2, Elastic Beanstalk, RDS setup

Basic setup of using these three services in.....haaaarrrmony. I'm using WinXP.

Index:
1. Setup EC2 instance
2. Setup Elastic Beanstalk with GIT (Tested with PHP projects)
3. Setup RDS to be used with MySQL Workbench

1. EC2 Instance
   Just follow the instructions and CREATE and DOWNLOAD your key/pair. Creating your instance is the only time you can assign a key/pair to it, let alone download it. Take note of the security group you are using for it. Also, go find your internet IP and add it to the selected security group.

2. Elastic Beanstalk
   This is basically your web host that you deploy to. Download GIT and the CLI Package (http://aws.amazon.com/code/6752709412171743). Find GIT on Google and the CLI Package in the Elastic Beanstalk documentation. Install GIT and run the CLI Package according to the instructions in the archive. 

Configuring Beanstalk for file uploading/deploying:
Go to your working folder in command line.
First, type eb init
Follow the instructions and you can find the your credentials here: https://aws-portal.amazon.com/gp/aws/securityCredentials
After you're done, enter the command: eb start

Now, you should be able to run git commands. Usually, this is the sequence I use:
1. git add .    (adds all files/folders/sub-folders)
2. git commit -m "<your message>"
3. git aws.push

3. RDS
1. Choose/create a database instance you would like to work with.
2. Go to the DB Security Groups section.
3. Add a new connection type of EC2 Security Group and choose the same one used in your EC2 Instance. You may also want to add a new CIDR/IP address using an IP finder.
-- MySQL Workbench
4. Setup a New Server Instance
5. Select Remote Host and input the address of your EC2 instance.
6. Select SSH type of connection
7. For SSH user, put ec2-user if using Amazon or ubuntu if using Linux
8. SSH password is not required.
9. Use the key/pair generated earlier
10. Enter the rest with the DB Instance info.

After all that, you should be good to go. Cheers



Monday, October 29, 2012

[.NET] Updating Detached Objects in Entity Framework

Here's the scenario.

An object is being passed like this


  1. Object gets pull from the database through the Business Logic layer and WCF, as well as getting converted into a detached object.
  2. Values are changed in the Business Logic Layer.
  3. Object gets passed back into the WCF for an update.
I've seen several ways of how a detached object could be updated. Previously in the data access layer, I was retrieving the original object from the database and getting the object again by the original's entity key. Then updated the values and applied the changes. It looks something like this:

using (MyDBContext db = new MyDBContext ())
                {

                    My_Object obj =  db.GetObjectByKey(GetObjectFromDatabaseByID(id).EntityKey) as My_Object;

                    obj.Name = <newName>;

                    if (obj != null)
                    {
                        db.ApplyCurrentValues("My_Object_Table_Name", obj);
                        db.SaveChanges();
                        return "Succesfully Updated!";
                    }
                    else
                        return "Record Does Not Exist.";
                }

So one thing, the method that surrounds this code is only passing an 'id'. There is no objects coming in. Therefore, the object would have to be retrieved again to use its Entity Key to grab the object again, except with an attached state. Another parameter that was passed into the method was the newName. So this newName variable has to be assigned to the new attached object. Only then, we can apply and save the changes. Yes, this is a crude way of doing it, but it works.

Recently, I found a new way of handling an update. So what if we pass in a whole object? Will we have to consider the change of all members of the object? What if the object has 50 members? Well, coding will definitely suck. This method was posted on MSDN, so I'm just going to take it as a valid strategy, and it goes something like this:

 EntityKey key = default(EntityKey);
                object originalObj = null;

                using (MESDataModel.e_MESEntities db = new MESDataModel.e_MESEntities())
                {
                    key = db.CreateEntityKey("KIT_Part", ct);

                    if (db.TryGetObjectByKey(key, out originalObj))
                    {
                        db.ApplyCurrentValues(key.EntitySetName, ct);
                        db.SaveChanges();
                        return "Succesfully Updated!";
                    }
                    else
                    {

                        return "Record Does Not Exist.";
                    }

                }

In this situation, we are creating an entity key out of the passed in object. If it already has a key, then it will return the original instead of creating a new one. Similar to the first method, we are using the key to retrieve an attached object. At this point, the attached object and the passed in object now has the same keys. Call ApplyCurrentValues and the data from the passed in object will write to the attached object within context. This is pretty much MSDN's definition of what ApplyCurrentValues does. Save changes and everything should work. Hope this kind of helps.

Hmm, Okay, what about using DetectChanges?
This method seems to be good, if you are pulling straight from the database, writing new values, and saving it back to the database. No detached objects involved here. If there is a way to use this method with cross platform in mind (Android, iPhone), please let me know.

Saturday, October 6, 2012

[SQL/MySQL/.NET] Setting databases for .NET usage

After setting up WCF services and having my android devices consuming it, I wanted my WCF to be the layer that communicates to a database resource. At first, I had a hard time with getting started with SQL Server, so I went with MySQL instead.

NOTE: In your IIS, make sure the ASP.NET 4.0 Application Pool "Identity" is set to Local System. This is the reason why SQL Server wouldn't go so smooth at first, but I will discuss details later.

MySQL setup:

1. Download MySQL server installer, MySQL OBDC connector, and MySQL Net connector. Optionally, download the Workbench, which provides a GUI solution for handling SQL functions. If you're lame like me, you would use this tool.

2. Set up your tables using Workbench or commandline.

3. In Visual Studio, add a new ADO.NET Entity Data Model and point to your MySQL Server when prompted. If you don't know the server name or IP Addy, you can always go to the Workbench and see the properties there. Mine was 127.0.0.1. Follow through with creating the .edmx file.

4. Now you should see the newly created entities right in front of you. The name of the object is exactly what the header of the entity is. So you can instantiate it like:

User objUser = new User();

Of course, we don't want to instantiate like this, but rather grab the info from the database and create the object then. We will use LINQ to do so.

 Now look for Entity Container Name in the properties of your .edmx file. This is the object you use to connect to the database. So lets just put 2 and 2 together with the entity object included:

MyDBEntities db = new MyDBEntities();
List<User> users = ( from p in db.Users select p ).ToList();

This should select all users from a "Users" table and return it as a list of User objects.

Run the WCF Test Client and test if it works.

SQL Server setup:

Okay, if you installed SQL Server 2008, I believe that it should've created an instance of SQLEXPRESS. So we will just go with this default setup, although, you might have set up another instance, you'll just have to remember the server name for that one.

So by default, your instance of SQLEXPRESS should be your <computername>\SQLEXPRESS. (ex. KETTLEPOT-PC\SQLEXPRESS).

Create tables in SQL Management Studio (Free) by using the server name.

From now on, follow step 3 from the MySQL setup section to configure everything in VS2010.

 Now, if you're getting the "underlying provider" error when you run the WCF Test Client and invoke your method, check out the "NOTE" at the beginning of this post.

Hope that helps!!!!


[Andoird/.NET] Android and WCF template

I've been working a lot with setting up WCF locally. Now it is time to do the true test and connect my android with the sucka!

To set up the WCF, just follow this post:

Setting Up WCF in Virtual Directories

All you need is Android and Eclipse set up. Also, get the KSoap plug-in and add it to your library. Now just add this to your code:


 private static String SERVICE_URI = "http://192.168.1.2/WcfService1/Service1.svc";

 private static final String METHOD_NAME = "GetData";

 private static final String NAMESPACE = "http://tempuri.org/";

 private static final String URL = "http://192.168.1.2/WCFService1/Service1.svc";

 private static final String SOAP_ACTION = "http://tempuri.org/IService1/GetData";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

request.addProperty("value","3");
            

 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

 envelope.dotNet = true;
 envelope.setOutputSoapObject(request);
           
 HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
 androidHttpTransport.call(SOAP_ACTION,envelope);
 SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
           
 String resultData = result.toString();


EDIT: Btw, the request.addProperty method is a parameter of your method. And if you don't know your namespace, look at the wsdl of your service. This was done to target an Android 2.2 device. If you noticed, I was using the template VS2010 gives when you create a new Web Service.

Also, I tried using HttpResponse and HttpEntity, but I got no response when I tried to do something like http://192.168.1.2/WCFService/Service1.svc/GetData/0. I believe it has something to do with the binding. By default, WCF uses WSHttpBinding I think. I tried changing to BasicHttpBinding, but the configuration had issues finding MetaData. That is it for now.

Friday, October 5, 2012

[.NET] Setting up WCF in Virtual Directories of IIS

Alright, this one was an adventure for me. So this info will be here for the next time I need to set up WCF in a virtual directory. This tutorial will start from the beginning, which is installing IIS. This is assumed that Visual Studio 2010 is already installed. So let's get started with the list:

1. Install IIS through Programs and Features. If you're feeling lazy, just try to install as much of the IIS options you can check. Otherwise, you just need ASP.NET under World Wide Web Services. This will auto-check dependencies as well. And IIS Metabase under IIS 6 Management Compatibilty. Also, you will need to go under the Microsoft .NET Framework 3.5.1 section, which is separated from the IIS section btw, and check both boxes under that. They should have the description with Windows Communication Foundation within it.

2. Make a new wcf service project or open an existing one. Go to it's project properties. Under the Web tab, select he use local IIS option. When you save, it will create the virtual directory for you. There are other ways to deal with the virtual directory like publishing, or adding it directory in the IIS manager. It is up to you.

If you get an error when you try to save the project properties, check if you have all the IIS components installed. VS2010 does a good job telling you what you need anyways.

Hmmm, that seemed to be a short list. But here are some problems + fixes that you may have to encounter.

Errors you may have encountered:

1. "Something about having a duplicate handler in your web.config". What happened here was that I tried to add a handler myself before installing the WCF stuff under Microsoft .NET Framework 3.5.1 section. Therefore, IIS couldn't even populate it's integrated handlers, let alone, let me add any more handlers. So I had to edit the web.config manually by copying it outside it's original directory, removing the handler, and then moving it back into the original directory. It will not let you edit it if you open it within the original directory.

2. 404.17: The requested content appears to be script and will not be served by the static file handler.

Check if you installed all the necessary components for IIS and WCF. You may have to run aspnet_regiis.exe -i under the command line if you have ASP.NET 4.0. After doing this, WCF should run smooth and you should be able to see the .svc file in your browser as intended.  This solution may be different if you are running an older version of ASP.NET.

3. Make sure  the application pools between the website and your virtual directory are ASP.NET 4.0. I haven't thoroughly tested this one out yet. I changed the website to ASP.NET anyways just to be safe. 

Local Host Stuff 

 If you tried to access your IIS or .svc from another computer, you may find that it will not connect by timing out or what not. This may be caused by the firewall. If you are using Windows Firewall, find and enable the inbound rule for World Wide Web Services. The port should be 80.

DNS

When on another computer, you may not want to type in 192.168.1.23 just to get to connect to your service. You may want to type in http://MySite instead. This will be controlled in a DNS Server. The DNS settings should be located in your router firmware.