protected List<Dictionary<string, int>> loadLevel(int level)
    {
        if(reader == null){
            text = (TextAsset)Resources.Load("LevelDesign/fases/fase" + level,typeof(TextAsset));
            reader = new StringReader(text.text);
        }

        while((line = reader.ReadLine()) != null){
            if(line.Contains(",")){
                string[] note = line.Split(new char[]{','});
                phaseNotes.Add(new Dictionary<string,int>(){
                    {"time",int.Parse(note[0])},
                    {"show",int.Parse(note[1])},
                    {"note",int.Parse(note[2])}
                });
                linecount++;
            }else if(line.Contains("tick"))
            {
                string[] tick = line.Split(new char[]{':'});
                musicTick = float.Parse(tick[tick.Length - 1]);

                linecount ++;
            }
        }
        linecount = 0;

        return getNotesDuration(excludeDoubleNotes(phaseNotes));
    }
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testStemming() throws Exception
 public virtual void testStemming()
 {
     Reader reader = new StringReader("questões");
     TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
     stream = tokenFilterFactory("PortugueseMinimalStem").create(stream);
     assertTokenStreamContents(stream, new string[] {"questão"});
 }
 /// <summary>
 /// if the synonyms are completely empty, test that we still analyze correctly </summary>
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testEmptySynonyms() throws Exception
 public virtual void testEmptySynonyms()
 {
     Reader reader = new StringReader("GB");
     TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
     stream = tokenFilterFactory("Synonym", TEST_VERSION_CURRENT, new StringMockResourceLoader(""), "synonyms", "synonyms.txt").create(stream); // empty file!
     assertTokenStreamContents(stream, new string[] {"GB"});
 }
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testStemming() throws Exception
 public virtual void testStemming()
 {
     Reader reader = new StringReader("räksmörgås");
     TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
     stream = tokenFilterFactory("ScandinavianNormalization").create(stream);
     assertTokenStreamContents(stream, new string[] {"ræksmørgås"});
 }
Exemple #5
0
        /// <summary>
        /// Parses "Min-SE" from specified reader.
        /// </summary>
        /// <param name="reader">Reader from where to parse.</param>
        /// <exception cref="ArgumentNullException">Raised when <b>reader</b> is null.</exception>
        /// <exception cref="SIP_ParseException">Raised when invalid SIP message.</exception>
        public override void Parse(StringReader reader)
        {
            /*
                Min-SE = delta-seconds *(SEMI generic-param)
            */

            if(reader == null){
                throw new ArgumentNullException("reader");
            }

            // Parse address
            string word = reader.ReadWord();
            if(word == null){
                throw new SIP_ParseException("Min-SE delta-seconds value is missing !");
            }
            try{
                m_Time = Convert.ToInt32(word);
            }
            catch{
                throw new SIP_ParseException("Invalid Min-SE delta-seconds value !");
            }

            // Parse parameters
            ParseParameters(reader);
        }
Exemple #6
0
        public static void Serialization1(Human human)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Human));
            StringBuilder sb = new StringBuilder();

            /* SERIALIZATION */
            using (StringWriter writer = new StringWriter(sb))
            {
                serializer.Serialize(writer, human);
            }
            // XML file
            //Console.WriteLine("SB: " +sb.ToString());
            /* END SERIALIZATION */



            /* DESERIALIZATION */
            Human newMartin = new Human();
            using (StringReader reader = new StringReader(sb.ToString()))
            {
                newMartin = serializer.Deserialize(reader) as Human;
            }
            Console.WriteLine(newMartin.ToString() + Environment.NewLine);
            /* END DESERIALIZATION */
        }
 /// <summary>
 /// Ensure the filter actually lowercases text.
 /// </summary>
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testCasing() throws Exception
 public virtual void testCasing()
 {
     Reader reader = new StringReader("AĞACI");
     TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
     stream = tokenFilterFactory("TurkishLowerCase").create(stream);
     assertTokenStreamContents(stream, new string[] {"ağacı"});
 }
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testStemming() throws Exception
 public virtual void testStemming()
 {
     Reader reader = new StringReader("cariñosa");
     TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
     stream = tokenFilterFactory("GalicianStem").create(stream);
     assertTokenStreamContents(stream, new string[] {"cariñ"});
 }
Exemple #9
0
 void PopulateWorld()
 {
     //from http://stackoverflow.com/questions/1500194/c-looping-through-lines-of-multiline-string
     using (StringReader reader = new StringReader(m_worldGrid))
     {
         string line = string.Empty;
         do
         {
             line = reader.ReadLine();
             if (line != null)
             {
                 //invert the line contents (they generate a flipped mesh for some reason, this fixes it)
                 line = Reverse(line);
                 //create a "line" of world
                 foreach(char tile in line)
                 {
                     CreateTile(tile);
                     x++;
                 }
             }
             x = 0;
             z++;
         } while (line != null);
     }
 }
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testStemming() throws Exception
 public virtual void testStemming()
 {
     Reader reader = new StringReader("chevaux");
     TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
     stream = tokenFilterFactory("FrenchMinimalStem").create(stream);
     assertTokenStreamContents(stream, new string[] {"cheval"});
 }
 /// <summary>
 /// Test ArabicNormalizationFilterFactory
 /// </summary>
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testNormalizer() throws Exception
 public virtual void testNormalizer()
 {
     Reader reader = new StringReader("الذين مَلكت أيمانكم");
     Tokenizer tokenizer = tokenizerFactory("Standard").create(reader);
     TokenStream stream = tokenFilterFactory("ArabicNormalization").create(tokenizer);
     assertTokenStreamContents(stream, new string[] {"الذين", "ملكت", "ايمانكم"});
 }
Exemple #12
0
    void NameEntered()
    {
        congratulationsUILabel.text = "";
        PlayerPrefs.SetString("name", playerName);

        StringReader reader = new StringReader(PlayerPrefs.GetString(Application.loadedLevel+"","600 IACONIC\n1200 IACONIC\n1800 IACONIC\n2400 IACONIC\n3000 IACONIC\n3600 IACONIC\n4200 IACONIC\n4800 IACONIC\n5400 IACONIC\n6000 IACONIC"));
        string output = "";
        bool counted = false;
        timeUILabel.text = "";
        nameUILabel.text = "";
        for(int i = 0; i < 10; i ++)
        {
            string input = reader.ReadLine();
            int timer = int.Parse(input.Split(' ')[0]);
            if(playTime<timer&&!counted)
            {
                timeUILabel.text += TimeToString(playTime) + "\n";
                nameUILabel.text += playerName + "\n";
                output += playTime + " " + playerName + "\n";
                i ++;
                counted = true;
            }
            timeUILabel.text += TimeToString(timer);
            nameUILabel.text += input.Split(' ')[1];
            if(i!=9)
            {
                timeUILabel.text +=  "\n";
                nameUILabel.text +=  "\n";
            }
            output += input + "\n";
        }
        reader.Close();
        PlayerPrefs.SetString(Application.loadedLevel+"",output);
    }
 // Test with some emails from TestUAX29URLEmailTokenizer's
 // email.addresses.from.random.text.with.email.addresses.txt
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testEmails() throws Exception
 public virtual void testEmails()
 {
     string textWithEmails = " some extra\nWords thrown in here. " + "[email protected]\n" + "kU-l6DS@[082.015.228.189]\n" + "\"%U\u0012@?\\B\"@Fl2d.md" + " samba Halta gamba " + "Bvd#@tupjv.sn\n" + "SBMm0Nm.oyk70.rMNdd8k.#[email protected]\n" + "[email protected]\n" + " inter Locutio " + "C'ts`@Vh4zk.uoafcft-dr753x4odt04q.UY\n" + "}[email protected]" + " blah Sirrah woof " + "lMahAA.j/[email protected]\n" + "lv'[email protected]\n";
     Reader reader = new StringReader(textWithEmails);
     TokenStream stream = tokenizerFactory("UAX29URLEmail").create(reader);
     assertTokenStreamContents(stream, new string[] {"some", "extra", "Words", "thrown", "in", "here", "*****@*****.**", "kU-l6DS@[082.015.228.189]", "\"%U\u0012@?\\B\"@Fl2d.md", "samba", "Halta", "gamba", "Bvd#@tupjv.sn", "SBMm0Nm.oyk70.rMNdd8k.#[email protected]", "[email protected]", "inter", "Locutio", "C'ts`@Vh4zk.uoafcft-dr753x4odt04q.UY", "}[email protected]", "blah", "Sirrah", "woof", "lMahAA.j/[email protected]", "lv'[email protected]"});
 }
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testTrimming() throws Exception
 public virtual void testTrimming()
 {
     Reader reader = new StringReader("trim me    ");
     TokenStream stream = new MockTokenizer(reader, MockTokenizer.KEYWORD, false);
     stream = tokenFilterFactory("Trim").create(stream);
     assertTokenStreamContents(stream, new string[] {"trim me"});
 }
Exemple #15
0
    // Use this for initialization
    void Start()
    {
        //DELETE THIS BEFORE RELEASE

        Data temp = GameObject.FindGameObjectWithTag("Load").GetComponent<Data>();
        Debug.Log("1");
        if (!temp.loaded)
        {
            Debug.Log("2");
            string s = PlayerPrefs.GetString(ADDRESS, "FIRST!");
            Debug.Log(s);
            if (!s.Equals("FIRST!"))
            {

                StringReader status = new StringReader(s);
                stats = (SavedData)serialize.Deserialize(status);
                Debug.Log(stats.gold);
            }
            else
            {
                stats = new SavedData();
                Debug.Log("no");
            }
            temp.setStats(stats);
        }
    }
Exemple #16
0
        /// <summary>
        /// Parses "CSeq" from specified reader.
        /// </summary>
        /// <param name="reader">Reader from where to parse.</param>
        /// <exception cref="ArgumentNullException">Raised when <b>reader</b> is null.</exception>
        /// <exception cref="SIP_ParseException">Raised when invalid SIP message.</exception>
        public override void Parse(StringReader reader)
        {
            // CSeq = 1*DIGIT LWS Method

            if(reader == null){
                throw new ArgumentNullException("reader");
            }

            // Get sequence number
            string word = reader.ReadWord();
            if(word == null){
                throw new SIP_ParseException("Invalid 'CSeq' value, sequence number is missing !");
            }
            try{
                m_SequenceNumber = Convert.ToInt32(word);
            }
            catch{
                throw new SIP_ParseException("Invalid CSeq 'sequence number' value !");
            }

            // Get request method
            word = reader.ReadWord();
            if(word == null){
                throw new SIP_ParseException("Invalid 'CSeq' value, request method is missing !");
            }
            m_RequestMethod = word;
        }
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testConsumeAllTokens() throws Exception
 public virtual void testConsumeAllTokens()
 {
     Reader reader = new StringReader("A1 B2 C3 D4 E5 F6");
     TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
     stream = tokenFilterFactory("LimitTokenPosition", "maxTokenPosition", "3", "consumeAllTokens", "true").create(stream);
     assertTokenStreamContents(stream, new string[] {"A1", "B2", "C3"});
 }
        /// <summary>
        /// Parses media from "t" SDP message field.
        /// </summary>
        /// <param name="tValue">"t" SDP message field.</param>
        /// <returns></returns>
        public static SDP_Time Parse(string tValue)
        {
            // t=<start-time> <stop-time>

            SDP_Time time = new SDP_Time();

            // Remove t=
            StringReader r = new StringReader(tValue);
            r.QuotedReadToDelimiter('=');

            //--- <start-time> ------------------------------------------------------------
            string word = r.ReadWord();
            if(word == null){
                throw new Exception("SDP message \"t\" field <start-time> value is missing !");
            }
            time.m_StartTime = Convert.ToInt64(word);

            //--- <stop-time> -------------------------------------------------------------
            word = r.ReadWord();
            if(word == null){
                throw new Exception("SDP message \"t\" field <stop-time> value is missing !");
            }
            time.m_StopTime = Convert.ToInt64(word);

            return time;
        }
 /// <summary>
 /// Ensure the filter actually lowercases (and a bit more) greek text.
 /// </summary>
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testNormalization() throws Exception
 public virtual void testNormalization()
 {
     Reader reader = new StringReader("Μάϊος ΜΆΪΟΣ");
     TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
     stream = tokenFilterFactory("GreekLowerCase").create(stream);
     assertTokenStreamContents(stream, new string[] {"μαιοσ", "μαιοσ"});
 }
        /// <summary>
        /// Parses MYRIGHTS response from MYRIGHTS-response string.
        /// </summary>
        /// <param name="myRightsResponse">MYRIGHTS response line.</param>
        /// <returns>Returns parsed MYRIGHTS response.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>myRightsResponse</b> is null reference.</exception>
        public static IMAP_Response_MyRights Parse(string myRightsResponse)
        {
            if(myRightsResponse == null){
                throw new ArgumentNullException("myRightsResponse");
            }

            /* RFC 4314 3.8. MYRIGHTS Response.
                Data:       mailbox name
                            rights

                The MYRIGHTS response occurs as a result of a MYRIGHTS command.  The
                first string is the mailbox name for which these rights apply.  The
                second string is the set of rights that the client has.

                Section 2.1.1 details additional server requirements related to
                handling of the virtual "d" and "c" rights.
             
                Example:    C: A003 MYRIGHTS INBOX
                            S: * MYRIGHTS INBOX rwiptsldaex
                            S: A003 OK Myrights complete
            */

            StringReader r = new StringReader(myRightsResponse);
            // Eat "*"
            r.ReadWord();
            // Eat "MYRIGHTS"
            r.ReadWord();

            string folder = IMAP_Utils.Decode_IMAP_UTF7_String(r.ReadWord(true));
            string rights = r.ReadToEnd().Trim();

            return new IMAP_Response_MyRights(folder,rights);
        }
    public override void OnHandleResponse(OperationResponse response)
    {

        NetworkManager view = _controller.ControlledView as NetworkManager;
        view.LogDebug("GOT A RESPONSE for KNOWN STARS");
        if (response.ReturnCode == 0)
        {
            view.LogDebug(response.Parameters[(byte)ClientParameterCode.KnownStars].ToString());

            // Deserialize
            var xmlData = response.Parameters[(byte)ClientParameterCode.KnownStars].ToString();
            XmlSerializer deserializer = new XmlSerializer(typeof(XmlStarPlayerList));
            TextReader reader = new StringReader(xmlData);
            object obj = deserializer.Deserialize(reader);
            XmlStarPlayerList starCollection = (XmlStarPlayerList)obj;
            reader.Close();

            List<KnownStar> stars = new List<KnownStar>();
            foreach (SanStarPlayer s in starCollection.StarPlayers)
                stars.Add(new KnownStar(s));

            // Update local data
            PlayerData.instance.UpdateKnownStars(stars);
        }
        else
        {
            view.LogDebug("RESPONSE: " + response.DebugMessage);
            DisplayManager.Instance.DisplayMessage(response.DebugMessage);
        }
    }
 /// <summary>
 /// Ensure the filter actually stems and normalizes text.
 /// </summary>
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testStemming() throws Exception
 public virtual void testStemming()
 {
     Reader reader = new StringReader("Brasília");
     Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
     TokenStream stream = tokenFilterFactory("BrazilianStem").create(tokenizer);
     assertTokenStreamContents(stream, new string[] {"brasil"});
 }
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testStemming() throws Exception
 public virtual void testStemming()
 {
     Reader reader = new StringReader("abc");
     TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
     stream = tokenFilterFactory("HunspellStem", "dictionary", "simple.dic", "affix", "simple.aff").create(stream);
     assertTokenStreamContents(stream, new string[] {"ab"});
 }
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testStemming() throws Exception
 public virtual void testStemming()
 {
     Reader reader = new StringReader("журналы");
     TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
     stream = tokenFilterFactory("RussianLightStem").create(stream);
     assertTokenStreamContents(stream, new string[] {"журнал"});
 }
    //Funcion que con el nombre del nivel (el mismo que el del xml) crea los gameobjects del nivel
    public GameObject generateLevel(string nameLevel)
    {
        //Extraemos el XML y lo deserializamos
        TextAsset xmlTextAsset = (TextAsset)Resources.Load("LevelsXML/"+nameLevel, typeof(TextAsset));
        StringReader stream = new StringReader(xmlTextAsset.text);
        XmlSerializer s = new XmlSerializer(typeof(structureXML));
        m_structureXML = s.Deserialize(stream) as structureXML;

        //Creamos un gameObject vacio que representará el nivel
        GameObject goLevel = new GameObject(nameLevel);
        goLevel.transform.position = Vector3.zero;
        goLevel.transform.parent = Managers.GetInstance.SceneMgr.rootScene.transform;

        Managers.GetInstance.TimeMgr.seconds = m_structureXML.time.seconds;
        Managers.GetInstance.SceneMgr.spawnPointPlayer = new Vector3(m_structureXML.spawnPoint.x, m_structureXML.spawnPoint.y, 0);

        //Creamos cada uno de los items definidos en el XML en la posicion alli indicada, con el scale alli indicado.
        foreach (structureXML.Item go in m_structureXML.prefabs.items)
        {
            GameObject newGO = Managers.GetInstance.SpawnerMgr.createGameObject(Resources.Load("Prefabs/GamePrefabs/" + go.prefab) as GameObject, new Vector3(go.x, go.y, 0), Quaternion.identity);
            newGO.transform.localScale = new Vector3(go.scaleX, go.scaleY, 1);
            //Finalmente como padre ponemos al gameObject que representa el nivel
            newGO.transform.parent = goLevel.transform;
        }

        return goLevel;
    }
