コード例 #1
0
        /// <summary>
        /// Parse RDF file from <c>path</c> and create profile
        /// </summary>
        /// <param name="profile">Profile profile the data will be stored in</param>
        public Profile LoadProfileDocument(Stream stream, string path, bool createCore = true)
        {
            try
            {
                this.profile       = new Profile();
                profile.SourcePath = path;

                StringBuilder message = new StringBuilder();
                message.Append("\r\n\t------------------Parsing profile------------------");
                message.Append("\r\nParsing file: ").Append(profile.SourcePath);
                OnMessage(message.ToString());

                if (!string.IsNullOrEmpty(profile.SourcePath))
                {
                    bool                 success;
                    TimeSpan             durationOfParsing = new TimeSpan(0);
                    RDFSXMLReaderHandler handler           = new RDFSXMLReaderHandler();

                    handler = (RDFSXMLReaderHandler)XMLParser.DoParse(handler, stream, profile.SourcePath, out success, out durationOfParsing);

                    StringBuilder msg = new StringBuilder("\r\nCIM profile loaded\r\n\t Duration of CIM profile loading: " + durationOfParsing);
                    if (success)
                    {
                        profile = handler.Profile;
                        msg.Append("\r\n TOTAL:\r\n\tPackages: ").Append(profile.PackageCount);
                        msg.Append("\r\n\tClasses: ").Append(profile.ClassCount);
                    }
                    else
                    {
                        msg.Append("\r\n\t loading CIM profile was unsuccessful");
                    }
                    OnMessage(msg.ToString());
                }
                else
                {
                    OnMessage("Parsing impossible - no profile or incorrect path");
                    return(null);
                }
                OnMessage("\r\n\t--------------Done parsing profile--------------");

                #region Manage dataType classes
                PredefinedClasses pf = new PredefinedClasses();

                if (profile.FindProfileElementByUri("#Package_Core") == null && createCore)
                {
                    pf.CreatePackage(profile, "Package_Core");
                }
                if (profile.FindProfileElementByUri("#UnitSymbol") == null)
                {
                    pf.CreateEnumeration(profile, "UnitSymbol");
                }
                if (profile.FindProfileElementByUri("#UnitMultiplier") == null)
                {
                    pf.CreateEnumeration(profile, "UnitMultiplier");
                }

                ExtractDataTypeClasses();
                if (predefined.Count > 0)
                {
                    foreach (Class e in predefined)
                    {
                        pf.updateClassData(e, profile);
                    }
                    AddPredefined();
                }
                #endregion Manage dataType classes

                #region Adjustments to simplify profile
                if (RemoveDataTypes)
                {
                    //// replace predefined data types with simple types
                    ReplaceDataTypesWithSimpleTypes(pf);
                    ExcludeDataTypesFromProfile(pf);
                }
                #endregion Adjustments to simplify profile

                return(profile);
            }
            catch (ThreadAbortException)
            {
                return(null);
            }
        }