Welcome Guest, you are in: Login

FDOT Wiki

RSS RSS

GisFramework



Search the wiki
»

WebApplicationLink Example

RSS
Modified on Wednesday, 13 July 2011 01:26 PM by Administrator Categorized as Feature Actions
Here's the implementation of the FinancialProjectSearchLink which implements the abstract class WebApplicationLink.


FinancialProjectSearchLink

    [Export(typeof(IApplicationLink))]
    public class FinancialProjectSearchLink : WebApplicationLink<FinancialProjectData>
    {
        const string FinancialProjectSearchLinkFormat = "{0}ExternalLink.ashx?redirect=http%3A%2F%2F{3}%2FFinancialProjectSearch%2FFPS_result.asp&srchwpitem={1}&srchwpitmseg={2}";

        public FinancialProjectSearchLink()
        {
            DataIdentifiers = new List<ApplicationLinkDataIdentifier<FinancialProjectData>> { new FinancialProjectDataIdentifier() };
        }

        protected override void OnApplicationLinkExecute(FinancialProjectData linkData)
        {
            if (linkData != null)
            {
                HtmlPage.Window.Navigate(new Uri(string.Format(FinancialProjectSearchLinkFormat, VirtualApplicationManager.HostSiteUrl, linkData.Item, linkData.Segment, WebServer)), "__blank");
            }

        }

        public override string GetDisplayName()
        {
            return "Financial Project Search";
        }
    }

FinancialProjectData

    public class FinancialProjectData
    {
        public string Item { get; set; }
        public string Segment { get; set; }
        public string Phase { get; set; }
        public string Sequence { get; set; }

        public override string ToString()
        {
            return string.Format("{0}{1}{2}{3}", Item, Segment, Phase, Sequence);
        }
    }

FinancialProjectDataIdentifier

  public class FinancialProjectDataIdentifier : ApplicationLinkDataIdentifier<FinancialProjectData>
    {
        public override bool CanLinkFromObject(Feature o)
        {
            return ContainsCombinedFinProjData(o) || ContainsSplitFinProjData(o);
        }

        private static bool ContainsSplitFinProjData(Feature o)
        {
            var itemKey = o.FeatureType.Attributes.FirstOrDefault(key => key.Name.Equals("WPITEM", StringComparison.OrdinalIgnoreCase));
            return itemKey != null;
        }

        private static bool ContainsCombinedFinProjData(Feature o)
        {
            var itemKey = GetCombinedFinProjDataKey(o);
            return itemKey != null;
        }

        private static AttributeDescription GetCombinedFinProjDataKey(Feature o)
        {
            return o.FeatureType.Attributes.FirstOrDefault(key => key.Name.Equals("PRIM_PRJ_NBR", StringComparison.OrdinalIgnoreCase) || key.Name.Equals("PROJNO", StringComparison.OrdinalIgnoreCase));
        }

        public override FinancialProjectData GetLinkData(Feature o)
        {
            if (ContainsCombinedFinProjData(o))
            {
                var finProjKey = GetCombinedFinProjDataKey(o);
                return ParseFinProj(o[finProjKey].ToString());
            }

            var itemKey = o.FeatureType.Attributes.FirstOrDefault(key => key.Name.Equals("WPITEM", StringComparison.OrdinalIgnoreCase));
            var segmentKey = o.FeatureType.Attributes.FirstOrDefault(key => key.Name.Equals("WPITMSEG", StringComparison.OrdinalIgnoreCase));
            var phaseKey = o.FeatureType.Attributes.FirstOrDefault(key => key.Name.Equals("WPPHGPTP", StringComparison.OrdinalIgnoreCase));
            var sequenceKey = o.FeatureType.Attributes.FirstOrDefault(key => key.Name.Equals("FINPRJSQ", StringComparison.OrdinalIgnoreCase));

            var data = new FinancialProjectData { Item = o[itemKey].ToString() };

            if (segmentKey != null && o[segmentKey] != null)
                data.Segment = o[segmentKey].ToString();

            if (phaseKey != null && o[phaseKey] != null)
                data.Phase = o[phaseKey].ToString();

            if (sequenceKey != null && o[sequenceKey] != null)
                data.Sequence = o[sequenceKey].ToString();

            return data;
        }

        private static FinancialProjectData ParseFinProj(string finproj)
        {
            if (string.IsNullOrEmpty(finproj)) return null;
            var trimmedFinProj = finproj.Trim();
            if (trimmedFinProj.Length < 6 || trimmedFinProj.Length > 11) return null;

            var data = new FinancialProjectData { Item = trimmedFinProj.Substring(0, 6) };

            if (trimmedFinProj.Length >= 7)
                data.Segment = trimmedFinProj.Substring(6, 1);

            if (trimmedFinProj.Length >= 9)
                data.Phase = trimmedFinProj.Substring(7, 2);

            if (trimmedFinProj.Length >= 11)
                data.Sequence = trimmedFinProj.Substring(9, 2);

            return data;
        }

    }

See Also

Any Questions or Comments? Email
Some of the icons created by FamFamFam.