public ItemControlViewModel(SIT2_Item item)
 {
     ItemProperties = new ObservableCollection <PropertyInfo>(item.GetType().GetProperties());
     SitObject      = item;
     Initial        = false;
     Final          = false;
 }
Beispiel #2
0
        private SIT2_Item ListToSitItem()
        {
            List <PropertyInfo> result =
                typeof(SIT2_Item)
                .GetProperties()
                .Where(
                    p =>
                    p.GetCustomAttributes(typeof(NameAttribute), false)
                    .Where(ca => ((NameAttribute)ca).Name == "Project")
                    .Any()
                    )
                .ToList();
            SIT2_Item item = new SIT2_Item();

            item.GetType().GetProperty("Project").SetValue(item, "asd");
            var s = item.GetType().GetProperties();

            return(null);
        }
        private async Task <List <SIT2_Item> > GetItemsFromMail(DateTime lastDate, User user)
        {
            List <SIT2_Item> list = new List <SIT2_Item>();

            List <EmailMessageEntity> messages = await ObjEWSClient.ReadMailAsync(lastDate);

            await Task.Run(() =>
            {
                foreach (var item in messages)
                {
                    Parser parser   = new Parser();
                    SIT2_Item table = parser.ParseHtml(item.Body);
                    if (table == null)
                    {
                        continue;
                    }
                    table.Id = item.Subject.Remove(0, item.Subject.IndexOf(" ID") + 3);
                    list.Add(table);
                }
            });

            if (messages.Count > 0)
            {
                FileHandler fHandler = new FileHandler();
                Settings    setting;
                JSONHandler jHandler   = new JSONHandler();
                var         jsonString = await fHandler.ReadFromSystem(FileHandler.FileName.Settings);

                if (jsonString != null)
                {
                    setting = jHandler.Deserialize <Settings>(jsonString);
                }
                else
                {
                    setting = new Settings();
                }
                setting.LastDate = DateTime.UtcNow;
                jsonString       = jHandler.Serialize <Settings>(setting);
                await fHandler.WriteOnSystem(jsonString, FileHandler.FileName.Settings);
            }

            return(list);
        }
Beispiel #4
0
        public SIT2_Item ParseHtml(string htmlString)
        {
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(htmlString);

            foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table"))
            {
                try
                {
                    SIT2_Item item    = new SIT2_Item();
                    int       counter = 0;
                    HtmlNode  tbody;
                    if (table.SelectSingleNode("tbody") != null)
                    {
                        tbody = table.SelectNodes("tbody").First();
                    }
                    else
                    {
                        tbody = table;
                    }
                    foreach (HtmlNode row in tbody.SelectNodes("tr"))
                    {
                        int    i   = 0;
                        string key = null;
                        foreach (var cell in row.SelectNodes("td"))
                        {
                            string temp = null;
                            if (i < 2)
                            {
                                temp = cell.InnerText;
                                while (temp.Contains("\r\n"))
                                {
                                    temp = temp.Replace("\r\n", "");
                                }
                                while (temp.Contains(@"&nbsp;"))
                                {
                                    temp = temp.Replace(@"&nbsp;", " ");
                                }
                            }
                            if (i == 0)
                            {
                                key = temp;
                            }
                            if (i == 1)
                            {
                                PropertyInfo info = typeof(SIT2_Item)
                                                    .GetProperties()
                                                    .Where(p =>
                                                           (p.GetCustomAttribute(typeof(NameAttribute), false) as NameAttribute).Name == key.Replace(":", "")).FirstOrDefault <PropertyInfo>();
                                if (info != null)
                                {
                                    info.SetValue(item, temp);
                                    counter++;
                                }
                            }
                            i++;
                        }
                    }
                    if (counter >= 27)
                    {
                        return(item);
                    }
                }
                catch (Exception)
                {
                }
            }
            return(null);
        }