Exemple #26
0
    public static LevelData Load(TextAsset asset)
    {
        LevelData level = null;
        var serializer = new XmlSerializer(typeof(LevelData));

        using (var stream = new StringReader(asset.text))
        {
            level = serializer.Deserialize(stream) as LevelData;
        }

        int yLength = level.Rows.Length;
        int xLength = yLength > 0 ? level.Rows[0].RowLength : 0;

        level.Grid = new int[xLength, yLength];

        for (int y = 0; y < yLength; ++y)
        {
            char[] row = level.Rows[y].RowData.ToCharArray();

            for (int x = 0; x < xLength; ++x)
            {
                level.Grid[x, y] = row[x] == WALL ? 1 : 0;
            }
        }

        return level;
    }
        /// <summary>
        /// Parses LSUB response from lsub-response string.
        /// </summary>
        /// <param name="lSubResponse">LSub response string.</param>
        /// <returns>Returns parsed lsub response.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>lSubResponse</b> is null reference.</exception>
        public static IMAP_r_u_LSub Parse(string lSubResponse)
        {
            if(lSubResponse == null){
                throw new ArgumentNullException("lSubResponse");
            }

            /* RFC 3501 7.2.3. LSUB Response.
                Contents:   name attributes
                            hierarchy delimiter
                            name

                The LSUB response occurs as a result of an LSUB command.  It
                returns a single name that matches the LSUB specification.  There
                can be multiple LSUB responses for a single LSUB command.  The
                data is identical in format to the LIST response.

                Example:    S: * LSUB () "." #news.comp.mail.misc
            */

            StringReader r = new StringReader(lSubResponse);
            // Eat "*"
            r.ReadWord();
            // Eat "LSUB"
            r.ReadWord();

            string attributes = r.ReadParenthesized();
            string delimiter  = r.ReadWord();
            string folder     = TextUtils.UnQuoteString(IMAP_Utils.DecodeMailbox(r.ReadToEnd().Trim()));

            return new IMAP_r_u_LSub(folder,delimiter[0],attributes == string.Empty ? new string[0] : attributes.Split(' '));
        }
 object Deserialize(string messageBody, Type objectType)
 {
     using (StringReader textReader = new StringReader(messageBody))
     {
         return serializer.Deserialize(textReader, objectType);
     }
 }
        /// <summary>
        /// Parses media from "a" SDP message field.
        /// </summary>
        /// <param name="aValue">"a" SDP message field.</param>
        /// <returns></returns>
        public static SDP_Attribute Parse(string aValue)
        {
            // a=<attribute>
            // a=<attribute>:<value>

            // Remove a=
            StringReader r = new StringReader(aValue);
            r.QuotedReadToDelimiter('=');

            //--- <attribute> ------------------------------------------------------------
            string name = "";
            string word = r.QuotedReadToDelimiter(':');
            if (word == null)
            {
                throw new Exception("SDP message \"a\" field <attribute> name is missing !");
            }
            name = word;

            //--- <value> ----------------------------------------------------------------
            string value = "";
            word = r.ReadToEnd();
            if (word != null)
            {
                value = word;
            }

            return new SDP_Attribute(name, value);
        }
Exemple #30
0
    static void Main()
    {
        Dictionary<string, string> dictionary = new Dictionary<string, string>();

        string textLines = @".NET - platform for applications from Microsoft
        CLR - managed execution environment for .NET
        namespace - hierarchical organization of classes
        ";

        StringReader readLines = new StringReader(textLines);

        string line;
        while ((line = readLines.ReadLine())!=null)
        {
            string[] token = line.Split('-');
            dictionary.Add(token[0].Trim(), token[1]);
        }

        string input = Console.ReadLine();

        if (dictionary.ContainsKey(input))
        {
            Console.WriteLine(dictionary[input]);
        }
        else
        {
            Console.WriteLine("No such term in dictionary");
        }
    }
        public static GitSubmoduleStatus?ParseSubmoduleStatus(string?text, GitModule module, string?fileName)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            string?name = null;

            string?  oldName        = null;
            bool     isDirty        = false;
            ObjectId?commitId       = null;
            ObjectId?oldCommitId    = null;
            int?     addedCommits   = null;
            int?     removedCommits = null;

            using (var reader = new StringReader(text))
            {
                string?line = reader.ReadLine();

                if (line is not null)
                {
                    var match = Regex.Match(line, @"diff --git [abic]/(.+)\s[abwi]/(.+)");
                    if (match.Groups.Count > 1)
                    {
                        name    = match.Groups[1].Value;
                        oldName = match.Groups[2].Value;
                    }
                    else
                    {
                        match = Regex.Match(line, @"diff --cc (.+)");
                        if (match.Groups.Count > 1)
                        {
                            name    = match.Groups[1].Value;
                            oldName = match.Groups[1].Value;
                        }
                    }
                }

                while ((line = reader.ReadLine()) is not null)
                {
                    // We are looking for lines resembling:
                    //
                    // -Subproject commit bfef4454fc51e345051ee5bf66686dc28deed627
                    // +Subproject commit 8b20498b954609770205c2cc794b868b4ac3ee69-dirty

                    if (!line.Contains("Subproject"))
                    {
                        continue;
                    }

                    char         c         = line[0];
                    const string commitStr = "commit ";
                    string       hash      = "";
                    int          pos       = line.IndexOf(commitStr);
                    if (pos >= 0)
                    {
                        hash = line.Substring(pos + commitStr.Length);
                    }

                    bool endsWithDirty = hash.EndsWith("-dirty");
                    hash = hash.Replace("-dirty", "");
                    if (c == '-')
                    {
                        oldCommitId = ObjectId.Parse(hash);
                    }
                    else if (c == '+')
                    {
                        commitId = ObjectId.Parse(hash);
                        isDirty  = endsWithDirty;
                    }

                    // TODO: Support combined merge
                }
            }

            if (oldCommitId is not null && commitId is not null)
            {
                if (oldCommitId == commitId)
                {
                    addedCommits   = 0;
                    removedCommits = 0;
                }
                else
                {
                    var submodule = module.GetSubmodule(fileName);
                    addedCommits   = submodule.GetCommitCount(commitId.ToString(), oldCommitId.ToString(), cache: true);
                    removedCommits = submodule.GetCommitCount(oldCommitId.ToString(), commitId.ToString(), cache: true);
                }
            }

            Validates.NotNull(name);

            return(new GitSubmoduleStatus(name, oldName, isDirty, commitId, oldCommitId, addedCommits, removedCommits));
        }
Exemple #32
0
 Parser(string jsonString)
 {
     json = new StringReader(jsonString);
 }
        /// <summary>
        /// This routine generate an HTML Table based on StringCad (\t=split columns \n=split rows)
        /// </summary>
        /// <param name="sCad">String Chain that hols the data separated by \t and \n</param>
        /// <param name="xTitle">If bImage then Show the Title after</param>
        /// <param name="bFrame">True if Frame is required</param>
        /// <param name="bImage">True if an imgae shall be included</param>
        /// <param name="bComputerInfo">True if information like User, Computer and domain need to be included</param>
        /// <param name="bTimeStamp">True if Timestamp is required</param>
        /// <param name="bAppendRSWPowered">True if "Powered by RSW" at the end will be included</param>
        /// <returns></returns>
        private string RSFormaTable(string sCad, string xTitle, bool bFrame, bool bImage, bool bComputerInfo,
                                    bool bTimeStamp, bool bAppendRSWPowered)
        {
            string xBody = RSFormaTableHeader(true, bFrame, "");

            if (bImage)
            {
                string xImage = RSGbl_Variable.DataPath + @"\Image";
                RSLib_File.CheckDirectoryIfNotExistCreateIt(xImage);
                xImage = Path.Combine(xImage, "zRSFaMFSmall.png");
                if (File.Exists(xImage))
                {
                    string xNoSpacesImage = RSGbl_Variable.sEmailLogo;
                    xBody += "<TR><TD><a href=\"http://fortalezamf.mx\" target=\"_blank\"><img src=\"" + xNoSpacesImage + "\"></img></a></TD>";
                    if (xTitle.Length > 0)
                    {
                        //xBody += "<TD><P><FONT FACE=\"Comic Sans MS\"SIZE=5>" +  De acuerdo a COCO mejor usar un solo FONT
                        xBody += "<TD><P><FONT SIZE=5>" + xTitle + "</FONT></P></TD>\n";
                        //xBody += "<FONT FACE=\"Comic Sans MS\"SIZE=1>" +
                        //    RSLib_Browse.GetTimeStamp() + "</FONT></TD>\n";
                    }
                    xBody += "</TR>";
                }
            }
            string xTABLE = sCad;

            if (bComputerInfo)
            {
                xTABLE += "&nbsp;\t&nbsp;\n";
                xTABLE += "Usuario:\t" + System.Environment.UserName + "\n";
                xTABLE += "Computadora:\t" + System.Environment.MachineName + "\n";
                //xTABLE += "Dominio:\t" + System.Environment.UserDomainName + "\n";
                xTABLE += "IP:\t" + WhatIsMyIP + "\n";
                xTABLE += "RS Report Versión:\t" + RSGbl_Variable.APPVersion + "\n";
            }
            if (bTimeStamp)
            {
                xTABLE += "Timestamp:\t" + RSLib_Browse.GetTimeStamp() + "\n";
            }
            TextReader stringReader = new StringReader(xTABLE);

            while (true)
            {
                string sxLine = stringReader.ReadLine();
                if (sxLine == null || sxLine.Length == 0)
                {
                    break;
                }
                xBody += "<TR>";
                string[] xParts = sxLine.Split('\t');
                foreach (string xPart in xParts)
                {
                    xBody += "<TD>" + xPart + "</TD>";
                }
                xBody += "</TR>";
            }
            xBody += RSFormaTableHeader(false, bFrame, "");
            if (bAppendRSWPowered)
            {
                xBody += "<Font Size=1>Powered by RSW</Font><br />";
            }
            return(xBody);
        }
