public string GetResultLabel(FetchQuerySettings config)
        {
            string label     = _entityMetadata[config.RootEntity.LogicalName].DisplayCollectionName.UserLocalizedLabel.Label;
            int?   totalRows = config.DataView.GetLength();

            return(label + "(" + totalRows.ToString() + ")");
        }
        public MultiSearchViewModel2013()
        {
            OrganizationServiceProxy.WithCredentials = true;

            // Get Config
            Dictionary <string, string> dataConfig = PageEx.GetWebResourceData();

            // Query the quick search entities
            QueryQuickSearchEntities();
            Dictionary <string, Entity> views = GetViewQueries();

            _parser = new QueryParser();

            foreach (string typeName in _entityTypeNames)
            {
                Entity view      = views[typeName];
                string fetchXml  = view.GetAttributeValueString("fetchxml");
                string layoutXml = view.GetAttributeValueString("layoutxml");

                // Parse the fetch and layout to get the attributes and columns
                FetchQuerySettings config = _parser.Parse(fetchXml, layoutXml);
                config.RecordCount = Knockout.Observable <string>();

                config.DataView = new VirtualPagedEntityDataViewModel(25, typeof(Entity), true);
                config.RecordCount.SetValue(GetResultLabel(config));
                Config.Push(config);


                // Wire up record count change
                config.DataView.OnPagingInfoChanged.Subscribe(OnPagingInfoChanged(config));
            }

            _parser.QueryDisplayNames();
        }
Ejemplo n.º 3
0
        public string GetFetchXmlForQuery(FetchQuerySettings config, string searchTerm)
        {
            jQueryObject fetchElement = config.FetchXml.Find("fetch");

            fetchElement.Attribute("count", "{0}");
            fetchElement.Attribute("paging-cookie", "{1}");
            fetchElement.Attribute("page", "{2}");
            fetchElement.Attribute("returntotalrecordcount", "true");
            fetchElement.Attribute("distinct", "true");
            fetchElement.Attribute("no-lock", "true");

            jQueryObject orderByElement = fetchElement.Find("order");

            orderByElement.Remove();

            // Add the search string and adjust any lookup columns
            jQueryObject conditions = fetchElement.Find("filter[isquickfindfields='1']");

            conditions.First().Children().Each(delegate(int index, Element element)
            {
                // Is this a lookup column?
                string logicalName = element.GetAttribute("attribute").ToString();
                if (LookupAttributes.ContainsKey(logicalName))
                {
                    element.SetAttribute("attribute", logicalName + "name");
                }
            });
            // Add the sort order placeholder
            string fetchXml = config.FetchXml.GetHtml().Replace("</entity>", "{3}</entity>");

            // Add the Query term
            fetchXml = fetchXml.Replace("#Query#", XmlHelper.Encode(searchTerm));
            return(fetchXml);
        }
 private Action <EventData, object> OnPagingInfoChanged(FetchQuerySettings config)
 {
     return(delegate(EventData e, object p)
     {
         PagingInfo paging = (PagingInfo)p;
         config.RecordCount.SetValue(GetResultLabel(config));
     });
 }
Ejemplo n.º 5
0
 private Action<EventData,object> OnPagingInfoChanged(FetchQuerySettings config)
 {
     return delegate(EventData e, object p)
     {
         PagingInfo paging = (PagingInfo)p;
         config.RecordCount.SetValue(GetResultLabel(config));
     };
 }
