Пример #1
0
        public override SolveResult Solve(ISudokuSquare[] group, GroupKind groupKind)
        {
            SolveResult result = SolveResult.None;

            for (int first = 0; first < group.Length; first++)
            {
                for (int second = 0; second < group.Length; second++)
                {
                    if (second == first)
                    {
                        continue;
                    }
                    else
                    {
                        for (int third = 0; third < group.Length; third++)
                        {
                            if (third == first || third == second)
                            {
                                continue;
                            }
                            else
                            {
                                List <int> indicesToCheck = new List <int>();
                                indicesToCheck.Add(first);
                                indicesToCheck.Add(second);
                                indicesToCheck.Add(third);
                                result = SolveForMany(group, result, indicesToCheck, groupKind);
                            }
                        }
                    }
                }
            }
            return(result);
        }
Пример #2
0
        Task <Message[]> GetClientGroupMessages(GroupKind groupKind)
        {
            switch (groupKind)
            {
            case GroupKind.None:
                var tcs = new TaskCompletionSource <Message[]>();
                tcs.SetResult(new Message[0]);
                return(tcs.Task);

            case GroupKind.MyFeed:
                return(client.GetMyFeed());

            case GroupKind.AllMessages:
                return(client.GetAllMessages());

            case GroupKind.Popular:
                return(client.GetPopular());

            case GroupKind.WithMedia:
                return(client.GetWithMedia());

            default:
                throw new ArgumentException("groupKind");
            }
        }
Пример #3
0
 public SampleDataGroup(GroupKind groupKind, string title, string imagePath, string smallImagePath, Brush brush)
     : base(title, string.Empty, imagePath, smallImagePath, null)
 {
     this.groupKind           = groupKind;
     this.brush               = brush;
     Items.CollectionChanged += ItemsCollectionChanged;
 }
Пример #4
0
        public override SolveResult Solve(ISudokuSquare[] group, GroupKind groupKind)
        {
            Dictionary <string, List <int> > dictionary = new Dictionary <string, List <int> >();

            Collect2x2Notes(group, dictionary);
            return(Solve2x2Notes(group, dictionary));
        }
Пример #5
0
		public override SolveResult Solve(ISudokuSquare[] group, GroupKind groupKind)
		{
			SolveResult result = SolveResult.None;

			for (int first = 0; first < group.Length; first++)
				for (int second = 0; second < group.Length; second++)
					if (second == first)
						continue;
					else
						for (int third = 0; third < group.Length; third++)
							if (third == first || third == second)
								continue;
							else
								for (int fourth = 0; fourth < group.Length; fourth++)
									if (fourth == first || fourth == second || fourth == third)
										continue;
									else
									{
										List<int> indicesToCheck = new List<int>();
										indicesToCheck.Add(first);
										indicesToCheck.Add(second);
										indicesToCheck.Add(third);
										indicesToCheck.Add(fourth);
										result = SolveForMany(group, result, indicesToCheck, groupKind);
									}
			return result;
		}
 private Group(string text, int index, GroupKind kind, IReadOnlyList <GroupAction> actions)
 {
     Text         = text;
     Index        = index;
     Kind         = kind;
     this.actions = actions;
 }
Пример #7
0
 public async Task InitializeGroup(GroupKind kind)
 {
     Group = rootItemsContainer.Root.Single(x => x.GroupKind == kind);
     if (Group.Items.Count == 0)
     {
         await messagesSourceService.FillItems(Group);
     }
 }
Пример #8
0
            /// <summary>
            /// Initializes a new instance of the <see cref="GroupInfo"/> struct.
            /// </summary>
            /// <param name="groupKind">Type of group.</param>
            /// <param name="nameFunc">Function returning localized name of category.</param>
            /// <param name="categories">List of category Ids to hardcode.</param>
            public GroupInfo(GroupKind groupKind, Func <string> nameFunc, params int[] categories)
            {
                this.GroupKind = groupKind;
                this.nameFunc  = nameFunc;

                this.Categories = new();
                this.Categories.AddRange(categories);
            }