Exemple #34
0
        public ObjectDiff DiffObj()
        {
            ObjectDiff objectDiff = new ObjectDiff();
            string     varAttrib  = null;

            using (StringReader reader = new StringReader(ReturnJsonTransformed()))
            {
                WhatInstanceOf(ReturnJsonTransformed());
                string line;
                if (IsEntityType)
                {
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line != string.Empty)
                        {
                            if ((line.Length > 1) && !line.Equals("    ],") && !line.Equals("    ]") && !line.Equals("  }"))
                            {
                                if (line.Substring(0, 3).Equals("  \""))
                                {
                                    objectDiff.ObjectName = line.Split(CHAR_DOUBLE_QUOTE)[1];
                                }
                                else
                                {
                                    if (line.Substring(0, 5).Equals("    \""))
                                    {
                                        varAttrib = line.Split(CHAR_DOUBLE_QUOTE)[1];
                                    }
                                    else
                                    {
                                        if (!IsIgnoreAttribute(varAttrib))
                                        {
                                            if (line.Substring(0, 6).Equals("      "))
                                            {
                                                string sValue = line.EndsWith(",") ? line.Substring(0, line.Length - 1).Trim() : line.Trim();
                                                sValue = (sValue.StartsWith(STRING_DOUBLE_QUOTE) && sValue.EndsWith(STRING_DOUBLE_QUOTE)) ? sValue = sValue.Substring(1, sValue.Length - 2).Trim() : sValue;
                                                ItemDiff dJsonDiffItemFIND = objectDiff.Items.Find(item => item.AttributeName == varAttrib);
                                                if (dJsonDiffItemFIND == null)
                                                {
                                                    ItemDiff itemDiff = new ItemDiff
                                                    {
                                                        AttributeName = varAttrib
                                                    };
                                                    itemDiff.Values.Add(sValue);
                                                    objectDiff.Items.Add(itemDiff);
                                                }
                                                else
                                                {
                                                    dJsonDiffItemFIND.Values.Add(sValue);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (IsStructureType)
                    {
                        while ((line = reader.ReadLine()) != null)
                        {
                            if ((line != null) && (line.Length > 1) && !line.Equals("  ],") && !line.Equals("  ]"))
                            {
                                if (line.Substring(0, 3).Equals("  \""))
                                {
                                    varAttrib = line.Split(CHAR_DOUBLE_QUOTE)[1];
                                }
                                else
                                {
                                    if (!IsIgnoreAttribute(varAttrib))
                                    {
                                        if (line.Substring(0, 4).Equals("    "))
                                        {
                                            string sValue = line.EndsWith(",") ? line.Substring(0, line.Length - 1).Trim() : line.Trim();
                                            sValue = (sValue.StartsWith(STRING_DOUBLE_QUOTE) && sValue.EndsWith(STRING_DOUBLE_QUOTE)) ? sValue = sValue.Substring(1, sValue.Length - 2).Trim() : sValue;
                                            ItemDiff dJsonDiffItemFIND = objectDiff.Items.Find(item => item.AttributeName == varAttrib);
                                            if (dJsonDiffItemFIND == null)
                                            {
                                                ItemDiff itemDiff = new ItemDiff
                                                {
                                                    AttributeName = varAttrib
                                                };
                                                itemDiff.Values.Add(sValue);
                                                objectDiff.Items.Add(itemDiff);
                                            }
                                            else
                                            {
                                                dJsonDiffItemFIND.Values.Add(sValue);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        objectDiff.ObjectName = "Structure";
                    }
                }
                objectDiff = NormalizeValues(objectDiff);
                if (objectDiff.Items.Count < 1)
                {
                    objectDiff = new ObjectDiff();
                }
            }
            return(objectDiff);
        }
        public static PluginDescriptor ParsePluginDescriptionFile(string filePath)
        {
            var descriptor = new PluginDescriptor();
            var text       = File.ReadAllText(filePath);

            if (String.IsNullOrEmpty(text))
            {
                return(descriptor);
            }

            var settings = new List <string>();

            using (var reader = new StringReader(text))
            {
                string str;
                while ((str = reader.ReadLine()) != null)
                {
                    if (String.IsNullOrWhiteSpace(str))
                    {
                        continue;
                    }
                    settings.Add(str.Trim());
                }
            }

            //Old way of file reading. This leads to unexpected behavior when a user's FTP program transfers these files as ASCII (\r\n becomes \n).
            //var settings = text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var setting in settings)
            {
                var separatorIndex = setting.IndexOf(':');
                if (separatorIndex == -1)
                {
                    continue;
                }
                string key   = setting.Substring(0, separatorIndex).Trim();
                string value = setting.Substring(separatorIndex + 1).Trim();

                switch (key)
                {
                case "Group":
                    descriptor.Group = value;
                    break;

                case "FriendlyName":
                    descriptor.FriendlyName = value;
                    break;

                case "SystemName":
                    descriptor.SystemName = value;
                    break;

                case "Version":
                    descriptor.Version = value;
                    break;

                case "SupportedVersions":
                {
                    //parse supported versions
                    descriptor.SupportedVersions = value.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                                   .Select(x => x.Trim())
                                                   .ToList();
                }
                break;

                case "Author":
                    descriptor.Author = value;
                    break;

                case "DisplayOrder":
                {
                    int displayOrder;
                    int.TryParse(value, out displayOrder);
                    descriptor.DisplayOrder = displayOrder;
                }
                break;

                case "FileName":
                    descriptor.PluginFileName = value;
                    break;

                case "LimitedToStores":
                {
                    //parse list of store IDs
                    foreach (var str1 in value.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                             .Select(x => x.Trim()))
                    {
                        int storeId;
                        if (int.TryParse(str1, out storeId))
                        {
                            descriptor.LimitedToStores.Add(storeId);
                        }
                    }
                }
                break;

                case "LimitedToCustomerRoles":
                {
                    //parse list of customer role IDs
                    foreach (var id in value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()))
                    {
                        int roleId;
                        if (int.TryParse(id, out roleId))
                        {
                            descriptor.LimitedToCustomerRoles.Add(roleId);
                        }
                    }
                }
                break;

                case "Description":
                    descriptor.Description = value;
                    break;

                default:
                    break;
                }
            }

            //nopCommerce 2.00 didn't have 'SupportedVersions' parameter
            //so let's set it to "2.00"
            if (!descriptor.SupportedVersions.Any())
            {
                descriptor.SupportedVersions.Add("2.00");
            }

            return(descriptor);
        }
Exemple #36
0
    public void Make(int stageLevel)
    {
        int     row = 0;
        Vector3 sub = Vector3.zero;

        if (_character != null)
        {
            _character.Restart();
        }

        // テキストからマップデータを読み込み
        StringReader reader = new StringReader(_mapchip[stageLevel].text);

        while (reader.Peek() > -1)
        {
            // カンマ区切りで読み込んで行ごとにマップを作成
            string   line   = reader.ReadLine();
            string[] values = line.Split(',');

            //1行目のみ
            if (row++ == 0)
            {
                if (_character != null)
                {
                    _character.canJump    = (values[0] == "0") ? false : true;
                    _character.canChange  = (values[1] == "0") ? false : true;
                    _character.canGravity = (values[2] == "0") ? false : true;
                    //_character.canBlink = (values[3] == "0") ? false : true;
                }
            }
            else
            {
                // 2行目以降
                foreach (string value in values)
                {
                    // 読み込んだからマップを作成
                    int integer = int.Parse(value);
                    if (integer >= 0 && integer < mapdate.Length)
                    {
                        // 位置座標の差分を加味してリソースを配置
                        var obj = Instantiate(mapdate[integer], transform);
                        obj.transform.position    = transform.position + sub;
                        obj.transform.localScale *= scaling;

                        switch (integer)
                        {
                        case 0:
                            obj.GetComponent <SpriteRenderer>().color = _character.colorMaterial.color;
                            break;

                        case 1:
                            if (_character != null)
                            {
                                _character.transform.position = obj.transform.position;
                                _character.respawn            = _character.transform.position;
                            }
                            break;

                        case 2:
                            break;

                        case 3:
                            UIAction.mapMoveBy = true;
                            break;

                        case 4:
                            UIAction.mapChangeGravity = true;
                            break;

                        case 5:
                            UIAction.mapBrokenGimmick = true;
                            break;

                        case 6:
                            UIAction.mapBlinkGimmick = true;
                            break;

                        default:
                            break;
                        }
                    }
                    sub.x += scaling * 1.25F;
                }
                sub.x = 0; sub.y -= scaling * 1.25F;
            }
        }
    }
Exemple #37
0
 public void Dispose()
 {
     json.Dispose();
     json = null;
 }
Exemple #38
0
        public static Queue <Token> ToTokens(string expression)
        {
            Queue <Token> tokens  = new Queue <Token>();
            StringBuilder builder = null;

            using (StringReader sr = new StringReader(expression))
            {
                int intChar = sr.Read();
                while (intChar != -1)
                {
                    char ch           = Convert.ToChar(intChar);
                    bool chIsOperator = false;

                    if (ch == '+')
                    {
                        chIsOperator = true;
                    }
                    else if (ch == '-')
                    {
                        chIsOperator = true;
                    }
                    else if (ch == '*')
                    {
                        chIsOperator = true;
                    }
                    else if (ch == '/')
                    {
                        chIsOperator = true;
                    }
                    else
                    {//简化处理,除操作符之外其他都认为是操作数
                        chIsOperator = false;
                    }

                    if (chIsOperator)
                    {//当前字符是操作符
                        if (builder != null)
                        {
                            tokens.Enqueue(new Token()
                            {
                                type  = TokenType.Number,
                                value = Convert.ToSingle(builder.ToString())
                            });
                            builder = null;
                        }
                        tokens.Enqueue(new Token()
                        {
                            type = TokenType.Operator,
                            op   = ch
                        });
                    }
                    else
                    {//当前字符是操作数
                        if (builder == null)
                        {
                            builder = new StringBuilder();
                        }
                        builder.Append(ch);
                    }
                    intChar = sr.Read();
                }

                //扫描结束,将操作数存到队列中
                if (builder != null)
                {
                    tokens.Enqueue(new Token()
                    {
                        type  = TokenType.Number,
                        value = Convert.ToSingle(builder.ToString())
                    });
                }
            }

            return(tokens);
        }
Exemple #39
0
        private static void TryIndent(TextArea textArea, int begin, int end)
        {
            string currentIndentation = "";
            var    tagStack           = new Stack <string>();

            var    document        = textArea.Document;
            string tab             = GetIndentationString(textArea);
            int    nextLine        = begin; // in #dev coordinates
            bool   wasEmptyElement = false;
            var    lastType        = XmlNodeType.XmlDeclaration;

            using (var stringReader = new StringReader(document.Text))
            {
                var r = new XmlTextReader(stringReader);
                r.XmlResolver = null; // prevent XmlTextReader from loading external DTDs
                while (r.Read())
                {
                    if (wasEmptyElement)
                    {
                        wasEmptyElement = false;
                        if (tagStack.Count == 0)
                        {
                            currentIndentation = "";
                        }
                        else
                        {
                            currentIndentation = tagStack.Pop();
                        }
                    }
                    if (r.NodeType == XmlNodeType.EndElement)
                    {
                        // Indent lines before closing tag.
                        while (nextLine < r.LineNumber)
                        {
                            // Set indentation of 'nextLine'
                            DocumentLine line     = document.GetLineByNumber(nextLine);
                            string       lineText = document.GetText(line);

                            string newText = currentIndentation + lineText.Trim();

                            if (newText != lineText)
                            {
                                document.Replace(line.Offset, line.Length, newText);
                            }

                            nextLine += 1;
                        }

                        if (tagStack.Count == 0)
                        {
                            currentIndentation = "";
                        }
                        else
                        {
                            currentIndentation = tagStack.Pop();
                        }
                    }

                    while (r.LineNumber >= nextLine)
                    {
                        if (nextLine > end)
                        {
                            break;
                        }
                        if (lastType == XmlNodeType.CDATA || lastType == XmlNodeType.Comment)
                        {
                            nextLine++;
                            continue;
                        }
                        // set indentation of 'nextLine'
                        DocumentLine line     = document.GetLineByNumber(nextLine);
                        string       lineText = document.GetText(line);

                        string newText;
                        // special case: opening tag has closing bracket on extra line: remove one indentation level
                        if (lineText.Trim() == ">")
                        {
                            newText = tagStack.Peek() + lineText.Trim();
                        }
                        else
                        {
                            newText = currentIndentation + lineText.Trim();
                        }

                        document.SmartReplaceLine(line, newText);
                        nextLine++;
                    }

                    if (r.LineNumber >= end)
                    {
                        break;
                    }

                    wasEmptyElement = r.NodeType == XmlNodeType.Element && r.IsEmptyElement;
                    string attribIndent = null;
                    if (r.NodeType == XmlNodeType.Element)
                    {
                        tagStack.Push(currentIndentation);
                        if (r.LineNumber <= begin)
                        {
                            var whitespace = TextUtilities.GetWhitespaceAfter(document, document.GetOffset(r.LineNumber, 1));
                            currentIndentation = document.GetText(whitespace);
                        }
                        if (r.Name.Length < 16)
                        {
                            attribIndent = currentIndentation + new string(' ', 2 + r.Name.Length);
                        }
                        else
                        {
                            attribIndent = currentIndentation + tab;
                        }
                        currentIndentation += tab;
                    }

                    lastType = r.NodeType;
                    if (r.NodeType == XmlNodeType.Element && r.HasAttributes)
                    {
                        int startLine = r.LineNumber;
                        r.MoveToAttribute(0); // move to first attribute
                        if (r.LineNumber != startLine)
                        {
                            attribIndent = currentIndentation; // change to tab-indentation
                        }
                        r.MoveToAttribute(r.AttributeCount - 1);
                        while (r.LineNumber >= nextLine)
                        {
                            if (nextLine > end)
                            {
                                break;
                            }
                            // set indentation of 'nextLine'
                            DocumentLine line    = document.GetLineByNumber(nextLine);
                            string       newText = attribIndent + document.GetText(line).Trim();
                            document.SmartReplaceLine(line, newText);
                            nextLine++;
                        }
                    }
                }

                r.Close();
            }
        }
            internal Impl(Stream readableStream)
                : this()
            {
                if (ReferenceEquals(readableStream, null))
                {
                    throw new ArgumentNullException(nameof(readableStream));
                }

                if (readableStream == Stream.Null || !readableStream.CanRead)
                {
                    throw new InvalidOperationException("Unable to read input.");
                }

                byte[] buffer = new byte[4096];
                int    read   = 0;

                int r;

                while ((r = readableStream.Read(buffer, read, buffer.Length - read)) > 0)
                {
                    read += r;

                    // if we've filled the buffer, make it larger this could hit an out of memory
                    // condition, but that'd require the called to be attempting to do so, since
                    // that's not a secyity threat we can safely ignore that and allow NetFx to
                    // handle it
                    if (read == buffer.Length)
                    {
                        Array.Resize(ref buffer, buffer.Length * 2);
                    }

                    if ((read > 0 && read < 3 && buffer[read - 1] == '\n'))
                    {
                        throw new InvalidDataException("Invalid input, please see 'https://www.kernel.org/pub/software/scm/git/docs/git-credential.html'.");
                    }

                    // the input ends with LFLF, check for that and break the read loop unless
                    // input is coming from CLRF system, in which case it'll be CLRFCLRF
                    if ((buffer[read - 2] == '\n' &&
                         buffer[read - 1] == '\n') ||
                        (buffer[read - 4] == '\r' &&
                         buffer[read - 3] == '\n' &&
                         buffer[read - 2] == '\r' &&
                         buffer[read - 1] == '\n'))
                    {
                        break;
                    }
                }

                // Git uses UTF-8 for string, don't let the OS decide how to decode it instead
                // we'll actively decode the UTF-8 block ourselves
                string input = Encoding.UTF8.GetString(buffer, 0, read);

                // the `StringReader` is just useful
                using (StringReader reader = new StringReader(input))
                {
                    string line;
                    while (!string.IsNullOrWhiteSpace((line = reader.ReadLine())))
                    {
                        string[] pair = line.Split(new[] { '=' }, 2);

                        if (pair.Length == 2)
                        {
                            switch (pair[0])
                            {
                            case "protocol":
                                _queryProtocol = pair[1];
                                break;

                            case "host":
                                _queryHost = pair[1];
                                break;

                            case "path":
                                _queryPath = pair[1];
                                break;

                            case "username":
                                _username = pair[1];
                                break;

                            case "password":
                                _password = pair[1];
                                break;
                            }
                        }
                    }
                }

                CreateTargetUri();
            }
Exemple #41
0
        private static BvhNode ParseNode(StringReader r, int level = 0)
        {
            var firstline = r.ReadLine().Trim();
            var splited   = firstline.Split();

            if (splited.Length != 2)
            {
                if (splited.Length == 1)
                {
                    if (splited[0] == "}")
                    {
                        return(null);
                    }
                }

                throw new BvhException(String.Format("splited to {0}({1})", splited.Length, firstline));
            }

            BvhNode node = null;

            if (splited[0] == "ROOT")
            {
                if (level != 0)
                {
                    throw new BvhException("nested ROOT");
                }
                node = new BvhNode(splited[1]);
            }
            else if (splited[0] == "JOINT")
            {
                if (level == 0)
                {
                    throw new BvhException("should ROOT, but JOINT");
                }
                node = new BvhNode(splited[1]);
            }
            else if (splited[0] == "End")
            {
                if (level == 0)
                {
                    throw new BvhException("End in level 0");
                }
                node = new EndSite();
            }
            else
            {
                throw new BvhException("unknown type: " + splited[0]);
            }

            if (r.ReadLine().Trim() != "{")
            {
                throw new BvhException("'{' is not found");
            }

            node.Parse(r);

            // child nodes
            while (true)
            {
                var child = ParseNode(r, level + 1);

                if (child == null)
                {
                    break;
                }

                if (!(child is EndSite))
                {
                    node.Children.Add(child);
                }
            }

            return(node);
        }
		public static RecognizeTemplate Load(string xml)
		{
			XmlSerializer serializer = new XmlSerializer(typeof(RecognizeTemplate));
			TextReader Reader = new StringReader(xml);
			return (RecognizeTemplate)serializer.Deserialize(Reader);
		}
Exemple #43
0
 public virtual void Parse(StringReader r)
 {
     Offset   = ParseOffset(r.ReadLine());
     Channels = ParseChannel(r.ReadLine());
 }
Exemple #44
0
		protected override bool MatchGroup(StringReader input)
		{
			return input.NextEquals(starts);
		}
Exemple #45
0
        public HttpResponseMessage GetPastOthersPrayers(long LastPrayerID)
        {
            PenYourPrayerIdentity user = (PenYourPrayerIdentity)User.Identity;

            using (DBDataContext db = new DBDataContext())
            {
                String        res          = "";
                List <Prayer> latestprayer = new List <Prayer>();
                List <usp_GetPastOthersPrayersResult> p = db.usp_GetPastOthersPrayers((long?)user.ID, (long?)LastPrayerID).ToList();
                foreach (usp_GetPastOthersPrayersResult t in p)
                {
                    Prayer prayer = new Prayer();
                    prayer.PrayerID = t.PrayerID;
                    var offset = TimeZoneInfo.Local.GetUtcOffset(DateTime.UtcNow);

                    prayer.UserID         = t.UserID;
                    prayer.TouchedWhen    = t.TouchedWhen;
                    prayer.CreatedWhen    = t.CreatedWhen;
                    prayer.Content        = t.PrayerContent;
                    prayer.publicView     = t.PublicView;
                    prayer.IfExecutedGUID = t.QueueActionGUID;
                    if (t.TagFriends != null)
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(AllFriends));
                        TextReader    reader     = new StringReader(t.TagFriends.ToString());

                        prayer.selectedFriends = ((AllFriends)serializer.Deserialize(reader)).friends;
                        reader.Close();
                    }
                    if (t.Attachments != null)
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(AllPrayerAttachment));
                        TextReader    reader     = new StringReader(t.Attachments.ToString());

                        prayer.attachments = ((AllPrayerAttachment)serializer.Deserialize(reader)).attachments;
                        reader.Close();
                    }
                    if (t.Comment != null)
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(AllPrayerComments));
                        TextReader    reader     = new StringReader(t.Comment.ToString());

                        prayer.comments = ((AllPrayerComments)serializer.Deserialize(reader)).comments;
                        reader.Close();
                    }
                    if (t.Answers != null)
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(AllPrayerAnswered));
                        TextReader    reader     = new StringReader(t.Answers.ToString());

                        prayer.answers = ((AllPrayerAnswered)serializer.Deserialize(reader)).answers;
                        reader.Close();
                    }
                    if (t.Amen != null)
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(AllPrayerAmen));
                        TextReader    reader     = new StringReader(t.Amen.ToString());

                        prayer.amen = ((AllPrayerAmen)serializer.Deserialize(reader)).amen;
                        reader.Close();
                    }
                    if (t.OwnerProfile != null)
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(PenYourPrayerUser));
                        TextReader    reader     = new StringReader(t.OwnerProfile.ToString());
                        prayer.OwnerProfile = (PenYourPrayerUser)serializer.Deserialize(reader);
                    }

                    latestprayer.Add(prayer);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, latestprayer));
                //return Request.CreateResponse(HttpStatusCode.OK, new CustomResponseMessage() { StatusCode = (int)HttpStatusCode.OK, Description = res });
            }
        }
Exemple #46
0
 public override void Parse(StringReader r)
 {
     r.ReadLine();
 }