Ejemplo n.º 6
0
        private void ParseFetchXml(FetchQuerySettings querySettings)
        {
            jQueryObject fetchElement = querySettings.FetchXml;

            // Get the entities and link entities - only support 1 level deep
            jQueryObject entityElement = fetchElement.Find("entity");
            string       logicalName   = entityElement.GetAttribute("name");

            EntityQuery rootEntity;

            // Get query from cache or create new
            if (!EntityLookup.ContainsKey(logicalName))
            {
                rootEntity             = new EntityQuery();
                rootEntity.LogicalName = logicalName;
                rootEntity.Attributes  = new Dictionary <string, AttributeQuery>();
                EntityLookup[rootEntity.LogicalName] = rootEntity;
            }
            else
            {
                rootEntity = EntityLookup[logicalName];
            }

            // Get Linked Entities(1 deep)
            jQueryObject linkEntities = entityElement.Find("link-entity");

            linkEntities.Each(delegate(int index, Element element)
            {
                EntityQuery link = new EntityQuery();
                link.Attributes  = new Dictionary <string, AttributeQuery>();
                link.AliasName   = element.GetAttribute("alias").ToString();
                link.LogicalName = element.GetAttribute("name").ToString();

                if (!EntityLookup.ContainsKey(link.LogicalName))
                {
                    EntityLookup[link.LogicalName] = link;
                }
                else
                {
                    string alias   = link.AliasName;
                    link           = EntityLookup[link.LogicalName];
                    link.AliasName = alias;
                }

                if (!AliasEntityLookup.ContainsKey(link.AliasName))
                {
                    AliasEntityLookup[link.AliasName] = link;
                }
            });

            querySettings.RootEntity = rootEntity;
        }
        public string GetEntityDisplayName(int index)
        {
            FetchQuerySettings[] settings = Config.GetItems();

            if (index >= settings.Length)
            {
                return(string.Empty);
            }
            else
            {
                FetchQuerySettings config = settings[index];
                int?   totalRows          = config.DataView.GetLength();
                string label = _entityMetadata[config.RootEntity.LogicalName].DisplayCollectionName.UserLocalizedLabel.Label;
                return(label + "(" + totalRows.ToString() + ")");
            }
        }
Ejemplo n.º 8
0
        public MultiSearchViewModel2013()
        {
            //OrganizationServiceProxy.WithCredentials = true;
            DependentObservableOptions <string> throttledSearchTermObservable = new DependentObservableOptions <string>();

            throttledSearchTermObservable.Model            = this;
            throttledSearchTermObservable.GetValueFunction = new Func <string>(delegate
            {
                return(this.SearchTerm.GetValue());
            });
            ThrottledSearchTerm = Knockout.DependentObservable <string>(throttledSearchTermObservable).Extend(new Dictionary("throttle", 400));
            ThrottledSearchTerm.Subscribe(new Action <string>(delegate(string search)
            {
                // Search whilst typing using the throttle extension
                SearchCommand();
            }));

            // Get Config
            Dictionary <string, string> dataConfig = PageEx.GetWebResourceData();

            // Query the quick search entities
            QueryQuickSearchEntities();
            Dictionary <string, Entity> views = GetViewQueries();

            _parser = new QueryParser();

            foreach (string typeName in _entityTypeNames)
            {
                Entity view      = views[typeName];
                string fetchXml  = view.GetAttributeValueString("fetchxml");
                string layoutXml = view.GetAttributeValueString("layoutxml");

                // Parse the fetch and layout to get the attributes and columns
                FetchQuerySettings config = _parser.Parse(fetchXml, layoutXml);
                config.RecordCount = Knockout.Observable <string>();

                config.DataView = new VirtualPagedEntityDataViewModel(25, typeof(Entity), true);
                config.RecordCount.SetValue(GetResultLabel(config));
                Config.Push(config);


                // Wire up record count change
                config.DataView.OnPagingInfoChanged.Subscribe(OnPagingInfoChanged(config));
            }

            _parser.QueryDisplayNames();
        }
Ejemplo n.º 9
0
        public FetchQuerySettings Parse(string fetchXml, string layoutXml)
        {
            FetchQuerySettings querySettings = new FetchQuerySettings();

            querySettings.Columns = new List <Column>();

            jQueryObject fetchXmlDOM  = jQuery.FromHtml("<query>" + fetchXml.Replace("{0}", "#Query#") + "</query>");
            jQueryObject fetchElement = fetchXmlDOM.Find("fetch");

            querySettings.FetchXml = fetchXmlDOM;

            ParseFetchXml(querySettings);

            querySettings.Columns = ParseLayoutXml(querySettings.RootEntity, layoutXml);

            return(querySettings);
        }
Ejemplo n.º 10
0
        public FetchQuerySettings Parse(string fetchXml, string layoutXml)
        {
           
            FetchQuerySettings querySettings = new FetchQuerySettings();
            
            querySettings.Columns = new List<Column>();

            jQueryObject fetchXmlDOM = jQuery.FromHtml("<query>" + fetchXml.Replace("{0}", "#Query#") + "</query>");
            jQueryObject fetchElement = fetchXmlDOM.Find("fetch");
            querySettings.FetchXml = fetchXmlDOM;

            ParseFetchXml(querySettings);
           
            querySettings.Columns = ParseLayoutXml(querySettings.RootEntity, layoutXml);

            return querySettings;

        }
