示例#1
0
文件: Blob.cs 项目: Ashrafnet/XIOT
        private List <FieldValue> CreateActionValues(Stream stream, string contentType, string fileName, int contentLength)
        {
            bool                    deleting         = (((contentType == "application/octet-stream") && (contentLength == 0)) && String.IsNullOrEmpty(fileName));
            List <string>           keyValues        = CreateKeyValues();
            int                     keyValueIndex    = 0;
            List <FieldValue>       actionValues     = new List <FieldValue>();
            ControllerConfiguration config           = Controller.CreateConfigurationInstance(typeof(Controller), DataController);
            XPathNodeIterator       keyFieldIterator = config.Select("/c:dataController/c:fields/c:field[@isPrimaryKey=\'true\']");

            while (keyFieldIterator.MoveNext())
            {
                FieldValue v = new FieldValue(keyFieldIterator.Current.GetAttribute("name", String.Empty));
                if (keyValueIndex < keyValues.Count)
                {
                    v.OldValue = keyValues[keyValueIndex];
                    v.Modified = false;
                    keyValueIndex++;
                }
                actionValues.Add(v);
            }
            if (stream != null)
            {
                XPathNavigator lengthField = config.SelectSingleNode("/c:dataController/c:fields/c:field[@name=\'{0}Length\']", ControllerFieldName);
                if (lengthField != null)
                {
                    actionValues.Add(new FieldValue(lengthField.GetAttribute("name", String.Empty), contentLength));
                    if (deleting)
                    {
                        ClearLastFieldValue(actionValues);
                    }
                }
                XPathNavigator contentTypeField = config.SelectSingleNode("/c:dataController/c:fields/c:field[@name=\'{0}ContentType\']", ControllerFieldName);
                if (contentTypeField != null)
                {
                    actionValues.Add(new FieldValue(contentTypeField.GetAttribute("name", String.Empty), contentType));
                    if (deleting)
                    {
                        ClearLastFieldValue(actionValues);
                    }
                }
                XPathNavigator fileNameField = config.SelectSingleNode("/c:dataController/c:fields/c:field[@name=\'{0}FileName\']", ControllerFieldName);
                if (fileNameField != null)
                {
                    actionValues.Add(new FieldValue(fileNameField.GetAttribute("name", String.Empty), Path.GetFileName(fileName)));
                    if (deleting)
                    {
                        ClearLastFieldValue(actionValues);
                    }
                }
                actionValues.Add(new FieldValue(ControllerFieldName, stream));
            }
            return(actionValues);
        }