Exemple #47
0
        private void WriteImage(XmlDocument document, string key,
                                string outputPath, XmlWriter writer, MediaTarget target)
        {
            writer.WriteStartElement("img");   // start: img

            if (target.Text != null)
            {
                writer.WriteAttributeString("alt", target.Text);
            }

            if (target.HasMap)
            {
                writer.WriteAttributeString("usemap", target.UseMap);
                // Prevent IE:6-8, Firefox:1-3 from drawing border...
                writer.WriteAttributeString("border", "0");
            }

            if (target.FormatXPath == null)
            {
                if (_useInclude)
                {
                    writer.WriteStartElement("span");
                    writer.WriteAttributeString("name", "SandMedia");
                    writer.WriteAttributeString("class", "tgtSentence");
                    writer.WriteString(target.Name);
                    writer.WriteEndElement();
                }
                else
                {
                    writer.WriteAttributeString("src", target.LinkPath);
                }
            }
            else
            {
                // WebDocs way, which uses the 'format' xpath expression
                // to calculate the target path and then makes it
                // relative to the current page if the 'relative-to'
                // attribute is used.
                string src = BuildComponentUtilities.EvalXPathExpr(
                    document, target.FormatXPath, "key",
                    Path.GetFileName(outputPath));

                if (target.RelativeToXPath != null)
                {
                    src = BuildComponentUtilities.GetRelativePath(src,
                                                                  BuildComponentUtilities.EvalXPathExpr(document,
                                                                                                        target.RelativeToXPath, "key", key));
                }

                if (_useInclude)
                {
                    writer.WriteStartElement("span");
                    writer.WriteAttributeString("name", "SandMedia");
                    writer.WriteAttributeString("class", "tgtSentence");
                    writer.WriteString(src);
                    writer.WriteEndElement();
                }
                else
                {
                    writer.WriteAttributeString("src", src);
                }
            }

            writer.WriteEndElement();          // end: img
            if (target.HasMap)
            {
                StringReader textReader = new StringReader(target.Map);
                using (XmlReader xmlReader = XmlReader.Create(textReader))
                {
                    writer.WriteNode(xmlReader, true);
                }
                textReader.Close();
            }
        }
        public static string ImportOfficersPrisoners(SoftJailDbContext context, string xmlString)
        {
            StringBuilder sb = new StringBuilder();

            XmlSerializer serializer = new XmlSerializer(typeof(List <ImportOfficerDto>), new XmlRootAttribute("Officers"));

            var officers = new List <Officer>();

            using (StringReader reader = new StringReader(xmlString))
            {
                var officerDtos = (List <ImportOfficerDto>)serializer.Deserialize(reader);

                foreach (var officerDto in officerDtos)
                {
                    if (!IsValid(officerDto))
                    {
                        sb.AppendLine("Invalid Data");
                        continue;
                    }

                    bool isValidPosition = Enum.TryParse(officerDto.Position, out Position position);
                    if (!isValidPosition)
                    {
                        sb.AppendLine("Invalid Data");
                        continue;
                    }

                    bool isValidWeapon = Enum.TryParse(officerDto.Weapon, out Weapon weapon);
                    if (!isValidWeapon)
                    {
                        sb.AppendLine("Invalid Data");
                        continue;
                    }

                    Officer officer = new Officer()
                    {
                        DepartmentId = officerDto.DepartmentId,
                        FullName     = officerDto.FullName,
                        Position     = position,
                        Weapon       = weapon,
                        Salary       = officerDto.Salary
                    };

                    foreach (var prisonerDto in officerDto.Prisoners)
                    {
                        // always valid
                        officer.OfficerPrisoners.Add(new OfficerPrisoner()
                        {
                            PrisonerId = prisonerDto.PrisonerId
                        });
                    }

                    officers.Add(officer);
                    sb.AppendLine($"Imported {officer.FullName} ({officer.OfficerPrisoners.Count} prisoners)");
                }
                context.Officers.AddRange(officers);

                context.SaveChanges();

                return(sb.ToString().TrimEnd());
            }
        }
    public SkeletonData GetSkeletonData(bool quiet)
    {
        if (atlasAssets == null)
        {
            atlasAssets = new AtlasAsset[0];
            if (!quiet)
            {
                Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
            }
            Reset();
            return(null);
        }

        if (skeletonJSON == null)
        {
            if (!quiet)
            {
                Debug.LogError("Skeleton JSON file not set for SkeletonData asset: " + name, this);
            }
            Reset();
            return(null);
        }

#if !SPINE_TK2D
        if (atlasAssets.Length == 0)
        {
            Reset();
            return(null);
        }
#else
        if (atlasAssets.Length == 0 && spriteCollection == null)
        {
            Reset();
            return(null);
        }
#endif

        Atlas[] atlasArr = new Atlas[atlasAssets.Length];
        for (int i = 0; i < atlasAssets.Length; i++)
        {
            if (atlasAssets[i] == null)
            {
                Reset();
                return(null);
            }
            atlasArr[i] = atlasAssets[i].GetAtlas();
            if (atlasArr[i] == null)
            {
                Reset();
                return(null);
            }
        }

        if (skeletonData != null)
        {
            return(skeletonData);
        }

        AttachmentLoader attachmentLoader;
        float            skeletonDataScale;

#if !SPINE_TK2D
        attachmentLoader  = new AtlasAttachmentLoader(atlasArr);
        skeletonDataScale = scale;
#else
        if (spriteCollection != null)
        {
            attachmentLoader  = new SpriteCollectionAttachmentLoader(spriteCollection);
            skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale);
        }
        else
        {
            if (atlasArr.Length == 0)
            {
                Reset();
                if (!quiet)
                {
                    Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
                }
                return(null);
            }
            attachmentLoader  = new AtlasAttachmentLoader(atlasArr);
            skeletonDataScale = scale;
        }
#endif

        try {
            //var stopwatch = new System.Diagnostics.Stopwatch();
            if (skeletonJSON.name.ToLower().Contains(".skel"))
            {
                var input  = new MemoryStream(skeletonJSON.bytes);
                var binary = new SkeletonBinary(attachmentLoader);
                binary.Scale = skeletonDataScale;
                //stopwatch.Start();
                skeletonData = binary.ReadSkeletonData(input);
            }
            else
            {
                var input = new StringReader(skeletonJSON.text);
                var json  = new SkeletonJson(attachmentLoader);
                json.Scale = skeletonDataScale;
                //stopwatch.Start();
                skeletonData = json.ReadSkeletonData(input);
            }
            //stopwatch.Stop();
            //Debug.Log(stopwatch.Elapsed);
        } catch (Exception ex) {
            if (!quiet)
            {
                Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
            }
            return(null);
        }

        stateData = new AnimationStateData(skeletonData);
        FillStateData();

        return(skeletonData);
    }
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        try
        {
            if (txtusername.Text == "" || txtusername.Text == null)
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "Message", "alert('Please Enter The UserName');", true);
                txtusername.Focus();
                return;
            }

            if (txtPassword.Text == "" || txtPassword.Text == null)
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "Message", "alert('Please Enter The Password with atleast one special charcter and a Capital latter');", true);
                txtPassword.Focus();
                return;
            }

            if (txtAnswer.Text == "" || txtAnswer.Text == null)
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "Message", "alert('Please Enter Answer For Selected Question');", true);
                txtAnswer.Focus();
                return;
            }
            bool          ticked   = false;
            List <string> userrole = new List <string>();
            if (chkAdmin.Checked)
            {
                userrole.Add(chkAdmin.Text); ticked = true;
            }
            if (chkUser.Checked)
            {
                userrole.Add(chkUser.Text); ticked = true;
            }
            if (chkLocation.Checked)
            {
                userrole.Add(chkLocation.Text); ticked = true;
            }
            if (!ticked)
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "Message", "alert('Please Select Atleast One Role');", true);
                return;
            }
            UserDetails objUserReq = new UserDetails();
            if (btnsubmit.Text == "Submit")
            {
                objUserReq.Username = txtusername.Text;
                objUserReq.Password = txtPassword.Text;
                string Role = string.Join("| ", userrole);
                if (txtLocation.Text != "" && chkLocation.Checked == true)
                {
                    objUserReq.Location = txtLocation.Text;
                }
                objUserReq.Role     = Role;
                objUserReq.Question = filterlist.SelectedValue.ToString();
                objUserReq.Answer   = txtAnswer.Text.ToString();

                if (objds == null)
                {
                    objds = new DataSet();
                }

                Reply objRes = new Reply();
                using (WebClient client = new WebClient())
                {
                    client.Headers[HttpRequestHeader.ContentType] = "text/json";

                    string     JsonString    = JsonConvert.SerializeObject(objUserReq);
                    EncRequest objEncRequest = new EncRequest();
                    objEncRequest.RequestData = AesGcm256.Encrypt(JsonString);
                    string dataEncrypted = JsonConvert.SerializeObject(objEncRequest);

                    string result = client.UploadString(URL + "/Adduser", "POST", dataEncrypted);

                    EncResponse objResponse = JsonConvert.DeserializeObject <EncResponse>(result);
                    objResponse.ResponseData = AesGcm256.Decrypt(objResponse.ResponseData);
                    JsonSerializer json = new JsonSerializer();
                    json.NullValueHandling = NullValueHandling.Ignore;
                    StringReader sr = new StringReader(objResponse.ResponseData);
                    Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr);
                    objRes = json.Deserialize <Reply>(reader);

                    if (objRes.res == true)
                    {
                        var page1 = HttpContext.Current.CurrentHandler as Page;
                        ScriptManager.RegisterStartupScript(page1, page1.GetType(), "alert", "alert('User Created Successfully' );window.location ='CreateUser.aspx';", true);
                        clearAll();
                    }
                    else
                    {
                        Response.Write("<script type='text/javascript'>alert( 'User Already Exist. / " + objRes.strError + "')</script>");
                        lblPassword.Text = "";
                    }
                    chkAdmin.Checked    = false;
                    chkUser.Checked     = false;
                    chkLocation.Checked = false;
                    chkUser.Enabled     = true;
                    chkAdmin.Enabled    = true;
                }
            }
            else
            {
                objUserReq.Username = txtusername.Text;
                objUserReq.Password = txtPassword.Text;
                string Role = string.Join("| ", userrole);
                if (txtLocation.Text != "" && chkLocation.Checked == true)
                {
                    objUserReq.Location = txtLocation.Text;
                }
                objUserReq.Role     = Role;
                objUserReq.Question = filterlist.SelectedValue.ToString();
                objUserReq.Answer   = txtAnswer.Text.ToString();

                if (objds == null)
                {
                    objds = new DataSet();
                }

                Reply objRes = new Reply();
                using (WebClient client = new WebClient())
                {
                    client.Headers[HttpRequestHeader.ContentType] = "text/json";

                    string     JsonString    = JsonConvert.SerializeObject(objUserReq);
                    EncRequest objEncRequest = new EncRequest();
                    objEncRequest.RequestData = AesGcm256.Encrypt(JsonString);
                    string dataEncrypted = JsonConvert.SerializeObject(objEncRequest);

                    string result = client.UploadString(URL + "/UpdateUser", "POST", dataEncrypted);

                    EncResponse objResponse = JsonConvert.DeserializeObject <EncResponse>(result);
                    objResponse.ResponseData = AesGcm256.Decrypt(objResponse.ResponseData);
                    JsonSerializer json = new JsonSerializer();
                    json.NullValueHandling = NullValueHandling.Ignore;
                    StringReader sr = new StringReader(objResponse.ResponseData);
                    Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr);
                    objRes = json.Deserialize <Reply>(reader);

                    if (objRes.res == true)
                    {
                        var page1 = HttpContext.Current.CurrentHandler as Page;
                        ScriptManager.RegisterStartupScript(page1, page1.GetType(), "alert", "alert('User Update Successfully' );window.location ='ViewUser.aspx';", true);
                    }
                    else
                    {
                        Response.Write("<script type='text/javascript'>alert( 'User Already Exist. / " + objRes.strError + "')</script>");
                        lblPassword.Text = "";
                    }
                }
            }
        }
        catch (Exception excp)
        {
            Response.Write("<script type='text/javascript'>alert( 'Error catch " + excp.Message + "')</script>");
        }
    }
Exemple #51
0
        public void BuildIndex()
        {
            if (_config == null)
            {
                throw new InvalidOperationException("The <search> element is missing from the configuration.");
            }

            Dictionary <string, string> hashes = new Dictionary <string, string>(StringComparer.Ordinal);

            foreach (KeyValuePair <string, ContentRecord> item in _content)
            {
                if (item.Key == SearchTemplate.SearchPath || item.Key == SearchTemplate.TemplatePath ||
                    item.Key == _config.TemplateUri)
                {
                    continue;
                }
                if (item.Value.HasContentStoreId == false)
                {
                    continue;
                }
                if (!_mimeInfo[item.Value.MimeType].Indexed || _mimeInfo[item.Value.MimeType].Type != ContentFormat.Html)
                {
                    continue;
                }
                if (item.Value.HasHashContents)
                {
                    if (hashes.ContainsKey(item.Value.HashContents))
                    {
                        continue;
                    }
                    hashes.Add(item.Value.HashContents, item.Key);
                }

                string            title = null, blurb = null, date = null;
                string            content = Encoding.UTF8.GetString(_content.ReadContent(item.Value, true));
                HtmlLightDocument xdoc = new HtmlLightDocument(content);
                XmlLightElement   found, selectFrom = _config.XPathBase == null ? xdoc.Root
                    : xdoc.SelectRequiredNode(_config.XPathBase.XPath);

                bool ignore = false;
                foreach (var xpath in _config.Conditions.SafeEnumeration())
                {
                    if (null != selectFrom.SelectSingleNode(xpath.XPath))
                    {
                        ignore = true;
                        break;
                    }
                }
                if (ignore)
                {
                    continue;
                }

                if (_config.TitlePath != null && selectFrom.TrySelectNode(_config.TitlePath.XPath, out found))
                {
                    title = found.InnerText.Trim();
                }
                else if (_config.TitlePath == null && false == _mimeInfo.TryGetTitle(item.Value.MimeType, content, out title))
                {
                    title = null;
                }
                if (String.IsNullOrEmpty(title))
                {
                    continue;
                }

                if (_config.BlubXPath != null)
                {
                    StringBuilder tmp = new StringBuilder();
                    foreach (XmlLightElement e in selectFrom.Select(_config.BlubXPath.XPath))
                    {
                        if (e.IsText)
                        {
                            tmp.Append(e.Value);
                        }
                        else
                        {
                            foreach (XmlLightElement txt in e.Select(".//text()"))
                            {
                                tmp.Append(txt.Value);
                            }
                        }
                    }
                    if (tmp.Length == 0)
                    {
                        tmp.Append(selectFrom.SelectRequiredNode(_config.BlubXPath.XPath).InnerText);
                    }
                    blurb = tmp.ToString();
                }
                DateTime dtvalue = item.Value.DateCreated;
                if (_config.DateXPath != null && selectFrom.TrySelectNode(_config.DateXPath.XPath, out found))
                {
                    DateTime contentDate;
                    string   dtText = found.InnerText.Trim();
                    dtText = DateTimeClean.Replace(dtText, m => m.Value.Substring(0, m.Length - 2));

                    if (!String.IsNullOrEmpty(_config.DateXPath.DateFormat))
                    {
                        if (DateTime.TryParseExact(dtText, _config.DateXPath.DateFormat, CultureInfo.InvariantCulture,
                                                   DateTimeStyles.AllowWhiteSpaces, out contentDate))
                        {
                            dtvalue = contentDate;
                        }
                        else
                        {
                            throw new FormatException("Unable to parse date/time: " + dtText);
                        }
                    }
                    else if (DateTime.TryParse(dtText, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out contentDate))
                    {
                        dtvalue = contentDate;
                    }
                    else
                    {
                        throw new FormatException("Unable to parse date/time: " + dtText);
                    }
                }
                date = dtvalue.ToString("yyyy-MM-dd HH:mm:ss");

                StringWriter indexed = new StringWriter();
                indexed.WriteLine(title);
                foreach (var xpath in _config.Indexed.SafeEnumeration())
                {
                    foreach (var indexItem in selectFrom.Select(xpath.XPath))
                    {
                        string innerText = indexItem.InnerText;
                        indexed.WriteLine(innerText);
                        indexed.WriteLine(NonAlphaNum.Replace(innerText, " "));//again, removing all special characters.
                    }
                }

                if (String.IsNullOrEmpty(blurb))
                {
                    blurb = indexed.ToString().Substring(title.Length).Trim();
                }

                title = WhiteSpaces.Replace(TrimString(title, _config.TitlePath != null ? (uint)_config.TitlePath.MaxLength : BlurbLength), " ");
                blurb = WhiteSpaces.Replace(TrimString(blurb, _config.BlubXPath != null ? (uint)_config.BlubXPath.MaxLength : BlurbLength), " ");

                string text = indexed.ToString();

                using (TextReader rdr = new StringReader(text))
                    AddToIndex(item.Key, date, title, blurb, rdr);
            }
        }
        /// <summary>
        /// 加载Androidmanifest
        /// </summary>
        /// <returns></returns>
        public bool LoadAssetManifest()
        {
            AssetBundleConfig config = null;

            switch (ABConfig.configWritingMode)
            {
            case ConfigWritingMode.Binary:
                if (FileHelper.JudgeFilePathExit(GetABConfigLocalPath()))
                {
                    if (configAB != null)
                    {
                        configAB.Unload(false);
                    }
                    configAB = AssetBundle.LoadFromFile(GetABConfigLocalPath());
                    TextAsset textAsset = configAB.LoadAsset <TextAsset>(ABConfigName);

                    if (textAsset == null)
                    {
                        Debug.LogError("AssetBundleConfig is no exist!");
                        return(false);
                    }
                    //反序列化,得到打包的信息
                    MemoryStream    stream = new MemoryStream(textAsset.bytes);
                    BinaryFormatter bf     = new BinaryFormatter();
                    config = (AssetBundleConfig)bf.Deserialize(stream);
                    stream.Close();
                }
                else
                {
                    AFLogger.e("AssetbundleConfig文件不存在");
                    return(false);
                }
                break;

            case ConfigWritingMode.TXT:
                string abJson = "";
                if (ABConfig.ABResLoadfrom == ABResLoadFrom.PersistentDataPathAB)
                {
                    abJson = FileHelper.ReadTxtToStr(GetABConfigLocalPath());
                    if (abJson.Equals(""))
                    {
                        AFLogger.e("AssetbundleConfig文件不存在或者内容为空");
                        return(false);
                    }
                }
                else if (ABConfig.ABResLoadfrom == ABResLoadFrom.StreamingAssetAB)
                {
                    string    abConfigPath = "AF-ABForLocal/AF-InfoFile" + GetVersionStr() + "/" + GetStrByPlatform() + ABConfigName;
                    TextAsset textAsset    = ResManager.Instance.LoadSync(ResLoadInfo.Allocate(ResFromType.ResourcesRes, abConfigPath, false)) as TextAsset;
                    abJson = textAsset.text;
                }
                config = SerializeHelper.FromJson <AssetBundleConfig>(abJson);
                break;

            case ConfigWritingMode.XML:
                XmlDocument  xml = new XmlDocument();
                MemoryStream ms  = null;
                if (ABConfig.ABResLoadfrom == ABResLoadFrom.PersistentDataPathAB)
                {
                    xml.Load(GetABConfigLocalPath());
                }
                else
                {
                    string    abConfigPath = "AF-ABForLocal/AF-InfoFile" + GetVersionStr() + "/" + GetStrByPlatform() + ABConfigName;
                    TextAsset textAsset    = ResManager.Instance.LoadSync(ResLoadInfo.Allocate(ResFromType.ResourcesRes, abConfigPath, false)) as TextAsset;

                    //由于编码问题,要设置编码方式
                    byte[] encodeString = System.Text.Encoding.UTF8.GetBytes(textAsset.text);
                    //以流的形式来读取
                    ms = new MemoryStream(encodeString);
                    xml.Load(ms);
                }
                if (xml == null)
                {
                    AFLogger.e("AssetbundleConfig文件不存在或者内容为空");
                    return(false);
                }
                XmlSerializer xmldes = new XmlSerializer(typeof(AssetBundleConfig));
                StringReader  sr     = new StringReader(xml.InnerXml);
                config = (AssetBundleConfig)xmldes.Deserialize(sr);
                if (ms != null)
                {
                    ms.Close();
                    ms.Dispose();
                }
                if (sr != null)
                {
                    sr.Close();
                    sr.Dispose();
                }
                break;
            }
            ResManager.Instance.CacheABConfig(config);
            return(true);
        }
