Exemple #1
0
 private String BuildDynamicFromSplitIDs(IController controller, String linkType, String[] idsToParse)
 {
     StringBuilder combinedID = new StringBuilder(5); // 2 hyphens, 3 dynamic IDs, can be more or less
     for (int i = 0; i < idsToParse.Length; i++)
     {
         combinedID.Append(componentHolder[idsToParse[i]]);
         if (i < idsToParse.Length - 1)
         {
             combinedID.Append("-");
         }
     }
     return controller.GetDynamicLinkType(linkType, combinedID.ToString());
 }
Exemple #2
0
        private String getLink(IController controller, String name)
        {
            if (name.Contains(Delimitter))
            {
                Int32 index = name.IndexOf(Delimitter);
                String linkType = name.Substring(0, index);
                String componentId = name.Substring(index + Delimitter.Length);
                if (!componentId.Contains("-"))
                {

                    return controller.GetDynamicLinkType(linkType, componentHolder[componentId].ToString());
                }
                else
                {
                    String[] idsToParse = componentId.Split('-');

                    // see if everything we split is an ID
                    bool splitOK = true;
                    for (int i = 0; i < idsToParse.Length; i++)
                    {
                        if (!componentHolder.ContainsKey(idsToParse[i]))
                        {
                            splitOK = false;
                            break;
                        }
                    }

                    if (!splitOK)
                    {
                        // it's possible the name itself just has a hyphen in it, check that
                        if (componentHolder.ContainsKey(componentId))
                        {
                            return controller.GetDynamicLinkType(linkType, componentHolder[componentId].ToString());
                        }
                        else // the difficult case, we need to try and build IDs now from the split strings
                        {
                            List<String> idList = new List<String>();
                            idList.AddRange(idsToParse);

                            bool looking = true;
                            while (looking)
                            {
                                int listIndex = -1;
                                String thisValue = "";
                                String nextValue = "";

                                bool lookingTest = false;
                                for (int i = 0; i < idList.Count; i++)
                                {
                                    String test = idList[i];
                                    if (!componentHolder.ContainsKey(test))
                                    {
                                        lookingTest = true;
                                        // try combining this value with the next value
                                        if (i + 1 < idList.Count)
                                        {
                                            thisValue = test;
                                            nextValue = idList[i + 1];
                                            listIndex = i;
                                            break;
                                        }
                                        else // we've hit the end of the list, give up
                                        {
                                            lookingTest = false;
                                        }
                                    }
                                }

                                looking = lookingTest;

                                if (listIndex != -1)
                                {
                                    idList[listIndex] = thisValue + "-"+ nextValue;
                                    idList.RemoveAt(listIndex + 1);
                                }
                            }
                            return BuildDynamicFromSplitIDs(controller, linkType, idList.ToArray());
                        }
                    }
                    else // build the dynamic from the split IDs
                    {
                        return BuildDynamicFromSplitIDs(controller, linkType, idsToParse);
                    }
                }
            }
            else
            {
                return name;
            }
        }