Example #1
0
        public static Guid GetListID(DataFormWebPart dfwp)
        {
#if SP12
            return(ProductPage.GetGuid(dfwp.ListName, true));
#else
            return(dfwp.ListId);
#endif
        }
        private static void RestoreDataViewInZone(SPWeb web, string filePath)
        {
            if (!File.Exists(filePath) || web == null)
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(filePath);
            }
            catch (XmlException)
            {
                return;
            }

            XmlNodeList xFixupFiles = doc.DocumentElement.SelectNodes("FixupFiles/FixupFile[@DataViewInZone=\"TRUE\"]");

            foreach (XmlNode xFixupFile in xFixupFiles)
            {
                XmlAttribute xRelativePath = xFixupFile.Attributes["RelativePath"];
                if (xRelativePath == null)
                {
                    continue;
                }
                string relativePath = xRelativePath.Value;

                SPFile file = web.GetFile(relativePath);
                if (file == null)
                {
                    continue;
                }

                SPLimitedWebPartManager    manager      = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
                SPLimitedWebPartCollection pageWebParts = manager.WebParts;
                if (pageWebParts == null)
                {
                    continue;
                }

                foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in pageWebParts)
                {
                    DataFormWebPart dataForm = webPart as DataFormWebPart;
                    if (dataForm == null)
                    {
                        continue;
                    }

                    SubstituteGuidInZone(web, manager, dataForm, filePath);
                }
            }
        }
        public static void Apply(roxority_FilterWebPart filterWebPart, DataFormWebPart bdcListWebPart)
        {
            BdcDataSource dataSource = bdcListWebPart.DataSource as BdcDataSource;
            List <roxority_FilterZen.FilterBase> filters = filterWebPart.GetFilters();
            List <KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> > > list2 = new List <KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> > >();
            Dictionary <string, roxority_FilterZen.FilterBase> dictionary = new Dictionary <string, roxority_FilterZen.FilterBase>();

            foreach (roxority_FilterZen.FilterBase base3 in filters)
            {
                dictionary[base3.Name] = base3;
            }
            using (List <KeyValuePair <string, roxority_FilterWebPart.FilterPair> > .Enumerator enumerator2 = filterWebPart.PartFilters.GetEnumerator())
            {
                Predicate <KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> > > match = null;
                KeyValuePair <string, roxority_FilterWebPart.FilterPair> kvp;
                while (enumerator2.MoveNext())
                {
                    kvp = enumerator2.Current;
                    KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> > item = new KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> >(kvp.Key, new List <roxority_FilterWebPart.FilterPair>());
                    if (list2.Count > 0)
                    {
                        if (match == null)
                        {
                            match = test => test.Key.Equals(kvp.Key);
                        }
                        item = list2.Find(match);
                    }
                    if (string.IsNullOrEmpty(item.Key) || (kvp.Value == null))
                    {
                        item = new KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> >(kvp.Key, new List <roxority_FilterWebPart.FilterPair>());
                    }
                    list2.Remove(item);
                    item.Value.Add(kvp.Value);
                    list2.Add(item);
                }
            }
            foreach (KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> > pair2 in list2)
            {
                foreach (roxority_FilterWebPart.FilterPair pair3 in pair2.Value)
                {
                    roxority_FilterZen.FilterBase base2;
                    Microsoft.SharePoint.WebControls.BusinessDataParameter parameter = new Microsoft.SharePoint.WebControls.BusinessDataParameter();
                    if (dictionary.TryGetValue(pair3.Key, out base2))
                    {
                        parameter.ConvertEmptyStringToNull = !base2.SendEmpty;
                    }
                    parameter.Name         = pair3.Key;
                    parameter.DefaultValue = pair3.Value;
                    parameter.Direction    = ParameterDirection.Input;
                    parameter.Operator     = ConvertCamlOperator(pair3.CamlOperator);
                    dataSource.FilterParameters.Add(parameter);
                }
            }
        }
