Пример #1
0
        private static BookmarkFolder RetriveFolder(SetRecord record)
        {
            string                name = record.ReadAs <string>("name");
            string                type;
            ListRecord            children  = record["children"] as ListRecord;
            List <Bookmark>       bookmarks = new List <Bookmark>();
            List <BookmarkFolder> folders   = new List <BookmarkFolder>();

            foreach (RecordBase rec in children)
            {
                if (rec is SetRecord set)
                {
                    type = set.ReadAs <string>("type");
                    if (type == "folder")
                    {
                        folders.Add(RetriveFolder(set));
                    }
                    else if (type == "url")
                    {
                        bookmarks.Add(RetriveBookmark(set));
                    }
                }
            }
            return(new BookmarkFolder()
            {
                Name = name,
                Bookmarks = bookmarks,
                Folders = folders
            });
        }
Пример #2
0
        internal static WordDefinitionsCollection FromRecord(ListRecord list)
        {
            List <WordDefinition> words = new List <WordDefinition>();

            if (list == null)
            {
                return(new WordDefinitionsCollection(words));
            }

            foreach (RecordBase record in list)
            {
                if (record is SetRecord set)
                {
                    if (set.TryGetValue("pos", out RecordBase posRec) &&
                        set.TryGetValue("def", out RecordBase defRec) &&
                        posRec is ScalerRecord pos &&
                        defRec is ScalerRecord def)
                    {
                        string posValue = pos.ReadAs <string>();
                        string defValue = def.ReadAs <string>();
                        words.Add(new WordDefinition(posValue, defValue));
                    }
                }
            }
            return(new WordDefinitionsCollection(words));
        }
Пример #3
0
        public static IConfiguartion Read(SetRecord set)
        {
            if (set == null)
            {
                throw new ArgumentNullException(nameof(set));
            }

            RecordBase record;
            SetRecord  setIncludeItems    = null;
            SetRecord  setGlobalExcludes  = null;
            ListRecord setScanDirectories = null;

            if (set.TryGetValue("scan", out record))
            {
                setScanDirectories = record as ListRecord;
            }
            if (set.TryGetValue("include", out record))
            {
                setIncludeItems = record as SetRecord;
            }
            if (set.TryGetValue("exclude", out record))
            {
                setGlobalExcludes = record as SetRecord;
            }

            ItemIncludeOptions resultInclude = ReadItemIncludeOptions(setIncludeItems);
            ScanFilterOptions  resultExclude = null;

            if (setGlobalExcludes == null)
            {
                resultExclude = ScanFilterOptions.CreateExcludeDefault();
            }
            else
            {
                resultExclude = ReadFilterOptions(setGlobalExcludes);
            }

            List <DirectoryScanOptions> resultScanDirectories = new List <DirectoryScanOptions>();

            if (setScanDirectories != null)
            {
                foreach (RecordBase scanOptions in setScanDirectories)
                {
                    if (scanOptions is SetRecord setScanOptions)
                    {
                        resultScanDirectories.Add(ReadDirectoryScanOptions(resultExclude, setScanOptions));
                    }
                }
            }

            return(new Configuration(resultExclude, resultInclude, resultScanDirectories));
        }
Пример #4
0
        private static ItemIncludeOptions ReadItemIncludeOptions(SetRecord set)
        {
            List <string> resultDirectories = new List <string>();
            List <string> resultFiles       = new List <string>();

            // return empty list if null
            if (set == null)
            {
                return(new ItemIncludeOptions(resultDirectories, resultFiles));
            }

            RecordBase record;
            ListRecord directories = null;
            ListRecord files       = null;

            if (set.TryGetValue("directories", out record))
            {
                directories = record as ListRecord;
            }
            if (set.TryGetValue("files", out record))
            {
                files = record as ListRecord;
            }

            if (directories != null)
            {
                foreach (RecordBase rec in directories)
                {
                    if (rec is ScalerRecord scaler && scaler.ScalerType == ScalerType.String)
                    {
                        resultDirectories.Add(scaler.ReadAs <string>());
                    }
                }
            }
            if (files != null)
            {
                foreach (RecordBase rec in files)
                {
                    if (rec is ScalerRecord scaler && scaler.ScalerType == ScalerType.String)
                    {
                        resultFiles.Add(scaler.ReadAs <string>());
                    }
                }
            }
            return(new ItemIncludeOptions(resultDirectories, resultFiles));
        }
