In the previous article, "Using C # to develop smartphone software: Push Box (v)", I introduced the improved Common/findpath.cs source program files. In this article, the Common/pub.cs source program file is introduced.
The following is a reference fragment:
1 using System;
2 using System.Drawing;
3 using System.Text;
4 using System.IO;
5 using System.Reflection;
6
7 namespace Skyiv.Ben.PushBox.Common
8 {
9///
10///Common fields and methods
11///
Static Class Pub
13 {
Public const int OverY = 4; The number of pixels allowed to exceed in the direction of the screen (Y)
Public const int defaultmaxlevelsize = 32; Default maximum off size (width and height)
Public const int defaultstepdelay = 100; Default Move time interval (ms)
Public const int defaultreplaydelay = 300; Default playback time interval (milliseconds)
Public const int maxdelay = 1000; Maximum allowable time interval (ms)
Public readonly static string configfilename = Path.Combine (basedirectory, "pushbox.cfg"); Configuration file full path name
public readonly static Encoding Encode = Encoding.GetEncoding ("GB2312"); Windows Mobile 6.0 does not support GB18030
static string BaseDirectory {get {return path.getdirectoryname (pub.codebases);}}//The directory in which this program is located
22
static Assembly Assembly {get {return assembly.getexecutingassembly ();}
static AssemblyName AssemblyName {get {return Pub.Assembly.GetName ();}}
public static version version {get {return Pub.AssemblyName.Version}}//This program versions
public static string Textdirectory {get {return Path.Combine (basedirectory, "text");}
public static string DataDirectory {get {return Path.Combine (basedirectory, "Data");}
public static string Stepsdirectory {get {return Path.Combine (basedirectory, "Steps");}
Public Const string textextname = ". Bxa"; Text file name extension
Public Const string dataextname = ". BxB"; Data file name extension
Public Const string stepsextname = ". Bxs"; Customs procedure file name extension
32
33///
34///The full path name of this program
35///
public static string codebases
37 {
39 {
string codeBase = Pub.AssemblyName.CodeBase;
a string uri = "file:///";
(Codebase.startswith (URI)) CodeBase = Codebase.substring (URI. Length);
return codeBase;
44}
45}
46
47///
48///gives a display string of the specified dimensions, in the format: wide x High
49///
50///The specified size
51///The display string for the specified dimension
public static string ToString (size size)
53 {
The return size. Width + "x" + size. Height;
55}
56
57///
58///Converts the steps to a string
59///
60///Steps
61///converted string
public static string ToString (step[] steps)
63 {
StringBuilder sb = new StringBuilder ();
foreach (step step in steps) sb. Append ((char) step);
char[] array = sb. ToString (). ToCharArray ();
Array.reverse (Array);
return to new string (array);
69}
70
71///
72///gives the specified version of the information in the format: x.x (BUILD:YYYY-MM-DD)
73///
74///The specified version
75///The specified version of the information
the public static string getversionbuildstring (version version)
77 {
Double days = version. Build + 2 * version. Revision/((double) timespan.ticksperday/timespan.tickspersecond);
a string. Format (' {0} (build: {1}) ', version. ToString (2), (New DateTime (2000, 1, 1)). AddDays (days). ToString ("Yyyy-mm-dd HH:mm:ss"));
80}
81
82///
83///gives information about the specified exception, including information about its containing exception
84///
85///The specified exception
86///Whether to give detailed information
87///Specifies the information for the exception
public static string GetMessage (Exception ex, BOOL Isdebug)
89 {
StringBuilder sb = new StringBuilder ();
for (Exception e = ex; e!= null; e = e.innerexception)
92 {
to SB. Append (Isdebug e.tostring (): E.message);
to SB. Append (Fcl.newline);
95}
return SB. ToString ();
97}
98}
99}
100