Example #4
0
        public static void Apply(roxority_FilterWebPart filterWebPart, DataFormWebPart bdcListWebPart)
        {
            BdcDataSource         dataSource = bdcListWebPart.DataSource as BdcDataSource;
            BusinessDataParameter param;
            FilterBase            filter;
            List <FilterBase>     filters = filterWebPart.GetFilters();
            List <KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> > > filterValues = new List <KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> > > ();
            Dictionary <string, FilterBase> allFilters = new Dictionary <string, FilterBase> ();
            KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> > tmp;

            foreach (FilterBase fb in filters)
            {
                allFilters [fb.Name] = fb;
            }
            foreach (KeyValuePair <string, roxority_FilterWebPart.FilterPair> kvp in filterWebPart.PartFilters)
            {
                tmp = new KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> > (kvp.Key, new List <roxority_FilterWebPart.FilterPair> ());
                if (filterValues.Count > 0)
                {
                    tmp = filterValues.Find(delegate(KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> > test) {
                        return(test.Key.Equals(kvp.Key));
                    });
                }
                if (string.IsNullOrEmpty(tmp.Key) || (kvp.Value == null))
                {
                    tmp = new KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> > (kvp.Key, new List <roxority_FilterWebPart.FilterPair> ());
                }
                filterValues.Remove(tmp);
                tmp.Value.Add(kvp.Value);
                filterValues.Add(tmp);
            }
            foreach (KeyValuePair <string, List <roxority_FilterWebPart.FilterPair> > kvp in filterValues)
            {
                foreach (roxority_FilterWebPart.FilterPair pair in kvp.Value)
                {
                    param = new BusinessDataParameter();
                    if (allFilters.TryGetValue(pair.Key, out filter))
                    {
                        param.ConvertEmptyStringToNull = !filter.SendEmpty;
                    }
                    param.Name         = pair.Key;
                    param.DefaultValue = pair.Value;
                    param.Direction    = ParameterDirection.Input;
                    param.Operator     = ConvertCamlOperator(pair.CamlOperator);
                    dataSource.FilterParameters.Add(param);
                }
            }
        }
        private void SubstituteGuidInZone(SPWeb web, SPLimitedWebPartManager manager, DataFormWebPart dataForm, string filePath)
        {
            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(filePath);
            }
            catch (XmlException)
            {
                return;
            }

            XmlNode xListInstances = doc.DocumentElement.SelectSingleNode("ListInstances");
            if (xListInstances == null)
            {
                return;
            }
            foreach (XmlNode xListInstance in xListInstances.ChildNodes)
            {
                if (xListInstance.Attributes["Id"] == null ||
                    xListInstance.Attributes["Title"] == null)
                {
                    return;
                }

                string oldId = xListInstance.Attributes["Id"].Value;
                string title = xListInstance.Attributes["Title"].Value;

                SPList list = null;
                try
                {
                    list = web.Lists[title];
                }
                catch (ArgumentException)
                {
                    continue;
                }

                if (list == null)
                {
                    continue;
                }
                string newId = list.ID.ToString();

                dataForm.ParameterBindings = Regex.Replace(dataForm.ParameterBindings, oldId, newId, RegexOptions.IgnoreCase);
                dataForm.DataSourcesString = Regex.Replace(dataForm.DataSourcesString, oldId, newId, RegexOptions.IgnoreCase);
                dataForm.Xsl = Regex.Replace(dataForm.Xsl, oldId, newId, RegexOptions.IgnoreCase);

                manager.SaveChanges(dataForm);
            }
        }
