Example #1
0
        private void addMediaItemsFromUrlToDictionary(string url)
        {
            if (url.EndsWith("ashx"))
            {
                DynamicLink dynamicLink;
                if (!DynamicLink.TryParse(url, out dynamicLink))
                {
                    return;
                }

                if (dynamicLink != null)
                {
                    addMediaItemsByIdToDictionary(dynamicLink.ItemId);
                }
            }
            else
            {
                var urlWithoutMedia = url.Substring(url.IndexOf("media/")).Replace("media/", "/sitecore/media library/");
                var urlWithoutExt   = urlWithoutMedia.Substring(0, urlWithoutMedia.LastIndexOf("."));
                var urlRevertSpaces = urlWithoutExt.Replace("-", " ");

                var item = processArgs.PublishOptions.SourceDatabase.GetItem(urlRevertSpaces);

                if (item != null)
                {
                    addMediaItemsByIdToDictionary(item.ID);
                }
            }
        }
        public JsonResult Edit(string group, string Url, string name, string Bak, string Pic, string Title, Boolean IsOpenNewWin = false, Boolean Enable = false)
        {
            DynamicLink dl = db.DynamicLink.SingleOrDefault(d => d.Name == name && d.Group == group);

            if (dl != null)
            {
                dl.Pic          = Pic;
                dl.Title        = Title;
                dl.Url          = Url;
                dl.Enable       = Enable;
                dl.Bak          = Bak;
                dl.IsOpenNewWin = IsOpenNewWin;
                db.SaveEx();

                //PublicCache.UpdateDynamicLink();

                /*
                 * switch (group)
                 * {
                 *                      case "1":
                 *                              PublicCache.UpdatePart_DynamicLink(this,"Left_TravelZhiNan.cshtml",group);
                 *                              break;
                 *                      case "其它":
                 *                              PublicCache.UpdatePart_DynamicLink(this, "Left_DynamicLink_other.cshtml", group);
                 *                              break;
                 * }
                 * */
            }

            return(myJson.success());
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param nickname="Name">名称,不可重复</param>
        /// <param nickname="Group">组名</param>
        /// <param nickname="db">数据对象</param>
        /// <param nickname="Index">排列序号</param>
        /// <param nickname="GroupIndex">组排列序号</param>
        /// <returns></returns>
        public static DynamicLink getDynamicLink(string Name, string Group, DBContext db = null, int Index = 0, int GroupIndex = 0)
        {
            if (db == null)
            {
                db = new DBContext();
            }

            var dl = db.DynamicLink.SingleOrDefault(d => d.Name == Name && d.Group == Group);

            if (dl == null)
            {
                dl = new DynamicLink()
                {
                    Title = "", Name = Name, Group = Group, Index = Index
                };
                try
                {
                    db.DynamicLink.Add(dl);

                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return(dl);
        }
        public BusinessOperationResult <bool> ValidatePasswordRecoveryRequest(Guid guidId)
        {
            var result = new BusinessOperationResult <bool>();

            DynamicLink link = accountContext.DynamicLinks.GetByGuidId(guidId);

            if (link == null)
            {
                result.AddError(BusinessMessageSource.BusinessRule, Resources.DynamicLinkNotFound);
            }
            else if (systemContext.DateTimeNow > link.ExpiresOn)
            {
                result.AddError(BusinessMessageSource.BusinessRule, Resources.DynamicLinkExpired);
            }
            else if (link.IsConsumed)
            {
                result.AddError(BusinessMessageSource.BusinessRule, Resources.DynamicLinkConsumed);
            }
            else
            {
                result.OperationResult = true;
            }

            return(result);
        }
Example #5
0
        private static void addDynamicLink(string Name, string Group, DBContext db = null, string bak1 = "", int Index = 0)
        {
            var dl = new DynamicLink()
            {
                Title = "", Name = Name, Group = Group, Index = Index, Bak1 = bak1
            };

            db.DynamicLink.Add(dl);
        }
Example #6
0
    // Break at the point along this link that is closest to "hingePoint" in world space and attach it to a specified "target" GameObject
    // returns the new link GamObject that was made.
    public DynamicLink HingeToObjectAtPoint(GameObject target, Vector2 hingePoint)
    {
        // first check to see we have not exceeded the maximum hinge limit.
        // if (GetNumHinges() >= maxHinges) {
        if (numLinks >= maxHinges)
        {
            return(null);
        }
        numLinks++;
        DynamicLink     newScript;
        DistanceJoint2D newJoint;

        // TODO: check if the object has a RigidBody2d and possibly spawn an anchor object if not.
        // transpose the point onto the line between the two conected objects
        hingePoint = ClosestPointOnAnchorLine(hingePoint);
        Vector3 hingePoint3d = hingePoint;
        // figure out the needed distances between the end points and the hinge point.
        float startSegmentDistance = (transform.TransformPoint(distanceLimiter.anchor) - hingePoint3d).magnitude;
        float endSegmentDistance   = (transform.TransformPoint(distanceLimiter.connectedAnchor) - hingePoint3d).magnitude;
        float leftoverDistance     = (distanceLimiter.distance - DistanceFromAnchors()) / 2;

        // add a new distance joint and script component to the ending object
        // TODO: manage/check if target has a distance join already or not. Also check if there is a DynamicLink Component and enable it instead?
        newJoint = targetEnd.gameObject.AddComponent <DistanceJoint2D>();
        // copy properties from this distance joint and tranfer them to the new distance joint.
        newJoint.maxDistanceOnly       = distanceLimiter.maxDistanceOnly;
        newJoint.autoConfigureDistance = distanceLimiter.autoConfigureDistance;
        newJoint.enableCollision       = distanceLimiter.enableCollision;
        // set the new distance for each distance limiter joint
        distanceLimiter.distance = startSegmentDistance + leftoverDistance;
        newJoint.distance        = endSegmentDistance + leftoverDistance;
        // add a new script component to the ending object
        newScript = targetEnd.gameObject.AddComponent <DynamicLink>();
        // make sure the new script has the same prefab as this one for the link component
        newScript.segmentPrefab = segmentPrefab;
        // TODO: possibly use a co-routine for monitering when to un-hinge the divided link segments back into the origional.
        // set the starting anchorpoint of the new link to the current links ending anchorpoint
        newScript.AnchorPointStart = AnchorPointEnd;
        // set the new link's end to the targetObject
        // TODO: MUST redesign to use an anchor prefab that has a kinematic rigidbody attached to it.
        //       MAYBE enable colisions on distance joind and add rigidbody to the ground???
        newScript.TargetEnd      = target.GetComponent <Rigidbody2D>();
        newScript.AnchorPointEnd = target.transform.InverseTransformPoint(hingePoint);
        // set this targetEnd to the same point
        TargetEnd      = newScript.TargetEnd;
        AnchorPointEnd = newScript.AnchorPointEnd;
        // set the new link's attached tail to this link's tail to keep the chain
        newScript.attachedTail = attachedTail;
        // set this link's attched tail to point to the new link script
        attachedTail = newScript;
        // set the new link's attached head to this link script
        newScript.attachedHead = this;
        // TODO: set max distance for this link and the new link to a proper length.
        // TEMP!!! disable update on the new, to see where/how it gets spawned
        // newScript.disableUpdate();
        return(newScript);
    }
Example #7
0
 // Initialization after the component first gets enabled. This happens on the very next Update() call.
 void Start()
 {
     // get the related DynamicLink script component if we have not already.
     if (attachedObject && !linkManager)
     {
         LinkManager = attachedObject.GetComponent <DynamicLink>();
     }
     // Debug.Log("worldSize"+linkNum.ToString());
     // Debug.Log(worldSize);
 }
		/// <summary>
		/// Gets the item from a dynamic link.
		/// </summary>
		/// <param name="link">
		/// The given link.
		/// </param>
		/// <returns>
		/// The Item<see cref="Item"/>.
		/// </returns>
		private static Item GetItem(DynamicLink link)
		{
			var site = link.Site ?? global::Sitecore.Context.Site;
			var database = site.Database;

			Language language;
			if (link.Language != null)
			{
				language = link.Language;
			}
			else
			{
				Language.TryParse(site.Language, out language);
			}

			return database.GetItem(link.ItemId, language);
		}
Example #9
0
        private void SaveDynamicLink(Guid guidId, string recoveryType, string url)
        {
            int keepAliveFor = configProvider.GetSectionKeyValue <int>("PasswordRecovery", "ResetLinkKeepAliveFor");

            var dynamicLink = new DynamicLink
            {
                GuidId     = guidId,
                Type       = "PasswordRecovery",
                SubType    = recoveryType,
                Url        = url,
                ExpiresOn  = systemContext.DateTimeNow.AddMinutes(keepAliveFor),
                IsConsumed = false
            };

            accountContext.DynamicLinks.Create(dynamicLink);
            accountContext.SaveChanges();
        }
        public override string ExpandDynamicLinks(string text, bool resolveSites)
        {
            // Walk through the text expanding token links along the way
            int startIndex = text.IndexOf(TOKEN_IDENTIFIER, StringComparison.Ordinal);

            while (startIndex >= 0)
            {
                string result = String.Empty;

                int startOfLink = text.Substring(0, startIndex).LastIndexOf("<a href=\"~/link.aspx?", StringComparison.Ordinal);
                int endOfLink   = text.IndexOf("</a>", startIndex, StringComparison.Ordinal) + 4;

                string      linkText    = text.Substring(startOfLink, endOfLink - startOfLink);
                DynamicLink dynamicLink = DynamicLink.Parse(linkText);

                Item tokenItem = Sitecore.Context.Database.GetItem(
                    dynamicLink.ItemId,
                    dynamicLink.Language ?? Sitecore.Context.Language);

                TokenProcessorConfig processorConfig = TokenConfig.Processors
                                                       .FirstOrDefault(x => x.TokenTemplates.Contains(tokenItem.TemplateID));

                if (processorConfig != null)
                {
                    BaseTokenProcessor processor = (BaseTokenProcessor)ReflectionUtil.CreateObject(processorConfig.Type);
                    if (processor != null)
                    {
                        result = processor.Process(tokenItem);
                    }
                    else
                    {
                        Log.Warn("No implementation found for token processor: " + processorConfig.Type, this);
                    }
                }
                else
                {
                    Log.Warn("No processor found for token: " + tokenItem.ID, this);
                }

                // Replace token and step forward
                text       = text.Replace(linkText, result);
                startIndex = text.IndexOf(TOKEN_IDENTIFIER, StringComparison.Ordinal);
            }

            return(base.ExpandDynamicLinks(text, resolveSites));
        }
Example #11
0
        /// <summary>
        /// Resolves Dynamic Links to either the item path or the media item path with extension
        /// </summary>
        /// <param name="link">The href value of a node</param>
        /// <param name="resolvedLink">Output of the resolved link.</param>
        /// <returns></returns>
        public static bool TryResolveInternalLink(string link, out string resolvedLink)
        {
            DynamicLink parsed;

            if (DynamicLink.TryParse(link, out parsed))
            {
                var item = Factory.GetDatabase(Constants.MasterDb).GetItem(parsed.ItemId);
                if (item != null)
                {
                    if (item.Paths.IsMediaItem)
                    {
                        bool includesExtension = false;
                        link = "/~/media" + GetMediaPath(parsed.ItemId, true, ref includesExtension);
                    }
                    else
                    {
                        using (var db = new SitecoreService(Constants.MasterDb))
                        {
                            var articleItem = db.GetItem <ArticleItem>(item.ID.Guid);
                            if (articleItem._TemplateId == IArticleConstants.TemplateId.Guid)
                            {
                                link = string.Format("{1}/a/{0}", articleItem.Article_Number, AssetLinkBase.BaseUrl);
                            }
                            else
                            {
                                link = LinkManager.GetItemUrl(item).ToLower();

                                const string partToRemove        = "/sitecore/shell";
                                int          indexOfPartToRemove = link.IndexOf(partToRemove);
                                if (indexOfPartToRemove != -1)
                                {
                                    link = link.Substring(partToRemove.Length + indexOfPartToRemove);
                                }
                            }
                        }
                    }
                }

                resolvedLink = link;
                return(true);
            }

            resolvedLink = null;
            return(false);
        }
        public void SetEventLink(IEvent e)
        {
            IEventPointer ep = e as IEventPointer;

            if (ep != null)
            {
                CompilerErrorCollection errors = DynamicLink.LinkEvent(ep, taskExecuter);
                if (errors != null && errors.Count > 0)
                {
                    StringCollection sc = new StringCollection();
                    for (int i = 0; i < errors.Count; i++)
                    {
                        sc.Add(errors[i].ErrorText);
                    }
                    MathNode.Log(sc);
                }
            }
        }
        private void SaveDynamicLink(Guid guidId, string recoveryType, string url)
        {
            int keepAliveFor = configProvider.GetSectionKeyValue<int>("PasswordRecovery", "ResetLinkKeepAliveFor");

            var dynamicLink = new DynamicLink
            {
                GuidId = guidId,
                Type = "PasswordRecovery",
                SubType = recoveryType,
                Url = url,
                ExpiresOn = systemContext.DateTimeNow.AddMinutes(keepAliveFor),
                IsConsumed = false
            };

            accountContext.DynamicLinks.Create(dynamicLink);
            accountContext.SaveChanges();
        }
		/// <summary>
		/// Parses a dynamic link.
		/// </summary>
		/// <param name="linkText">The link text.</param>
		/// <returns>The dynamic link.</returns>
		public override DynamicLink ParseDynamicLink(string linkText)
		{
			Assert.ArgumentNotNullOrEmpty(linkText, "linkText");
			var dynamicLink = new DynamicLink();
			dynamicLink.Initialize(linkText);
			return dynamicLink;
		}
Example #15
0
        private void HandleNextNode(Queue <HtmlNode> nodes, IDataMap map, string itemPath, Item importRow)
        {
            var node       = nodes.Dequeue();
            var nodeName   = node.Name.ToLower();
            var parentNode = node.ParentNode;
            var childNodes = node.SelectNodes("./*|./text()");

            if (childNodes != null)
            {
                foreach (var child in childNodes)
                {
                    nodes.Enqueue(child);
                }
            }

            if (UnwantedTags.Any(tag => tag == nodeName))
            {
                // if this node is one to remove
                if (childNodes != null)
                {
                    // make sure children are added back
                    foreach (var child in childNodes)
                    {
                        parentNode.InsertBefore(child, node);
                    }
                }

                parentNode.RemoveChild(node);
            }
            else if (node.HasAttributes)
            {
                // if it's not being removed
                foreach (string s in UnwantedAttributes)                 // remove unwanted attributes
                {
                    node.Attributes.Remove(s);
                }

                //replace images
                if (nodeName.Equals("img"))
                {
                    // see if it exists
                    string      imgSrc = node.Attributes["src"].Value;
                    DynamicLink dynamicLink;
                    if (!DynamicLink.TryParse(imgSrc, out dynamicLink))
                    {
                        return;
                    }
                    MediaItem mediaItem       = importRow.Database.GetItem(dynamicLink.ItemId, dynamicLink.Language ?? map.ImportToLanguage);
                    var       mediaParentItem = BuildMediaPath(map.ToDB, mediaItem.InnerItem.Paths.ParentPath);
                    MediaItem newImg          = HandleMediaItem(map, mediaParentItem, itemPath, mediaItem);
                    if (newImg != null)
                    {
                        string newSrc = string.Format("-/media/{0}.ashx", newImg.ID.ToShortID().ToString());
                        // replace the node with sitecore tag
                        node.SetAttributeValue("src", newSrc);
                    }
                }
            }
            else if (ReplaceTags.ContainsKey(nodeName))
            {
                // Replace tag
                node.Name = ReplaceTags[nodeName];
            }
            else
            {
                //Keep node as is
            }
        }