Esempio n. 1
0
        //[EditArticles]
        public static TeamMentor_Article        xmlDB_GuidanceItem(this TM_Xml_Database tmDatabase, Guid guidanceItemId, string fullPath)
        {
            try
            {
                if (TM_Xml_Database.Current.Cached_GuidanceItems.hasKey(guidanceItemId))
                {
                    //"found match for id: {0} in {1}".info(guidanceItemId, fullPath);
                    if (TM_Xml_Database.Current.GuidanceItems_FileMappings[guidanceItemId] != fullPath)
                    {
                        //"[xmlDB_GuidanceItem] GuidanceItem ID conflict, the Id '{0}' was already mapped. \nExisting path: \t{1} \nNew path:  \t{2}".error(
                        //	guidanceItemId, TM_Xml_Database.GuidanceItems_FileMappings[guidanceItemId] , fullPath);
                        return(tmDatabase.fixGuidanceItemFileDueToGuidConflict(guidanceItemId, fullPath));
                    }
                    return(TM_Xml_Database.Current.Cached_GuidanceItems[guidanceItemId]);
                }

                if (fullPath.notNull())
                {
                    //"trying to load id {0} from virtualPath: {1}".info(guidanceItemId, virtualPath);
                    //var pathXmlLibraries = TM_Xml_Database.Current.Path_XmlLibraries;

                    /*var fullPath = virtualPath.fileExists()
                     *                  ? virtualPath
                     *                  : pathXmlLibraries.pathCombine(virtualPath).fullPath();*/
                    if (fullPath.fileExists())
                    {
                        //"loading {0}".info(fullPath);

                        var article = fullPath.teamMentor_Article(); //.transform_into_guidanceItem();
                        if (article.isNull())
                        {
                            // _guidanceItem = guidanceItem.Load(fullPath).transform();
                            article = fullPath.load <Guidance_Item_Import>().transform();
                            article.saveAs(fullPath);   // to do an import in place
                        }
                        if (article.notNull())
                        {
                            if (article.Metadata.Id != guidanceItemId)
                            {
                                "FOUND GUID CHANGE".error();
                                article.Metadata.Id_History += article.Metadata.Id.str() + ",";
                                article.Metadata.Id          = guidanceItemId;
                                article.saveAs(fullPath);
                            }
                            //guidanceItemV3.guidanceItemId		 = original_Guid;		// this gives us the ability to track its source
                            //guidanceItemV3.source_guidanceItemId = newGuid;				// also provides support for moving GuidanceItems across libraries
                            //var _guidanceItemV3 = _guidanceItem.tmGuidanceItemV3();

                            TM_Xml_Database.Current.Cached_GuidanceItems.Add(guidanceItemId, article);
                            TM_Xml_Database.Current.GuidanceItems_FileMappings.add(guidanceItemId, fullPath);


                            return(article);
                        }
                        else
                        {
                            "[xmlDB_GuidanceItem] Failed to load article at path: {0} (see errors for reason)".error(fullPath);
                        }
                    }
                    else
                    {
                        "[xmlDB_GuidanceItem] could not find file: {0}".error(fullPath);
                    }
                }
                else
                {
                    "no virtualPath provided for id: {0}".error(guidanceItemId);
                }
            }
            catch (Exception ex)
            {
                "[TM_Xml_Database] in xmlDB_GuidanceItem: {0}".error(ex.Message);
            }
            return(null);
        }