Esempio n. 1
0
        /// <summary>
        /// Creates a query to load an instance and a set of options paths.
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="scope"></param>
        /// <param name="paths"></param>
        /// <returns></returns>
        public static ServiceRequest.Query Query(object instance, ViewScope scope, params string[] paths)
        {
            ModelType type;

            ModelInstance[] roots;
            bool            isList;

            if (ExoWeb.TryConvertQueryInstance(instance, out type, out roots, out isList))
            {
                return(new ServiceRequest.Query(type, roots, scope == ViewScope.InScope, isList, paths));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
 public static IQueryable <TEntity> Scope <TEntity>(
     this IQueryable <TEntity> source, ViewScope scope)
     where TEntity : class, IListItemEntity, new()
 {
     Check.NotNull(source, nameof(source));
     if (source is SpEntityQueryable <TEntity, ISpEntryDataContext> )
     {
         var executor = (source as SpEntityQueryable <TEntity, ISpEntryDataContext>).GetExecutor();
         if (executor != null)
         {
             var args = (SpQueryArgs <ISpEntryDataContext>)executor.SpQueryArgs.Clone();
             args.ViewScope = scope;
             source         = new SpEntityQueryable <TEntity>(new SpEntityQueryable <TEntity>(args).Provider, source.Expression);
         }
     }
     return(source);
 }
        protected virtual object LocateForView(object view)
        {
            if (view == null)
                return null;
            var element = view as FrameworkElement;
            if (element != null && element.DataContext != null && (element.DataContext as INotifyPropertyChanged != null))
                return element.DataContext;

            var viewType = view.GetType();
            if (!_viewsToScope.ContainsKey(viewType))
            {
                var scope = Container.BeginLifetimeScope(viewType);
                _viewsToScope.Add(viewType, new ViewScope(view, scope));
            }
            else
            {
                var current = _viewsToScope[viewType];
                _viewsToScope[viewType] = new ViewScope(view, current.LifetimeScope);
            }

            return ViewModelLocator.LocateForViewType(viewType);
        }
Esempio n. 4
0
        /// <summary>
        /// Root &lt;View&gt; and &lt;Query&gt; nodes.
        /// </summary>
        /// <param name="scope">View scope</param>
        /// <param name="whereClause">&lt;Where&gt; node.</param>
        /// <param name="viewFields">&lt;ViewFields&gt; node.</param>
        /// <param name="orderByClause">&lt;OrderBy&gt; node.</param>
        /// <param name="rowLimit">&lt;RowLimit&gt; node.</param>
        /// <returns>String to be used in CAML queries</returns>
        public static string ViewQuery(ViewScope scope, string whereClause = "", string orderByClause = "", string viewFields = "", int rowLimit = 100)
        {
            string viewScopeStr = scope == ViewScope.DefaultValue ? string.Empty : scope.ToString();

            return(string.Format(VIEW_XML_WRAPPER, viewScopeStr, whereClause, orderByClause, viewFields, rowLimit));
        }
Esempio n. 5
0
 /// <summary>
 /// Root &lt;View&gt; and &lt;Query&gt; nodes.
 /// </summary>
 /// <param name="scope">View scope</param>
 /// <param name="whereClause">&lt;Where&gt; node.</param>
 /// <param name="viewFields">&lt;ViewFields&gt; node.</param>
 /// <param name="orderByClause">&lt;OrderBy&gt; node.</param>
 /// <param name="rowLimit">&lt;RowLimit&gt; node.</param>
 /// <returns>String to be used in CAML queries</returns>
 public static string ViewQuery(ViewScope scope, string whereClause = "", string orderByClause = "", string viewFields = "", int rowLimit = 100)
 {
     string viewScopeStr = scope == ViewScope.DefaultValue ? string.Empty : scope.ToString();
     return string.Format(VIEW_XML_WRAPPER, viewScopeStr, whereClause, orderByClause, viewFields, rowLimit);
 }
Esempio n. 6
0
 /// <summary>
 /// Creates a query to load an instance and a set of options paths.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="id"></param>
 /// <param name="scope"></param>
 /// <param name="paths"></param>
 /// <returns></returns>
 public static ServiceRequest.Query Query(Type type, string id, ViewScope scope, params string[] paths)
 {
     return(new ServiceRequest.Query(ModelContext.Current.GetModelType(type), new string[] { id }, scope == ViewScope.InScope, false, paths));
 }
Esempio n. 7
0
 /// <summary>
 /// Creates a query to load an instance and a set of options paths.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="id"></param>
 /// <param name="scope"></param>
 /// <param name="paths"></param>
 /// <returns></returns>
 public static ServiceRequest.Query Query <T>(string id, ViewScope scope, params string[] paths)
 {
     return(Query(typeof(T), id, scope, paths));
 }
        /// <summary>
        /// Get View Properties to update view.
        /// </summary>
        /// <param name="defaultView">Represents whether this is a default view.</param>
        /// <param name="displayName">Represents the display name.</param>
        /// <param name="fpmodified">Represents the whether the view has been modified by a client application.</param>
        /// <param name="viewScope">Represents whether and how files and sub-folders are included in a view.</param>
        /// <returns>The instance of UpdateViewHtml2ViewProperties.</returns>
        protected UpdateViewHtml2ViewProperties GetViewProperties(bool defaultView, string displayName, bool fpmodified, ViewScope viewScope)
        {
            UpdateViewHtml2ViewProperties update2ViewProperties = new UpdateViewHtml2ViewProperties();
            update2ViewProperties.View = new UpdateViewPropertiesDefinition();
            update2ViewProperties.View.DefaultView = defaultView.ToString();
            update2ViewProperties.View.DisplayName = displayName;
            update2ViewProperties.View.FPModified = fpmodified.ToString();
            update2ViewProperties.View.Scope = viewScope;

            return update2ViewProperties;
        }
Esempio n. 9
0
        private void CreateView(Web web, View view, ViewCollection existingViews, List createdList)
        {
            var viewElement        = XElement.Parse(view.SchemaXml);
            var displayNameElement = viewElement.Attribute("DisplayName");

            if (displayNameElement == null)
            {
                throw new ApplicationException("Invalid View element, missing a valid value for the attribute DisplayName.");
            }

            var existingView = existingViews.FirstOrDefault(v => v.Title == displayNameElement.Value);

            if (existingView != null)
            {
                existingView.DeleteObject();
                web.Context.ExecuteQueryRetry();
            }

            var viewTitle = displayNameElement.Value;

            // Type
            var viewTypeString = viewElement.Attribute("Type") != null?viewElement.Attribute("Type").Value : "None";

            viewTypeString = viewTypeString[0].ToString().ToUpper() + viewTypeString.Substring(1).ToLower();
            var viewType = (ViewType)Enum.Parse(typeof(ViewType), viewTypeString);

            // Fields
            string[] viewFields        = null;
            var      viewFieldsElement = viewElement.Descendants("ViewFields").FirstOrDefault();

            if (viewFieldsElement != null)
            {
                viewFields = (from field in viewElement.Descendants("ViewFields").Descendants("FieldRef") select field.Attribute("Name").Value).ToArray();
            }

            // Default view
            var viewDefault = viewElement.Attribute("DefaultView") != null && Boolean.Parse(viewElement.Attribute("DefaultView").Value);

            // Row limit
            var  viewPaged       = true;
            uint viewRowLimit    = 30;
            var  rowLimitElement = viewElement.Descendants("RowLimit").FirstOrDefault();

            if (rowLimitElement != null)
            {
                if (rowLimitElement.Attribute("Paged") != null)
                {
                    viewPaged = bool.Parse(rowLimitElement.Attribute("Paged").Value);
                }
                viewRowLimit = uint.Parse(rowLimitElement.Value);
            }

            // Query
            var viewQuery = new StringBuilder();

            foreach (var queryElement in viewElement.Descendants("Query").Elements())
            {
                viewQuery.Append(queryElement.ToString());
            }

            var viewCI = new ViewCreationInformation
            {
                ViewFields       = viewFields,
                RowLimit         = viewRowLimit,
                Paged            = viewPaged,
                Title            = viewTitle,
                Query            = viewQuery.ToString(),
                ViewTypeKind     = viewType,
                PersonalView     = false,
                SetAsDefaultView = viewDefault,
            };

            var createdView = createdList.Views.Add(viewCI);

            web.Context.Load(createdView, v => v.Scope, v => v.JSLink);
            web.Context.ExecuteQueryRetry();

            // Scope
            var scope = viewElement.Attribute("Scope") != null?viewElement.Attribute("Scope").Value : null;

            ViewScope parsedScope = ViewScope.DefaultValue;

            if (!string.IsNullOrEmpty(scope) && Enum.TryParse <ViewScope>(scope, out parsedScope))
            {
                createdView.Scope = parsedScope;
                createdView.Update();
            }

            // JSLink
            var jslinkElement = viewElement.Descendants("JSLink").FirstOrDefault();

            if (jslinkElement != null)
            {
                var jslink = jslinkElement.Value;
                if (createdView.JSLink != jslink)
                {
                    createdView.JSLink = jslink;
                    createdView.Update();
                }
            }

            createdList.Update();
            web.Context.ExecuteQueryRetry();
        }
Esempio n. 10
0
        /// <summary>
        /// Get View Properties to update view.
        /// </summary>
        /// <param name="defaultView">Represents whether this is a default view.</param>
        /// <param name="displayName">Represents the display name.</param>
        /// <param name="fpmodified">Represents the whether the view has been modified by a client application.</param>
        /// <param name="viewScope">Represents whether and how files and sub-folders are included in a view.</param>
        /// <returns>The instance of UpdateViewHtml2ViewProperties.</returns>
        protected UpdateViewHtml2ViewProperties GetViewProperties(bool defaultView, string displayName, bool fpmodified, ViewScope viewScope)
        {
            UpdateViewHtml2ViewProperties update2ViewProperties = new UpdateViewHtml2ViewProperties();

            update2ViewProperties.View             = new UpdateViewPropertiesDefinition();
            update2ViewProperties.View.DefaultView = defaultView.ToString();
            update2ViewProperties.View.DisplayName = displayName;
            update2ViewProperties.View.FPModified  = fpmodified.ToString();
            update2ViewProperties.View.Scope       = viewScope;

            return(update2ViewProperties);
        }
Esempio n. 11
0
 /// <summary>
 /// Returns a modal default view associated with the current action and passes a view model
 /// </summary>
 /// <param name="model">The model that is to be passed to the view</param>
 /// <param name="level">The level the view desires to be</param>
 /// <param name="scope">The scope of the view (global or local/child).</param>
 /// <returns>A view result</returns>
 /// <example>
 /// public ActionResult ShowDetails()
 /// {
 /// var model = new MyModel();
 /// return ViewModal(model, ViewLevel.Popup);
 /// }
 /// </example>
 protected virtual ViewResult ViewModal(object model = null, ViewLevel level = ViewLevel.Normal, ViewScope scope = ViewScope.Global)
 {
     var result = View(model, level);
     result.IsModal = true;
     result.ViewScope = scope;
     return result;
 }
Esempio n. 12
0
 public ViewDefinition()
 {
     this.aggregateViewField = "FALSE";
     this.defaultViewField = "FALSE";
     this.failIfEmptyField = "FALSE";
     this.fileDialogField = "FALSE";
     this.fPModifiedField = "FALSE";
     this.hiddenField = "FALSE";
     this.defaultViewForContentTypeField = "FALSE";
     this.includeRootFolderField = "FALSE";
     this.personalField = "FALSE";
     this.readOnlyField = "FALSE";
     this.recurrenceRowsetField = "FALSE";
     this.requiresClientIntegrationField = "FALSE";
     this.showHeaderUIField = "FALSE";
     this.typeField = ViewType.HTML;
     this.useSchemaXmlToolbarField = "FALSE";
     this.mobileViewField = "FALSE";
     this.levelField = 1;
     this.frameStateField = "Normal";
     this.isIncludedField = "TRUE";
     this.includeVersionsField = "FALSE";
     this.hackLockWebField = "FALSE";
     this.moderationTypeField = ViewModerationType.Item;
     this.scopeField = ViewScope.Item;
     this.threadedField = "FALSE";
     this.tabularViewField = "TRUE";
 }