Пример #9
0
        public override SolveResult Solve(ISudokuSquare[] group, GroupKind groupKind)
        {
            SolveResult result = SolveResult.None;

            Dictionary <int, int> numbersFound = new Dictionary <int, int>();

            for (int i = 0; i < group.Length; i++)
            {
                ISudokuSquare sudokuSquare = group[i];
                List <int>    notes        = GetNumbers(sudokuSquare.Notes);
                foreach (int note in notes)
                {
                    if (!numbersFound.ContainsKey(note))
                    {
                        numbersFound.Add(note, 1);
                    }
                    else
                    {
                        numbersFound[note]++;
                    }
                }
            }

            foreach (int note in numbersFound.Keys)
            {
                if (numbersFound[note] == 1)
                {
                    int onlyOneNote = note;
                    if (GroupAlreadyIsShowing(group, onlyOneNote))
                    {
                        continue;
                    }
                    // note has to be in this square!
                    for (int i = 0; i < group.Length; i++)
                    {
                        ISudokuSquare sudokuSquare = group[i];
                        List <int>    notes        = GetNumbers(sudokuSquare.Notes);
                        if (notes.Contains(onlyOneNote))
                        {
                            sudokuSquare.Notes = "";
                            sudokuSquare.Value = onlyOneNote.ToString()[0];
                            result             = SolveResult.SquaresSolved;
                        }
                    }
                }
            }
            return(result);
        }
Пример #10
0
 async void InitializeViewModel(GroupKind kind, int? selectedItemId) {
     await ViewModel.InitializeGroup(kind);
     if(selectedItemId == null) {
         itemListView.SelectedItem = null;
         // When this is a new page, select the first item automatically unless logical page
         // navigation is being used (see the logical page navigation #region below.)
         if(!UsingLogicalPageNavigation() && itemsViewSource.View != null && itemsViewSource.View.Count > 0) {
             itemsViewSource.View.MoveCurrentToFirst();
         }
     } else if(itemsViewSource.View != null) {
         var mid = selectedItemId.Value;
         var item = ViewModel.Items.FirstOrDefault(x => x.MId == mid);
         if(item != null) {
             itemsViewSource.View.MoveCurrentTo(item);
         }
     }
 }
Пример #11
0
        /// <summary>
        /// Create this Element as HTML and process down with all children.
        /// </summary>
        /// <param name="snippets">Create HTML for these snippets in distinct order, section resolve their children independently.</param>
        /// <param name="target">The current production target the builder is working for.</param>
        /// <param name="targetFragment"></param>
        /// <returns></returns>
        protected string CreateChildren(IEnumerable <Snippet> snippets, GroupKind target, FrozenFragment targetFragment)
        {
            Element opus = this;

            do
            {
                opus = opus.Parent;
            } while (!(opus is Opus));
            var numbering            = ((Opus)opus).Numbering;
            var flatContent          = new StringBuilder();
            Action <Snippet> convert = null;

            convert = e => {
                var builder = e.GetType().GetCustomAttributes(typeof(SnippetBuilderAttribute), true).OfType <SnippetBuilderAttribute>().First(sb => sb.Target == target);
                flatContent.Append(builder.BuildHtml(e, numbering, targetFragment));
            };
            snippets.OrderBy(s => s.OrderNr).ToList().ForEach(c => convert(c));
            return(flatContent.ToString());
        }