Exemple #53
0
 public static DataTable ReadDataTableFromString(string csv)
 {
     using (var reader = new StringReader(csv))
         return(CsvParser.CreateDataTable(reader));
 }
Exemple #54
0
    public void AnimationInit()
    {
        string line;

        string[]     info;
        StringReader packetInfoString = new StringReader(elapsedTimeString);

        PacketTypeInfo.Add("NO", Global.PacketType.Normal);
        PacketTypeInfo.Add("PR", Global.PacketType.Parity);
        PacketTypeInfo.Add("MCD", Global.PacketType.MCD);
        PacketTypeInfo.Add("MCDC", Global.PacketType.MCDcache);
        PacketTypeInfo.Add("HC", Global.PacketType.HC);
        PacketTypeInfo.Add("TCP", Global.PacketType.TCP);
        PacketTypeInfo.Add("ICMP", Global.PacketType.ICMP);
        PacketTypeInfo.Add("NAK", Global.PacketType.NAK);
        PacketTypeInfo.Add("TUNNEL", Global.PacketType.Tunnel);
        PacketTypeInfo.Add("QOS", Global.PacketType.Qos);
        PacketTypeInfo.Add("HTTP2", Global.PacketType.HTTP2);

        line = packetInfoString.ReadLine();
        while (line != null)
        {
            info = line.Split(' ');
            PacketInfo pInfo = new PacketInfo();
            pInfo.packetTime  = int.Parse(info[(int)PacketInfoIdx.Time]);
            pInfo.sourcePos   = topo.GetNodePosition(info[(int)PacketInfoIdx.Source]);
            pInfo.targetPos   = topo.GetNodePosition(info[(int)PacketInfoIdx.Target]);
            pInfo.source      = info[(int)PacketInfoIdx.Source];
            pInfo.target      = info[(int)PacketInfoIdx.Target];
            pInfo.origin      = info[(int)PacketInfoIdx.Origin];
            pInfo.destination = info[(int)PacketInfoIdx.Destination];
            pInfo.packetID    = info[(int)PacketInfoIdx.Pid];
            pInfo.packetType  = PacketTypeInfo[info[(int)PacketInfoIdx.Type]];

            // Setting up the time if two packet have exactly same time
            if (packetTime.Contains(pInfo.packetTime))
            {
                pInfo.packetTime = pInfo.packetTime + 1;
            }
            else
            {
                packetTime.Add(pInfo.packetTime);
            }

            // Findout origin and destination of the pckets which doesn't have these
            if (pInfo.origin == "00000000" && OriginDestinationMap.ContainsKey(pInfo.packetID) == true)
            {
                pInfo.origin      = OriginDestinationMap[pInfo.packetID].Item1;
                pInfo.destination = OriginDestinationMap[pInfo.packetID].Item2;
                // Debug.Log("CHANGE = " + pInfo.packetTime + " : " +  pInfo.packetID + " : " + pInfo.origin + " - " + pInfo.destination);
            }
            else if (pInfo.origin != "00000000" && OriginDestinationMap.ContainsKey(pInfo.packetID) == false)
            {
                Tuple <string, string> orgDest = new Tuple <string, string>(pInfo.origin, pInfo.destination);
                OriginDestinationMap.Add(pInfo.packetID, orgDest);
            }

            if (packetBySource.ContainsKey(pInfo.source))
            {
                packetBySource[pInfo.source].Add(pInfo.packetTime, pInfo);
            }
            else
            {
                SortedDictionary <int, PacketInfo> dict = new SortedDictionary <int, PacketInfo>();
                dict.Add(pInfo.packetTime, pInfo);
                packetBySource.Add(pInfo.source, dict);
                packetBySourcePtr.Add(pInfo.source, -1);
            }

            if (packetByTarget.ContainsKey(pInfo.target))
            {
                packetByTarget[pInfo.target].Add(pInfo.packetTime, pInfo);
            }
            else
            {
                SortedDictionary <int, PacketInfo> dict = new SortedDictionary <int, PacketInfo>();
                dict.Add(pInfo.packetTime, pInfo);
                packetByTarget.Add(pInfo.target, dict);
                packetByTargetPtr.Add(pInfo.target, -1);
            }

            if (packetIDSequence.ContainsKey(pInfo.packetID))
            {
                packetIDSequence[pInfo.packetID].Add(pInfo.packetTime);
            }
            else
            {
                List <int> l = new List <int>();
                l.Add(pInfo.packetTime);
                packetIDSequence.Add(pInfo.packetID, l);
                packetIDSequencePtr.Add(pInfo.packetID, 0);
            }

            line = packetInfoString.ReadLine();
            // Debug.Log(pInfo.packetTime);
        }

        // Display packet by source
        Debug.Log("Packet By Source");
        // foreach(var s in packetBySource.Keys){
        //     foreach(var k in packetBySource[s].Keys){
        //         Debug.Log(s + " : " + k + " : " + packetBySource[s][k].packetID);
        //     }
        // }
        Debug.Log("Packet By Target");
        // foreach(var s in packetByTarget.Keys){
        //     foreach(var k in packetByTarget[s].Keys){
        //         Debug.Log(s + " : " + k + " : " + packetByTarget[s][k].packetID);
        //     }
        // }
        foreach (var t in packetByTarget.Keys)
        {
            for (int i = 0; i < packetByTarget[t].Count; i++)
            {
                var k = packetByTarget[t].ElementAt(i).Key;
                Debug.Log(i + " = " + t + " : " + k + " : " + packetByTarget[t][k].packetID);
            }
        }
        // Debug.Log("Packet ID Sequence");
        // foreach(var k in packetIDSequence.Keys){
        //     foreach(var t in packetIDSequence[k]){
        //         Debug.Log(k + " : " + packetIDSequencePtr[k] + " : " + t);
        //     }
        // }

        packetTime.Clear();
        mcdCache.Clear();

        graphInput.ClearPlot();
        graphInput.GraphInputInit();

        animParamBeforeSliderJump.sliderJump   = false;
        animParamBeforeSliderJump.jumpDuration = 0f;

        LossyLinkObjects = topo.GetDropperLinkObjects();

        if (LossyLinkObjects.Count > 0)
        {
            InvokeRepeating("LossyLinkBlink", 0, 0.05f);
        }
        loadingPanel.SetActive(false);
        AdjustSpeed(1f);
        if (prePlay == true)
        {
            AdjustSpeed(prePlayTimeScale);
            StartAnimation();
        }
    }