Ejemplo n.º 11
0
        public ActivitySubGridViewModel()
        {

            // Get the Quick Find View for the entity
            string getviewfetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                              <entity name='savedquery'>
                                <attribute name='name' />
                                <attribute name='fetchxml' />
                                <attribute name='layoutxml' />
                                <attribute name='returnedtypecode' />
                                <filter type='and'>
                                <filter type='or'>";

            getviewfetchXml += @"<condition attribute='returnedtypecode' operator='eq' value='" + "4200" + @"'/>";
            
            getviewfetchXml += @"
                                    </filter>
                                 <condition attribute='isquickfindquery' operator='eq' value='1'/>
                                    <condition attribute='isdefault' operator='eq' value='1'/>
                                </filter>
                               
                              </entity>
                            </fetch>";
            // Get the Quick Find View
            EntityCollection quickFindQuery = OrganizationServiceProxy.RetrieveMultiple(getviewfetchXml);
            _parser = new QueryParser();
            Entity view = quickFindQuery.Entities[0];
            string fetchXml = view.GetAttributeValueString("fetchxml");
            string layoutXml = view.GetAttributeValueString("layoutxml");

            // Parse the fetch and layout to get the attributes and columns
            ViewConfig = _parser.Parse(fetchXml, layoutXml);
            ViewConfig.DataView = new EntityDataViewModel(10, typeof(Entity), true);
            
            // Load the display name metadata
            _parser.QueryDisplayNames();
            
           
        }
Ejemplo n.º 12
0
        public MultiSearchViewModel()
        {
            // Get Config
            Dictionary <string, string> dataConfig = PageEx.GetWebResourceData();

            List <string> typeCodes = new List <string>();
            List <string> typeNames = new List <string>();

            // There is an odd behaviour with the savedquery fetchxml where you query with typecodes and get back typenames
            // so we need both to preserve the display order
            if (dataConfig.ContainsKey("typeCodes"))
            {
                typeCodes = (List <string>)(object) dataConfig["typeCodes"].Split(",");
                typeNames = (List <string>)(object) dataConfig["typeNames"].Split(",");
            }
            else
            {
                typeCodes = new List <string>("1", "2", "4", "4200", "3");
                typeNames = new List <string>("account", "contact", "lead", "activitypointer", "opportunity");
            }

            // Get the Quick Find View for the entity
            string getviewfetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                              <entity name='savedquery'>
                                <attribute name='name' />
                                <attribute name='fetchxml' />
                                <attribute name='layoutxml' />
                                <attribute name='returnedtypecode' />
                                <filter type='and'>
                                <filter type='or'>";

            foreach (string view in typeCodes)
            {
                getviewfetchXml += @"<condition attribute='returnedtypecode' operator='eq' value='" + view + @"'/>";
            }
            getviewfetchXml += @"
                                    </filter>
                                 <condition attribute='isquickfindquery' operator='eq' value='1'/>
                                    <condition attribute='isdefault' operator='eq' value='1'/>
                                </filter>
                               
                              </entity>
                            </fetch>";
            // Get the Quick Find View
            EntityCollection quickFindQuery = OrganizationServiceProxy.RetrieveMultiple(getviewfetchXml);

            parser = new QueryParser();
            Dictionary <string, Entity> entityLookup = new Dictionary <string, Entity>();

            // Preseve the requested view order
            foreach (Entity view in quickFindQuery.Entities)
            {
                entityLookup[view.GetAttributeValueString("returnedtypecode")] = view;
            }
            foreach (string typeName in typeNames)
            {
                Entity view      = entityLookup[typeName];
                string fetchXml  = view.GetAttributeValueString("fetchxml");
                string layoutXml = view.GetAttributeValueString("layoutxml");

                // Parse the fetch and layout to get the attributes and columns
                FetchQuerySettings config = parser.Parse(fetchXml, layoutXml);
                config.DataView = new EntityDataViewModel(10, typeof(Entity), true);
                Config.Push(config);
            }

            // Load the display name metadata
            parser.QueryDisplayNames();
        }
 public string GetResultLabel(FetchQuerySettings config)
 {
     string label = _entityMetadata[config.RootEntity.LogicalName].DisplayCollectionName.UserLocalizedLabel.Label;
     int? totalRows = config.DataView.GetLength();
     return label + " (" + totalRows.ToString() + ")";
 }