Пример #5
0
        private static string ListJson(ListRecord record, int indent, bool ignoreFirstIndent)
        {
            StringBuilder builder = new StringBuilder(capacity: record.Count * 64);

            if (ignoreFirstIndent == false)
            {
                builder.AppendIndent(indent);
            }
            builder.Append('[');
            int indentPlus = indent + 1;

            if (record.All(rec => rec is ScalerRecord))
            {
                foreach (var value in record)
                {
                    builder.Append(Json(value, indentPlus, true));
                    builder.Append(',');
                }
                if (record.Count > 0)
                {
                    builder.Remove(builder.Length - 1, 1);
                }
                builder.Append(']');
            }
            else
            {
                foreach (var value in record)
                {
                    builder.AppendLine();
                    builder.Append(Json(value, indentPlus, false));
                    builder.Append(',');
                }
                if (builder.Length > 0)
                {
                    builder.Remove(builder.Length - 1, 1);
                }
                builder.AppendLine();
                builder.AppendIndent(indent);
                builder.Append(']');
            }
            return(builder.ToString());
        }
        internal static SentencesCollection FromRecord(ListRecord list)
        {
            List <SentenceSample> sentences = new List <SentenceSample>();

            if (list == null)
            {
                return(new SentencesCollection(sentences));
            }

            foreach (RecordBase record in list)
            {
                if (record is SetRecord set)
                {
                    if (set.TryGetValue("eng", out RecordBase engRecord) && engRecord is ScalerRecord engScaler &&
                        set.TryGetValue("chn", out RecordBase chnRecord) && chnRecord is ScalerRecord chnScaler &&
                        set.TryGetValue("mp3Url", out RecordBase mp3Record) && mp3Record is ScalerRecord mp3Scaler &&
                        set.TryGetValue("mp4Url", out RecordBase mp4Record) && mp4Record is ScalerRecord mp4Scaler)
                    {
                        string eng = engScaler.ReadAs <string>();
                        string chn = chnScaler.ReadAs <string>();
                        Uri    mp3 = null;
                        if (mp3Scaler.ScalerType == ScalerType.String)
                        {
                            mp3 = new Uri(mp3Scaler.ReadAs <string>(), UriKind.Absolute);
                        }
                        Uri mp4 = null;
                        if (mp4Scaler.ScalerType == ScalerType.String)
                        {
                            mp4 = new Uri(mp4Scaler.ReadAs <string>(), UriKind.Absolute);
                        }
                        sentences.Add(new SentenceSample(eng, chn, mp3, mp4));
                    }
                }
            }
            return(new SentencesCollection(sentences));
        }
Пример #7
0
            /// <summary>
            /// Creates a new list Record instance. Providers to load a specifics records from database.
            /// </summary>
            /// <param name="pTransaction">A specifics transaction</param>
            /// <param name="pSelectQuery">Select Command Text</param>
            /// <param name="pParameters">arameters list. This list represents a WHERE on load from db.</param>
            public Records(DbTransaction pTransaction, String pSelectQuery, params RecordParameter[] pParameters)
            {
                _list = ListRecord <TRECORD> .CreateNewInstance(pTransaction, pSelectQuery, pParameters);

                _list.Load(pTransaction, pSelectQuery, pParameters);
            }
Пример #8
0
            /// <summary>
            /// Creates a new list Record instance. Providers to load a specifics records from database.
            /// </summary>
            /// <param name="pTransaction">A specifics transaction</param>
            /// <param name="pCondition">Condition, This represents a WHERE on load from db.</param>
            public Records(DbTransaction pTransaction, Condition pCondition)
            {
                _list = ListRecord <TRECORD> .CreateNewInstance(pTransaction, pCondition);

                _list.Load(pTransaction, pCondition);
            }