Exemple #55
0
        static void Main(string[] args)
        {
            var input = @"o inc 394 if tcy >= -3
s inc -204 if s <= -5
keq inc -34 if keq > -6
ip inc 762 if ip == 4
zr inc -644 if ip >= 6
myk dec 894 if yq == -10
pc dec -990 if keq > -44
hwk inc 106 if qfz == -5
o inc 406 if qfz != -3
ljs dec 34 if myk == 0
n inc 579 if n != -6
sd dec -645 if pc <= 992
ow inc 154 if bio == 0
ige dec 108 if ip >= -9
py dec 799 if vt == 0
qfz dec -943 if tcy <= -9
hwk inc 569 if o == 800
tcy inc 90 if gij < 3
qpa inc -15 if ip < 1
keq inc -2 if u == 0
qpa inc -132 if keq <= -38
hwk inc -87 if zr == 7
ige dec 759 if g >= 9
cy inc -232 if scy > -8
hwk dec 539 if vt >= -7
d inc 517 if d <= 8
keq inc -65 if d < 509
sd dec -585 if vt >= -1
zr dec 970 if vt < 6
yq dec -670 if n == 579
qpa inc -839 if sd != 1226
s dec -633 if hwk > 26
sd inc -310 if g > 6
ljs inc 764 if o != 790
yq dec -785 if tcy >= 83
qfz inc 136 if ljs == 721
myk inc -699 if n == 579
qpa dec -16 if ow > 146
ow dec -257 if ige >= -112
d inc 675 if d != 517
gij dec 294 if bio >= 1
bio dec -937 if vt < 9
myk dec -630 if ige < -105
qpa inc -630 if bio > 930
ip dec -280 if ljs >= 738
hwk inc 532 if myk <= -61
sd inc -71 if pc >= 987
zr inc -753 if ip == -10
bio inc 716 if scy >= -3
u dec -59 if ljs >= 721
tcy dec -872 if py <= -803
si dec -480 if py != -799
cy dec -99 if gij <= 7
bio inc 804 if d <= 508
cy inc 489 if si > 0
o inc -910 if si <= 9
pc dec 393 if s <= 633
zr inc -580 if zr != -967
ige inc -824 if qfz >= -7
d dec -138 if o >= -116
ige inc -16 if scy < 2
s dec -29 if ip != 6
py inc -172 if bio <= 1657
keq inc 648 if tcy != 89
cy dec 324 if n > 575
ljs inc 624 if myk <= -61
n inc -643 if qpa == -1468
py dec -637 if g != -2
zr dec -174 if myk == -74
hwk dec 746 if scy >= -4
myk dec 775 if pc < 602
ljs inc -490 if s < 670
vt dec 173 if yq >= 1453
bio inc -106 if bio <= 1661
ljs inc 654 if qfz <= 6
gij dec -932 if d == 655
ige inc 146 if ljs == 1518
py dec 294 if myk > -850
zr inc 370 if n > -68
pc inc 463 if ige != -802
sd inc -300 if d != 645
ip dec -523 if hwk < -178
sd inc -652 if vt > -164
yq dec -493 if d < 663
ljs inc -612 if o < -110
myk inc -211 if bio <= 1544
gij dec -630 if pc < 598
ige inc -45 if ow <= 403
keq dec -658 if cy == -457
py dec -171 if gij <= 1565
hwk inc -159 if ljs < 1521
sd inc 475 if qfz >= 4
myk inc 516 if ow >= 411
hwk dec -812 if u < 53
d inc 544 if ige >= -805
cy inc -594 if ow >= 414
zr inc -98 if tcy < 85
cy dec -242 if sd == 859
bio dec 177 if ljs == 1518
myk inc -485 if ow < 420
s dec 451 if myk < -810
qfz dec 865 if yq > 1954
zr dec -430 if cy != -211
yq dec -640 if py < -451
qfz inc -886 if ljs == 1518
gij inc -636 if keq > 1267
bio inc 932 if ow >= 411
qpa inc -638 if sd != 859
qfz dec -726 if n != -61
tcy dec 303 if yq <= 2579
vt inc -915 if keq <= 1275
n inc -653 if zr > -747
ow inc -583 if keq <= 1277
scy inc 522 if pc > 596
gij inc -186 if n <= -56
sd dec 908 if qpa < -1472
o dec -157 if si < 3
g inc -239 if si < -9
ige inc -454 if hwk < -333
qfz inc 992 if qpa >= -1470
py dec -876 if sd > 852
py inc 983 if scy >= 513
vt inc -633 if yq <= 2592
o dec -167 if pc < 599
yq inc -784 if ip < 529
bio dec -179 if cy <= -209
keq dec -213 if keq <= 1278
s inc 845 if u >= 56
vt dec -890 if n <= -60
ow dec 479 if myk > -815
gij dec 93 if pc > 591
qfz dec 976 if pc == 597
myk dec -402 if pc > 588
cy dec -248 if s != 1054
n dec -519 if ljs == 1518
ow inc 323 if o < 224
ow dec 386 if ljs > 1509
scy inc 175 if ow != -715
tcy inc -344 if ip > 525
o inc 200 if si <= 4
ip dec 942 if bio > 2477
keq dec 983 if sd < 864
o inc 776 if o < 420
vt inc 284 if ljs > 1510
qfz inc 272 if myk > -407
tcy dec 276 if myk != -411
si inc -634 if keq == 500
gij inc -767 if g == 0
o inc 857 if o > 1189
yq inc -490 if cy != 27
vt inc -646 if qfz != -153
n dec 388 if n >= 447
yq dec -734 if pc > 603
ljs inc 382 if vt <= -1187
si dec 933 if bio > 2477
qpa dec -572 if ip == -419
scy inc -520 if keq == 500
g inc 133 if ljs <= 1908
ow dec -77 if ige >= -1264
si dec 984 if yq >= 1305
n dec 53 if pc == 597
zr inc -682 if tcy >= 89
g inc -839 if n > 16
keq inc 975 if qfz <= -145
hwk inc -592 if u >= 51
s inc -786 if gij != -113
keq dec -805 if n < 16
ige dec 854 if hwk < -940
yq inc 656 if ow <= -643
qfz inc -577 if pc <= 590
d dec -85 if d < 1208
keq inc 546 if cy == 33
bio dec 23 if ip == -419
si inc 205 if cy < 37
ige dec 979 if sd >= 855
o dec -482 if vt > -1198
cy dec -72 if gij <= -112
yq inc 276 if hwk > -930
zr inc 994 if qfz > -153
hwk inc 843 if py >= 1412
ige inc 468 if hwk >= -940
sd inc 477 if myk < -406
vt inc 557 if gij >= -124
tcy inc 949 if ljs == 1900
qpa dec 321 if g < 136
scy inc 502 if pc < 603
ljs inc -339 if cy <= 95
gij dec -963 if ljs < 1902
myk inc 1000 if bio >= 2449
sd dec 317 if gij != 849
qfz dec 148 if sd > 1027
g dec -786 if s <= 279
py dec -451 if ip != -422
ljs inc -756 if gij != 837
d inc 459 if ljs > 1140
hwk inc -371 if u > 58
u inc 765 if qfz < -141
ljs inc -69 if yq != 1324
ip inc -347 if o <= 2530
gij inc -56 if cy < 108
zr inc 988 if qpa <= -1216
o dec -671 if zr < 552
n inc -680 if qfz < -136
ow dec -709 if sd < 1027
ip inc -73 if si <= -2352
hwk dec 673 if gij <= 796
s inc 806 if py != 1856
zr dec -792 if g >= 910
si dec 325 if gij > 787
u dec -950 if ow == 73
yq dec 821 if sd <= 1025
g dec -160 if myk == 589
ljs inc -870 if gij >= 795
ow inc -309 if o == 3200
s dec -472 if s == 1076
ip dec 510 if keq < 1852
sd dec -599 if vt != -629
ige dec -147 if g > 1076
sd dec 602 if hwk == -1979
keq dec 215 if ip <= -1286
cy dec -290 if tcy >= 1038
pc inc 816 if g == 1079
cy inc 171 if bio != 2467
ip inc 104 if d >= 1734
scy inc -577 if qfz > -146
n inc 209 if cy != 558
qfz dec 130 if yq < 501
ow dec 740 if ip <= -1165
d dec -857 if vt > -639
pc inc -981 if bio < 2460
zr dec -979 if ow == -972
n inc -167 if ljs == 1071
ljs inc -315 if vt >= -636
vt dec -276 if gij > 779
g dec 778 if ip >= -1178
sd inc -976 if tcy >= 1040
d inc -517 if n > -467
ljs dec 359 if ow <= -976
gij inc -811 if u >= 820
ljs dec -768 if scy != 102
u dec -584 if zr < 1333
qfz dec 588 if qfz > -268
zr inc -775 if ow < -972
myk dec -693 if vt >= -367
cy inc 937 if s > 1549
hwk dec -686 if u >= 821
tcy dec -868 if qfz != -276
qpa inc 97 if scy > 111
gij inc 296 if pc != 432
cy dec -559 if o != 3199
g dec 59 if ip < -1166
keq inc -262 if zr != 563
o dec 823 if py >= 1844
ljs dec -253 if g < 243
ow inc -351 if tcy != 1914
myk dec -684 if d <= 2092
zr dec -175 if qpa == -1221
s inc -96 if scy <= 92
o inc 492 if keq <= 1589
tcy inc 563 if n > -464
ljs inc 764 if s < 1553
qpa inc -475 if qfz > -278
hwk dec -474 if myk >= 1957
o dec -709 if vt >= -364
ip dec -372 if bio == 2458
ip dec 361 if qfz != -272
tcy inc 986 if sd < 1019
ow dec 405 if hwk >= -809
n inc 894 if ow != -1336
g dec 648 if cy != 1116
si inc -49 if gij == -24
ip dec -787 if myk <= 1974
ljs dec 449 if scy <= 111
ow dec 940 if qpa != -1698
pc dec 788 if qfz > -277
u inc -955 if bio <= 2465
sd dec 113 if pc < -352
n dec 827 if ow <= -2260
tcy inc 298 if myk < 1973
g inc -615 if ige > -1630
ige inc 561 if o != 3578
scy dec -853 if myk > 1962
ige dec -248 if scy == 955
ip dec -961 if ige <= -1372
gij dec 441 if bio >= 2456
cy inc -631 if o == 3578
o dec -801 if gij == -465
zr dec -313 if scy <= 946
s dec -959 if yq == 493
s inc 77 if g > -1023
sd inc -160 if yq >= 485
yq dec -274 if pc != -357
d dec -882 if ige >= -1379
vt dec 311 if o != 4383
ip inc 732 if n < -384
ljs inc 742 if py < 1854
yq dec 707 if s < 2588
si inc -970 if cy != 486
cy inc 867 if scy >= 961
ow inc -880 if myk != 1972
pc inc -36 if ige <= -1369
g dec 308 if qpa > -1698
ljs dec -900 if gij >= -474
qpa inc 87 if hwk != -817
zr inc -763 if py == 1853
g dec 990 if myk <= 1975
tcy dec -579 if vt < -672
keq dec -565 if pc >= -399
u inc 381 if pc < -384
o dec -195 if bio > 2456
myk dec -39 if yq != 60
qpa dec 416 if bio == 2458
u inc 351 if keq < 2150
s inc 854 if vt >= -668
d dec 502 if myk < 1976
scy inc 372 if qpa >= -2023
hwk inc 362 if g == -2319
keq dec -972 if n != -390
pc inc 415 if tcy <= 3759
n inc 37 if sd > 737
n inc -617 if py != 1860
yq dec -446 if yq <= 62
ow inc -865 if pc == 23
n inc -157 if ljs == 2619
qfz inc 885 if keq != 2147
ige dec 106 if d <= 2460
sd dec 409 if d < 2469
ige dec 219 if d >= 2454
g dec -861 if qpa > -2029
cy dec 216 if ljs == 2611
ljs dec -993 if qpa < -2027
qfz inc 777 if d < 2467
ljs inc 348 if d != 2470
o dec -187 if bio > 2455
gij inc -778 if d == 2463
ige inc 798 if ip != 1321
n dec 160 if tcy < 3762
ip dec 431 if o > 4758
keq inc 889 if ip <= 890
si inc -272 if zr <= -192
zr inc -289 if sd != 344
si inc 843 if o == 4761
ige inc -940 if ip >= 887
pc inc -189 if keq < 3045
o inc -658 if yq >= 501
n dec -886 if keq >= 3045
tcy inc -3 if o > 4095
ow dec -639 if n < -1125
n dec 81 if ip < 891
qpa dec -430 if qfz <= 1394
cy inc 602 if bio >= 2457
qpa inc -579 if hwk >= -448
qfz inc 559 if g > -1460
u inc -902 if yq <= 507
py dec 556 if s > 2578
ige dec 439 if bio != 2467
hwk inc 327 if scy <= 1330
d dec -634 if o > 4103
myk dec 919 if qfz < 1957
tcy inc 680 if keq < 3050
qpa dec 628 if cy == 880
zr dec 112 if u <= -650
o dec -214 if si <= -2788
keq inc 132 if bio > 2451
myk inc 229 if qpa != -2219
keq inc 651 if n != -1203
si inc -655 if qfz != 1942
py inc -726 if zr < -595
scy inc -565 if py >= 567
qfz dec -219 if vt >= -661
py dec -405 if u > -656
ip dec 668 if g != -1454
sd inc -496 if py == 976
zr dec 315 if s != 2590
o dec -355 if myk >= 1047
cy dec -575 if keq <= 3831
o dec 589 if qfz != 1947
sd dec 487 if scy != 768
qfz inc -742 if n == -1211
n inc -81 if n > -1220
pc dec -747 if bio >= 2454
pc inc 814 if qpa == -2219
myk inc -874 if sd < -642
myk inc 375 if bio <= 2450
u inc -7 if ip <= 229
scy dec 677 if cy >= 1455
keq dec 746 if zr != -917
yq inc 594 if hwk >= -121
qpa inc -511 if bio != 2456
tcy dec 24 if zr < -919
o inc 10 if vt >= -679
ow dec -995 if yq != 506
py dec -144 if tcy >= 4425
g dec 501 if si > -3457
sd inc 911 if scy > 82
gij inc 545 if keq == 3080
gij inc 498 if vt <= -671
yq inc 728 if ip >= 227
si inc -751 if u > -669
keq dec 819 if d > 2453
ow inc -863 if pc == 1395
bio inc 651 if hwk < -134
s inc -818 if gij != -200
scy dec -26 if vt >= -675
ow dec -279 if d > 2454
n dec -451 if pc <= 1403
myk dec -113 if ljs != 2967
myk inc 14 if ip <= 210
bio inc 473 if hwk < -126
sd dec -907 if pc > 1392
qfz dec 21 if sd <= 1170
s inc 612 if vt != -664
qpa inc -734 if o != 4686
zr dec -487 if cy > 1453
myk dec -733 if sd > 1176
tcy inc -873 if ip >= 220
tcy inc -28 if vt <= -670
scy dec -793 if qpa <= -3465
u inc 301 if qfz >= 1180
d inc 515 if g > -1950
scy dec -335 if g > -1965
hwk inc 563 if scy == 446
bio dec -980 if py > 1112
yq dec 504 if o <= 4683
keq dec 458 if scy > 443
o inc -840 if sd > 1159
pc inc 922 if g <= -1957
si dec -305 if ljs < 2960
si inc 576 if ip > 212
pc inc 167 if n == -841
u dec 354 if d < 2470
py dec -167 if qpa > -3469
bio inc -599 if bio < 3912
u dec -783 if s >= 3190
hwk inc -838 if gij != -210
ow dec 803 if keq >= 1803
ow inc -592 if qpa > -3463
gij dec 475 if d == 2463
g dec -344 if u <= 69
si inc -575 if yq != -7
ige inc 247 if py != 1296
scy inc -847 if g >= -1966
zr inc 405 if yq > -5
si dec -102 if zr > -25
ow dec -630 if ip <= 221
o inc 563 if si <= -3788
qfz inc 722 if myk != 285
gij inc 461 if ow > -4139
bio inc -605 if cy < 1461
ige inc -235 if scy > -404
zr dec -637 if n != -840
n dec 847 if gij < -211
keq dec -165 if keq != 1806
o inc -27 if ige >= -2166
d dec -751 if n <= -1681
o dec -847 if scy < -395
hwk inc 526 if n < -1681
ow dec -197 if o > 5234
o dec 730 if py != 1285
ljs inc 300 if o < 4503
vt dec -530 if u > 66
n dec 862 if zr >= 615
si inc 804 if py <= 1289
myk dec -87 if n == -2550
pc inc -633 if vt >= -141
scy inc -392 if myk == 373
scy dec 444 if scy != -793
tcy inc 806 if zr < 624
vt inc 957 if ip <= 212
zr inc -380 if keq == 1968
n inc 519 if ow <= -4124
bio inc 738 if d != 3219
hwk inc -599 if yq == 2
ip dec -795 if ige < -2155
s inc -205 if myk == 373
zr dec 36 if keq <= 1970
pc dec -69 if ige == -2160
hwk dec 239 if tcy != 4333
ige dec 197 if s <= 3000
u dec 564 if tcy != 4326
u dec -109 if zr != 197
py inc 61 if vt >= -147
s dec -736 if tcy != 4330
u inc 385 if n != -2030
keq dec 98 if s > 3726
bio dec 467 if d == 3214
si dec 616 if ljs <= 3259
scy inc -799 if o == 4495
myk inc -364 if u < 8
qfz inc -180 if s != 3718
py dec 954 if gij == -214
qfz inc -608 if o >= 4487
ige dec -214 if ow < -4130
py dec 31 if qpa > -3471
d dec -625 if d <= 3210
ljs dec -407 if cy < 1460
n dec -218 if py >= 355
vt dec 577 if py == 363
hwk dec 406 if cy != 1464
g inc -243 if bio != 2968
keq inc -322 if vt > -727
tcy inc -159 if bio < 2970
qfz dec 208 if ljs > 3661
u inc 130 if u != -2
si dec 283 if g == -2202
hwk inc -489 if n <= -1812
u inc -895 if gij < -219
vt dec -375 if ljs < 3668
pc dec 325 if o == 4495
qpa dec 655 if yq == 2
ow inc 433 if sd <= 1172
ip inc 932 if ige != -2145
qpa inc 256 if g == -2202
ige inc -839 if qfz <= 916
o inc 108 if yq <= 9
myk dec 49 if ige >= -2983
d dec -825 if keq < 1556
hwk dec 756 if ige >= -2989
tcy dec 17 if u == 131
keq dec -841 if u >= 129
scy inc -926 if si > -3897
bio inc 880 if d > 4035
sd inc -230 if qpa <= -3861
si dec 782 if n <= -1808
myk inc 998 if vt != -337
hwk inc -363 if ljs < 3670
qpa dec 349 if keq == 2389
ip dec 17 if s <= 3736
u dec -985 if ige != -2984
zr dec 470 if hwk == -2731
ige dec -767 if py <= 368
yq dec 766 if keq >= 2385
ige dec 790 if yq == -758
cy inc 712 if ip > 1939
qfz inc 379 if ljs != 3666
py inc -287 if ljs == 3666
cy inc 148 if gij > -220
cy dec -389 if ip >= 1925
s dec 405 if g == -2202
ljs dec -95 if vt != -353
sd dec -511 if qfz <= 912
ljs dec -997 if gij < -204
scy dec -731 if ow != -3698
yq inc -383 if bio >= 3853
myk inc -272 if tcy >= 4321
py inc -162 if scy <= -2514
g dec -975 if keq <= 2392
bio dec -327 if n >= -1816
u inc -309 if d == 4039
scy inc -593 if cy > 1988
bio dec 737 if cy >= 1990
o inc 978 if o == 4603
ow inc -788 if bio <= 3448
qfz inc 568 if qpa != -4212
gij dec 637 if cy <= 1998
cy dec -603 if n == -1821
ljs inc 642 if ip > 1925
qpa inc 159 if ljs <= 5404
ip inc 987 if cy == 1992
d dec -499 if ige > -2225
n inc -267 if gij != -857
u dec 396 if cy >= 1987
hwk inc -131 if vt < -335
tcy dec 878 if gij != -841
cy dec -269 if d >= 4530
sd dec 706 if si >= -4670
n dec 239 if pc <= 1594
sd dec 318 if zr >= -274
ow dec 897 if s <= 3330
zr inc -891 if si >= -4661
u dec 119 if gij != -853
keq dec 427 if ige == -2215
ige dec 185 if pc < 1596
n inc 200 if py >= -90
scy inc 289 if u == 292
scy dec -570 if ige < -2390
myk dec 676 if qpa == -4053
yq dec 232 if sd < 434
ljs dec 685 if yq != -1379
n dec -747 if ow >= -5389
bio dec 900 if ige < -2398
hwk inc 106 if qfz != 906
o inc -687 if u < 294
sd inc 905 if sd > 430
yq inc -405 if qpa == -4053
u inc 871 if gij > -850
pc dec -145 if hwk > -2760
sd dec -673 if u >= 284
si dec 407 if qpa > -4055
ip dec 491 if s < 3329
bio inc 90 if ige != -2404
g dec 429 if ljs > 5398
qpa inc -965 if o >= 4888
s dec 419 if myk > 279
cy inc 309 if scy != -2261
u inc -585 if pc <= 1740
myk inc 933 if ow >= -5382
bio dec -959 if keq <= 1966
zr inc -68 if d == 4538
gij dec 418 if n <= -1127
cy dec -537 if scy > -2260
n dec -912 if scy <= -2251
yq inc -880 if ow < -5382
u dec -593 if yq <= -2663
u dec -628 if qfz >= 907
hwk dec -978 if keq == 1962
py dec 286 if o > 4903
o dec 626 if vt >= -349
vt dec 244 if si >= -5079
g inc -282 if ip <= 2428
zr dec 729 if py >= -86
pc dec 626 if vt >= -594
myk inc -630 if u == 928
bio inc -318 if ige <= -2393
hwk dec -636 if bio <= 3272
gij inc 4 if tcy != 3437
d inc -633 if keq != 1954
cy dec -845 if qfz > 909
bio dec -701 if zr < -1060
bio dec 33 if bio <= 3985
gij dec -770 if scy == -2252
o inc -301 if yq > -2673
s inc -11 if s != 2903
ip inc -527 if yq > -2674
d dec -700 if scy < -2245
o dec 157 if yq <= -2655
g dec -914 if cy < 3962
ige inc -380 if s < 2908
qpa inc -37 if hwk != -1784
pc inc 300 if keq == 1955
s dec 259 if s < 2907
yq inc 415 if cy < 3956
d inc -713 if vt < -584
si inc -257 if ip < 1902
n dec 573 if ljs > 5398
n dec -227 if py == -84
cy dec -469 if zr <= -1062
qfz inc -210 if ige != -2779
myk dec -63 if ip < 1894
keq inc 573 if gij <= -486
tcy dec 552 if keq < 2528
s inc 340 if qpa == -5055
zr inc 258 if qfz == 700
keq dec 528 if scy >= -2256
g dec 876 if g < -1021
si dec -939 if si < -5340
cy dec 200 if py > -80
qfz inc -714 if o <= 3814
g inc -497 if yq > -2253
bio dec -953 if ow > -5384
g dec 215 if ljs < 5396
yq dec 24 if ip > 1906
n inc 371 if scy <= -2248
o dec 264 if s < 2987
s dec -428 if gij > -502
ige dec 629 if yq <= -2242
gij inc -461 if g <= -2393
d dec -217 if u > 926
cy dec -781 if u != 926
hwk dec 929 if tcy < 3450
u dec 835 if ip >= 1897
tcy dec 753 if u < 99
ow inc 592 if py >= -91
ip dec -141 if pc != 1114
tcy inc -295 if zr == -808
o inc -627 if d == 4109
cy inc 469 if bio != 4905
vt inc -913 if vt != -587
sd dec 242 if zr > -809
qfz dec -166 if g > -2407
s dec 375 if yq >= -2253
scy inc -741 if qpa != -5051
myk dec 358 if g >= -2406
myk dec 873 if u != 90
hwk dec -387 if qpa == -5061
ow dec -360 if n < -431
py inc -907 if yq < -2239
pc dec -403 if myk >= -1576
sd inc -788 if si > -5328
qfz inc -95 if qfz > 158
s inc -25 if si != -5337
tcy inc -216 if qpa < -5054
ow dec -542 if bio > 4899
tcy dec 425 if hwk > -2707
tcy inc -543 if ljs < 5404
sd dec -200 if py < -989
zr dec 421 if u <= 91
d dec -522 if ljs != 5394
cy inc -533 if ljs >= 5398
vt inc -761 if py != -1001
bio inc -888 if ige > -3419
hwk inc -757 if gij == -956
yq dec 982 if ip >= 1892
scy dec 498 if myk != -1588
sd dec -884 if o < 2922
si dec 630 if qpa < -5047
bio dec -509 if gij == -947
vt dec 811 if pc >= 1113
yq inc 973 if ow <= -4257
s inc 564 if zr != -805
qpa dec 40 if ow > -4259
tcy dec -628 if u >= 93
qfz inc -951 if qpa != -5105
si dec 314 if py >= -994
n dec 41 if scy >= -3497
hwk inc -338 if pc > 1112
cy inc -982 if g < -2387
ow dec -651 if cy <= 4163
sd inc 463 if g >= -2405
yq dec -669 if qpa <= -5090
zr inc -237 if ljs > 5393
pc inc 594 if zr != -1047
bio inc -336 if keq <= 2001
py inc 303 if s < 3586
tcy dec 239 if gij != -965
tcy dec -514 if g > -2407
cy dec 362 if scy > -3493
ige dec 194 if o > 2917
cy inc 547 if u != 91
n inc 925 if si <= -6269
ow dec -786 if py <= -687
s inc 759 if zr != -1047
py dec 844 if yq == -2562
cy inc 640 if keq <= 2011
zr inc 13 if d < 4634
d dec -439 if o >= 2915
u dec 616 if n >= 456
myk dec -754 if tcy > 2541
sd dec 166 if vt == -2153
bio inc -776 if vt >= -2161
ljs dec -616 if myk >= -1583
zr inc 612 if ow < -2813
vt dec 735 if ip >= 1896
yq dec -856 if ige >= -3602
zr dec 927 if py >= -1535
u dec -416 if myk == -1579
py dec -76 if sd < 2412
myk dec -48 if ip >= 1905
qfz dec 95 if o > 2912
vt dec 810 if d != 5070
qfz inc 89 if qfz > -896
qfz dec -527 if scy > -3500
bio inc -851 if keq > 2005
u inc -43 if pc != 1704
u dec -143 if scy != -3487
gij dec 947 if sd >= 2411
g dec 202 if ow <= -2810
tcy dec 438 if bio != 2384
n inc -784 if sd <= 2400
ljs dec -64 if ip > 1893
yq inc 951 if keq >= 2004
bio dec -37 if vt == -2894
ige dec -280 if o > 2917
qpa dec -373 if ige == -3323
qpa dec 697 if yq > -1617
scy dec -430 if s < 4329
zr inc -253 if g == -2599
keq dec 339 if vt <= -2893
g dec 703 if ljs <= 6078
hwk dec -571 if vt == -2894
ige dec -954 if o <= 2928
keq dec 568 if o > 2914
ljs inc -645 if scy >= -3498
keq dec -827 if ljs != 5434
cy dec 784 if g == -2599
gij dec -47 if qpa == -5428
hwk inc -260 if myk == -1579
qpa dec -586 if g > -2608
o dec -581 if hwk > -3486
qpa inc -86 if o == 2919
gij dec -946 if zr < -2210
u dec 212 if ow == -2812
ow dec 268 if qpa < -4915
qpa inc 867 if hwk <= -3487
py dec -844 if hwk == -3491
g inc 35 if ow != -3078
gij dec -783 if vt <= -2885
u dec 57 if tcy >= 2097
pc dec -465 if tcy >= 2103
zr dec -262 if vt > -2904
hwk inc 153 if myk < -1571
si dec 295 if tcy >= 2092
u inc -59 if u < -270
sd dec 18 if gij != 769
gij inc -803 if bio < 2417
cy inc 523 if myk < -1579
vt dec -929 if ip < 1909
s dec -584 if ow < -3079
hwk dec -717 if keq < 1931
gij inc -114 if sd != 2386
qfz inc -478 if tcy != 2092
sd inc -322 if cy < 4198
ige dec 271 if tcy >= 2106
myk inc -298 if g != -2564
zr dec 711 if pc >= 1707
si dec -542 if sd < 2074
vt dec 819 if scy <= -3493
qfz inc 700 if ip >= 1891
g inc 134 if sd < 2067
qfz inc -572 if pc > 1703
ow dec -770 if keq <= 1931
o inc -63 if bio != 2422
hwk inc 797 if py < -612
qpa dec 679 if si >= -6031
qfz inc 46 if bio == 2422
g dec 182 if g < -2423
vt inc 488 if o != 2926
o dec -900 if cy > 4193
zr inc -625 if d > 5070
scy inc -64 if scy >= -3481
s inc 958 if tcy >= 2091
n inc -824 if myk != -1586
n dec -601 if u > -338
qfz inc 503 if s <= 5878
hwk inc 445 if d >= 5074
ow dec -123 if tcy != 2099
s inc -160 if hwk >= -1831
ige inc -959 if pc == 1708
s dec 526 if d > 5062
si inc -250 if pc > 1714
scy dec -40 if n >= 233
ow dec 909 if py == -614
ow inc 147 if u <= -333
sd inc -748 if pc > 1717
qpa dec 303 if cy >= 4190
qfz dec -347 if cy < 4206
vt inc 575 if scy < -3458
ow inc -59 if cy < 4201
ow dec -701 if ip <= 1896
qpa inc -666 if ige < -3318
g dec -595 if ige == -3328
sd dec 968 if u < -333
d dec -135 if u > -334
zr inc 501 if ljs != 5438
qpa inc 126 if qfz >= 264
ip dec 334 if keq > 1926
si inc 979 if ljs >= 5427
ip dec -474 if vt > -1485
vt dec -262 if pc <= 1710
u dec -960 if ige == -3328
scy inc -621 if ow < -3125
zr inc -256 if cy > 4189
u inc -133 if sd == 1096
si inc -53 if pc < 1706
vt dec 695 if keq <= 1928
zr inc 373 if hwk > -1833
qpa dec -198 if ow >= -3139
cy dec 636 if s != 5181
ip inc -732 if sd <= 1105
tcy inc -756 if tcy <= 2091
zr dec 503 if py <= -618
yq inc 451 if ip > 1298
gij dec 391 if zr < -2033
ow dec -258 if tcy <= 2106
yq inc 957 if g != -2022
gij dec 639 if u < 502
sd dec 253 if vt < -1908
tcy inc -882 if cy < 3570
s dec 556 if gij != -256
cy dec -820 if keq == 1927
py inc 885 if d < 5078
ige dec -207 if qpa != -5376
scy dec -417 if py == 271
g inc 45 if u >= 484
o dec -198 if o <= 3824
d dec -978 if pc >= 1705
scy dec -770 if ip != 1310
hwk dec -35 if hwk > -1826
pc dec 470 if si > -5047
n dec -141 if u > 483
ow inc 244 if scy == -2885
pc dec 538 if d <= 6055
sd inc 289 if ow >= -2638
keq inc -931 if ip != 1317
py inc 746 if py != 278
qfz dec -957 if si == -5051
yq dec -374 if cy < 4377
vt dec -749 if ljs >= 5426
n inc 922 if bio != 2422
scy dec 758 if s <= 4644
qfz inc -739 if s <= 4635
si inc 653 if s >= 4634
d inc 297 if ow == -2629
vt inc 963 if zr != -2033
g inc 977 if si <= -4393
myk dec -141 if qfz == 486
s dec 68 if d == 6345
zr inc 882 if s <= 4564
cy inc -492 if pc == 1170
myk dec -492 if ow <= -2633
s dec -186 if cy <= 3893
tcy inc -947 if hwk == -1789
pc dec 455 if s > 4745
gij dec 601 if n <= 370
scy inc -688 if hwk < -1797
scy inc 768 if qfz < 491
myk inc -187 if qfz != 490
g dec -732 if ow != -2629
cy dec 355 if qfz != 480
ip inc 901 if cy == 3534
qfz dec 460 if yq != -203
py dec 366 if d <= 6349
qpa inc 474 if d > 6343
keq dec -768 if tcy == 270
gij inc 876 if ljs >= 5427
tcy inc 617 if bio > 2419
sd inc -649 if ljs != 5441
ow dec -20 if gij < 627
qfz dec 436 if vt <= -198
pc dec -752 if d <= 6337
ip dec 928 if scy < -2867
qpa inc 780 if d > 6344
bio inc 963 if n == 379
ige inc 93 if gij != 620
ige inc -185 if scy == -2875
py inc -650 if qpa >= -4129
ip dec -895 if gij < 621
s dec -539 if ip != 2180
py dec 71 if qpa >= -4127
bio dec 229 if gij != 619
yq dec 56 if vt > -205
qfz dec -389 if sd != 485
s dec -85 if cy < 3540
ip inc 386 if yq < -253
gij dec 571 if qpa != -4119
ip inc -645 if bio == 3380
qpa inc -822 if qpa < -4118
ljs inc -43 if myk == -1625
bio inc -462 if tcy == 887
myk inc -717 if vt > -200
scy dec 228 if myk != -2348
myk dec -518 if myk <= -2336
d inc -593 if si < -4397
ip inc -912 if ige < -3428
si inc -320 if vt <= -196
n dec 997 if ige != -3420
ip inc -801 if ip > 2557
pc dec -526 if hwk < -1781
ige dec -279 if ip <= 1762
ow dec -488 if qfz >= 436
scy inc 408 if qfz != 443
gij inc -992 if scy <= -2691
pc inc 238 if ige != -3143
g inc 760 if scy >= -2697
s dec -57 if hwk <= -1783
si dec 368 if ip == 1760
qfz dec 760 if vt >= -205
myk dec 254 if u == 491
sd inc -466 if myk <= -1818
cy dec -64 if qfz != -331
vt dec -632 if qpa == -4944
gij inc 382 if zr == -2042
py inc 585 if zr <= -2050
n dec 612 if d < 5760
o inc 673 if py <= -62
u inc 986 if py <= -61
ip dec 128 if gij == -954
u inc -173 if ige <= -3140
ip inc 358 if scy <= -2687
o inc 114 if py > -67
hwk dec -413 if n <= -233
scy dec 979 if s == 5434
myk inc -190 if py <= -62
u dec 884 if hwk != -1376
sd inc -711 if zr > -2038
pc inc -292 if o <= 4690
d inc -490 if d < 5749
py dec 812 if ljs <= 5397
keq dec -74 if qfz >= -324
qfz dec 820 if ige >= -3149
ow dec 629 if d >= 5746
scy dec 481 if qfz != -1144
gij dec 272 if ip == 2118
keq inc -957 if scy == -4161
ljs dec -974 if hwk == -1376
gij dec 848 if sd < 20
o inc -718 if scy >= -4160
s dec 807 if g <= -244
zr inc -12 if sd != 23
ip dec 332 if sd >= 19
sd inc -237 if ljs >= 6370
o dec 105 if ow == -2750
u inc -466 if qpa > -4950
cy inc -11 if keq >= 1846
gij dec 576 if scy > -4159
py inc -470 if u == 834
qfz inc 812 if vt != 434
yq inc -447 if bio <= 2927
qpa inc 983 if bio != 2926
g dec -396 if py != -882
qfz dec -504 if vt < 437
d inc 202 if ip > 2121
ip dec -112 if n < -230
hwk inc -295 if keq <= 1845
hwk dec -244 if d == 5752
tcy inc 905 if n != -235
ljs dec 901 if yq >= -710
keq dec -871 if sd <= 20
u inc -900 if s == 5434
pc dec 916 if vt <= 426";

//            input = @"b inc 5 if a > 1
//a inc 1 if b < 5
//c dec -10 if a >= 1
//c inc -20 if c == 10";

            //var Registers = new List<Register>();

            using (StringReader reader = new StringReader(input))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    Console.WriteLine(line);
                    ExecuteInstruction(line);
                }
            }

            var max = Registers.Values.Max();

            Console.WriteLine(max);
            Console.WriteLine(MaxValFound);
        }