Пример #12
0
        /// <summary>
        /// This function stores a media file in blob storage and returns a serializable reference object
        /// for the order process.
        /// </summary>
        /// <param name="fileName">The internal name</param>
        /// <param name="group">The media type, such as 'epub', 'pdf'</param>
        /// <param name="content">The actual content</param>
        /// <param name="userName">The user this content is applied to.</param>
        /// <returns></returns>
        public MediaFile StoreMediaFile(string fileName, GroupKind group, byte[] content, string userName)
        {
            if (content == null)
            {
                return(null);
            }
            var id = Guid.NewGuid();

            using (var blob = BlobFactory.GetBlobStorage(id, BlobFactory.Container.MediaFiles)) {
                blob.Content = content;
                var fileRes = new UserFile {
                    Name       = fileName,
                    Owner      = userName == null ? null : GetCurrentUser(userName),
                    ResourceId = id,
                    Folder     = BlobFactory.Container.MediaFiles.ToString(),
                    Private    = true
                };
                Ctx.UserFiles.Add(fileRes);
                SaveChanges();
                blob.Save();
            }
            return(new MediaFile(id, group.ToString().ToLowerInvariant()));
        }
Пример #13
0
        async void InitializeViewModel(GroupKind kind, int?selectedItemId)
        {
            await ViewModel.InitializeGroup(kind);

            if (selectedItemId == null)
            {
                itemListView.SelectedItem = null;
                // When this is a new page, select the first item automatically unless logical page
                // navigation is being used (see the logical page navigation #region below.)
                if (!UsingLogicalPageNavigation() && itemsViewSource.View != null && itemsViewSource.View.Count > 0)
                {
                    itemsViewSource.View.MoveCurrentToFirst();
                }
            }
            else if (itemsViewSource.View != null)
            {
                var mid  = selectedItemId.Value;
                var item = ViewModel.Items.FirstOrDefault(x => x.MId == mid);
                if (item != null)
                {
                    itemsViewSource.View.MoveCurrentTo(item);
                }
            }
        }
Пример #14
0
 public async Task InitializeGroup(GroupKind kind) {
     Group = rootItemsContainer.Root.Single(x => x.GroupKind == kind);
     if(Group.Items.Count == 0) {
         await messagesSourceService.FillItems(Group);
     }
 }
Пример #15
0
        /// <summary>
        /// Create deep level copy of one chapter of an opus and export as plain HTML using the goven groups builder attributes.
        /// </summary>
        /// <param name="opus">Reference to parent opus</param>
        /// <param name="chapter">Source Chapter</param>
        /// <param name="createImage">handler to store images</param>
        /// <param name="scaleImage">handler to scale/change images according to image properties</param>
        /// <param name="builderContent">Callback to get the content from caller</param>
        /// <param name="numbering">Instruction to create section numbers.</param>
        /// <param name="path">Path to savely store temporary files.</param>
        /// <param name="target">Build for HTML, RSS, PDF, and so  on.</param>
        /// <returns>HTML</returns>
        public string CreateChapterHtml(Opus document, Section chapter, CreateImageHandler createImage, ScaleImageHandler scaleImage, string path, GroupKind target, bool withNumbers = true)
        {
            if (chapter.Parent.Id != document.Id)
            {
                throw new ArgumentOutOfRangeException("chapter");
            }
            document.CreateImage += createImage;
            document.ScaleImage  += scaleImage;
            document.TempPath     = path;
            document.Numbering    = GetLocalizedNumberingSchema();
            var html = new StringBuilder();

            html.Append(CreateHtmlInner(new Snippet[] { chapter }, document.Numbering, target));
            return(html.ToString());
        }
Пример #16
0
 public SnippetBuilderAttribute(GroupKind target, string pattern, params string[] properties)
 {
     Target      = target;
     Properties  = properties;
     HtmlPattern = pattern;
 }
Пример #17
0
 public abstract string this[GroupKind target, FrozenFragment targetFragment] {
     get;
 }