Пример #9
0
            /// <summary>
            /// Creates a new list Record instance. Providers to NOT load a specifics records from database.
            /// </summary>
            public Records()
            {
                _list = ListRecord <TRECORD> .CreateNewInstance();

                _list.Load(null);
            }
Пример #10
0
        internal void UpdateConfigurations(ICurrentEnvironment env)
        {
            actions.Clear();
            logger.LogMessageAsync("A");
            string filename   = "runner.json";
            string iconPath   = "icons";
            string configPath = Path.Combine(env.ConfigDirectory.FullName, "runner");

            if (!Directory.Exists(configPath))
            {
                Directory.CreateDirectory(configPath);
            }
            iconPath = Path.Combine(configPath, iconPath);
            filename = Path.Combine(configPath, filename);
            logger.LogMessageAsync("B");
            if (File.Exists(filename))
            {
                FileStream stream = File.Open(filename, FileMode.Open);
                ListRecord record = Hake.Extension.ValueRecord.Json.Converter.ReadJson(stream) as ListRecord;
                stream.Close();
                stream.Dispose();
                logger.LogMessageAsync("C");
                try
                {
                    List <CommandData> data = ObjectMapper.ToObject <List <CommandData> >(record);
                    foreach (CommandData cmd in data)
                    {
                        if (cmd.IconPath != null)
                        {
                            actions.Add(new RunCommandAction(cmd.Command, cmd.ExePath, Path.Combine(iconPath, cmd.IconPath), cmd.Admin, cmd.WorkingDirectory, cmd.Args));
                        }
                        else
                        {
                            actions.Add(new RunCommandAction(cmd.Command, cmd.ExePath, null, cmd.Admin, cmd.WorkingDirectory, cmd.Args));
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.LogExceptionAsync(ex);
                }
            }
            else
            {
                List <CommandData> data = new List <CommandData>();
                foreach (string command in PREDEFINED_COMMANDS)
                {
                    data.Add(new CommandData()
                    {
                        Command  = command,
                        ExePath  = null,
                        IconPath = null
                    });
                    actions.Add(new RunCommandAction(command, null, null, false, null, null));
                }
                FileStream   stream = File.Create(filename);
                ListRecord   record = GetCommandsRecord(data);
                string       json   = Hake.Extension.ValueRecord.Json.Converter.Json(record);
                StreamWriter writer = new StreamWriter(stream);
                writer.Write(json);
                writer.Flush();
                writer.Close();
                writer.Dispose();
                stream.Close();
                stream.Dispose();
                logger.LogWarningAsync("runner.json not exists, write default configuration to new file");
            }
        }
Пример #11
0
        private ListRecord GetCommandsRecord(List <CommandData> commands)
        {
            ListRecord commandRecords = (ListRecord)ObjectMapper.ToRecord(commands);

            return(commandRecords);
        }
Пример #12
0
        public void Persist(ListRecord _listRecord)
        {
            ListRecordDAO dao = new ListRecordDAO(MongoDB);

            dao.Persist(_listRecord);
        }
Пример #13
0
 public void ListNavigate <T>(ListRecord <T> record)
 {
     App.NavigationPage.PushAsync(FreshPageModelResolver.ResolvePageModel <MainTabPageModel>());
 }
Пример #14
0
        public void GenFile()
        {
            string all_str = "";
            int    num     = 1;
            string sss     = "";
            string tmp     = "";

            if (this.TimeGap == 24)
            {
                /*最大要素*/
                var entity = new HydrologicReader().RetrieveHighestEntity(TimeFrom, TimeTo, Type);
                foreach (HydrologicEntityItem item in entity.Items)
                {
                    if (!double.IsNaN(item.Latitude) && !double.IsNaN(item.Longitude))
                    {
                        MicapsRecord record = new MicapsRecord();
                        record.Uid       = item.Stationid.GetHashCode();
                        record.Latitude  = item.Latitude;
                        record.Longitude = item.Longitude;
                        record.ValueL    = item.L;
                        record.ValueQ    = item.Q;
                        record.ValueWL1  = item.Wl1;
                        record.ValueWL2  = item.Wl2;
                        ListRecord.Add(record);
                        all_str += num + "\t\t";
                        num++;
                        all_str += item.Basin + "\t\t";
                        all_str += item.Administrativeregion + "\t\t";
                        all_str += item.River + "\t\t";
                        all_str += item.Name + "\t\t";
                        all_str += item.Latitude.ToString("F2") + "\t\t";
                        all_str += item.Longitude.ToString("F2") + "\t\t";
                        if (double.IsNaN(item.L))
                        {
                            all_str += "9999\t\t";
                        }
                        else
                        {
                            all_str += item.L.ToString("F2") + "\t\t";
                        }
                        if (double.IsNaN(item.Q))
                        {
                            all_str += "9999\t\t";
                        }
                        else
                        {
                            all_str += item.Q.ToString("F2") + "\t\t";
                        }
                        if (double.IsNaN(item.Wl1))
                        {
                            all_str += "9999\t\t";
                        }
                        else
                        {
                            all_str += item.Wl1.ToString("F2") + "\t\t";
                        }
                        if (double.IsNaN(item.Wl2))
                        {
                            all_str += "9999" + System.Environment.NewLine;
                        }
                        else
                        {
                            all_str += item.Wl2.ToString("F2") + System.Environment.NewLine;
                        }
                    }
                }

                if (Type.Equals("河道站"))
                {
                    sss = "最高水位\t\t最大流量\t\t警戒水位\t\t保证水位" + System.Environment.NewLine;
                }
                if (Type.Equals("水库站"))
                {
                    sss = "最高库水位\t\t最大蓄水量\t\t警戒水位\t\t保证水位" + System.Environment.NewLine;
                }
                all_str = "序号\t\t流域\t\t行政区\t\t河名\t\t站名\t\t纬度\t\t经度\t\t" + sss + all_str;
                /*生成最大全部要素*/
                infodir       = this.TimeGap + "小时最大全部要素";
                tmp           = TimeGap.ToString("D3");
                this.FilePath = @"D:/products/" + Type + @"/" + tmp + @"/" + this.infodir + @"/" + this.FileName;
                FileInfo fileInfo = new FileInfo(this.FilePath);
                if (!fileInfo.Exists)
                {
                    Directory.CreateDirectory(fileInfo.Directory.FullName);
                }
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(FilePath, false, Encoding.Default))
                {
                    file.Write(all_str);
                }


                /*生成最新要素*/
                all_str = "";
                num     = 1;
                entity  = new HydrologicReader().RetrieveEntity(TimeFrom, TimeTo, Type);
                foreach (HydrologicEntityItem item in entity.Items)
                {
                    if (!double.IsNaN(item.Latitude) && !double.IsNaN(item.Longitude))
                    {
                        MicapsRecord record = new MicapsRecord();
                        record.Uid       = item.Stationid.GetHashCode();
                        record.Latitude  = item.Latitude;
                        record.Longitude = item.Longitude;
                        record.ValueL    = item.L;
                        record.ValueQ    = item.Q;
                        record.ValueWL1  = item.Wl1;
                        record.ValueWL2  = item.Wl2;
                        ListRecord.Add(record);
                        all_str += num + "\t\t";
                        num++;
                        all_str += item.Basin + "\t\t";
                        all_str += item.Administrativeregion + "\t\t";
                        all_str += item.River + "\t\t";
                        all_str += item.Name + "\t\t";
                        all_str += item.Latitude.ToString("F2") + "\t\t";
                        all_str += item.Longitude.ToString("F2") + "\t\t";
                        if (double.IsNaN(item.L))
                        {
                            all_str += "9999\t\t";
                        }
                        else
                        {
                            all_str += item.L.ToString("F2") + "\t\t";
                        }
                        if (double.IsNaN(item.Q))
                        {
                            all_str += "9999\t\t";
                        }
                        else
                        {
                            all_str += item.Q.ToString("F2") + "\t\t";
                        }
                        if (double.IsNaN(item.Wl1))
                        {
                            all_str += "9999\t\t";
                        }
                        else
                        {
                            all_str += item.Wl1.ToString("F2") + "\t\t";
                        }
                        if (double.IsNaN(item.Wl2))
                        {
                            all_str += "9999" + System.Environment.NewLine;;
                        }
                        else
                        {
                            all_str += item.Wl2.ToString("F2") + System.Environment.NewLine;
                        }
                    }
                }
                sss = "";
                if (Type.Equals("河道站"))
                {
                    sss = "最新水位\t\t最新流量\t\t警戒水位\t\t保证水位" + System.Environment.NewLine;
                }
                if (Type.Equals("水库站"))
                {
                    sss = "最新库水位\t\t最新蓄水量\t\t警戒水位\t\t保证水位" + System.Environment.NewLine;
                }
                all_str = "序号\t\t流域\t\t行政区\t\t河名\t\t站名\t\t纬度\t\t经度\t\t" + sss + all_str;
                /*生成最新全部要素*/
                infodir       = this.TimeGap + "小时最新全部要素";
                tmp           = TimeGap.ToString("D3");
                this.FilePath = @"D:/products/" + Type + @"/" + tmp + @"/" + this.infodir + @"/" + this.FileName;
                fileInfo      = new FileInfo(this.FilePath);
                if (!fileInfo.Exists)
                {
                    Directory.CreateDirectory(fileInfo.Directory.FullName);
                }
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(FilePath, false, Encoding.Default))
                {
                    file.Write(all_str);
                }
            }

            if (this.TimeGap == 1)
            {
                /*生成最新要素*/
                all_str = "";
                num     = 1;
                var entity = new HydrologicReader().RetrieveEntity(TimeFrom, TimeTo, Type);
                foreach (HydrologicEntityItem item in entity.Items)
                {
                    if (!double.IsNaN(item.Latitude) && !double.IsNaN(item.Longitude))
                    {
                        MicapsRecord record = new MicapsRecord();
                        record.Uid       = item.Stationid.GetHashCode();
                        record.Latitude  = item.Latitude;
                        record.Longitude = item.Longitude;
                        record.ValueL    = item.L;
                        record.ValueQ    = item.Q;
                        record.ValueWL1  = item.Wl1;
                        record.ValueWL2  = item.Wl2;
                        ListRecord.Add(record);
                        all_str += num + "\t\t";
                        num++;
                        all_str += item.Basin + "\t\t";
                        all_str += item.Administrativeregion + "\t\t";
                        all_str += item.River + "\t\t";
                        all_str += item.Name + "\t\t";
                        all_str += item.Latitude.ToString("F2") + "\t\t";
                        all_str += item.Longitude.ToString("F2") + "\t\t";
                        if (double.IsNaN(item.L))
                        {
                            all_str += "9999\t\t";
                        }
                        else
                        {
                            all_str += item.L.ToString("F2") + "\t\t";
                        }
                        if (double.IsNaN(item.Q))
                        {
                            all_str += "9999\t\t";
                        }
                        else
                        {
                            all_str += item.Q.ToString("F2") + "\t\t";
                        }
                        if (double.IsNaN(item.Wl1))
                        {
                            all_str += "9999\t\t";
                        }
                        else
                        {
                            all_str += item.Wl1.ToString("F2") + "\t\t";
                        }
                        if (double.IsNaN(item.Wl2))
                        {
                            all_str += "9999" + System.Environment.NewLine;;
                        }
                        else
                        {
                            all_str += item.Wl2.ToString("F2") + System.Environment.NewLine;
                        }
                    }
                }
                sss = "";
                if (Type.Equals("河道站"))
                {
                    sss = "最新水位\t\t最新流量\t\t警戒水位\t\t保证水位" + System.Environment.NewLine;
                }
                if (Type.Equals("水库站"))
                {
                    sss = "最新库水位\t\t最新蓄水量\t\t警戒水位\t\t保证水位" + System.Environment.NewLine;
                }
                all_str = "序号\t\t流域\t\t行政区\t\t河名\t\t站名\t\t纬度\t\t经度\t\t" + sss + all_str;
                /*生成最新全部要素*/
                infodir       = this.TimeGap + "小时最新全部要素";
                tmp           = TimeGap.ToString("D3");
                this.FilePath = @"D:/products/" + Type + @"/" + tmp + @"/" + this.infodir + @"/" + this.FileName;
                FileInfo fileInfo = new FileInfo(this.FilePath);
                fileInfo = new FileInfo(this.FilePath);
                if (!fileInfo.Exists)
                {
                    Directory.CreateDirectory(fileInfo.Directory.FullName);
                }
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(FilePath, false, Encoding.Default))
                {
                    file.Write(all_str);
                }
            }
        }