Exemple #56
0
        public MainWindow(ReadOnlyCollection <string> args)
        {
            if (!Debugger.IsAttached)
            {
                splashScreen = new SplashScreen("Resources/d-ide_256.png");
                splashScreen.Show(false, true);
            }

            // Init Manager
            WorkbenchLogic.Instance = new WorkbenchLogic(this);
            IDEManager.Instance     = new IDEManager(this);

            // Load global settings
            try
            {
                GlobalProperties.Init();
            }
            catch { }

            InitializeComponent();

            encoding_DropDown.ItemsSource = new[] {
                Encoding.ASCII,
                Encoding.UTF8,
                Encoding.Unicode,
                Encoding.UTF32
            };

            // Init logging support
            ErrorLogger.Instance = new IDELogger(this);

            // Showing the window is required because the DockMgr has to init all panels first before being able to restore last layouts
            Show();

            #region Init panels and their layouts
            Panel_Locals.Name        = "LocalsPanel";
            Panel_Locals.HideOnClose = true;

            StartPage             = new Controls.Panels.StartPage();
            StartPage.Name        = "IDEStartPage";
            StartPage.HideOnClose = true;

            // Note: To enable the docking manager saving&restoring procedures it's needed to name all the panels
            Panel_ProjectExplorer.Name        = "ProjectExplorer";
            Panel_ProjectExplorer.HideOnClose = true;

            Panel_Log.Name           = "Output";
            Panel_Log.DockableStyle |= DockableStyle.AutoHide;

            Panel_ErrorList.Name           = "ErrorList";
            Panel_ErrorList.HideOnClose    = true;
            Panel_ErrorList.DockableStyle |= DockableStyle.AutoHide;

            RestoreDefaultPanelLayout();
            #endregion

            try
            {
                var layoutFile = Path.Combine(IDEInterface.ConfigDirectory, GlobalProperties.LayoutFile);

                // Exclude this call in develop (debug) time
                if (                //!System.Diagnostics.Debugger.IsAttached&&
                    File.Exists(layoutFile))
                {
                    var fcontent = File.ReadAllText(layoutFile);
                    if (!string.IsNullOrWhiteSpace(fcontent))
                    {
                        var s = new StringReader(fcontent);
                        DockMgr.RestoreLayout(s);
                        s.Close();
                    }
                }
            }
            catch (Exception ex) { ErrorLogger.Log(ex); }

            WorkbenchLogic.Instance.InitializeEnvironment(args);

            /*
             * if (GlobalProperties.Instance.IsFirstTimeStart)
             * {
             *      if(splashScreen!=null)
             *              splashScreen.Close(TimeSpan.FromSeconds( 0));
             *      if (MessageBox.Show("D-IDE seems to be launched for the first time. Start configuration now?", "First time startup", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes)
             *              new GlobalSettingsDlg() { Owner = this }.ShowDialog();
             * }*/
        }
Exemple #57
0
        private void button2_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            using (WebClient client = new WebClient()) // WebClient class inherits IDisposable
            {
                client.Encoding = Encoding.UTF8;
                client.Headers.Add("User-Agent: Other");
                //string htmlCode = client.DownloadString("http://www.sdna.gr/teams/paok").Replace("<div", "\n<div");
                string htmlCode = client.DownloadString("http://www.sdna.gr/teams/paok")
                                  .Replace("><",
                                           ">\n<"); //.Replace("<span class=\"field-content\">", "<span class=\"field-content\">\b");
                StringReader reader        = new StringReader(htmlCode);
                int          articlesFound = 0;
                string       line;


                //Το SDNA έχει όλες τις πληροφορίες σε μια γραμμή! Την εντοπίζουμε και την σπάμε σε σειρές ώστε να μπορέσουμε να πάρουμε τα άρθρα
                bool foundStart = false;

                while ((line = reader.ReadLine()) != null)
                {
                    //Μέχρι να συναντήσουμε το <div class="row"> που είναι και η μοναδική γραμμή που θέλουμε
                    if (line.Contains("<div class=\"external-wrapper\">"))
                    {
                        foundStart = true;
                    }

                    if (!foundStart)
                    {
                        continue;
                    }

                    //Έλεγχος για τις δυο περιπτώσεις ημερομηνίας
                    if (line.Contains("<em class=\"placeholder\">"))
                    {
                        //Το string περιέχει δεδομένα όπως 1 ωρα 11 λεπτά. Το μετατρέπουμε σε κανονική ημερομηνία
                        line = line.Replace("<span class=\"field-content\"> <em class=\"placeholder\">", "").Replace("</em> πριν </span>", "").Trim();

                        string[] splitString = line.Split(new[] { " " }, StringSplitOptions.None);
                        int      secondsPassedFromPublish = 0;

                        //Μετατρεπουμε τα δεδομένα μας σε δευτερόλεπτα και βρίσκομε την ακριβή ώρα δημοσίευσης
                        for (int i = 0; i < splitString.Length; i++)
                        {
                            switch (splitString[i].ToLower())
                            {
                            case "ώρα":
                            case "ώρες":
                                secondsPassedFromPublish += int.Parse(splitString[i - 1]) * 3600;
                                break;

                            case "λεπτό":
                            case "λεπτά":
                                secondsPassedFromPublish += int.Parse(splitString[i - 1]) * 60;
                                break;

                            case "δευτ.":
                                secondsPassedFromPublish += int.Parse(splitString[i - 1]);
                                break;
                            }
                        }


                        richTextBox1.AppendText(DateTime.Now.AddSeconds(secondsPassedFromPublish * (-1)).ToString("g") + Environment.NewLine);
                    }

                    else if (line.Contains("<span class=\"field-content\">") && line.Contains("</span>"))
                    {
                        //Η σειρά μας ενδιαφέρει μόνο αν έχει ημερομηνία μέσα
                        string[] format = { "dd MMMM yyyy, HH:mm" };
                        line = line.Replace("<span class=\"field-content\">", "").Replace("</span>", "").TrimStart().TrimEnd();
                        DateTime retrievedDateTime;

                        if (DateTime.TryParseExact(line, format,
                                                   new CultureInfo("el-GR"),
                                                   //CultureInfo.CurrentCulture,
                                                   DateTimeStyles.AssumeLocal, out retrievedDateTime))
                        {
                            richTextBox1.AppendText(retrievedDateTime.ToString("g") + Environment.NewLine);
                        }
                    }
                    else if (!line.Contains("div class") && line.Contains("<a href=\"/"))
                    {
                        line = line.Replace("<a href=\"", string.Empty).Replace("</a>", string.Empty);

                        //Το σύμβολο (") χωρίζει το url από τον τίτλο
                        int    breakSymbolIndex = line.IndexOf('\"');
                        string url = line.Substring(0, breakSymbolIndex);
                        richTextBox1.AppendText("www.sdna.gr" + url + Environment.NewLine);

                        //Αφαιρούμε το url και τα διαχωριστικά (">) και μένει μόνο ο τίτλος του άρθρου
                        string title = line.Replace(url, string.Empty).Replace("\">", string.Empty);
                        richTextBox1.AppendText(title + Environment.NewLine);
                        articlesFound++;
                    }

                    if (articlesFound >= 15)
                    {
                        return;
                    }
                }
            }
        }