Example #6
0
 public static bool CanApply(roxority_FilterWebPart filterWebPart, DataFormWebPart bdcListWebPart)
 {
     return(bdcListWebPart.DataSource is BdcDataSource);
 }
        /// <summary>
        /// Replaces the content of a <see cref="DataFormWebPart"/> web part.
        /// </summary>
        /// <param name="web">The web that the file belongs to.</param>
        /// <param name="file">The file that the web part is associated with.</param>
        /// <param name="settings">The settings object containing user provided parameters.</param>
        /// <param name="wp">The web part whose content will be replaced.</param>
        /// <param name="regex">The regular expression object which contains the search pattern.</param>
        /// <param name="manager">The web part manager.  This value may get updated during this method call.</param>
        /// <param name="wasCheckedOut">if set to <c>true</c> then the was checked out prior to this method being called.</param>
        /// <param name="modified">if set to <c>true</c> then the web part was modified as a result of this method being called.</param>
        /// <returns>
        /// The modified web part.  This returned web part is what must be used when saving any changes.
        /// </returns>
        internal static WebPart ReplaceValues(SPWeb web,
           SPFile file,
           Settings settings,
           DataFormWebPart wp,
           Regex regex,
           ref SPLimitedWebPartManager manager,
           ref bool wasCheckedOut,
           ref bool modified)
        {
            if (string.IsNullOrEmpty(wp.DataSourcesString) && string.IsNullOrEmpty(wp.ParameterBindings) && string.IsNullOrEmpty(wp.ListName) && string.IsNullOrEmpty(wp.Xsl) && string.IsNullOrEmpty(wp.XslLink))
                return wp;

            bool isDataSourcesMatch = false;
            if (!string.IsNullOrEmpty(wp.DataSourcesString))
                isDataSourcesMatch = regex.IsMatch(wp.DataSourcesString);

            bool isParameterBindingsMatch = false;
            if (!string.IsNullOrEmpty(wp.ParameterBindings))
                isParameterBindingsMatch = regex.IsMatch(wp.ParameterBindings);

            bool isListNameMatch = false;
            if (!string.IsNullOrEmpty(wp.ListName))
                isListNameMatch = regex.IsMatch(wp.ListName);

            bool isXslMatch = false;
            if (!string.IsNullOrEmpty(wp.Xsl))
                isXslMatch = regex.IsMatch(wp.Xsl);

            bool isXslLinkMatch = false;
            if (!string.IsNullOrEmpty(wp.XslLink))
                isXslLinkMatch = regex.IsMatch(wp.XslLink);

            if (!isDataSourcesMatch && !isParameterBindingsMatch && !isListNameMatch && !isXslMatch && !isXslLinkMatch)
                return wp;

            string dataSourcesContent = wp.DataSourcesString;
            string parameterBindingsContent = wp.ParameterBindings;
            string listNameContent = wp.ListName;
            string xslContent = wp.Xsl;
            string xslLinkContent = wp.XslLink;

            string dataSourcesResult = dataSourcesContent;
            string parameterBindingsResult = parameterBindingsContent;
            string listNameResult = listNameContent;
            string xslResult = xslContent;
            string xslLinkResult = xslLinkContent;

            if (!string.IsNullOrEmpty(dataSourcesContent))
                dataSourcesResult = regex.Replace(dataSourcesContent, settings.ReplaceString);
            if (!string.IsNullOrEmpty(listNameContent))
                listNameResult = regex.Replace(listNameContent, settings.ReplaceString);
            try
            {
                if (!string.IsNullOrEmpty(parameterBindingsContent))
                {
                    if (!settings.UnsafeXml)
                        parameterBindingsResult = ReplaceXmlValues(regex, settings.ReplaceString, parameterBindingsContent);
                    else
                        parameterBindingsResult = regex.Replace(parameterBindingsContent, settings.ReplaceString);
                }
            }
            catch (XmlException ex)
            {
                isParameterBindingsMatch = false;
                string msg = string.Format(
                    "WARNING: An error occured replacing data in a DataFormWebPart: File={0}, WebPart={1}\r\n{2}",
                    file.ServerRelativeUrl, wp.Title, Utilities.FormatException(ex));
                Logger.WriteWarning(msg);
            }
            if (!string.IsNullOrEmpty(xslContent))
                xslResult = regex.Replace(xslContent, settings.ReplaceString);
            if (!string.IsNullOrEmpty(xslLinkContent))
                xslLinkResult = regex.Replace(xslLinkContent, settings.ReplaceString);

            if (isDataSourcesMatch)
                Logger.Write("Match found: File={0}, WebPart={1}, Replacement={2} => {3}",
                                  file.ServerRelativeUrl, wp.Title, dataSourcesContent, dataSourcesResult);
            if (isParameterBindingsMatch)
                Logger.Write("Match found: File={0}, WebPart={1}, Replacement={2} => {3}",
                                  file.ServerRelativeUrl, wp.Title, parameterBindingsContent, parameterBindingsResult);
            if (isListNameMatch)
                Logger.Write("Match found: File={0}, WebPart={1}, Replacement={2} => {3}",
                                  file.ServerRelativeUrl, wp.Title, listNameContent, listNameResult);
            if (isXslMatch)
                Logger.Write("Match found: File={0}, WebPart={1}, Replacement={2} => {3}",
                                  file.ServerRelativeUrl, wp.Title, xslContent, xslResult);
            if (isXslLinkMatch)
                Logger.Write("Match found: File={0}, WebPart={1}, Replacement={2} => {3}",
                                  file.ServerRelativeUrl, wp.Title, xslLinkContent, xslLinkResult);
            if (!settings.Test)
            {
                if (file.CheckOutType == SPFile.SPCheckOutType.None)
                {
                    file.CheckOut();
                    wasCheckedOut = false;
                }
                // We need to reset the manager and the web part because a checkout (now or from an earlier call)
                // could mess things up so safest to just reset every time.
                manager.Web.Dispose(); // manager.Dispose() does not dispose of the SPWeb object and results in a memory leak.
                manager.Dispose();
                manager = web.GetLimitedWebPartManager(file.Url, PersonalizationScope.Shared);

                wp.Dispose();
                wp = (DataFormWebPart)manager.WebParts[wp.ID];

                if (isDataSourcesMatch)
                    wp.DataSourcesString = dataSourcesResult;
                if (isParameterBindingsMatch)
                    wp.ParameterBindings = parameterBindingsResult;
                if (isListNameMatch)
                    wp.ListName = listNameResult;
                if (isXslMatch)
                    wp.Xsl = xslResult;
                if (isXslLinkMatch)
                    wp.XslLink = xslLinkResult;

                modified = true;
            }
            return wp;
        }
        private static void SubstituteGuidInZone(SPWeb web, SPLimitedWebPartManager manager, DataFormWebPart dataForm, string filePath)
        {
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(filePath);
            }
            catch (XmlException)
            {
                return;
            }

            XmlNode xListInstances = doc.DocumentElement.SelectSingleNode("ListInstances");

            if (xListInstances == null)
            {
                return;
            }
            foreach (XmlNode xListInstance in xListInstances.ChildNodes)
            {
                if (xListInstance.Attributes["Id"] == null ||
                    xListInstance.Attributes["Title"] == null)
                {
                    return;
                }

                string oldId = xListInstance.Attributes["Id"].Value;
                string title = xListInstance.Attributes["Title"].Value;

                SPList list = null;
                try
                {
                    list = web.Lists[title];
                }
                catch (ArgumentException)
                {
                    continue;
                }

                if (list == null)
                {
                    continue;
                }
                string newId = list.ID.ToString();

                dataForm.ParameterBindings = Regex.Replace(dataForm.ParameterBindings, oldId, newId, RegexOptions.IgnoreCase);
                dataForm.DataSourcesString = Regex.Replace(dataForm.DataSourcesString, oldId, newId, RegexOptions.IgnoreCase);
                dataForm.Xsl = Regex.Replace(dataForm.Xsl, oldId, newId, RegexOptions.IgnoreCase);

                manager.SaveChanges(dataForm);
            }
        }