Alfresco 4: Restoring From a Cold Backup (Windows)

No Comments »

For the sake of this article, assume Alfresco 4 has been installed to C:\Alfresco (the application directory) and that the dir.root directory is C:\Alfresco\alf_data. The name of the database being used is simply “alfresco“.

This article assumes you have been following the Alfresco cold backup procedure documented in the following Alfresco Wiki page. Note that it is essential that you are keeping a dump of the Postgresql database along with a copy of the dir.root data directory from the point in time of the database dump.

http://wiki.alfresco.com/wiki/Backup_and_Restore

There are a couple of changes to the restoration procedure on that Wiki page when it comes to Alfresco 4. This is mostly down to the fact that it uses the Postgresql database platform. You may have noticed that the database files are stored in ‘dir.root/postgresql’  directory which complicates things a little? OK, the restoration procedure is as follows:

1.  Stop the Alfresco services

  • This is easily done through the Start menu (START –> Programs –> Alfresco Community –> Service –> Stop).
  • You can also stop both services using the “services.msc” snapin (alfrescoPostgreSQL and alfrescoTomcat) .

2.  Start the Postgresql Database On It’s Own

  • You need to start the Postgresql database platform on its own. This is harder to do than you might think and running the ‘postgresql/scripts/servicerun.bat’ file from the application directory does nothing.
  • Open a command prompt (START –> Run –> cmd)
  • Change in to the Postgresql/bin folder in the application directory (e.g. cd C:\Alfresco\postgresql\bin).
  • Issue the command: pg_ctl start -D [Database Data] in this case pg_ctl start -D C:\Alfresco\alf_data\postgresql to start the Postgresql database server on its own.

3.  Drop the existing database

  • You need to drop the existing copy of the database. You can do so by issuing the following command at the command prompt:  dropdb -U [DBUser] [DBName]  in this case dropdb -U alfresco alfresco