Пример #15
0
        private static void Recursive(WebRecord records)
        {
            Webs webs = new Webs();

            webs.Url         = records.Url + "/" + "_vti_bin/webs.asmx";
            webs.Credentials = credential;
            //webs.CookieContainer = GetAuthCookies();
            XmlNode subwebs = webs.GetWebCollection();

            foreach (XmlNode node in subwebs.ChildNodes)
            {
                WebRecord web = new WebRecord()
                {
                    Title        = node.Attributes[0].Value,
                    Url          = node.Attributes[1].Value,
                    LastModified = DateTime.MinValue.Year
                };

                Lists lists = new Lists();
                lists.Url         = web.Url + "/_vti_bin/lists.asmx";
                lists.Credentials = credential;
                //lists.CookieContainer = GetAuthCookies();

                XmlNode list = lists.GetListCollection();

                List <ListRecord> listRecordList = new List <ListRecord>();

                foreach (XmlNode listnode in list.ChildNodes)
                {
                    ListRecord currentList = new ListRecord()
                    {
                        Title        = listnode.Attributes[3].Value,
                        LastModified = DateTime.ParseExact(listnode.Attributes[10].Value, "yyyyMMdd HH:mm:ss", CultureInfo.InvariantCulture).Year,
                        ItemCount    = int.Parse(listnode.Attributes["ItemCount"].Value)
                    };

                    //web.Lists.Add(currentList);

                    listRecordList.Add(currentList);
                }

                List <string> adminList = new List <string>();
                adminList.AddRange(GetUsersInRole(web, "Administrator"));
                adminList.AddRange(GetUsersInRole(web, "Admin"));
                adminList.AddRange(GetUsersInRole(web, "Beheerder"));
                adminList          = adminList.Distinct().ToList();
                web.Administrators = string.Join(",", adminList);

                if (web.Administrators == string.Empty)
                {
                    web.Administrators = "-";
                }

                Recursive(web);

                web.ItemCount = web.Children.Sum(f => f.ItemCount) + listRecordList.Sum(f => f.ItemCount);

                int listMax = 0;
                int siteMax = 0;

                if (listRecordList.Count > 1)
                {
                    listMax = listRecordList.Max(f => f.LastModified);
                }

                if (web.Children.Count > 1)
                {
                    siteMax = web.Children.Max(f => f.LastModified);
                }

                web.LastModified = Math.Max(listMax, siteMax);
                web.Parent       = records.Title;

                records.Children.Add(web);
            }
        }