Пример #18
0
        private SolveResult SolveForManyWithIndicesToCheck(ISudokuSquare[] group, ref SolveResult result, List <int> indicesToCheck, GroupKind groupKind, List <List <int> > allNoteNumbers)
        {
            // We want to add the new logic!
            if (groupKind == GroupKind.Column || groupKind == GroupKind.Row)
            {
                // TODO: Group by block

                Dictionary <int, List <int> > blockMap = new Dictionary <int, List <int> >();

                foreach (int index in indicesToCheck)
                {
                    int key = group[index].Block;
                    if (!blockMap.ContainsKey(key))
                    {
                        blockMap.Add(key, new List <int>());
                    }

                    List <int> allBlockNotes = blockMap[key];
                    List <int> notes         = GetNumbers(group[index].Notes);
                    foreach (int note in notes)
                    {
                        if (allBlockNotes.IndexOf(note) < 0)
                        {
                            allBlockNotes.Add(note);
                        }
                    }
                }

                if (blockMap.Count > 1)
                {
                    foreach (int key in blockMap.Keys)
                    {
                        List <int> targetBlock = blockMap[key];
                        List <int> resultsForThisSubtraction = new List <int>();
                        resultsForThisSubtraction = targetBlock.ToList();
                        foreach (int sourceKey in blockMap.Keys)
                        {
                            List <int> sourceBlock = blockMap[sourceKey];
                            if (targetBlock == sourceBlock)
                            {
                                continue;
                            }

                            // We need to subtract!!
                            foreach (int note in sourceBlock)
                            {
                                if (resultsForThisSubtraction.IndexOf(note) >= 0)
                                {
                                    resultsForThisSubtraction.Remove(note);
                                }
                            }
                        }

                        // Subtraction for this block is done!

                        if (resultsForThisSubtraction.Count > 0)
                        {
                            // Magic!!! We can remove these from other squares in the targetBlock!
                            ISudokuSquare[] blocks = SudokuBoard.GetBlock(key);

                            // We need to make sure that any blocks we examine are not among those already in group[indicesToCheck]
                        }
                    }
                }

                //foreach (List<int> noteNumbers in allNoteNumbers)
                //{

                //}

                // TODO: Do we have more than one block?
                // Yes? It's magic!!!
                // TODO: Set Subtraction (e.g., b1 - b2) - b1 is the first block we subtract from
                // TODO: Set Subtraction the other (b2 - b1) - so b2 is the first block we subtract from
                // TODO: Anything left over???
                // Yes? Then we can remove those leftover numbers from **all the other squares** in the first block we subtracted from.
                // LaterCommands.Add(new RemoveCommand(b2, "1, 3"));
            }

            List <int> allNumbersFound = new List <int>();

            foreach (List <int> noteNumbers in allNoteNumbers)
            {
                AddNumbersTo(allNumbersFound, noteNumbers);
            }

            if (allNumbersFound.Count > indicesToCheck.Count)
            {
                return(SolveResult.None);
            }
            else
            {
                for (int i = 0; i < group.Length; i++)
                {
                    if (indicesToCheck.Contains(i))
                    {
                        continue;
                    }

                    // We can actually remove!!!
                    if (RemoveNotesFrom(group[i], string.Join(", ", allNumbersFound)) == SolveResult.SquaresSolved)
                    {
                        result = SolveResult.SquaresSolved;
                    }
                }
            }

            return(result);
        }
Пример #19
0
        protected SolveResult SolveForMany(ISudokuSquare[] group, SolveResult result, List <int> indicesToCheck, GroupKind groupKind)
        {
            if (!NoteCountsAreSufficient(group, indicesToCheck, out List <List <int> > allNoteNumbers))
            {
                return(SolveResult.None);
            }

            // We have N squares that all contain N notes or fewer (in indicesToCheck)!!!
            return(SolveForManyWithIndicesToCheck(group, ref result, indicesToCheck, groupKind, allNoteNumbers));
        }
