Refactored the Kernel registration fluent interface to be more readable, better suppo...
[castle.git] / Experiments / AnakiaNet / Anakia / SimpleHelper.cs
blob3b66a88c81cc69a9006a15e4c196ef0c716ec2b5
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Anakia
17 using System;
18 using System.Collections;
19 using System.IO;
20 using System.Globalization;
22 public class SimpleHelper
24 public String FileSizeInKBytes(String basePath, String file)
26 FileInfo info = new FileInfo(Path.Combine(basePath, file));
28 if (info.Exists)
30 return String.Format(CultureInfo.InvariantCulture,"{0:#.##}", info.Length / 1024f).ToString();
33 throw new Exception("File " + info.FullName + " was not found");
36 public String RemoveOffset(String offset, String path)
38 return path.Substring(offset.Length);
41 public String Relativize(String offset, String path, String page)
43 try
45 if (offset.Length >= path.Length)
47 return String.Format("./{0}", page);
49 else
51 String newPath = path.Substring(offset.Length);
52 return String.Format(".{0}/{1}", newPath, page);
55 catch(Exception)
57 throw;
61 public String GetShortTypeName(String typeName)
63 String[] parts = typeName.Split('.');
65 return parts[parts.Length - 1];
68 public int GetLevels(String path)
70 return path.Split('/').Length - 1;
73 public Stack CreateStack()
75 return new Stack();
78 public int Push(Stack stack)
80 stack.Push(String.Empty);
81 return stack.Count;
84 public int Pop(Stack stack)
86 stack.Pop();
87 return stack.Count;