Пример #16
0
        public static RecordBase ToRecord(object input, bool ignoreKeyCase = false)
        {
            if (input == null)
            {
                return(new ScalerRecord(null));
            }

            Type valueType = input.GetType();

#if NETSTANDARD1_2
            TypeInfo valueTypeInfo = valueType.GetTypeInfo();
#endif

#if NETSTANDARD2_0 || NET452
            if (valueType.IsEnum)
#else
            if (valueTypeInfo.IsEnum)
#endif
            {
                string typeName   = $"{valueType.Namespace}.{valueType.Name}";
                string writeValue = $"{typeName}.{input}";
                return(new ScalerRecord(writeValue));
            }

#if NETSTANDARD2_0 || NET452
            if (valueType.IsPrimitive)
#else
            if (valueTypeInfo.IsPrimitive)
#endif
            { return(new ScalerRecord(input)); }

            if (valueType.Name == "String" && valueType.Namespace == "System")
            {
                return(new ScalerRecord(input));
            }

#if NETSTANDARD2_0 || NET452
            Type ienumType = valueType.GetInterface("System.Collections.IEnumerable");
#else
            Type     ienumType     = valueTypeInfo.ImplementedInterfaces.FirstOrDefault(t => t.FullName == "System.Collections.IEnumerable");
            TypeInfo ienumTypeInfo = ienumType == null ? null : ienumType.GetTypeInfo();
#endif
            if (ienumType != null)
            {
#if NETSTANDARD2_0 || NET452
                MethodInfo getEnumeratorMethod = ienumType.GetMethod("GetEnumerator");
#else
                MethodInfo getEnumeratorMethod = ienumTypeInfo.DeclaredMethods.FirstOrDefault(m => m.Name == "GetEnumerator");
#endif
                IEnumerator enumerator = (IEnumerator)getEnumeratorMethod.Invoke(input, null);
                ListRecord  listRecord = new ListRecord();
                while (enumerator.MoveNext())
                {
                    listRecord.Add(ToRecord(enumerator.Current, ignoreKeyCase));
                }
                return(listRecord);
            }

#if NETSTANDARD2_0 || NET452
            if (valueType.IsClass)
#else
            if (valueTypeInfo.IsClass)
#endif
            {
#if NETSTANDARD2_0 || NET452
                BindingFlags propertyFlags = BindingFlags.Instance;
#if PROPERTY_PUBLIC_ONLY
                propertyFlags |= BindingFlags.Public;
                PropertyInfo[] properties = valueType.GetProperties(propertyFlags);
#endif
#else
                PropertyInfo[] properties = valueTypeInfo.DeclaredProperties.ToArray();
#endif
                SetRecord            setRecord = new SetRecord(ignoreKeyCase);
                MapPropertyAttribute mapPropertyAttribute;
                MethodInfo           getMethod;
                string propertyName;
                object propertyValue;
                foreach (PropertyInfo property in properties)
                {
                    getMethod = property.GetMethod;
                    if (getMethod == null)
                    {
                        continue;
                    }
                    mapPropertyAttribute = property.GetCustomAttribute <MapPropertyAttribute>();
                    if (mapPropertyAttribute == null)
                    {
                        continue;
                    }
                    propertyName  = GetNameOrDefault(property, mapPropertyAttribute);
                    propertyValue = getMethod.Invoke(input, null);
                    if (mapPropertyAttribute.ConverterType == null)
                    {
                        setRecord.Add(propertyName, ToRecord(propertyValue, ignoreKeyCase));
                    }
                    else
                    {
#if NETSTANDARD2_0 || NET452
                        MethodInfo convertToScaler = mapPropertyAttribute.ConverterType.GetMethod(nameof(IScalerTargetTypeConverter <string, string> .ConvertToScaler));
#else
                        MethodInfo convertToScaler = mapPropertyAttribute.ConverterType.GetRuntimeMethods().First(method => method.Name == nameof(IScalerTargetTypeConverter <string, string> .ConvertToScaler));
#endif
                        object converterObject = Activator.CreateInstance(mapPropertyAttribute.ConverterType);
                        object scaler          = convertToScaler.Invoke(converterObject, new object[] { propertyValue });
                        setRecord.Add(propertyName, ToRecord(scaler, ignoreKeyCase));
                    }
                }
                return(setRecord);
            }

            throw new Exception($"can not map to record of type {valueType.Namespace}.{valueType.Name}");
        }
