Ejemplo n.º 1
0
        public static int FindByPath(ItemTree tree, StringStore strings, string path, char delimiter = '\\')
        {
            String8    path8      = String8.Convert(path, new byte[String8.GetLength(path)]);
            String8Set pathSplit8 = path8.Split(delimiter, new int[String8Set.GetLength(path8, delimiter)]);

            return(tree.FindByPath(0, pathSplit8, strings));
        }
Ejemplo n.º 2
0
        public async Task WriteMessageCreatesQueueMessageFromStringTest()
        {
            var queueName = Guid.NewGuid().ToString("N");
            var expected  = Guid.NewGuid().ToString();

            var target = new StringStore(Config.Storage.ConnectionString, queueName);

            var storageAccount = CloudStorageAccount.Parse(Config.Storage.ConnectionString);
            var client         = storageAccount.CreateCloudQueueClient();
            var queue          = client.GetQueueReference(queueName);

            try
            {
                await target.WriteMessage(expected, null, null, CancellationToken.None).ConfigureAwait(false);

                var queueItem = await queue.GetMessageAsync().ConfigureAwait(false);

                var actual = queueItem.AsString;

                actual.Should().Be(expected);
            }
            finally
            {
                await queue.DeleteIfExistsAsync().ConfigureAwait(false);
            }
        }
Ejemplo n.º 3
0
        public void UpdateIdentifiers(StringStore strings)
        {
            // Remap all words *and merge pages with only casing differences*
            Dictionary <int, List <int> > remappedIndex = new Dictionary <int, List <int> >(_wordToItemsIndex.Count);

            foreach (int wordIdentifier in _wordToItemsIndex.Keys)
            {
                int   updatedIdentifier = strings.GetSerializationIdentifier(wordIdentifier);
                Range wordMatches       = strings.RangeForString(updatedIdentifier);
                int   firstCaseInsensitiveWordIdentifier = wordMatches.Start;

                List <int> existingMatchesForWord;
                if (!remappedIndex.TryGetValue(firstCaseInsensitiveWordIdentifier, out existingMatchesForWord))
                {
                    // This is the first (or only) case-insensitive copy of the word - use the list we had
                    remappedIndex[firstCaseInsensitiveWordIdentifier] = _wordToItemsIndex[wordIdentifier];
                }
                else
                {
                    // There are already values for another casing of this word.
                    // Merge them to the current list in sorted order (this preserves ranking, if indexing was done in ranked order)
                    existingMatchesForWord.AddRange(_wordToItemsIndex[wordIdentifier]);
                    existingMatchesForWord.Sort();
                }
            }

            _wordToItemsIndex = remappedIndex;
        }
Ejemplo n.º 4
0
    public void init(string message)
    {
        label.text = message;

        yesButton.setText(StringStore.retrieve("yes"));
        noButton.setText(StringStore.retrieve("no"));
    }
Ejemplo n.º 5
0
        public bool TryFindByPath(int startIndex, String8Set path, StringStore strings, out int matchingIndex)
        {
            // If we find nothing we should return 0 (the root was the last matching thing we found)
            matchingIndex = 0;

            return(TryFindByPath(startIndex, 0, path, strings, ref matchingIndex));
        }
Ejemplo n.º 6
0
    public static List <CardData> retrieveCardDeck(string teamId)
    {
        string query = "SELECT id, teamId, player1Id, player2Id, value, inAction, outAction FROM cards WHERE teamId = '" + teamId + "'";

        DataBaseHandler.open(Application.persistentDataPath + "/Data/PlayerData.db");
        DataTable data = DataBaseHandler.executeQuery(query);

        List <CardData> cardDataList = new List <CardData>();

        for (int i = 0; i < data.Rows.Count; i++)
        {
            CardData cardData = new CardData();

            cardData.id     = data.Rows[i]["id"].ToString();
            cardData.teamId = data.Rows[i]["teamId"].ToString();

            cardData.title   = StringStore.retrieve(cardData.id + "Title");
            cardData.comment = StringStore.retrieve(cardData.id + "Comment");
            cardData.action  = StringStore.retrieve(cardData.id + "Action");

            cardData.player1Id = data.Rows[i]["player1Id"].ToString();
            cardData.player2Id = data.Rows[i]["player2Id"].ToString();
            cardData.value     = (int)data.Rows[i]["value"];
            cardData.inAction  = data.Rows[i]["inAction"].ToString();
            cardData.outAction = data.Rows[i]["outAction"].ToString();

            cardDataList.Add(cardData);
        }

        DataBaseHandler.close();

        return(cardDataList);
    }
