示例#1
0
        public ListQuery GetListQueryByTitle(string title)
        {
            if (LoadedList.Count == 0)
            {
                return(null);
            }

            return(LoadedList.First(l => l.Title.Equals(title)));
        }
示例#2
0
        public override void Execute()
        {
            try
            {
                using (_clientContext)
                {
                    for (int i = 0; i < _loadData.Keys.Count; i++)
                    {
                        var       loadDataKey     = _loadData.Keys.ElementAt(i);
                        var       loadDataCommand = _loadCommand[loadDataKey];
                        List      list            = null;
                        CamlQuery query           = CamlQuery.CreateAllItemsQuery();
                        String    queryBuilder    = string.Empty;
                        var       modelName       = loadDataCommand.Model.GetCustomAttribute <ContentAttribute>(true).Name;

                        if (!string.IsNullOrEmpty(loadDataCommand.ListName))
                        {
                            list = _clientContext.Web.Lists.GetByTitle(loadDataCommand.ListName);
                        }

                        if (loadDataCommand.Retrievals != null)
                        {
                            queryBuilder += "<ViewFields>" + string.Join("", loadDataCommand.Retrievals.Select(j => "<FieldRef Name=\"" + j + "\" />")
                                                                         .ToArray()) + "</ViewFields>";
                        }

                        if (loadDataCommand.Limit > 0)
                        {
                            queryBuilder += string.Format("<RowLimit>{0}</RowLimit>", loadDataCommand.Limit);
                        }

                        if (queryBuilder.Length > 0)
                        {
                            queryBuilder += "</View>";

                            if (!string.IsNullOrEmpty(loadDataCommand.CamlQuery))
                            {
                                var tmpQueryXml = query.ViewXml.Replace("<View>", "<View Scope='RecursiveAll'>")
                                                  .Replace("<Query>\r\n    </Query>", "<Query><Where>" + loadDataCommand.CamlQuery + "</Where></OrderBy></Query>");

                                query.ViewXml = tmpQueryXml.Replace("</View>", queryBuilder);
                            }
                            else
                            {
                                var tmpQueryXml = query.ViewXml.Replace("<View>", "<View Scope='RecursiveAll'>")
                                                  .Replace("<Query>\r\n    </Query>", "<Query><Where><Eq><FieldRef Name='ContentType' /><Value Type='Computed'>" + modelName + "</Value></Eq></Where></OrderBy></Query>");

                                query.ViewXml = tmpQueryXml.Replace("</View>", queryBuilder);
                            }

                            if (loadDataCommand.OrderBy == null)
                            {
                                loadDataCommand.OrderBy = "";
                            }

                            query.ViewXml = query.ViewXml.Replace("</OrderBy>", loadDataCommand.OrderBy);
                        }

                        _clientContext.Load(list, l => l.DefaultViewUrl);
                        _listData[loadDataKey] = list;

                        Logger.Information("ClientQuery.Execute", string.Format("List = {0}, ContentType = {1}, Query = {2}", loadDataCommand.ListName, modelName, query.ViewXml));

                        var items = list.GetItems(query);

                        if (loadDataCommand.Retrievals != null && loadDataCommand.Retrievals.Any(f => f.Equals("File")))
                        {
                            _clientContext.Load(items,
                                                item => item.IncludeWithDefaultProperties(i1 => i1, i3 => i3.File));
                        }
                        else
                        {
                            _clientContext.Load(items);
                        }

                        _loadData[loadDataKey] = items;
                    }

                    _clientContext.ExecuteQuery();

                    for (int i = 0; i < _loadData.Keys.Count; i++)
                    {
                        var loadDataKey     = _loadData.Keys.ElementAt(i);
                        var loadDataCommand = _loadCommand[loadDataKey];
                        var items           = (ListItemCollection)_loadData[loadDataKey];
                        var listResult      = (IList)Activator.CreateInstance(loadDataCommand.Result);

                        LoadedList.Add(new ListQuery(loadDataCommand.ListName,
                                                     ((List)_listData[loadDataKey]).DefaultViewUrl));

                        foreach (var item in items)
                        {
                            object newModel = Activator.CreateInstance(loadDataCommand.Model);

                            foreach (var property in loadDataCommand.Retrievals)
                            {
                                var propertyInfo = loadDataCommand.Model.GetProperty(property);

                                object value     = null;
                                string valueType = null;

                                try
                                {
                                    if (!propertyInfo.Name.Equals("File"))
                                    {
                                        if (item.FieldValues.ContainsKey(propertyInfo.Name))
                                        {
                                            value     = ValidateValueType(item.FieldValues[propertyInfo.Name]);
                                            valueType = item.FieldValues[propertyInfo.Name] == null
                                                ? null
                                                : item.FieldValues[propertyInfo.Name].GetType().ToString();
                                        }
                                        else
                                        {
                                            value     = item[propertyInfo.Name];
                                            valueType = value == null ? null : value.GetType().ToString();
                                        }
                                    }
                                    else
                                    {
                                        value     = ValidateValueType(item.File);
                                        valueType = value == null ? null : value.GetType().ToString();
                                    }

                                    Logger.Information("ClientQuery.Execute", string.Format("Property = {0}, ValueType = {1}, Value = {2}", propertyInfo.Name, valueType, value));

                                    propertyInfo.SetValue(newModel, value);
                                }
                                catch (Exception e)
                                {
                                    Logger.Unexpected("ClientQuery.Execute", string.Format("Property = {0}, ValueType = {1}, Value = {2}, Exception = {3}", propertyInfo.Name, valueType, value, e.Message));
                                }
                            }

                            listResult.Add(newModel);
                        }
                        _loadData[loadDataKey] = listResult;
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Unexpected("ClientQuery.Execute", e.Message);
                throw e;
            }
        }
示例#3
0
        /// <summary>
        /// 搜索插件
        /// </summary>
        public void SearchPlugin()
        {
            //遍历启动目前下所有dll
            string[] files = System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory() + @"\\" + _plugPath);
            //
            foreach (string file in files)
            {
                //确定结尾
                if (file.ToUpper().EndsWith(_startWith.ToUpper()) && !LoadedList.Contains(file))
                {
                    //已加载的列表中不存在file,则新增
                    LoadedList.Add(file);
                    try
                    {
                        Assembly assembly = null;
                        //将插件拷贝到内存缓冲
                        byte[] addinStream = null;
                        using (System.IO.FileStream input = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
                        {
                            BinaryReader reader = new BinaryReader(input);
                            addinStream = reader.ReadBytes((int)input.Length);
                        }
                        //加载内存中的Dll
                        assembly = Assembly.Load(addinStream);
                        Type[] types = assembly.GetTypes();

                        //生成传入参数
                        object[] args = new object[1];
                        args[0] = assembly;

                        foreach (Type element in types)
                        {
                            try
                            {
                                string            plgName   = element.FullName;
                                ICommand          plugin    = null;
                                ICommandUI        pluginUI  = null;
                                ICommandWorkSpace pluginWks = null;
                                //command初始化时执行new操作,其他情况则只执行转换操作
                                if (element.GetInterface(_ifcmd) != null)
                                {
                                    plugin = assembly.CreateInstance(element.FullName, true, System.Reflection.BindingFlags.Default, null,
                                                                     //传入参数
                                                                     args,
                                                                     //
                                                                     null, null) as ICommand;
                                }
                                //commandUI
                                if (element.GetInterface(_ifcui) != null)
                                {
                                    pluginUI = plugin as ICommandUI;
                                }
                                //
                                if (element.GetInterface(_ifcwks) != null)
                                {
                                    pluginWks = plugin as ICommandWorkSpace;
                                }
                                if (plugin == null & pluginUI == null & pluginWks == null)
                                {
                                    continue;
                                }
                                //查找是否存在plugin
                                if (CmdPlgin.HasPlugin(plgName))
                                {
                                    CmdPlgin.FindPlugin(plgName).Plugin          = CmdPlgin.FindPlugin(plgName).Plugin == null ? plugin : CmdPlgin.FindPlugin(plgName).Plugin;
                                    CmdPlgin.FindPlugin(plgName).PluginUI        = CmdPlgin.FindPlugin(plgName).PluginUI == null ? pluginUI : CmdPlgin.FindPlugin(plgName).PluginUI;
                                    CmdPlgin.FindPlugin(plgName).PluginWorkSpace = CmdPlgin.FindPlugin(plgName).PluginWorkSpace == null ? pluginWks : CmdPlgin.FindPlugin(plgName).PluginWorkSpace;
                                }
                                else
                                {
                                    PlginModel newPlugin = new PlginModel(plugin, pluginUI, pluginWks, plgName);
                                    CmdPlgin.Add(newPlugin);
                                }
                                //加载UI
                                if (pluginUI != null)
                                {
                                    Function.ExtSington.AttributeControl.AddTable(pluginUI.UserContrl);
                                    pluginUI.IsAdded = true;
                                }
                                //加载插件
                                if (plugin != null)
                                {
                                    _outPut.Add(plugin.OutPut);
                                }
                            }
                            catch
                            {
                                continue;
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
示例#4
0
        public override void Execute()
        {
            try
            {
                using (_serverContext)
                {
                    for (int i = 0; i < _loadData.Keys.Count; i++)
                    {
                        var    loadDataKey     = _loadData.Keys.ElementAt(i);
                        var    loadDataCommand = _loadCommand[loadDataKey];
                        SPList list            = null;
                        var    query           = new SPQuery
                        {
                            ViewAttributes = "Scope=\"RecursiveAll\""
                        };


                        if (!string.IsNullOrEmpty(loadDataCommand.ListName))
                        {
                            list = _serverContext.Lists.TryGetList(loadDataCommand.ListName);
                        }

                        if (loadDataCommand.Retrievals != null)
                        {
                            query.ViewFields = string.Join("", loadDataCommand.Retrievals.Select(j => "<FieldRef Name=\"" + j + "\" />").ToArray());
                        }
                        if (loadDataCommand.Limit > 0)
                        {
                            query.RowLimit = (uint)loadDataCommand.Limit;
                        }

                        var modelName = loadDataCommand.Model.GetCustomAttribute <ContentAttribute>(true).Name;

                        if (!string.IsNullOrEmpty(loadDataCommand.CamlQuery))
                        {
                            query.Query = "<Where>" + loadDataCommand.CamlQuery + "</Where>";
                        }
                        else
                        {
                            query.Query = "<Where><Eq><FieldRef Name='ContentType' /><Value Type='Computed'>" +
                                          modelName + "</Value></Eq></Where>";
                        }

                        if (!string.IsNullOrEmpty(loadDataCommand.OrderBy))
                        {
                            query.Query += loadDataCommand.OrderBy;
                        }

                        var items = list.GetItems(query);
                        LoadedList.Add(new ListQuery(loadDataCommand.ListName, list.DefaultViewUrl));
                        _loadData[loadDataKey] = items;
                    }


                    for (int i = 0; i < _loadData.Keys.Count; i++)
                    {
                        var loadDataKey     = _loadData.Keys.ElementAt(i);
                        var loadDataCommand = _loadCommand[loadDataKey];
                        var items           = (SPListItemCollection)_loadData[loadDataKey];
                        var listResult      = (IList)Activator.CreateInstance(loadDataCommand.Result);

                        foreach (SPListItem item in items)
                        {
                            object newModel = Activator.CreateInstance(loadDataCommand.Model);

                            foreach (var property in loadDataCommand.Retrievals)
                            {
                                var propertyInfo = loadDataCommand.Model.GetProperty(property);


                                if (item.Fields.ContainsField(propertyInfo.Name))
                                {
                                    _currentField = item.Fields.GetFieldByInternalName(propertyInfo.Name);
                                    if (item[propertyInfo.Name] != null)
                                    {
                                        var fieldValue = item[propertyInfo.Name];

                                        propertyInfo.SetValue(newModel, ValidateValueType(fieldValue));
                                    }
                                }
                                else
                                {
                                    try
                                    {
                                        if (propertyInfo.Name.Equals("File"))
                                        {
                                            File titFile = item.File;
                                            propertyInfo.SetValue(newModel, titFile);
                                        }
                                        else
                                        {
                                            propertyInfo.SetValue(newModel, item[propertyInfo.Name].ToString());
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Logger.Unexpected("ServerQuery.Execute", ex.Message);
                                        throw ex;
                                    }
                                }
                            }

                            listResult.Add(newModel);
                        }
                        _loadData[loadDataKey] = listResult;
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Unexpected("ServerQuery.Execute", e.Message);
                throw e;
            }
        }