示例#2
0
        protected string PreparePrefetch(string content)
        {
            string output = null;

            if (!(String.IsNullOrEmpty(Request.Url.Query)) || (Request.Headers["X-Cot-Manifest-Request"] == "true"))
            {
                return(output);
            }
            JToken        token = ApplicationServices.TryGetJsonProperty(ApplicationServices.Current.DefaultSettings, "ui.history.dataView");
            bool          supportGridPrefetch = ((token == null) || !(Regex.IsMatch(((string)(token)), "\\b(search|sort|group|filter)\\b")));
            List <string> prefetches          = new List <string>();
            bool          prefetch            = false;
            List <Tuple <string, AttributeDictionary> > dataViews = new List <Tuple <string, AttributeDictionary> >();

            foreach (Match m in Regex.Matches(content, "<div\\s+(id=\"(?\'Id\'\\w+)\")\\s+(?\'Props\'data-controller.*?)>"))
            {
                dataViews.Add(new Tuple <string, AttributeDictionary>(m.Groups["Id"].Value, new AttributeDictionary(m.Groups["Props"].Value)));
            }
            if (dataViews.Count == 1)
            {
                prefetch = true;
            }
            else
            {
                // LEGACY MASTER DETAIL PAGE SUPPORT
                //
                //
                // 1. convert text of containers into single container with single dataview referring to virtual dashboard controller
                //
                // <div data-flow="row">
                //   <div id="view1" data-controller="Dashboards" data-view="form1" data-show-action-buttons="none"></div>
                //
                // </div>
                //
                // 2. produce response for this controller.
                // a. standalone data views become data view fields of the virtual controller
                // b. the layout of the page is optionally converted into form1 layout of the virtual controller
                // c. render json response of virtual controller with layout in it
                //
            }
            if (prefetch)
            {
                for (int i = 0; (i < dataViews.Count); i++)
                {
                    Tuple <string, AttributeDictionary> dataView = dataViews[i];
                    string dataViewId         = dataView.Item1;
                    AttributeDictionary attrs = dataView.Item2;
                    foreach (string p in UnsupportedDataViewProperties)
                    {
                        if (attrs.ContainsKey(p))
                        {
                            return(output);
                        }
                    }
                    string controllerName = attrs["data-controller"];
                    string viewId         = null;
                    string tags           = null;
                    attrs.TryGetValue("data-tags", out tags);
                    ControllerConfiguration c = Controller.CreateConfigurationInstance(GetType(), controllerName);
                    if (!(attrs.TryGetValue("data-view", out viewId)))
                    {
                        viewId = ((string)(c.Evaluate("string(/c:dataController/c:views/c:view[1]/@id)")));
                    }
                    XPathNavigator viewNav = c.SelectSingleNode("/c:dataController/c:views/c:view[@id=\'{0}\']", viewId);
                    if (!(Context.User.Identity.IsAuthenticated) && !((viewNav.GetAttribute("access", String.Empty) == "Public")))
                    {
                        return(output);
                    }
                    string roles = null;
                    if (attrs.TryGetValue("data-roles", out roles) && !(new ControllerUtilities().UserIsInRole(roles.Split(','))))
                    {
                        return(output);
                    }
                    tags = (tags
                            + (" " + viewNav.GetAttribute("tags", String.Empty)));
                    bool isForm = (viewNav.GetAttribute("type", String.Empty) == "Form");
                    if (isForm)
                    {
                        _summaryDisabled = true;
                    }
                    if ((String.IsNullOrEmpty(tags) || !(Regex.IsMatch(tags, "\\bprefetch-data-none\\b"))) && (supportGridPrefetch || isForm))
                    {
                        PageRequest request = new PageRequest(-1, 30, null, null);
                        request.Controller      = controllerName;
                        request.View            = viewId;
                        request.Tag             = tags;
                        request.ContextKey      = dataViewId;
                        request.SupportsCaching = true;
                        if (attrs.ContainsKey("data-search-on-start"))
                        {
                            request.DoesNotRequireData = true;
                        }
                        ViewPage response = ControllerFactory.CreateDataController().GetPage(request.Controller, request.View, request);
                        string   result   = String.Format("{{ \"d\": {0} }}", ApplicationServices.CompressViewPageJsonOutput(JsonConvert.SerializeObject(response)));
                        prefetches.Add(String.Format("<script type=\"application/json\" id=\"_{0}_prefetch\">{1}</script>", dataViewId, Regex.Replace(result, "(<(/?\\s*script)(\\s|>))", "]_[$2$3]^[", RegexOptions.IgnoreCase)));
                        if (isForm)
                        {
                            foreach (DataField field in response.Fields)
                            {
                                if (String.IsNullOrEmpty(field.DataViewFilterSource) && (field.Type == "DataView"))
                                {
                                    AttributeDictionary fieldAttr = new AttributeDictionary(String.Empty);
                                    fieldAttr.Add("data-controller", field.DataViewController);
                                    fieldAttr.Add("data-view", field.DataViewId);
                                    fieldAttr.Add("data-tags", field.Tag);
                                    if (field.DataViewSearchOnStart)
                                    {
                                        fieldAttr.Add("data-search-on-start", "true");
                                    }
                                    dataViews.Add(new Tuple <string, AttributeDictionary>(String.Format("{0}_{1}", dataViewId, field.Name), fieldAttr));
                                }
                            }
                        }
                    }
                }
            }
            if (prefetches.Count > 0)
            {
                output = string.Join(String.Empty, prefetches);
            }
            return(output);
        }