Ejemplo n.º 7
0
        public int FindByPath(int startIndex, String8Set path, StringStore strings)
        {
            int matchingIndex;

            if (TryFindByPath(startIndex, path, strings, out matchingIndex))
            {
                return(matchingIndex);
            }

            StringBuilder message = new StringBuilder();

            using (StringWriter writer = new StringWriter(message))
            {
                writer.Write("Could not find '");
                path.Value.WriteTo(writer);
                writer.WriteLine("' in tree.");

                int partsFound = this.GetDepth(matchingIndex) - this.GetDepth(startIndex);
                writer.Write("Could not find '");
                path[partsFound].WriteTo(writer);
                writer.Write("' under '");
                this.GetPath(matchingIndex, strings, '|').WriteTo(writer);
                writer.WriteLine("' with children:");
                WriteChildrenOf(writer, strings, matchingIndex);
                writer.WriteLine();
            }

            throw new TreeItemNotFoundException(message.ToString());
        }
Ejemplo n.º 8
0
        public void WriteBinary(BinaryWriter w)
        {
            // Don't write database if empty (BinarySerializable will detect and delete file)
            if (IsEmpty)
            {
                return;
            }

            // Ensure the database has been converted to queryable/writable form
            ConvertToImmutable();

            w.Write(BinaryFileFormatVersion);

            // Write strings
            StringStore.WriteBinary(w);

            // Write symbol tree
            DeclaredMembers.WriteBinary(w);

            // Write details
            w.Write(DeclaredMemberDetails);

            // Write symbol locations
            w.Write(DeclaredMemberLocations);

            // Write file tree
            FileTree.WriteBinary(w);

            // Write search index
            Index.WriteBinary(w);

            // Write identity details (last; likely to change)
            // PackageIdentity must be last so DownloadCount can be seeked to
            Identity.WriteBinary(w);
        }
Ejemplo n.º 9
0
        public async Task WriteWithNegativeVisibleInValueMakesDataImmediatelyAvailableTest()
        {
            var queueName = Guid.NewGuid().ToString("N");
            var expected  = Guid.NewGuid().ToString("N");

            var target = new StringStore(Config.Storage.ConnectionString, queueName);

            var storageAccount = CloudStorageAccount.Parse(Config.Storage.ConnectionString);
            var client         = storageAccount.CreateCloudQueueClient();
            var queue          = client.GetQueueReference(queueName);

            try
            {
                await target.WriteMessage(expected, null, TimeSpan.FromMinutes(-1), CancellationToken.None)
                .ConfigureAwait(false);

                var queueItem = await queue.GetMessageAsync().ConfigureAwait(false);

                var actual = queueItem.AsString;

                actual.Should().Be(expected);
            }
            finally
            {
                await queue.DeleteIfExistsAsync().ConfigureAwait(false);
            }
        }