Ejemplo n.º 14
0
        private void ParseFetchXml(FetchQuerySettings querySettings)
        {
            jQueryObject fetchElement = querySettings.FetchXml;

            // Get the entities and link entities - only support 1 level deep
            jQueryObject entityElement = fetchElement.Find("entity");
            string logicalName = entityElement.GetAttribute("name");

            EntityQuery rootEntity;
            // Get query from cache or create new
            if (!EntityLookup.ContainsKey(logicalName))
            {
                rootEntity = new EntityQuery();
                rootEntity.LogicalName = logicalName;
                rootEntity.Attributes = new Dictionary<string, AttributeQuery>();
                EntityLookup[rootEntity.LogicalName] = rootEntity;
            }
            else
            {
                rootEntity = EntityLookup[logicalName];
            }

            // Get Linked Entities(1 deep)
            jQueryObject linkEntities = entityElement.Find("link-entity");
            linkEntities.Each(delegate(int index, Element element)
            {
                EntityQuery link = new EntityQuery();
                link.Attributes = new Dictionary<string, AttributeQuery>();
                link.AliasName = element.GetAttribute("alias").ToString();
                link.LogicalName =  element.GetAttribute("name").ToString();

                if (!EntityLookup.ContainsKey(link.LogicalName))
                {
                    EntityLookup[link.LogicalName] = link;
                }
                else
                {
                    string alias = link.AliasName;
                    link = EntityLookup[link.LogicalName];
                    link.AliasName = alias;
                }

                if (!AliasEntityLookup.ContainsKey(link.AliasName))
                {
                    AliasEntityLookup[link.AliasName] = link;
                }
            });

            querySettings.RootEntity = rootEntity;

            // Issue #35 - Add any lookup/picklist quick find fields that are not included in results attributes will cause a format execption
            // because we don't have the metadata - this means that 'name' is not appended to the attribute

            // Add the search string and adjust any lookup columns
            jQueryObject conditions = fetchElement.Find("filter[isquickfindfields='1']");
            conditions.First().Children().Each(delegate(int index, Element element)
            {
                logicalName = element.GetAttribute("attribute").ToString();
                jQueryObject e = jQuery.FromElement(element);
                jQueryObject p =e.Parents("link-entity");
                if (!querySettings.RootEntity.Attributes.ContainsKey(logicalName))
                {
                    AttributeQuery attribute = new AttributeQuery();
                    attribute.LogicalName = logicalName;
                    attribute.Columns = new List<Column>();
                    querySettings.RootEntity.Attributes[logicalName] = attribute;
                }
            });

        }
Ejemplo n.º 15
0
        private void ParseFetchXml(FetchQuerySettings querySettings)
        {
            jQueryObject fetchElement = querySettings.FetchXml;

            // Get the entities and link entities - only support 1 level deep
            jQueryObject entityElement = fetchElement.Find("entity");
            string       logicalName   = entityElement.GetAttribute("name");

            EntityQuery rootEntity;

            // Get query from cache or create new
            if (!EntityLookup.ContainsKey(logicalName))
            {
                rootEntity             = new EntityQuery();
                rootEntity.LogicalName = logicalName;
                rootEntity.Attributes  = new Dictionary <string, AttributeQuery>();
                EntityLookup[rootEntity.LogicalName] = rootEntity;
            }
            else
            {
                rootEntity = EntityLookup[logicalName];
            }

            // Get Linked Entities(1 deep)
            jQueryObject linkEntities = entityElement.Find("link-entity");

            linkEntities.Each(delegate(int index, Element element)
            {
                EntityQuery link = new EntityQuery();
                link.Attributes  = new Dictionary <string, AttributeQuery>();
                link.AliasName   = element.GetAttribute("alias").ToString();
                link.LogicalName = element.GetAttribute("name").ToString();

                if (!EntityLookup.ContainsKey(link.LogicalName))
                {
                    EntityLookup[link.LogicalName] = link;
                }
                else
                {
                    string alias   = link.AliasName;
                    link           = EntityLookup[link.LogicalName];
                    link.AliasName = alias;
                }

                if (!AliasEntityLookup.ContainsKey(link.AliasName))
                {
                    AliasEntityLookup[link.AliasName] = link;
                }
            });

            querySettings.RootEntity = rootEntity;

            // Issue #35 - Add any lookup/picklist quick find fields that are not included in results attributes will cause a format execption
            // because we don't have the metadata - this means that 'name' is not appended to the attribute

            // Add the search string and adjust any lookup columns
            jQueryObject conditions = fetchElement.Find("filter[isquickfindfields='1']");

            conditions.First().Children().Each(delegate(int index, Element element)
            {
                logicalName    = element.GetAttribute("attribute").ToString();
                jQueryObject e = jQuery.FromElement(element);
                jQueryObject p = e.Parents("link-entity");
                if (!querySettings.RootEntity.Attributes.ContainsKey(logicalName))
                {
                    AttributeQuery attribute = new AttributeQuery();
                    attribute.LogicalName    = logicalName;
                    attribute.Columns        = new List <Column>();
                    querySettings.RootEntity.Attributes[logicalName] = attribute;
                }
            });
        }