Exemple #58
0
        /// <summary>Parses a line of text, and produces a
        /// <see cref="MarkupParseResult"/> containing the processed
        /// text.</summary>
        /// <param name="input">The text to parse.</param>
        /// <returns>The resulting markup information.</returns>
        internal MarkupParseResult ParseMarkup(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                // We got a null input; return an empty markup parse result
                return(new MarkupParseResult
                {
                    Text = string.Empty,
                    Attributes = new List <MarkupAttribute>(),
                });
            }

            this.input = input.Normalize();

            this.stringReader = new StringReader(this.input);

            var stringBuilder = new StringBuilder();

            var markers = new List <MarkupAttributeMarker>();

            int nextCharacter;

            char lastCharacter = char.MinValue;

            // Read the entirety of the line
            while ((nextCharacter = this.stringReader.Read()) != -1)
            {
                char c = (char)nextCharacter;

                if (c == '[')
                {
                    // How long is our current string, in text elements
                    // (i.e. visible glyphs)?
                    this.position = new System.Globalization.StringInfo(stringBuilder.ToString()).LengthInTextElements;

                    // The start of a marker!
                    MarkupAttributeMarker marker = this.ParseAttributeMarker();

                    markers.Add(marker);

                    var hadPrecedingWhitespaceOrLineStart = this.position == 0 || char.IsWhiteSpace(lastCharacter);

                    bool wasReplacementMarker = false;

                    // Is this a replacement marker?
                    if (marker.Name != null && this.markerProcessors.ContainsKey(marker.Name))
                    {
                        wasReplacementMarker = true;

                        // Process it and get the replacement text!
                        var replacementText = this.ProcessReplacementMarker(marker);

                        // Insert it into our final string and update our
                        // position accordingly
                        stringBuilder.Append(replacementText);
                    }

                    bool trimWhitespaceIfAble = false;

                    if (hadPrecedingWhitespaceOrLineStart)
                    {
                        // By default, self-closing markers will trim a
                        // single trailing whitespace after it if there was
                        // preceding whitespace. This doesn't happen if the
                        // marker was a replacement marker, or it has a
                        // property "trimwhitespace" (which must be
                        // boolean) set to false. All markers can opt-in to
                        // trailing whitespace trimming by having a
                        // 'trimwhitespace' property set to true.
                        if (marker.Type == TagType.SelfClosing)
                        {
                            trimWhitespaceIfAble = !wasReplacementMarker;
                        }

                        if (marker.TryGetProperty(TrimWhitespaceProperty, out var prop))
                        {
                            if (prop.Type != MarkupValueType.Bool)
                            {
                                throw new MarkupParseException($"Error parsing line {this.input}: attribute {marker.Name} at position {this.position} has a {prop.Type.ToString().ToLower()} property \"{TrimWhitespaceProperty}\" - this property is required to be a boolean value.");
                            }

                            trimWhitespaceIfAble = prop.BoolValue;
                        }
                    }

                    if (trimWhitespaceIfAble)
                    {
                        // If there's trailing whitespace, and we want to
                        // remove it, do so
                        if (this.PeekWhitespace())
                        {
                            // Consume the single trailing whitespace
                            // character (and don't update position)
                            this.stringReader.Read();
                            this.sourcePosition += 1;
                        }
                    }
                }
                else
                {
                    // plain text! add it to the resulting string and
                    // advance the parser's plain-text position
                    stringBuilder.Append(c);
                    this.sourcePosition += 1;
                }

                lastCharacter = c;
            }

            var attributes = this.BuildAttributesFromMarkers(markers);

            var characterAttributeIsPresent = false;

            foreach (var attribute in attributes)
            {
                if (attribute.Name == CharacterAttribute)
                {
                    characterAttributeIsPresent = true;
                }
            }

            if (characterAttributeIsPresent == false)
            {
                // Attempt to generate a character attribute from the start
                // of the string to the first colon
                var match = EndOfCharacterMarker.Match(this.input);

                if (match.Success)
                {
                    var endRange      = match.Index + match.Length;
                    var characterName = this.input.Substring(0, match.Index);

                    MarkupValue nameValue = new MarkupValue
                    {
                        Type        = MarkupValueType.String,
                        StringValue = characterName,
                    };

                    MarkupProperty nameProperty = new MarkupProperty(CharacterAttributeNameProperty, nameValue);

                    var characterAttribute = new MarkupAttribute(0, 0, endRange, CharacterAttribute, new[] { nameProperty });

                    attributes.Add(characterAttribute);
                }
            }

            return(new MarkupParseResult
            {
                Text = stringBuilder.ToString(),
                Attributes = attributes,
            });
        }
Exemple #59
0
        public Interfaces.ITokenList TokenizeSQL(string inputSQL)
        {
            TokenList           tokenContainer = new TokenList();
            StringReader        inputReader    = new StringReader(inputSQL);
            SqlTokenizationType?currentTokenizationType;
            StringBuilder       currentTokenValue = new StringBuilder();
            int commentNesting;

            currentTokenizationType  = null;
            currentTokenValue.Length = 0;
            commentNesting           = 0;

            int currentCharInt = inputReader.Read();

            while (currentCharInt >= 0)
            {
                char currentCharacter = (char)currentCharInt;
                if (currentTokenizationType == null)
                {
                    ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                }
                else
                {
                    switch (currentTokenizationType.Value)
                    {
                    case SqlTokenizationType.WhiteSpace:
                        if (IsWhitespace(currentCharacter))
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        else
                        {
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.SinglePeriod:
                        if (currentCharacter >= '0' && currentCharacter <= '9')
                        {
                            currentTokenizationType = SqlTokenizationType.DecimalValue;
                            currentTokenValue.Append('.');
                            currentTokenValue.Append(currentCharacter);
                        }
                        else
                        {
                            currentTokenValue.Append('.');
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.SingleZero:
                        if (currentCharacter == 'x' || currentCharacter == 'X')
                        {
                            currentTokenizationType = SqlTokenizationType.BinaryValue;
                            currentTokenValue.Append('0');
                            currentTokenValue.Append(currentCharacter);
                        }
                        else if (currentCharacter >= '0' && currentCharacter <= '9')
                        {
                            currentTokenizationType = SqlTokenizationType.Number;
                            currentTokenValue.Append('0');
                            currentTokenValue.Append(currentCharacter);
                        }
                        else if (currentCharacter == '.')
                        {
                            currentTokenizationType = SqlTokenizationType.DecimalValue;
                            currentTokenValue.Append('0');
                            currentTokenValue.Append(currentCharacter);
                        }
                        else
                        {
                            currentTokenValue.Append('0');
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.Number:
                        if (currentCharacter == 'e' || currentCharacter == 'E')
                        {
                            currentTokenizationType = SqlTokenizationType.FloatValue;
                            currentTokenValue.Append(currentCharacter);
                        }
                        else if (currentCharacter == '.')
                        {
                            currentTokenizationType = SqlTokenizationType.DecimalValue;
                            currentTokenValue.Append(currentCharacter);
                        }
                        else if (currentCharacter >= '0' && currentCharacter <= '9')
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        else
                        {
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.DecimalValue:
                        if (currentCharacter == 'e' || currentCharacter == 'E')
                        {
                            currentTokenizationType = SqlTokenizationType.FloatValue;
                            currentTokenValue.Append(currentCharacter);
                        }
                        else if (currentCharacter >= '0' && currentCharacter <= '9')
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        else
                        {
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.FloatValue:
                        if (currentCharacter >= '0' && currentCharacter <= '9')
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        else if (currentCharacter == '-' && currentTokenValue.ToString().EndsWith("e", StringComparison.OrdinalIgnoreCase))
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        else
                        {
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.BinaryValue:
                        if ((currentCharacter >= '0' && currentCharacter <= '9') ||
                            (currentCharacter >= 'A' && currentCharacter <= 'F') ||
                            (currentCharacter >= 'a' && currentCharacter <= 'f')
                            )
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        else
                        {
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.SingleDollar:
                        currentTokenValue.Append('$');
                        currentTokenValue.Append(currentCharacter);

                        if ((currentCharacter >= 'A' && currentCharacter <= 'Z') ||
                            (currentCharacter >= 'a' && currentCharacter <= 'z')
                            )
                        {
                            currentTokenizationType = SqlTokenizationType.PseudoName;
                        }
                        else
                        {
                            currentTokenizationType = SqlTokenizationType.MonetaryValue;
                        }

                        break;

                    case SqlTokenizationType.MonetaryValue:
                        if (currentCharacter >= '0' && currentCharacter <= '9')
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        else if (currentCharacter == '-' && currentTokenValue.Length == 1)
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        else if (currentCharacter == '.' && !currentTokenValue.ToString().Contains("."))
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        else
                        {
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.SingleHyphen:
                        if (currentCharacter == '-')
                        {
                            currentTokenizationType = SqlTokenizationType.SingleLineComment;
                        }
                        else if (currentCharacter == '=')
                        {
                            currentTokenizationType = SqlTokenizationType.OtherOperator;
                            currentTokenValue.Append('-');
                            currentTokenValue.Append(currentCharacter);
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                        }
                        else
                        {
                            currentTokenizationType = SqlTokenizationType.OtherOperator;
                            currentTokenValue.Append('-');
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.SingleSlash:
                        if (currentCharacter == '*')
                        {
                            currentTokenizationType = SqlTokenizationType.BlockComment;
                            commentNesting++;
                        }
                        else if (currentCharacter == '/')
                        {
                            currentTokenizationType = SqlTokenizationType.SingleLineCommentCStyle;
                        }
                        else if (currentCharacter == '=')
                        {
                            currentTokenizationType = SqlTokenizationType.OtherOperator;
                            currentTokenValue.Append('/');
                            currentTokenValue.Append(currentCharacter);
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                        }
                        else
                        {
                            currentTokenizationType = SqlTokenizationType.OtherOperator;
                            currentTokenValue.Append('/');
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.SingleLineComment:
                    case SqlTokenizationType.SingleLineCommentCStyle:
                        if (currentCharacter == (char)13 || currentCharacter == (char)10)
                        {
                            currentTokenValue.Append(currentCharacter);

                            int nextCharInt = inputReader.Peek();
                            if (currentCharacter == (char)13 && nextCharInt == 10)
                            {
                                currentTokenValue.Append((char)inputReader.Read());
                            }

                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                        }
                        else
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        break;

                    case SqlTokenizationType.BlockComment:
                        if (currentCharacter == '*')
                        {
                            if (inputReader.Peek() == (int)'/')
                            {
                                commentNesting--;
                                char nextCharacter = (char)inputReader.Read();
                                if (commentNesting > 0)
                                {
                                    currentTokenValue.Append(currentCharacter);
                                    currentTokenValue.Append(nextCharacter);
                                }
                                else
                                {
                                    CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                                }
                            }
                            else
                            {
                                currentTokenValue.Append(currentCharacter);
                            }
                        }
                        else
                        {
                            currentTokenValue.Append(currentCharacter);

                            if (currentCharacter == '/' && inputReader.Peek() == (int)'*')
                            {
                                currentTokenValue.Append((char)inputReader.Read());
                                commentNesting++;
                            }
                        }
                        break;

                    case SqlTokenizationType.OtherNode:
                    case SqlTokenizationType.PseudoName:
                        if (IsNonWordCharacter(currentCharacter))
                        {
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        else
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        break;

                    case SqlTokenizationType.SingleN:
                        if (currentCharacter == '\'')
                        {
                            currentTokenizationType = SqlTokenizationType.NString;
                        }
                        else
                        {
                            currentTokenizationType = SqlTokenizationType.OtherNode;
                            currentTokenValue.Append('N');
                            currentTokenValue.Append(currentCharacter);
                        }
                        break;

                    case SqlTokenizationType.NString:
                    case SqlTokenizationType.String:
                        if (currentCharacter == '\'')
                        {
                            if (inputReader.Peek() == (int)'\'')
                            {
                                inputReader.Read();
                                currentTokenValue.Append(currentCharacter);
                            }
                            else
                            {
                                CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            }
                        }
                        else
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        break;

                    case SqlTokenizationType.QuotedString:
                        if (currentCharacter == '"')
                        {
                            if (inputReader.Peek() == (int)'"')
                            {
                                inputReader.Read();
                                currentTokenValue.Append(currentCharacter);
                            }
                            else
                            {
                                CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            }
                        }
                        else
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        break;

                    case SqlTokenizationType.BracketQuotedName:
                        if (currentCharacter == ']')
                        {
                            if (inputReader.Peek() == (int)']')
                            {
                                inputReader.Read();
                                currentTokenValue.Append(currentCharacter);
                            }
                            else
                            {
                                CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            }
                        }
                        else
                        {
                            currentTokenValue.Append(currentCharacter);
                        }
                        break;

                    case SqlTokenizationType.SingleLT:
                        currentTokenValue.Append('<');
                        currentTokenizationType = SqlTokenizationType.OtherOperator;
                        if (currentCharacter == '=' || currentCharacter == '>' || currentCharacter == '<')
                        {
                            currentTokenValue.Append(currentCharacter);
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                        }
                        else
                        {
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.SingleGT:
                        currentTokenValue.Append('>');
                        currentTokenizationType = SqlTokenizationType.OtherOperator;
                        if (currentCharacter == '=' || currentCharacter == '>')
                        {
                            currentTokenValue.Append(currentCharacter);
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                        }
                        else
                        {
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.SingleAsterisk:
                        currentTokenValue.Append('*');
                        if (currentCharacter == '=')
                        {
                            currentTokenValue.Append(currentCharacter);
                            currentTokenizationType = SqlTokenizationType.OtherOperator;
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                        }
                        else
                        {
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.SingleOtherCompoundableOperator:
                        currentTokenizationType = SqlTokenizationType.OtherOperator;
                        if (currentCharacter == '=')
                        {
                            currentTokenValue.Append(currentCharacter);
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                        }
                        else
                        {
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.SinglePipe:
                        currentTokenizationType = SqlTokenizationType.OtherOperator;
                        currentTokenValue.Append('|');
                        if (currentCharacter == '=' || currentCharacter == '|')
                        {
                            currentTokenValue.Append(currentCharacter);
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                        }
                        else
                        {
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.SingleEquals:
                        currentTokenValue.Append('=');
                        if (currentCharacter == '=')
                        {
                            currentTokenValue.Append(currentCharacter);
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                        }
                        else
                        {
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    case SqlTokenizationType.SingleExclamation:
                        currentTokenValue.Append('!');
                        if (currentCharacter == '=' || currentCharacter == '<' || currentCharacter == '>')
                        {
                            currentTokenizationType = SqlTokenizationType.OtherOperator;
                            currentTokenValue.Append(currentCharacter);
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                        }
                        else
                        {
                            currentTokenizationType = SqlTokenizationType.OtherNode;
                            CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
                            ProcessOrOpenToken(ref currentTokenizationType, currentTokenValue, currentCharacter, tokenContainer);
                        }
                        break;

                    default:
                        throw new Exception("In-progress node unrecognized!");
                    }
                }

                currentCharInt = inputReader.Read();
            }


            if (currentTokenizationType != null)
            {
                if (currentTokenizationType.Value == SqlTokenizationType.BlockComment ||
                    currentTokenizationType.Value == SqlTokenizationType.String ||
                    currentTokenizationType.Value == SqlTokenizationType.NString ||
                    currentTokenizationType.Value == SqlTokenizationType.QuotedString ||
                    currentTokenizationType.Value == SqlTokenizationType.BracketQuotedName
                    )
                {
                    tokenContainer.HasUnfinishedToken = true;
                }

                CompleteToken(ref currentTokenizationType, tokenContainer, currentTokenValue);
            }

            return(tokenContainer);
        }
        /// <summary>
        /// Attempt to parse a njox object from a string
        /// </summary>
        /// <param name="raw">The raw string in njox format</param>
        /// <param name="njoxRoot">The object where the root njox will be stored</param>
        /// <returns>True if the string is successfully parsed</returns>
        public static bool TryParseObject(string raw, out NjoxNode njoxRoot)
        {
            njoxRoot = null;

            using (StringReader reader = new StringReader(raw))
            {
                List <NjoxNode> currentIndents = new List <NjoxNode>();

                while (reader.Peek() > -1)
                {
                    string line = reader.ReadLine();

                    int indentation = 0;
                    foreach (char c in line)
                    {
                        if (c != '\t')
                        {
                            break;
                        }
                        else
                        {
                            ++indentation;
                        }
                    }
                    line = line.Trim();

                    // Attempting to read root node
                    if (indentation == 0)
                    {
                        if (njoxRoot == null)
                        {
                            List <NjoxProperty> properties;

                            if (!TryParseProperties(line, out properties))
                            {
                                return(false);
                            }

                            // Could be comment line, so only use
                            if (properties.Count != 0)
                            {
                                njoxRoot = new NjoxNode(properties);
                                currentIndents.Add(njoxRoot);
                            }
                        }

                        // Discovered multiple root nodes
                        else
                        {
                            Logger.LogError("Found a second root node in njox file at '" + line + "'");
                            return(false);
                        }
                    }
                    else
                    {
                        // Check parent node exists
                        NjoxNode parentNode;
                        if (indentation - 1 < currentIndents.Count)
                        {
                            parentNode = currentIndents[indentation - 1];
                        }
                        else
                        {
                            Logger.LogError("Unexpected indentation at '" + line + "'");
                            return(false);
                        }

                        // Remove any previous sub-indentation indentations over this
                        if (currentIndents.Count >= indentation)
                        {
                            currentIndents.RemoveRange(indentation, currentIndents.Count - indentation);
                        }

                        // Attempt to read node
                        List <NjoxProperty> properties;

                        if (!TryParseProperties(line, out properties))
                        {
                            return(false);
                        }

                        // Could be comment line, so make sure to check
                        if (properties.Count != 0)
                        {
                            NjoxNode newNode = new NjoxNode(properties);
                            parentNode.AddChild(newNode);
                            currentIndents.Add(newNode);
                        }
                    }
                }
            }

            return(true);
        }