Ejemplo n.º 10
0
        private bool MatchesDetailed(ItemTree declaredMembers, StringStore strings, IMemberDatabase db, int symbolIndex)
        {
            if (!Matches(declaredMembers, strings, symbolIndex))
            {
                return(false);
            }

            if (Type != SymbolType.Any && db.GetMemberType(symbolIndex) != Type)
            {
                return(false);
            }
            if (!Modifiers.Matches(db.GetMemberModifiers(symbolIndex)))
            {
                return(false);
            }

            // ISSUE: Need a way to specify you want the empty params overload of a method (other than full match)
            // NOTE: Parameters8 was a copy gotten from StringStore to make this comparison fast (rather than a byte-by-byte comparison)
            // NOTE: Case insensitive comparison because StringStore lookup was case-insensitive, so Parameters8 casing isn't specific
            // NOTE: Need String8 rather than just checking Range.Contains because IMemberDatabase doesn't offer returning the identifier
            if ((IsFullSuffix || !this.ParametersIdentifiers.IsEmpty()) && db.GetMemberParameters(symbolIndex).CompareTo(Parameters8, true) != 0)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 11
0
        private bool Matches(ItemTree declaredMembers, StringStore strings, int symbolIndex)
        {
            int candidateNameIdentifier = declaredMembers.GetNameIdentifier(symbolIndex);

            if (!SymbolNameSuffixIdentifiers.Contains(candidateNameIdentifier))
            {
                return(false);
            }

            if (this.IgnoreCase == true)
            {
                return(true);
            }
            else
            {
                String8 candidateName8 = strings[candidateNameIdentifier];
                if (this.IsFullSuffix)
                {
                    return(this.SymbolNameSuffix.CompareTo(candidateName8, false) == 0);
                }
                else
                {
                    return(this.SymbolNameSuffix.CompareAsPrefixTo(candidateName8, false) == 0);
                }
            }
        }
Ejemplo n.º 12
0
 public void UpdateIdentifiers(StringStore strings)
 {
     for (int i = 0; i < this.Count; ++i)
     {
         _nameIdentifier[i] = strings.GetSerializationIdentifier(_nameIdentifier[i]);
     }
 }
Ejemplo n.º 13
0
        public void WriteTree(TextWriter writer, StringStore strings, int index = 0, int indent = -1, Action <int, TextWriter> writeAdditionalDetail = null)
        {
            // Write element (but only if indent is positive)
            // Write everything under the sentinel root with WriteTree(w, s, 0, -1)
            if (indent >= 0)
            {
                for (int i = 0; i < indent; ++i)
                {
                    writer.Write('\t');
                }

                strings[this.GetNameIdentifier(index)].WriteTo(writer);
                if (writeAdditionalDetail != null)
                {
                    writeAdditionalDetail(index, writer);
                }
                writer.WriteLine();
            }

            int childIndex = this.GetFirstChild(index);

            while (childIndex > 0)
            {
                WriteTree(writer, strings, childIndex, indent + 1, writeAdditionalDetail);
                childIndex = this.GetNextSibling(childIndex);
            }
        }
Ejemplo n.º 14
0
        internal bool ResolveStringsTo(StringStore store)
        {
            // If we've already resolved to this store, don't re-resolve
            if (store == this.LastResolvedStore)
            {
                return(this.LastResolveResult);
            }

            // Record we last resolved against this store and failed
            this.LastResolvedStore = store;
            this.LastResolveResult = false;

            // Look up symbol name *prefix* parts (all exact)
            for (int i = 0; i < this.SplitSymbolName8.Count - 1; ++i)
            {
                if (!store.TryFindString(this.SplitSymbolName8[i], this.IgnoreCase, out this.SymbolNamePrefixIdentifiers[i]))
                {
                    return(false);
                }
            }

            // Look up symbol name suffix (exact only if IsFullSuffix)
            if (this.IsFullSuffix)
            {
                if (!store.TryFindString(this.SymbolNameSuffix, this.IgnoreCase, out this.SymbolNameSuffixIdentifiers))
                {
                    return(false);
                }
            }
            else
            {
                if (this.SymbolNameSuffix.IsEmpty())
                {
                    this.SymbolNameSuffixIdentifiers = Range.Max;
                }
                else
                {
                    if (!store.TryGetRangeStartingWith(this.SymbolNameSuffix, out this.SymbolNameSuffixIdentifiers))
                    {
                        return(false);
                    }

                    // NOTE: Can't make a prefix Range case sensitive, so have to validate casing later
                    // Case-insensitive sort means you can have [..., array, Array, arrayList, ArrayList, ...], so no way to return case sensitive range starting with 'Array'
                }
            }

            // Look up parameters [and get the copy from the StringStore for fast comparison on signature]
            if (!store.TryFindString(this.Parameters8, this.IgnoreCase, out this.ParametersIdentifiers))
            {
                return(false);
            }
            this.Parameters8 = store[this.ParametersIdentifiers.Start];

            // If we found everything, record we succeeded
            this.LastResolveResult = true;

            return(true);
        }
Ejemplo n.º 15
0
 internal Path8(StringStore strings, ItemTree tree, int index, byte delimiter, int includeDepth = -1)
 {
     _strings      = strings;
     _tree         = tree;
     _index        = index;
     _delimiter    = (byte)delimiter;
     _includeDepth = includeDepth;
 }
Ejemplo n.º 16
0
 public Path8(StringStore strings, ItemTree tree, int index, char delimiter, int includeDepth = -1)
     : this(strings, tree, index, (byte)delimiter, includeDepth)
 {
     if ((ushort)delimiter >= 0x80)
     {
         throw new ArgumentException(String.Format(Resources.UnableToSupportMultibyteCharacter, delimiter));
     }
 }
Ejemplo n.º 17
0
 public void Clear()
 {
     this.Strings           = new StringStore();
     this.NameIdentifiers   = new PartialArray <int>();
     this.TargetIdentifiers = new PartialArray <int>();
     this.Types             = new PartialArray <byte>();
     this.EventTimes        = new PartialArray <long>();
 }
Ejemplo n.º 18
0
    void Start()
    {
        SetPopupStartAni(true);
        m_pStringStore_Src = GameObject.Find("JAImshiMng").transform.FindChild("JATextData").transform.FindChild("JATextXML").GetComponent <StringStore>();

        m_pTitleLabel.text = m_pStringStore_Src.strings[0];
        m_pMainLabel.text  = m_pStringStore_Src.strings[JAManager.I.m_nSelectPopTextIndex];
    }
Ejemplo n.º 19
0
    private void userTurnEnded()
    {
        match.currentTeam.endTurn();
        match.currentTeam = match.currentTeam.opponentTeam;

        TurnOverlay turnOverlay = GUICreator.instantiateTurnOverlay();

        turnOverlay.init(StringStore.retrieve("Turn") + " " + match.currentTeam.teamData.name, onTurnOverlayEnded);
    }
Ejemplo n.º 20
0
        public void String8Column_Basic()
        {
            StringStore  store = new StringStore();
            String8Block block = new String8Block();

            String8[] samples = new String8[] { String8.Empty, block.GetCopy("One"), block.GetCopy("two"), block.GetCopy("three") };

            String8Column column = new String8Column(store);

            Assert.AreEqual(0, column.Count);

            Verify.Exception <ArgumentOutOfRangeException>(() => { String8 value = column[0]; });

            // Set values and verify they are read back consistently (all UTC)
            for (int i = 0; i < samples.Length; ++i)
            {
                column.Add();
                column[i] = samples[i];
                Assert.AreEqual(samples[i], column[i]);
            }

            Assert.AreEqual(samples.Length, column.Count);

            // Round-Trip the column
            column.ConvertToImmutable();

            StringStore readStore = new StringStore();

            Verify.RoundTrip(store, readStore);

            String8Column readColumn = new String8Column(readStore);

            Verify.RoundTrip <String8Column>(column, readColumn);

            Assert.AreEqual(column.Count, readColumn.Count);

            for (int i = 0; i < column.Count; ++i)
            {
                Assert.AreEqual(column[i], readColumn[i]);
            }

            // Verify asking for raw identifiers works
            int firstStringIdentifier = column.IdentifierFor(1);

            Assert.AreEqual(store[firstStringIdentifier], column[1]);

            // Verify clear works
            column.Clear();
            Assert.AreEqual(0, column.Count);
            Verify.Exception <ArgumentOutOfRangeException>(() => { String8 value = column[0]; });

            // Verify SetCount works
            column.SetCount(2);
            Assert.AreEqual(2, column.Count);
            Assert.AreEqual(String8.Empty, column[1]);
        }
Ejemplo n.º 21
0
        private string MatchesForPrefixToString(MemberIndex index, StringStore strings, String8 prefix)
        {
            Range matches;

            if (!strings.TryGetRangeStartingWith(prefix, out matches))
            {
                return(String.Empty);
            }
            return(MatchesToString(index, matches));
        }
Ejemplo n.º 22
0
        private string MatchesForWordToString(MemberIndex index, StringStore strings, String8 word)
        {
            Range matches;

            if (!strings.TryFindString(word, out matches))
            {
                return(String.Empty);
            }
            return(MatchesToString(index, matches));
        }
Ejemplo n.º 23
0
        public void WriteMessageThrowsExceptionWhenValueIsNullTest()
        {
            var queueName = Guid.NewGuid().ToString("N");

            var target = new StringStore(Config.Storage.ConnectionString, queueName);

            Func <Task> action = async() =>
                                 await target.WriteMessage(null, null, null, CancellationToken.None).ConfigureAwait(false);

            action.Should().Throw <ArgumentNullException>();
        }
        public void AlphanumericSplitter_EndToEndPerformance()
        {
            String8            code           = AllCodeText.AllCode8;
            String8Set         set            = default(String8Set);
            PartialArray <int> matchContainer = new PartialArray <int>(2048);

            HashSet <String8> uniqueWords = new HashSet <String8>();
            StringStore       strings     = new StringStore();
            MemberIndex       index       = new MemberIndex();

            int iterations      = 10;
            int totalWordsSplit = 0;

            // Split, Add, Index Goal: 30k per millisecond [30 MB/sec]
            Verify.PerformanceByBytes(30 * LongExtensions.Megabyte, () =>
            {
                for (int iteration = 0; iteration < iterations; ++iteration)
                {
                    String8Set codeByLine = code.Split(UTF8.Newline, new PartialArray <int>());
                    for (int lineIndex = 0; lineIndex < codeByLine.Count; ++lineIndex)
                    {
                        // Convert and Split the line
                        String8 line = codeByLine[lineIndex];
                        set          = AlphanumericSplitter.Split(line, ref matchContainer);

                        totalWordsSplit += set.Count;

                        if (set.Count > 0)
                        {
                            int matchIndex = AlphanumericSplitter.IsAlphaNumeric(set[0][0]) ? 0 : 1;
                            for (; matchIndex < set.Count; matchIndex += 2)
                            {
                                // If the word is long enough...
                                String8 word = set[matchIndex];
                                if (word.Length > 2)
                                {
                                    if (!uniqueWords.Contains(word))
                                    {
                                        int wordIdentifier = strings.FindOrAddString(word);
                                        uniqueWords.Add(strings[wordIdentifier]);
                                        index.AddItem(wordIdentifier, lineIndex);
                                    }
                                }
                            }
                        }
                    }
                }

                return(iterations * code.Length);
            });
        }
Ejemplo n.º 25
0
        public MergedMembersDatabase(StringStore sharedStore = null)
        {
            this.StringStore = sharedStore;
            if (this.StringStore == null)
            {
                this.StringStore = new StringStore();
            }

            this.MergedMembers = new ItemTree();
            this.MergedMemberSourcePackageIdentifier = new PartialArray <int>();
            this.MergedMemberSourcePackageIdentifier.Add(0);

            this.MergedMemberDuplicateCount = new PartialArray <int>();
            this.MergedMemberDuplicateCount.Add(0);
        }
Ejemplo n.º 26
0
        public void MemberIndex_Basic()
        {
            StringStore strings = new StringStore();
            MemberIndex index   = new MemberIndex();

            // Add six sample strings to StringStore
            string[] testValues   = new string[] { "Zero", "One", "Two", "Three", "Four", "Five" };
            int[]    testValueIDs = new int[testValues.Length];
            for (int i = 0; i < testValues.Length; ++i)
            {
                testValueIDs[i] = strings.FindOrAddString(testValues[i]);
            }

            // Add 100 items to index - each item has the values it is evenly divisible by (10 has "Five" and "Two")
            for (int indexId = 1; indexId < 20; ++indexId)
            {
                for (int wordIndex = 1; wordIndex < testValueIDs.Length; ++wordIndex)
                {
                    if (indexId % wordIndex == 0)
                    {
                        index.AddItem(testValueIDs[wordIndex], indexId);
                    }
                }
            }

            // Convert for search
            strings.ConvertToImmutable();
            index.ConvertToImmutable(strings);

            // Verify matches for three are correct
            Assert.AreEqual("3, 6, 9, 12, 15, 18", MatchesForWordToString(index, strings, strings[testValueIDs[3]]));
            Assert.AreEqual("3, 6, 9, 12, 15, 18", MatchesForPrefixToString(index, strings, String8.Convert("Three", new byte[String8.GetLength("Three")])));

            // Verify matches for five are correct
            Assert.AreEqual("5, 10, 15", MatchesForWordToString(index, strings, strings[testValueIDs[5]]));
            Assert.AreEqual("5, 10, 15", MatchesForPrefixToString(index, strings, String8.Convert("Five", new byte[String8.GetLength("Five")])));

            // Verify no matches for zero
            Assert.AreEqual("", MatchesForWordToString(index, strings, strings[testValueIDs[0]]));
            Assert.AreEqual("", MatchesForPrefixToString(index, strings, String8.Convert("Zero", new byte[String8.GetLength("Zero")])));

            // Verify "Four" and "Five" matches for "F"
            Assert.AreEqual("5, 10, 15, 4, 8, 12, 16", MatchesForPrefixToString(index, strings, String8.Convert("F", new byte[String8.GetLength("F")])));
        }
Ejemplo n.º 27
0
        public void ReadBinary(BinaryReader r)
        {
            int formatVersion = r.ReadInt32();

            if (formatVersion != BinaryFileFormatVersion)
            {
                throw new IOException(String.Format(Resources.DatabaseFormatVersionWrong, BinaryFileFormatVersion, formatVersion));
            }

            StringStore.ReadBinary(r);
            DeclaredMembers.ReadBinary(r);
            DeclaredMemberDetails   = r.ReadList <SymbolDetails>();
            DeclaredMemberLocations = r.ReadList <SymbolLocation>();
            FileTree.ReadBinary(r);
            Index.ReadBinary(r);

            // PackageIdentity must be last so DownloadCount can be seeked to
            Identity.ReadBinary(r);
        }
Ejemplo n.º 28
0
        public int AddPath(int rootIndex, String8Set path, StringStore strings)
        {
            int currentIndex = rootIndex;

            for (int i = 0; i < path.Count; ++i)
            {
                String8 part = path[i];
                int     partNameIdentifier = strings.FindOrAddString(part);

                int foundNode;
                if (!TryFindChildByName(currentIndex, partNameIdentifier, out foundNode))
                {
                    foundNode = Add(currentIndex, partNameIdentifier);
                }

                currentIndex = foundNode;
            }

            return(currentIndex);
        }
Ejemplo n.º 29
0
        public void WriteChildrenOf(TextWriter writer, StringStore strings, int parentIndex)
        {
            // Consider -1 (not found) to be the same as the sentinel root
            if (parentIndex == -1)
            {
                parentIndex = 0;
            }

            int childIndex = this.GetFirstChild(parentIndex);

            while (childIndex > 0)
            {
                strings[this.GetNameIdentifier(childIndex)].WriteTo(writer);
                childIndex = this.GetNextSibling(childIndex);
                if (childIndex > 0)
                {
                    writer.Write(", ");
                }
            }
        }
Ejemplo n.º 30
0
        private static void CountNonAsciiStrings(string databasePath)
        {
            int nonAsciiPackageDownloadCount = 0;

            int packageCount = 0;
            int stringCount  = 0;

            int packagesWithNonAscii = 0;
            int stringsWithNonAscii  = 0;

            using (new TraceWatch("Counting Non-Ascii in '{0}'...", databasePath))
            {
                // Load individual package databases
                foreach (PackageDatabase db in BinarySerializableExtensions.LoadEach <PackageDatabase>(Directory.GetFiles(databasePath), true))
                {
                    bool isPackageAllAscii = true;

                    StringStore strings = ((IMemberDatabase)db).StringStore;
                    for (int i = 0; i < strings.Count; ++i)
                    {
                        if (strings[i].IsAscii() == false)
                        {
                            stringsWithNonAscii++;
                            isPackageAllAscii = false;
                        }
                    }

                    stringCount += strings.Count;
                    packageCount++;
                    if (!isPackageAllAscii)
                    {
                        packagesWithNonAscii++;
                        nonAsciiPackageDownloadCount += db.Identity.DownloadCount;
                        Trace.WriteLine(String.Format("Non-ASCII: {0} [{1} downloads]", db.Identity.PackageName, db.Identity.DownloadCount));
                    }
                }
            }

            Console.WriteLine("{0:n0} / {1:n0} packages contain non-Ascii; {2:n0} / {3:n0} strings.", packagesWithNonAscii, packageCount, stringsWithNonAscii, stringCount);
            Console.WriteLine("Total Non-Ascii Package Downloads: {0:n0}", nonAsciiPackageDownloadCount);
        }