Пример #20
0
        /// <summary>
        /// Create deep level copy of an opus and export as plain HTML using the goven groups builder attributes.
        /// </summary>
        /// <param name="opus">Source</param>
        /// <param name="createImage">handler to store images</param>
        /// <param name="scaleImage">handler to scale/change images according to image properties</param>
        /// <param name="builderContent">Callback to get the content from caller</param>
        /// <param name="numbering">Instruction to create section numbers.</param>
        /// <param name="path">Path to savely store temporary files.</param>
        /// <param name="target">Build for HTML, RSS, PDF, and so  on.</param>
        /// <returns>HTML</returns>
        public string CreateDocumentHtml(Opus opus, CreateImageHandler createImage, ScaleImageHandler scaleImage, Func <string> builderContent, IDictionary <string, NumberingSchema> numbering, string path, GroupKind target)
        {
            opus.CreateImage += createImage;
            opus.ScaleImage  += scaleImage;
            opus.TempPath     = path;
            opus.Numbering    = numbering;
            var builder = opus.GetType().GetCustomAttributes(typeof(SnippetBuilderAttribute), true).OfType <SnippetBuilderAttribute>().Single(sb => sb.Target == target);

            opus.BuiltContent = builderContent();
            return(builder.BuildHtml(opus, numbering, null));
        }
Пример #21
0
 public void OpenReadThreads(GroupKind kind)
 {
     Navigate <ReadThreadsPage>(kind.ToString());
 }
Пример #22
0
 public SampleDataGroup(GroupKind groupKind, string title, string imagePath, string smallImagePath, Brush brush)
     : base(title, string.Empty, imagePath, smallImagePath, null)
 {
     this.groupKind = groupKind;
     this.brush = brush;
     Items.CollectionChanged += ItemsCollectionChanged;
 }
Пример #23
0
        public async Task SaveGroup(GroupKind groupKind, Message[] messages)
        {
            var fileName = GetFileName(groupKind);

            await SaveCore(fileName, messages);
        }
Пример #24
0
 public LabelGroup(IReadOnlyList <int> children, GroupKind kind)
 {
     Children = children ?? throw new ArgumentNullException(nameof(children));
     Kind     = kind;
 }
Пример #25
0
        public async Task <Message[]> LoadGroup(GroupKind groupKind)
        {
            var fileName = GetFileName(groupKind);

            return(await LoadCore <Message>(fileName));
        }
Пример #26
0
        private string CreateHtmlInner(IEnumerable <Snippet> source, IDictionary <string, NumberingSchema> numbering, GroupKind target)
        {
            // each snippet has its very own numbering schema
            var flatContent = new StringBuilder();

            foreach (var elm in source)
            {
                // Get the final HTML
                var builder = elm.GetType().GetCustomAttributes(typeof(SnippetBuilderAttribute), true).OfType <SnippetBuilderAttribute>().Single(sb => sb.Target == target);
                var html    = builder.BuildHtml(elm, numbering, null);
                flatContent.Append(html);
                if (numbering == null)
                {
                    continue;
                }
                // add chapter and reset all other counters
                numbering["Section1"].Major       = numbering["Section1"].Major + 1;
                numbering["Section2"].Major       = numbering["Section1"].Major;
                numbering["Section3"].Major       = numbering["Section1"].Major;
                numbering["Section4"].Major       = numbering["Section1"].Major;
                numbering["ImageSnippet"].Major   = numbering["Section1"].Major;
                numbering["TableSnippet"].Major   = numbering["Section1"].Major;
                numbering["ListingSnippet"].Major = numbering["Section1"].Major;
                numbering["Section1"].Minor       = 1;
                numbering["Section2"].Minor       = 1;
                numbering["Section3"].Minor       = 1;
                numbering["Section4"].Minor       = 1;
                numbering["ImageSnippet"].Minor   = 1;
                numbering["TableSnippet"].Minor   = 1;
                numbering["ListingSnippet"].Minor = 1;
            }
            return(flatContent.ToString().Replace("&shy;", "&#173;"));
        }
Пример #27
0
 public abstract SolveResult Solve(ISudokuSquare[] group, GroupKind groupKind);           // I'm not going to implement it here.