Пример #17
0
        private static ScanFilterOptions ReadFilterOptions(SetRecord set)
        {
            if (set == null)
            {
                throw new ArgumentNullException(nameof(set));
            }

            string     pattern;
            Regex      tempRegex;
            RecordBase recordbase;
            ListRecord directories = null;
            ListRecord files       = null;
            ListRecord common      = null;
            ListRecord paths       = null;

            if (set.TryGetValue("directory", out recordbase))
            {
                directories = recordbase as ListRecord;
            }
            if (set.TryGetValue("file", out recordbase))
            {
                files = recordbase as ListRecord;
            }
            if (set.TryGetValue("common", out recordbase))
            {
                common = recordbase as ListRecord;
            }
            if (set.TryGetValue("path", out recordbase))
            {
                paths = recordbase as ListRecord;
            }
            List <Regex> resultDirectories = new List <Regex>();
            List <Regex> resultFiles       = new List <Regex>();
            List <Regex> resultCommon      = new List <Regex>();
            List <Regex> resultPaths       = new List <Regex>();

            if (directories != null)
            {
                foreach (RecordBase rec in directories)
                {
                    if (rec is ScalerRecord scaler && scaler.ScalerType == ScalerType.String)
                    {
                        pattern = scaler.ReadAs <string>();
                        try
                        {
                            tempRegex = new Regex(pattern);
                            resultDirectories.Add(tempRegex);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            if (files != null)
            {
                foreach (RecordBase rec in files)
                {
                    if (rec is ScalerRecord scaler && scaler.ScalerType == ScalerType.String)
                    {
                        pattern = scaler.ReadAs <string>();
                        try
                        {
                            tempRegex = new Regex(pattern);
                            resultFiles.Add(tempRegex);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            if (common != null)
            {
                foreach (RecordBase rec in common)
                {
                    if (rec is ScalerRecord scaler && scaler.ScalerType == ScalerType.String)
                    {
                        pattern = scaler.ReadAs <string>();
                        try
                        {
                            tempRegex = new Regex(pattern);
                            resultCommon.Add(tempRegex);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            if (paths != null)
            {
                foreach (RecordBase rec in paths)
                {
                    if (rec is ScalerRecord scaler && scaler.ScalerType == ScalerType.String)
                    {
                        pattern = scaler.ReadAs <string>();
                        try
                        {
                            tempRegex = new Regex(pattern);
                            resultPaths.Add(tempRegex);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            return(new ScanFilterOptions(resultFiles, resultDirectories, resultCommon, resultPaths));
        }
Пример #18
0
        private static ListRecord ReadList(InternalTextReader reader, bool ignoreKeyCase)
        {
            // resolve '['
            reader.Read();

            ListRecord list = new ListRecord();
            char       peek;
            int        result;

            while (true)
            {
                RecordBase record = ReadJson(reader, true, ignoreKeyCase);
                if (record == null)
                {
                    break;
                }
                list.Add(record);
                while (true)
                {
                    result = reader.Peek();
                    if (result == -1)
                    {
                        throw new Exception("']' excepted but end of stream reached");
                    }
                    peek = (char)result;
                    if (peek.IsWhiteSpace())
                    {
                        reader.Read();
                    }
                    else if (peek == '/')
                    {
                        reader.Read();
                        result = reader.Peek();
                        if (result == -1)
                        {
                            throw new Exception("'/' excepted but end of stream reached");
                        }
                        peek = (char)result;
                        if (peek != '/')
                        {
                            throw BuildException($"unexcepted char '{peek}' while scanning comment", reader);
                        }
                        reader.Read();
                        while (true)
                        {
                            result = reader.Peek();
                            if (result == -1)
                            {
                                throw new Exception("']' excepted but end of stream reached");
                            }
                            peek = (char)result;
                            if (peek == '\n')
                            {
                                reader.Read(); break;
                            }
                            reader.Read();
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (peek == ',')
                {
                    reader.Read();
                }
                else if (peek == ']')
                {
                    reader.Read(); break;
                }
                else
                {
                    throw BuildException($"unexcepted char '{peek}' while scanning list", reader);
                }
            }
            return(list);
        }