Ejemplo n.º 16
0
        private void ParseFetchXml(FetchQuerySettings querySettings)
        {
            jQueryObject fetchElement = querySettings.FetchXml;

            // Get the entities and link entities - only support 1 level deep
            jQueryObject entityElement = fetchElement.Find("entity");
            string logicalName = entityElement.GetAttribute("name");

            EntityQuery rootEntity;
            // Get query from cache or create new
            if (!EntityLookup.ContainsKey(logicalName))
            {
                rootEntity = new EntityQuery();
                rootEntity.LogicalName = logicalName;
                rootEntity.Attributes = new Dictionary<string, AttributeQuery>();
                EntityLookup[rootEntity.LogicalName] = rootEntity;
            }
            else
            {
                rootEntity = EntityLookup[logicalName];
            }

            // Get Linked Entities(1 deep)
            jQueryObject linkEntities = entityElement.Find("link-entity");
            linkEntities.Each(delegate(int index, Element element)
            {
                EntityQuery link = new EntityQuery();
                link.Attributes = new Dictionary<string, AttributeQuery>();
                link.AliasName = element.GetAttribute("alias").ToString();
                link.LogicalName =  element.GetAttribute("name").ToString();

                if (!EntityLookup.ContainsKey(link.LogicalName))
                {
                    EntityLookup[link.LogicalName] = link;
                }
                else
                {
                    string alias = link.AliasName;
                    link = EntityLookup[link.LogicalName];
                    link.AliasName = alias;
                }

                if (!AliasEntityLookup.ContainsKey(link.AliasName))
                {
                    AliasEntityLookup[link.AliasName] = link;
                }
            });

            querySettings.RootEntity = rootEntity;
        }
Ejemplo n.º 17
0
        public string GetFetchXmlForQuery(FetchQuerySettings config, string searchTerm)
        {
            jQueryObject fetchElement = config.FetchXml.Find("fetch");
            fetchElement.Attribute("count", "{0}");
            fetchElement.Attribute("paging-cookie", "{1}");
            fetchElement.Attribute("page", "{2}");
            fetchElement.Attribute("returntotalrecordcount", "true");
            fetchElement.Attribute("distinct", "true");
            fetchElement.Attribute("no-lock", "true");

            jQueryObject orderByElement = fetchElement.Find("order");
            orderByElement.Remove();

            // Add the search string and adjust any lookup columns
            jQueryObject conditions = fetchElement.Find("filter[isquickfindfields='1']");

            conditions.First().Children().Each(delegate(int index, Element element)
            {
                // Is this a lookup column?
                string logicalName = element.GetAttribute("attribute").ToString();
                if (LookupAttributes.ContainsKey(logicalName))
                {
                    element.SetAttribute("attribute", logicalName + "name");
                }
            });
            // Add the sort order placeholder
            string fetchXml = config.FetchXml.GetHtml().Replace("</entity>", "{3}</entity>");

            // Add the Query term
            fetchXml = fetchXml.Replace("#Query#", XmlHelper.Encode(searchTerm));
            return fetchXml;
        }