天天看點

MapGuide應用開發系列(六)---- MapGuide Studio中Load Procedures分析

SHP、SDF等資料在通過Load Procedure加載到MapGuide站點伺服器後,由MapGuide伺服器管理,稱為Managed Resource,對應的檔案存儲到MapGuide Server内,預設位置是C:\Program Files\OSGeo\MapGuide\Server\Repositories\Library\

MapGuide應用開發系列(六)---- MapGuide Studio中Load Procedures分析

如果你仔細看一下,你就會發現原先的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的加載過程。

郵箱:[email protected] 

轉載請保留此資訊。

本文轉自峻祁連. Moving to Cloud/Mobile部落格園部落格,原文連結:http://www.cnblogs.com/junqilian/archive/2009/10/26/1590272.html,如需轉載請自行聯系原作者

繼續閱讀