Пример #1
0
 internal void AddList2ListListDescriptor
     (List <ListDescriptor> ListDescriptorsList, Dictionary <Guid, ListDescriptor> listsDictionary, PRColumn[] commonColumns)
 {
     try
     {
         if (listsDictionary.ContainsKey(this.ListGuid) || this.IsProxy || !this.Checked)
         {
             return;
         }
         if (m_recursive)
         {
             throw new ApplicationException(); //TODO
         }
         m_recursive = true;
         UniqueColumns  _columns        = new UniqueColumns(CreateColumnDescriptors(commonColumns, commonColumns, ListDescriptorsList, listsDictionary));
         ListDescriptor _ListDescriptor = new ListDescriptor(this.Name);
         listsDictionary.Add(this.ListGuid, _ListDescriptor);
         foreach (PRContentType _clx in ContentType)
         {
             _columns.AddRange(CreateColumnDescriptors(_clx.Column, commonColumns, ListDescriptorsList, listsDictionary));
         }
         _ListDescriptor.Columns = _columns.ToArray();
         ListDescriptorsList.Add(_ListDescriptor);
     }
     finally
     {
         m_recursive = false;
     }
 }
Пример #2
0
        public void TestCollectionDescriptor()
        {
            var attributeRegistry = new AttributeRegistry();
            var factory           = new TypeDescriptorFactory(attributeRegistry);
            var descriptor        = new ListDescriptor(factory, typeof(List <string>), false, new DefaultNamingConvention());

            descriptor.Initialize(new DefaultKeyComparer());

            // No Capacity as a member
            Assert.Equal(0, descriptor.Count);
            Assert.True(descriptor.IsPureCollection);
            Assert.Equal(typeof(string), descriptor.ElementType);

            descriptor = new ListDescriptor(factory, typeof(NonPureCollection), false,
                                            new DefaultNamingConvention());
            descriptor.Initialize(new DefaultKeyComparer());

            // Has name as a member
            Assert.Equal(1, descriptor.Count);
            Assert.False(descriptor.IsPureCollection);
            Assert.Equal(typeof(int), descriptor.ElementType);

            descriptor = new ListDescriptor(factory, typeof(ArrayList), false, new DefaultNamingConvention());
            descriptor.Initialize(new DefaultKeyComparer());

            // No Capacity
            Assert.Equal(0, descriptor.Count);
            Assert.True(descriptor.IsPureCollection);
            Assert.Equal(typeof(object), descriptor.ElementType);
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PRList" /> class.
        /// </summary>
        /// <param name="columns">The columns.</param>
        /// <param name="commonColumns">The common columns.</param>
        /// <param name="listDescriptorsList">The list descriptors list.</param>
        /// <param name="listsDictionary">The lists dictionary.</param>
        /// <returns></returns>
        private IEnumerable <RegularColumn> CreateColumnDescriptors
            (IEnumerable <PRColumn> columns, PRColumn[] commonColumns, List <ListDescriptor> listDescriptorsList, Dictionary <Guid, ListDescriptor> listsDictionary)
        {
            List <RegularColumn> _regularColums = new List <RegularColumn>();

            foreach (PRColumn _clmx in columns)
            {
                if (_clmx.PivateKeyColumn)
                {
                    _regularColums.Add(new RegularColumn(ColumnType.PrivateKey, _clmx.Member, false, _clmx.SQLDataType, _clmx.SQLPrecision));
                }
                else if (!_clmx.Checked)
                {
                    continue;
                }
                else if (_clmx.LookupColumn && _clmx.ListLookup.Checked && !_clmx.ListLookup.IsProxy)
                {
                    _clmx.ListLookup.AddList2ListListDescriptor(listDescriptorsList, listsDictionary, commonColumns);
                    ListDescriptor _dest = listsDictionary[_clmx.ListLookup.ListGuid];
                    _regularColums.Add(new ForeignKeyColumn(_clmx.Member, _clmx.SQLNullable, _clmx.SQLDataType)
                    {
                        ReferencedTableName = _dest.SQLTableName,
                        ReferencedColumn    = _dest.PFColumnName,
                    });
                }
                else
                {
                    _regularColums.Add(new RegularColumn(ColumnType.Regular, _clmx.Member, _clmx.SQLNullable, _clmx.SQLDataType, _clmx.SQLPrecision));
                }
            }
            return(_regularColums);
        }
Пример #4
0
        /// <summary>
        /// Choose a command
        /// </summary>
        /// <param name="input">The users input.</param>
        public static void ChooseCommand(string input, ListDescriptor list, NoteDescriptor note)
        {
            if (string.IsNullOrEmpty(input))
            {
                Print.Color("red", "You must enter a command.");
                Index(list, note);
            }
            else
            {
                switch (input)
                {
                case "view all":
                    ViewAll(list);
                    Index(list, note);
                    break;

                case "create note":
                    Create(note.ListId);
                    Index(list, note);
                    break;

                case "help":
                    Command.HelpCommand.ShowListCommands();
                    Index(list, note);
                    break;

                default:
                    Navigate(input, list, note);
                    break;
                }
            }
        }
Пример #5
0
        /// <summary>
        /// View all your notes in the list.
        /// </summary>
        public static void ViewAll(ListDescriptor thisList)
        {
            System.Console.WriteLine(">>> >>> Here are your notes:");

            var lists = NoteRepository.ReadAllNotesInList(thisList.ListId);

            var cacheDate = "";

            foreach (var list in lists)
            {
                var date = Helper.GetDate(list.CreatedDateTime);

                if (date != cacheDate)
                {
                    System.Console.WriteLine("\n > " + date);
                }
                if (list.ListId == thisList.ListId)
                {
                    Print.Color("orange", "\n > " + list.NoteId);
                    Print.Color("blue", list.Content);
                }
            }

            Print.Color("orange", "\n");

            ListController.Index(thisList);
        }
Пример #6
0
        /// <summary>
        /// Display the information about a specified list.
        /// </summary>
        /// <param name="list">The list in focus.</param>
        public static void Index(ListDescriptor list)
        {
            System.Console.WriteLine(">>> Welcome to [" + list.Title + "]");

            System.Console.WriteLine(">>> Type 'help' for a list of available commands!");
            System.Console.WriteLine(">>> Please enter a command...");

            ChooseCommand(System.Console.ReadLine(), list);
        }
Пример #7
0
        /// <summary>
        /// Display the information about a specified note.
        /// </summary>
        /// <param name="note">The note in focus.</param>
        public static void Index(ListDescriptor list, NoteDescriptor note)
        {
            System.Console.WriteLine(">>> >>> Welcome to note: [" + note.NoteId + "]");

            System.Console.WriteLine(">>> >>> Type 'help' for a list of available commands!");
            System.Console.WriteLine(">>> >>> Please enter a command...");

            ChooseCommand(System.Console.ReadLine(), list, note);;
        }
Пример #8
0
        private static IEnumerable EnumerateList([NotNull] object list, [NotNull] ListDescriptor listDescriptor)
        {
            var count = listDescriptor.GetCollectionCount(list);

            for (var i = 0; i < count; i++)
            {
                yield return(listDescriptor.GetValue(list, i));
            }
        }
 private static string BuildScript(ListDescriptor _ldx, StringBuilder script)
 {
     SQLGenerator.CreateTableScript _generator = new SQLGenerator.CreateTableScript();
     _generator.ColumnDefinitions    = new List <SQLGenerator.CreateTableScript.ColumDescriptor>(GetColumnDefinitions(_ldx.Columns));
     _generator.ConstrainDefinitions = new List <SQLGenerator.CreateTableScript.ConstrainDescriptor>(GetConstrainDescriptors(_ldx.Columns, _generator));
     _generator.PrivateKeyColumnName = _ldx.PFColumnName;
     _generator.TableName            = _ldx.SQLTableName;
     return(_generator.TransformText());
     //IEnumerable<PRColumn> _columns = ObjectModelRoot.ObjectModelRoot.Columns.Where<PRColumn>( _clx => _clx.) ;
 }
Пример #10
0
        /// <summary>
        /// Tries to convert the <paramref name="sourceList"/> to the type described by <paramref name="listDescriptor"/>.
        /// </summary>
        /// <param name="sourceList"></param>
        /// <param name="listDescriptor"></param>
        /// <param name="convertedList"></param>
        /// <returns><c>true</c> if the <paramref name="sourceList"/> could be converted to the type described by <paramref name="listDescriptor"/>; otherwise, <c>false</c>.</returns>
        private static bool TryConvertListData([NotNull] object sourceList, [NotNull] ListDescriptor listDescriptor, out object convertedList)
        {
            try
            {
                var sourceListType = sourceList.GetType();
                // Already same type
                if (listDescriptor.Type == sourceListType)
                {
                    convertedList = sourceList;
                    return(true);
                }

                convertedList = Activator.CreateInstance(listDescriptor.Type, true);
                var sourceListDescriptor = (ListDescriptor)TypeDescriptorFactory.Default.Find(sourceListType);
                foreach (var item in EnumerateList(sourceList, sourceListDescriptor))
                {
                    object obj;
                    if (!TypeConverterHelper.TryConvert(item, listDescriptor.ElementType, out obj))
                    {
                        // (optimistic) try to convert the remaining items
                        continue;
                    }
                    listDescriptor.Add(sourceList, obj);
                }
                return(listDescriptor.GetCollectionCount(convertedList) > 0);
            }
            catch (InvalidCastException) { }
            catch (InvalidOperationException) { }
            catch (FormatException) { }
            catch (NotSupportedException) { }
            catch (Exception ex) when(ex.InnerException is InvalidCastException)
            {
            }
            catch (Exception ex) when(ex.InnerException is InvalidOperationException)
            {
            }
            catch (Exception ex) when(ex.InnerException is FormatException)
            {
            }
            catch (Exception ex) when(ex.InnerException is NotSupportedException)
            {
            }

            // Incompatible type and no conversion available
            convertedList = null;
            return(false);
        }
Пример #11
0
 /// <summary>
 /// Navigate around the notes view.
 /// </summary>
 /// <param name="input">The user input.</param>
 /// <param name="list">The current list in focus.</param>
 public static void Navigate(string input, ListDescriptor list)
 {
     if (input.Contains("view") && !input.Contains("view all") && !string.IsNullOrEmpty(input))
     {
         try
         {
             var noteId = Convert.ToInt32(input.Split("view ")[1].Trim());
             NoteController.Display(noteId);
         }
         catch (Exception e)
         {
             Print.Color("red", e.ToString());
             Print.Color("red", "Please specify which list to navigate to.");
         }
     }
     Index(list);
 }
Пример #12
0
        /// <summary>
        /// Choose a command.
        /// </summary>
        /// <param name="input">The users input.</param>
        public static void ChooseCommand(string input, ListDescriptor list)
        {
            if (string.IsNullOrEmpty(input))
            {
                Print.Color("red", "You must enter a command.");
                Index(list);
            }
            else
            {
                switch (input)
                {
                case "view all":
                    NoteController.ViewAll(list);
                    Index(list);
                    break;

                case "create note":
                    NoteController.Create(list.ListId);
                    Index(list);
                    break;

                case "help":
                    Command.HelpCommand.ShowListCommands();
                    Index(list);
                    break;

                case "export all":
                    Command.ExportCommand.Export(list);
                    Index(list);
                    break;

                case "back":
                    Print.Color("Yellow", "Redirecting to home...");
                    Startup.Introduction();
                    break;

                default:
                    Navigate(input, list);
                    break;
                }
            }
        }
Пример #13
0
        /// <summary>
        /// Reads a list by Id.
        /// </summary>
        /// <param name="title">The title of the list to view.</param>
        public static ListDescriptor ReadListDetailsByTitle(string title)
        {
            using var context = new Context();

            var list = context.Lists
                       .FirstOrDefault(l => l.Title == title && l.Archived == false);

            if (list == null)
            {
                return(new ListDescriptor());
            }

            var listDescriptor = new ListDescriptor()
            {
                ListId          = list.ListId,
                Title           = list.Title,
                CreatedDateTime = list.CreatedDateTime
            };

            return(listDescriptor);
        }
Пример #14
0
        private static bool ConvertForList(ListDescriptor listDescriptor, ref object data)
        {
            if (ListDescriptor.IsList(data.GetType()))
            {
                if (!TryConvertListData(data, listDescriptor, out data))
                {
                    return(false);
                }
            }
            else
            {
                object convertedData;
                if (!TypeConverterHelper.TryConvert(data, listDescriptor.ElementType, out convertedData))
                {
                    return(false);
                }

                var convertedCollection = Activator.CreateInstance(listDescriptor.Type, true);
                listDescriptor.Add(convertedCollection, convertedData);
                data = convertedCollection;
            }
            return(true);
        }
Пример #15
0
        public static void Export(ListDescriptor list)
        {
            Print.Color("yellow", "The new file will be created in: C:\\Source\\Notes.");
            var folderPath = "C:\\Source\\Notes";

            Print.Color("yellow", "Choose a name for your file:");
            var fileName = System.Console.ReadLine();

            if (folderPath.EndsWith("/"))
            {
                folderPath = folderPath.Substring(folderPath.Length - 1);
            }

            var path = folderPath + "/" + fileName;

            var notes = NoteRepository.ReadAllNotesInList(list.ListId);

            if (File.Exists(path))
            {
                return;
            }

            using (StreamWriter sw = File.CreateText(path))
            {
                sw.WriteLine("List ID: " + list.ListId + ", Created: " + list.CreatedDateTime);
                sw.WriteLine(list.Title.ToUpper());
                sw.WriteLine("----------");

                var cacheDate = "098uio8u";
                var cacheTime = "098uio8u";
                foreach (var note in notes)
                {
                    var formattedDate = Helper.GetDate(note.CreatedDateTime);

                    if (cacheDate == formattedDate)
                    {
                        var formattedTime = Helper.GetTime(note.CreatedDateTime);

                        if (cacheTime == formattedTime)
                        {
                            sw.WriteLine("\n" + note.Content);
                        }
                        else
                        {
                            sw.WriteLine("\n" + formattedTime);
                            sw.WriteLine("\n" + note.Content);
                        }
                    }
                    else
                    {
                        sw.WriteLine("\n" + formattedDate);

                        var time = note.CreatedDateTime.Hour + " : " + note.CreatedDateTime.Minute + " : " + note.CreatedDateTime.Second;
                        sw.WriteLine("\n" + time + "\n" + note.Content);
                    }
                    cacheDate = formattedDate;
                }
            }

            var oldFileName = Path.GetFileName(path);
            var newFileName = Path.ChangeExtension(oldFileName, ".doc");
            var newFilePath = folderPath + "/" + newFileName;

            File.Move(path, newFilePath);
            Print.Color("green", "Export successful!");
        }
Пример #16
0
 private static bool HasCollectionReference(Type type)
 {
     return(type.IsArray || ListDescriptor.IsList(type) || DictionaryDescriptor.IsDictionary(type) || SetDescriptor.IsSet(type) || OldCollectionDescriptor.IsCollection(type));
 }