Ejemplo n.º 1
0
        public static bool                   xmlDB_DeleteGuidanceExplorer(this TM_Xml_Database tmDatabase, Guid libraryId)
        {
            var tmLibrary = tmDatabase.tmLibrary(libraryId);

            if (tmLibrary.isNull())
            {
                return(false);
            }
            if (tmDatabase.UsingFileStorage)
            {
                "[xmlDB_DeleteGuidanceExplorer] deleting library with caption: {0}".info(tmLibrary.Caption);
                var pathToLibraryFolder = tmDatabase.xmlDB_Path_Library_RootFolder(tmLibrary);
                // this is also the Library Root
                if (pathToLibraryFolder.notValid() || pathToLibraryFolder == tmDatabase.Path_XmlDatabase ||
                    pathToLibraryFolder == tmDatabase.Path_XmlLibraries)
                {
                    "[xmlDB_DeleteGuidanceExplorer][Stopping delete] Something is wrong with the pathToLibrary to delete : {0}"
                    .error(pathToLibraryFolder);
                    return(false);
                }
                if (pathToLibraryFolder.contains(tmDatabase.Path_XmlLibraries).isFalse())
                {
                    "[xmlDB_DeleteGuidanceExplorer][Stopping delete] the  pathToLibrary should contain tmDatabase.Path_XmlLibraries : {0}"
                    .error(pathToLibraryFolder);
                    return(false);
                }
                // the checks above are important since the line below is a recursive folder delete (which can delete a LOT of content is pointed to the wrong folder)
                if (Files.deleteFolder(pathToLibraryFolder, true).isFalse())
                {
                    "[xmlDB_DeleteGuidanceExplorer] there was an error deleting the folder: {0}".error(
                        pathToLibraryFolder);
                    return(false);
                }

                "[xmlDB_DeleteGuidanceExplorer] Library folder deleted OK: {0}".info(pathToLibraryFolder);
                tmDatabase.reloadGuidanceExplorerObjects(); //reset these
            }
            else
            {
                TM_Xml_Database.Current.GuidanceExplorers_XmlFormat.remove(tmLibrary.Id);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public static string                             getXmlFilePathForGuidanceId(this TM_Xml_Database tmDatabase, Guid guidanceItemId, Guid libraryId)
        {
            //first see if we already have this mapping
            if (TM_Xml_Database.Current.GuidanceItems_FileMappings.hasKey(guidanceItemId))
            {
                //"in getXmlFilePathForGuidanceId, found id in current mappings: {0}".info( guidanceItemId);
                return(TM_Xml_Database.Current.GuidanceItems_FileMappings[guidanceItemId]);
            }
            //then update the GuidanceItems_FileMappings dictionary

            //tmDatabase.populateGuidanceItemsFileMappings();

            if (TM_Xml_Database.Current.GuidanceItems_FileMappings.hasKey(guidanceItemId))
            {
                "[getXmlFilePathForGuidanceId] found id after reindex: {0}".info(guidanceItemId);
                return(TM_Xml_Database.Current.GuidanceItems_FileMappings[guidanceItemId]);
            }

            if (libraryId == Guid.Empty)
            {
                "[getXmlFilePathForGuidanceId] When creating a new GuidanceItem a libraryId must be provided".error();
                return(null);
            }
            var tmLibrary = tmDatabase.tmLibrary(libraryId);

            if (tmLibrary == null)
            {
                "[getXmlFilePathForGuidanceId] When creating a new GuidanceItem could not find library for libraryId: {0}".error(libraryId);
                return(null);
            }
            var newGuidanceVirtualFolder = "{0}\\Articles".format(tmLibrary.Caption);
            // if not store it on a _GuidanceItems folder
            var xmlPath = TM_Xml_Database.Current.Path_XmlLibraries
                          .pathCombine(newGuidanceVirtualFolder)
                          .createDir()
                          .pathCombine("{0}.xml".format(guidanceItemId));

            "in getXmlFilePathForGuidanceId, no previous mapping found so guidanceitem to :{0}".info(xmlPath);

            TM_Xml_Database.Current.GuidanceItems_FileMappings.add(guidanceItemId, xmlPath); //add it to the file_mappings dictionary so that we know it for next time
            return(xmlPath);
        }
Ejemplo n.º 3
0
        public static string Get_Path_To_File(this TM_Xml_Database tmDatabase, Guid itemGuid, string fileName)
        {
            var library = tmDatabase.tmLibrary(itemGuid);

            if (library.notNull())
            {
                return(tmDatabase.Get_Path_To_File(library.Caption, fileName));
            }

            /*var article = tmDatabase.getGuidanceItem(itemGuid);
             * if (article.notNull())
             * {
             *  var path = tmDatabase.getXmlFilePathForGuidanceId(itemGuid);
             *  if (path.fileExists())
             *  {
             *      var file
             *  }
             * }*/
            return(null);
        }
Ejemplo n.º 4
0
        [EditArticles]  public static urn.microsoft.guidanceexplorer.View           xmlDB_NewView(this TM_Xml_Database tmDatabase, Guid parentFolderId, View tmView)
        {
            UserRole.EditArticles.demand();
            if (tmView.isNull())
            {
                return(null);
            }
            var tmLibrary = tmDatabase.tmLibrary(tmView.library.guid());

            //var guidanceExplorer = tmDatabase.xmlDB_GuidanceExplorer(tmView.library.guid());
            if (tmLibrary.notNull())
            {
                if (tmView.id.isNull() || (tmView.id.isGuid() && tmView.id == Guid.Empty.str()))
                {
                    tmView.id = Guid.NewGuid().str();
                }
                var view = tmView.view();

                if (parentFolderId == Guid.Empty)
                {
                    var guidanceExplorer = tmLibrary.guidanceExplorer(tmDatabase);
                    guidanceExplorer.library.libraryStructure.view.Add(view);
                    //tmLibrary.xmlDB_Save_GuidanceExplorer(tmDatabase);
                    //return tmDatabase.xmlDB_View(tmView.id.guid());
                }
                else
                {
                    var folder = tmDatabase.xmlDB_Folder(tmLibrary.Id, parentFolderId);
                    if (folder.isNull())
                    {
                        "[xmlDB_NewView] could not find parent folder (to add view) with id {0}".error(parentFolderId);
                        return(null);
                    }
                    folder.view.Add(view);
                }
                tmLibrary.xmlDB_Save_GuidanceExplorer(tmDatabase);
                return(view);
                //return folder.xmlDB_View(tmView.id.guid());                   // I have to get the reference again since the object is different after the calls to xmlDB_Save_GuidanceExplorer
            }
            return(null);
        }
Ejemplo n.º 5
0
        [EditArticles]  public static urn.microsoft.guidanceexplorer.View           xmlDB_UpdateView(this TM_Xml_Database tmDatabase, View tmView, List <Guid> guidanceItems)
        {
            UserRole.EditArticles.demand();
            if (tmView.isNull())
            {
                return(null);
            }
            var tmLibrary = tmDatabase.tmLibrary(tmView.library.guid());

            if (tmLibrary.isNull())
            {
                "[TM_Xml_Database] in xmlDB_UpdateView, could not find library with id: {0}".error(tmView.library);
                return(null);
            }

            /*var targetFolder = tmLibrary.xmlDB_Folder(tmView.parentFolder, tmDatabase);
             * if (targetFolder.isNull())
             * {
             *  "[TM_Xml_Database] in xmlDB_UpdateView, could not find target Folder with name: {0}".error(tmView.parentFolder);
             *  return null;
             * }*/
            var targetView = tmDatabase.xmlDB_View(tmView.id.guid());

            if (targetView.isNull())
            {
                "[TM_Xml_Database] in xmlDB_UpdateView, could not find view with id: {0}".error(tmView.id);
                return(null);
            }
            //"Updating view with caption {0} in folder {1} with id {2}".info(targetView.caption, targetFolder.caption, targetView.id);
            targetView.caption = tmView.caption;
            targetView.author  = tmView.creator;

            //foreach(var guid in guidanceItems)

            tmLibrary.xmlDB_Save_GuidanceExplorer(tmDatabase);
            return(targetView);
            //existingView.creationDate = tmView.lastUpdate // should we also update this?
        }
Ejemplo n.º 6
0
        public static Guid xmlBD_resolveDirectMapping(this TM_Xml_Database tmDatabase, string mapping)
        {
            if (mapping.inValid())
            {
                return(Guid.Empty);
            }


            /*foreach(var item in TM_Xml_Database.Current.Cached_GuidanceItems)
             *  if(item.Value.Metadata.DirectLink.lower() == mapping ||item.Value.Metadata.Title.lower() == mapping)
             *      return item.Key;
             */
            mapping = mapping.lower();

            //first resolve by direct link
            var directLinkResult = (from item in TM_Xml_Database.Current.Cached_GuidanceItems
                                    where (item.Value.Metadata.DirectLink.notNull() && item.Value.Metadata.DirectLink.lower() == mapping)
                                    select item.Key).first();

            if (directLinkResult != Guid.Empty)
            {
                return(directLinkResult);
            }

            var mapping_Segments = mapping.split("^");

            //if there are no ^ on the title: resolve by title
            if (mapping_Segments.size() == 1)
            {
                var mapping_Extra = mapping.Replace(" ", "_");
                var titleResult   = (from item in TM_Xml_Database.Current.Cached_GuidanceItems
                                     where titleMatch(item.Value, mapping, mapping_Extra)
                                     select item.Key).first();
                if (titleResult != Guid.Empty)
                {
                    return(titleResult);
                }
            }
            //if there are ^ on the title: resolve by title^library^technology^phase^type^category
            else
            {
                var title       = mapping_Segments.value(0);
                var title_Extra = title.valid() ? title.Replace(" ", "_") : title;
                var library     = mapping_Segments.value(1);
                var technology  = mapping_Segments.value(2);
                var phase       = mapping_Segments.value(3);
                var type        = mapping_Segments.value(4);
                var category    = mapping_Segments.value(5);

                //var libraryNames = tmDatabase.tmLibraries().names().lower();//pre calculate this to make it faster

                foreach (var item in TM_Xml_Database.Current.Cached_GuidanceItems)
                {
                    if (titleMatch(item.Value, title, title_Extra))             // check Title
                    {
                        if (library.inValid())
                        {
                            return(item.Key);
                        }
                        if (tmDatabase.tmLibrary(item.Value.Metadata.Library_Id).Caption.lower() == library)                     // check Library
                        {
                            if (technology.inValid())
                            {
                                return(item.Key);
                            }
                            if (item.Value.Metadata.Technology.lower() == technology)   // check Technology
                            {
                                if (phase.inValid())
                                {
                                    return(item.Key);
                                }
                                if (item.Value.Metadata.Phase.lower() == phase)         // check Phase
                                {
                                    if (type.inValid())
                                    {
                                        return(item.Key);
                                    }
                                    if (item.Value.Metadata.Type.lower() == type)      // check type
                                    {
                                        if (category.inValid())
                                        {
                                            return(item.Key);
                                        }
                                        if (item.Value.Metadata.Category.lower() == category) // check category
                                        {
                                            return(item.Key);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(Guid.Empty);
        }
        [EditArticles]  public static urn.microsoft.guidanceexplorer.Folder xmlDB_Add_Folder(this TM_Xml_Database tmDatabase, Guid libraryId, Guid parentFolderId, string folderCaption)
        {
            var tmLibrary = tmDatabase.tmLibrary(libraryId);

            return(tmLibrary.xmlDB_Add_Folder(parentFolderId, folderCaption, tmDatabase));
        }
 [EditArticles]  public static bool                                          xmlDB_RemoveView(this TM_Xml_Database tmDatabase, Guid libraryId, Guid viewId)
 {
     return(tmDatabase.xmlDB_RemoveView(tmDatabase.tmLibrary(libraryId), viewId));
 }
Ejemplo n.º 9
0
 public static urn.microsoft.guidanceexplorer.Folder         xmlDB_Folder        (this TM_Xml_Database tmDatabase, Guid libraryId,  string folderCaption)
 {
     var tmLibrary = tmDatabase.tmLibrary(libraryId); 
     return tmLibrary.xmlDB_Folder(folderCaption, tmDatabase);
 }