Example #1
0
 public Category this [Category.DirectionCode dir, Category.GroupCode gro]
 {
     get{ return(categories.Find(x => x.Direction == dir && x.Group == gro)); }
 }
Example #2
0
 public void Remove(Category.DirectionCode dir, Category.GroupCode gro)
 {
     categories.RemoveAll(x => x.Direction == dir && x.Group == gro);
 }
Example #3
0
 /// <summary>
 /// Gets the category determined by its DirectionCode and GroupCode. Returns null when a matching category doesn't exists
 /// </summary>
 /// <param name='dir'>
 /// DirectionCode.
 /// </param>
 /// <param name='gro'>
 /// GroupCode.
 /// </param>
 public Category Get(Category.DirectionCode dir, Category.GroupCode gro)
 {
     return(categories.Find(x => x.Direction == dir && x.Group == gro));
 }
Example #4
0
 public bool Contains(Category.DirectionCode dir, Category.GroupCode gro)
 {
     return(categories.Exists(x => x.Direction == dir && x.Group == gro));
 }
        public static List <Document> LoadFrom(Category parent, string path)
        {
            List <Document> documents = new List <Document>();

            //Los documentos pueden estar en directorios o solo un archivo
            //00_0000_12_noviembre_2012_nombre guay
            List <string> directories = new List <string>(Directory.EnumerateDirectories(path));

            foreach (var dire in directories)
            {
                int    pos = dire.LastIndexOf(Path.DirectorySeparatorChar);
                string dir = dire.Substring(pos + 1);

                string[] pieces = dir.Split('_');
                bool     ok     = true;

                if (pieces.Length == 6)
                {
                    Category.DirectionCode direc = Category.DirectionCode.Entrada;
                    if (!Category.DirectionCode.TryParse(pieces [0] [0].ToString(), out direc))
                    {
                        ok = false;
                    }
                    else
                    {
                        if (parent.Direction != direc)
                        {
                            ok = false;
                            throw new FileLoadException(String.Format(Mono.Unix.Catalog.GetString("Document {0} has {1} as direction code, but is in {2} folder"), pieces[5], direc.ToString(), parent.Direction.ToString()));
                        }
                    }

                    Category.GroupCode grou = Category.GroupCode.AsambleaGeneral;
                    if (!Category.GroupCode.TryParse(pieces [0] [1].ToString(), out grou))
                    {
                        ok = false;

                        if (parent.Group != grou)
                        {
                            ok = false;
                            throw new FileLoadException(String.Format(Mono.Unix.Catalog.GetString("Document {0} has {1} as group code, but is in {2} folder"), pieces[5], dire.ToString(), parent.Direction.ToString()));
                        }
                    }

                    int id = 0;
                    if (!int.TryParse(pieces[1], out id))
                    {
                        ok = false;
                    }

                    DateTime regDate = DateTime.Now;

                    if (!DateTime.TryParse(pieces[2] + "/" + pieces[3] + "/" + pieces[4], System.Globalization.CultureInfo.CreateSpecificCulture("ES-es").DateTimeFormat, System.Globalization.DateTimeStyles.AssumeLocal, out regDate))
                    {
                        ok = false;
                    }

                    string nam = pieces[5];
                    if (ok == true)
                    {
                        Document doc = new Document(parent, id, nam, regDate);

                        documents.Add(doc);
                    }
                }
            }

            List <string> files = new List <string>(Directory.EnumerateFiles(path));

            foreach (var file in files)
            {
                int    pos        = file.LastIndexOf(Path.DirectorySeparatorChar);
                string filewopath = file.Substring(pos + 1);

                int    lastPoint = filewopath.LastIndexOf('.');
                string fil       = filewopath;

                if (lastPoint >= 0)
                {
                    fil = filewopath.Substring(0, lastPoint);
                }

                string[] pieces = fil.Split('_');
                bool     ok     = true;

                if (pieces.Length == 6)
                {
                    Category.DirectionCode direc = Category.DirectionCode.Entrada;
                    if (!Category.DirectionCode.TryParse(pieces [0] [0].ToString(), out direc))
                    {
                        ok = false;
                    }
                    else
                    {
                        if (parent.Direction != direc)
                        {
                            ok = false;
                            throw new FileLoadException(String.Format(Mono.Unix.Catalog.GetString("Document {0} has {1} as direction code, but is in {2} folder"), pieces[4], direc.ToString(), parent.Direction.ToString()));
                        }
                    }

                    Category.GroupCode grou = Category.GroupCode.AsambleaGeneral;
                    if (!Category.GroupCode.TryParse(pieces [0] [1].ToString(), out grou))
                    {
                        ok = false;

                        if (parent.Group != grou)
                        {
                            ok = false;
                            throw new FileLoadException(String.Format(Mono.Unix.Catalog.GetString("Document {0} has {1} as group code, but is in {2} folder"), pieces[4], grou.ToString(), parent.Group.ToString()));
                        }
                    }

                    int id = 0;
                    if (!int.TryParse(pieces[1], out id))
                    {
                        ok = false;
                                                #if DEBUG
                        System.Diagnostics.Debugger.Log(0, null, String.Format("Error parsing id:{0}", pieces[1]));
                                                #endif
                    }

                    DateTime regDate = DateTime.Now;

                    if (!DateTime.TryParse(pieces[2] + "/" + pieces[3] + "/" + pieces[4], System.Globalization.CultureInfo.CreateSpecificCulture("ES-es").DateTimeFormat, System.Globalization.DateTimeStyles.AssumeLocal, out regDate))
                    {
                        ok = false;
                                                #if DEBUG
                        System.Diagnostics.Debugger.Log(0, null, String.Format("Error parsing date:{0}", pieces[2] + "/" + pieces[3] + "/" + pieces[4]));
                                                #endif
                    }

                    string nam = pieces[5];
                    if (ok == true)
                    {
                        Document doc = new Document(parent, id, nam, regDate);

                        documents.Add(doc);
                    }
                }
                                #if DEBUG
                System.Diagnostics.Debugger.Log(0, null, String.Format("Error parsing file:{0}", fil));
                                #endif
            }
            documents.Sort();
            return(documents);
        }