SHP、SDF等数据在通过Load Procedure加载到MapGuide站点服务器后,由MapGuide服务器管理,称为Managed Resource,对应的文件存储到MapGuide Server内,缺省位置是C:\Program Files\OSGeo\MapGuide\Server\Repositories\Library\
如果你仔细看一下,你就会发现原先的shp文件已经被转换成了sdf文件。那么Load Procedure的内部机理到底是怎么样的么?我们可以用reflector分析一下他的主要的几个assembly :Autodesk.MapGuide.Studio.Load.dll 和 Autodesk.MapGuide.Studio.Site.dll。
代码比语言更有说服力,还是看看代码吧。下面是我以前分析的一部分反编译的代码:
LoadProcedure的Execute方法:
////通过siteConnection直接上传到指定的mapGuide Server
public void Execute(SiteConnection connection)
{
if (connection == null)
{
throw new NullReferenceException();
}
FileInfo info = null;
Stream stream = null;
try
info = new FileInfo(Path.GetTempFileName()); //生成一个临时的mpg文件
this.Execute(info.FullName, connection); ///调用生成mpg文件,然后上传到mapguide server
stream = info.OpenRead();
connection.ApplyPackage(stream);
finally
if (stream != null)
{
stream.Close();
}
if ((info != null) && info.Exists)
info.Delete();
}
//////真正上传的过程
public virtual void Execute(string packageFilePath, SiteConnection connection)
PackageWriter package = null;
this.usedBaseNames.Clear();
string str = string.Format("Created by {0}.Execute().", base.GetType().Name);
package = new PackageWriter(packageFilePath, str);
if (this.SourceFiles.Count > 0)
foreach (string str2 in this.sourceFiles)
{
FileInfo info = new FileInfo(str2);
if (!info.Exists)
{
throw new FileNotFoundException(null, str2);
}
}
this.ResourceIds.Clear();
foreach (string str3 in this.sourceFiles)
this.ProcessSourceFile(package, str3, connection); //真正上传的过程
if (package != null)
package.Close();
在基类LoadProcedure中的ProcessSourceFile是一个抽象方法,具体实现在他的派生子类中定义
protected abstract void ProcessSourceFile(PackageWriter package, string filePath, SiteConnection connection);
下面看一个加载sdf的procedure ----SdfLoadProcedure的ProcessSourceFile
protected override void ProcessSourceFile(PackageWriter package, string filePath, SiteConnection connection)
///............这里省略的部分代码
///.............................................................
bool flag = GetSdfVersion(destFileName) < 3;
if (flag) //如果sdf文件的版本不是sdf3,则把它转换成sdf3格式
string dst = Path.Combine(path, "converted_" + Path.GetFileName(destFileName));
if (this.SdfKeyTreatment == SdfKeyTreatment.AutogenerateAll)
SdfConverter.Convert(destFileName, dst, wkt, false);
else
SdfConverter.Convert(destFileName, dst, wkt, true, this.SdfKeyTreatment == SdfKeyTreatment.MergeDuplicates);
destFileName = dst;
////////////////////////////////////
/// 后面就是上传过程了,
///
// Stream stream = FeatureSource.CreateDocumentForSDF(Path.GetFileName(destFileName), connection, extensions);
// package.AddSdfFeatureSource(str12, stream, null, destFileName);
if (base.ShouldCreateLayer(connection, layerFullName)) //如果要同时创建图层的话
MdfVersion version = null;
if ((connection != null) && base.IsConnectedToPre2008Server(connection))
int nMajorNumber = 1;
int nMinorNumber = 0;
int nRevisionNumber = 0;
version = new MdfVersion(nMajorNumber, nMinorNumber, nRevisionNumber);
//创建图层的featureSouce
base.CreateFeatureSourceLayer(package, resourceId, schemaFilePath, layerFullName, version);
if (Directory.Exists(path))
Directory.Delete(path, true);
//////////////////////////////////////
/// 下面是sdf版本转换类的方法列表
public class SdfConverter
// Methods
public SdfConverter();
public static void Convert(string src, string dst, string wkt, [MarshalAs(UnmanagedType.U1)] bool useKey);
public static void Convert(string src, string dst, string wkt, [MarshalAs(UnmanagedType.U1)] bool useKey, [MarshalAs(UnmanagedType.U1)] bool mergeDuplicates);
public static int GetSdfFileBounds(string path, ref double xMin, ref double yMin, ref double xMax, ref double yMax);
public static int GetSdfFileVersion(string path);
就是这样,大概的一个MapGuide Studio的加载过程。
转载请保留此信息。
本文转自峻祁连. Moving to Cloud/Mobile博客园博客,原文链接:http://www.cnblogs.com/junqilian/archive/2009/10/26/1590272.html,如需转载请自行联系原作者