4.  Restore the Database

  • Create and restore the Postgresql database at the same time by issuing the following command at the command prompt:  pg_restore -U postgres -C -d postgres [Path Dump File] in this case pg_restore -U postgres -C -d postgres C:\backup\19-01-2012\alfresco.bak.
  • Don’t worry about the fact that the database (-d) is postgres. This just needs to be a pre-existing database name that exists in the cluster. When you are restoring using the -C parameter, the data is restore to the database name that exists in the dump file (http://www.postgresql.org/docs/8.3/static/app-pgrestore.html).
  • The user needs to have administrative rights to create databases. That is why the postgres account is being used (-U postgres). You will need to know the password you set on this account.

5.  Stop the Postgresql Database Again

  • Issue the command: pg_ctl stop -D [Database Data] in this case pg_ctl stop -D C:\Alfresco\alf_data\postgresql to stop the Postgresql database server.

6.  Restore the Data in dir.root

  • Finally, you need to restore the data in the dir.root directory. While the Wiki article says to delete everything in dir.root, you must in fact leave the ‘postgresql’ directory for Alfresco 4. This is because it contains the database files which you just restored.
  • As per the image below, delete the highlighted folders and leave the ‘postgresql’ directory. These are the exact same folders that you should restore from your backup.
  • Just to emphasise the point, do not overwrite the dir.root/postgresql directory with the one from your backup. Just restore the other folders instead.
Alfresco Restore Folders

Fig 1: Folders to delete / retore.

 7.  Start the Alfresco Services

  • As per before, just restart the Alfresco services through the Start menu.

Alfresco: Change Company Home Name

No Comments »

To change the “Company Home” name in Alfresco Explorer you must perform the following configuration:

  • Stop the Alfresco service.
  • Find the appropriate webclient properties file for your language. For example, to change this setting for English (US) you would open and edit the following file in a text editor: 

    tomcat/webapps/alfresco/WEB-INF/classes/alfresco/messages/webclient_en_US.properties”

  • You will see this file containts a list of key/value pairs. Do a search for “Company home” and edit the value accordingly.
  • Restart Alfresco.

Enable Versioning For All Documents In Alfresco 4

No Comments »

Version of Alfresco used:  4.0b

The following steps show how to enable version control for all documents in Alfresco 4. In a nutshell, you are essentially adding the “Versioning” aspect as a mandatory part of the cm:content property (of which all content is derived).

Step 1:  Edit “contentModel.xml” File

  • Open the “contentModel.xml” configuration file in a text editor. This is found in “tomcat/webapps/alfresco/WEB-INF/classes/alfresco/model”.
  • Note that in previous versions of Alfresco this file was called “content.xml“.

Step 2:  Add in the Versionable Aspect

  • Find the “cm:content” type. This starts on line 83. In Windows, do CTRL+F and search for “cm:content”.
  • After the closing “</properties>” tag, add in the following text:

<mandatory-aspects>
    <aspect>cm:versionable</aspect>
</mandatory-aspects>

  • Restart the Alfresco service.

To verify this has worked, add a new document to the system and check its properties. Its “Version History” block at the bottom of the properties screen should already be enabled.


Espionage Development Video 02

No Comments »

Since the first video I have implemented more goal behaviours (specifically Fight Opponent and Escape Complex) for the AI. Once an agent has the four items it will make its was to the exit and complete the game. It can get the items from the containers or from another agent if he beats it when fighting.

This short video demonstrated a four room complex with two AI agents.

My next objective is to implement the player object and HUD so that the game can actually be played and interacted with rather than watching the AI entites fight it out. I also intend to tweak the goal evaluation/selection behaviour of the AI entities.


Working With Fonts In Unity3D

2 Comments »

OK, so you’re sick of the default font in Unity3D and want to use something different in your game? How do you go about using fonts in a script with C#? How do you change the font colour? How do you make it bold and change the font size? I recently came across this issue when trying to output scrolling text above the head of my game’s protagonist.

I was hoping for a simple way of creating a font, something like:

new Font(“Arial”, 16, FontStyle.Bold, Color.Red);

It turned out to be a surprisingly convoluted process involving importing a True-Type Font file (*.ttf) in to the editor and loading it as a resource before assigning it to a GUIText component.

1. Importing a True Type Font in to Unity3D

This is the easy bit. Simply create a sub-folder in “Resources” for storing your fonts (i.e. “Resources/Fonts”). You then drag a TTF file from your computer in to this folder and Unity will automatically import it for you. You can get free TTF files online and also from your PC (e.g. C:\Windows\Fonts).

Say you click and drag the “Broadway.ttf” file in to the “Fonts” folder you created in Unity. Once you have a font file imported in to Unity you can load it in a C# script as follows:

Font BroadwayFont = (Font)Resources.Load("Fonts/Broadway");

2. Using the Font with GameObject and GUIText

The first thing to realise here is that although you can now associate your font with a GUIText object, you must associate the GUIText object with a GameObject (or derived subclass). This makes sense when you think about it. Everything in Unity is derived from a GameObject. A GameObject contains the transformation information etc. GUIText is actually a component of GameObject and is instantiated as in the following code:

// Create an instance of GameObject for the text
GameObject TextObject = new GameObject();
 
// Add a GUIText component to the above GameObject (cast in to GUIText
// reference)
GUIText GText = (GUIText)TextObject.AddComponent(typeof(GUIText));

You can then associate the font and set other parameters of the GUIText accordingly:

// Set text, font and default properties of the text item
GText.text = "Test Text!";
GText.font = BroadwayFont;
GText.material.color = Color.white;
GText.transform.position = Vector3.zero;

3. Changing the Font Size, Color and Style

Assuming your GUIText component is set up as above, you can then change the font size, color and style (i.e. bold, italic or both) through a C# script too. It is simply a case of changing the properties in the GUIText component:

// Change the font size to 48 points
GText.fontSize = 48;
 
// Make the font bold
GText.fontStyle = FontStyle.Bold;
 
// Change the font color to Green
GText.material.color = Color.Green;

4. Setting the Position of the Text

Finally the position of the text would usually be set in screen space (i.e. on the X and Y axis). Unity uses normalised screen space coordinates where the top-left is (0,0) and the bottom-right is (1,1). Say your screen resolution is 800×600 and you want to put some text starting at the centre of the screen (i.e. at position (400,300))? The positions would be calculated as follows:

XPos = 400.0f / Screen.width;  // 0.5f
YPos = 300.0f / Screen.height; // Also 0.5f

And you set the position as follows:

GText.transform.position = new Vector3(XPos, YPos, 0.0f);

5. Calculating the Text Width and Height

How can you calculate the text width and height using your font? GUIStyle comes to the rescue here with it’s CalcSize() method. You have to instantiate a GUIStyle object, set the appropriate Font, Size and FontStyle parameters and then call CalcSize() as per below:

GUIStyle GStyle = new GUIStyle();
 
// Set the relevant style parameters for calculating size
GStyle.font = BroadwayFont;
GStyle.fontSize = GText.fontSize;
GStyle.fontStyle = GText.fontStyle;
 
// Calculate the text width and height
float TextWidth = GStyle.CalcSize(new GUIContent(GText.text)).x;
float TextHeight = GStyle.CalcSize(new GUIContent(GText.text)).y;

Linked below is a class I wrote called CTextItem. It is a wrapper class around a GameObject with GUIText component and has methods for adjusting text, color, font size, style and position. The position can be set in screen space or world space (for example if you wish to make text appear above an object’s head in your game world). It assumes you know how it import TTF files in to your project and load a font resource as per above. I hope you find it useful.

CTextItem