Esempio n. 1
0
        public void ToXlf12Test()
        {
            Assert.ThrowsException <ArgumentNullException>(() => StateConverter.ToXlfV12(null));
            StateConverter.ToXlfV12(string.Empty).Should().Be(Xlf12States.New);
            StateConverter.ToXlfV12(" ").Should().Be(Xlf12States.New);

            // XLIFF 1.2 states
            foreach (var state in Xlf12States.Enumerate())
            {
                StateConverter.ToXlfV12(state).Should().Be(state);
            }

            // XLIFF 1.2 user states
            foreach (var state in new string[] { StateConverter.XlfV12UserStatePrefix, StateConverter.XlfV12UserStatePrefix + "asasdsadj kljkl" })
            {
                StateConverter.ToXlfV12(state).Should().Be(state, "All user specific states are passed through 1:1.");
            }

            // MuiDB states
            StateConverter.ToXlfV12(MuiDbStates.New).Should().Be(Xlf12States.New);
            StateConverter.ToXlfV12(MuiDbStates.Translated).Should().Be(Xlf12States.Translated);
            StateConverter.ToXlfV12(MuiDbStates.Reviewed).Should().Be(Xlf12States.SignedOff);
            StateConverter.ToXlfV12(MuiDbStates.Final).Should().Be(Xlf12States.Final);

            // XLIFF v2.0 states
            StateConverter.ToXlfV12(Xlf20States.Initial).Should().Be(Xlf12States.New);
            StateConverter.ToXlfV12(Xlf20States.Translated).Should().Be(Xlf12States.Translated);
            StateConverter.ToXlfV12(Xlf20States.Reviewed).Should().Be(Xlf12States.SignedOff);
            StateConverter.ToXlfV12(Xlf20States.Final).Should().Be(Xlf12States.Final);
        }
Esempio n. 2
0
 private void PostCommit()
 {
     foreach (var entry in ChangeTracker.Entries())
     {
         ((IObjectState)entry.Entity).ObjectState = StateConverter.ToObjectState(entry.State);
     }
 }
Esempio n. 3
0
        public void ToXlf20Test()
        {
            Assert.ThrowsException <ArgumentNullException>(() => StateConverter.ToXlfV20(null));
            StateConverter.ToXlfV20(string.Empty).Should().Be(Xlf20States.Initial);
            StateConverter.ToXlfV20(" ").Should().Be(Xlf20States.Initial);

            // XLIFF v2.0 states
            foreach (var state in Xlf20States.Enumerate())
            {
                StateConverter.ToXlfV20(state).Should().Be(state);
            }

            // MuiDB states
            StateConverter.ToXlfV20(MuiDbStates.New).Should().Be(Xlf20States.Initial);
            StateConverter.ToXlfV20(MuiDbStates.Translated).Should().Be(Xlf20States.Translated);
            StateConverter.ToXlfV20(MuiDbStates.Reviewed).Should().Be(Xlf20States.Reviewed);
            StateConverter.ToXlfV20(MuiDbStates.Final).Should().Be(Xlf20States.Final);

            // XLIFF 1.2
            StateConverter.ToXlfV20(Xlf12States.New).Should().Be(Xlf20States.Initial);
            StateConverter.ToXlfV20(Xlf12States.NeedsAdaptation).Should().Be(Xlf20States.Initial);
            StateConverter.ToXlfV20(Xlf12States.NeedsReviewAdaptation).Should().Be(Xlf20States.Initial);
            StateConverter.ToXlfV20(Xlf12States.NeedsL10n).Should().Be(Xlf20States.Initial);
            StateConverter.ToXlfV20(Xlf12States.NeedsTranslation).Should().Be(Xlf20States.Initial);
            StateConverter.ToXlfV20(Xlf12States.Translated).Should().Be(Xlf20States.Translated);
            StateConverter.ToXlfV20(Xlf12States.NeedsReviewL10n).Should().Be(Xlf20States.Translated);
            StateConverter.ToXlfV20(Xlf12States.NeedsReviewTranslation).Should().Be(Xlf20States.Translated);
            StateConverter.ToXlfV20(Xlf12States.SignedOff).Should().Be(Xlf20States.Reviewed);
            StateConverter.ToXlfV20(Xlf12States.Final).Should().Be(Xlf20States.Final);

            // XLIFF 1.2 user states
            StateConverter.ToXlfV20(StateConverter.XlfV12UserStatePrefix).Should().Be(Xlf20States.Initial, "All user specific states are mapped to the New state!");
            StateConverter.ToXlfV20(StateConverter.XlfV12UserStatePrefix + "hkjfhskfahsldf").Should().Be(Xlf20States.Initial, "All user specific states are mapped to the New state!");
        }
Esempio n. 4
0
        public void GetTextStateNullArgTest()
        {
            StateConverter stateConverter = new StateConverter();

            try
            {
                var textState = stateConverter.GetTextState(null);
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentNullException));
            }
        }
Esempio n. 5
0
        public void GetTextStateTest()
        {
            StateConverter stateConverter = new StateConverter();
            var            textState      = stateConverter.GetTextState("IL");

            Assert.AreEqual("Illinois", textState);

            textState = stateConverter.GetTextState("CA");
            Assert.AreEqual("California", textState);

            textState = stateConverter.GetTextState("NY");
            Assert.AreEqual("New York", textState);
        }
Esempio n. 6
0
        private void StatusWatcherOnEventArrived(object sender, EventArrivedEventArgs e)
        {
            var instance = GetTargetInstance(e);
            var vmId     = Guid.Parse(instance.GetPropertyValue("Name") as string
                                      ?? throw new InvalidOperationException());

            var enabledState      = (ushort)instance.GetPropertyValue("EnabledState");
            var otherEnabledState = (string)instance.GetPropertyValue("OtherEnabledState");
            var healthState       = (ushort)instance.GetPropertyValue("HealthState");

            _bus.SendLocal(new VirtualMachineStateChangedEvent
            {
                VmId  = vmId,
                State = StateConverter.ConvertVMState(enabledState, otherEnabledState, healthState)
            });
        }
Esempio n. 7
0
        public void ToMuiDBTest()
        {
            Assert.ThrowsException <ArgumentNullException>(() => StateConverter.ToMuiDB(null));
            StateConverter.ToMuiDB(string.Empty).Should().Be(MuiDbStates.New);
            StateConverter.ToMuiDB(" ").Should().Be(MuiDbStates.New);

            // MuiDB states
            foreach (var state in MuiDbStates.Enumerate())
            {
                StateConverter.ToMuiDB(state).Should().Be(state);
            }

            // XLIFF 1.2
            StateConverter.ToMuiDB(Xlf12States.New).Should().Be(MuiDbStates.New);
            StateConverter.ToMuiDB(Xlf12States.NeedsAdaptation).Should().Be(MuiDbStates.New);
            StateConverter.ToMuiDB(Xlf12States.NeedsReviewAdaptation).Should().Be(MuiDbStates.New);
            StateConverter.ToMuiDB(Xlf12States.NeedsL10n).Should().Be(MuiDbStates.New);
            StateConverter.ToMuiDB(Xlf12States.NeedsTranslation).Should().Be(MuiDbStates.New);
            StateConverter.ToMuiDB(Xlf12States.Translated).Should().Be(MuiDbStates.Translated);
            StateConverter.ToMuiDB(Xlf12States.NeedsReviewL10n).Should().Be(MuiDbStates.Translated);
            StateConverter.ToMuiDB(Xlf12States.NeedsReviewTranslation).Should().Be(MuiDbStates.Translated);
            StateConverter.ToMuiDB(Xlf12States.SignedOff).Should().Be(MuiDbStates.Reviewed);
            StateConverter.ToMuiDB(Xlf12States.Final).Should().Be(MuiDbStates.Final);

            // XLIFF 1.2 user states
            StateConverter.ToMuiDB(StateConverter.XlfV12UserStatePrefix).Should().Be(MuiDbStates.New, "All user specific states are mapped to the New state!");
            StateConverter.ToMuiDB(StateConverter.XlfV12UserStatePrefix + "hkjfhskfahsldf").Should().Be(MuiDbStates.New, "All user specific states are mapped to the New state!");

            // XLIFF 2.0
            StateConverter.ToMuiDB(Xlf20States.Initial).Should().Be(MuiDbStates.New);
            StateConverter.ToMuiDB(Xlf20States.Translated).Should().Be(MuiDbStates.Translated);
            StateConverter.ToMuiDB(Xlf20States.Reviewed).Should().Be(MuiDbStates.Reviewed);
            StateConverter.ToMuiDB(Xlf20States.Final).Should().Be(MuiDbStates.Final);

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => StateConverter.ToMuiDB("asdsadsad"), "States that can not be mapped result in an ArgumentException");
        }
Esempio n. 8
0
        private static void SyncEntityState(DbEntityEntry entry)
        {
            var state = ((IObjectState)entry.Entity).ObjectState;

            entry.State = StateConverter.ToEntityState(state, entry.State);
        }
 /// <summary>
 /// Imports deserialized JSON data into this state controller
 /// </summary>
 /// <param name="data">Dictionary representing a deserialized JSON object</param>
 internal void ImportState(Dictionary <string, object> data)
 {
     StateConverter.PopulateState(data);
     Dirty = true;
 }
Esempio n. 10
0
 public AddressValidator()
 {
     stateConverter  = new StateConverter();
     streetConverter = new StreetConverter();
 }
Esempio n. 11
0
 public void Log <TState>(TState state, Exception exception)
 {
     StreamFile.Write(StateConverter.GetLogFor(state));
 }
Esempio n. 12
0
        public void consoleCommandHandler(string cmd)
        {
            try
            {
                string   tofind = "";
                string[] tofindall = null;
                ushort   modid, stid;
                uint     txid;
                cmd = cmd.Trim();
                this.cmdHistory.Add(cmd);
                cmdIdx = this.cmdHistory.Count - 1;
                string[] splitted = cmd.Split(new char[] { ' ' }, 2);
                switch (splitted[0])
                {
                case "readdb":
                    if (splitted.Length > 1 && splitted[1].Trim() != "")
                    {
                        this.fi = new FileInfo(splitted[1].Trim());
                    }
                    this.checkDB();
                    break;

                case "unloaddb":
                    this.db = null;
                    // We're taking out a huge chunk of memory, so let GC clear it out right away.
                    GC.Collect();
                    break;

                case "stringid":
                    this.checkDB();

                    stid = Util.parseUShort(splitted[1]);

                    StringRecord stringRec = (StringRecord)this.db.tables[Database.TABLE_STRINGS].getRecord(stid);
                    if (stringRec != null)
                    {
                        string toWrite = "text: " + stringRec.text;
                        if (stringRec.obdCodeString != "" && stringRec.obdCodeString != " ")
                        {
                            toWrite += "; OBD: " + stringRec.obdCodeString;
                        }
                        this.writeToConsole(toWrite + Environment.NewLine);
                    }
                    else
                    {
                        this.writeToConsole("(null)" + Environment.NewLine);
                    }

                    break;

                case "stringsearch":
                    this.checkDB();

                    this.writeBulkToConsoleStart();

                    string searching = splitted[1].ToLower();

                    foreach (StringRecord sr in this.db.tables[Database.TABLE_STRINGS].records)
                    {
                        if (sr.text.ToLower().Contains(searching) || sr.obdCodeString.ToLower().Contains(searching))
                        {
                            string toWrite = "0x" + sr.id.ToString("x4") + ": text: " + sr.text;
                            if (sr.obdCodeString != "" && sr.obdCodeString != " ")
                            {
                                toWrite += "; OBD: " + sr.obdCodeString;
                            }
                            this.writeBulkToConsole(toWrite);
                        }
                    }

                    this.writeBulkToConsoleEnd();

                    break;

                case "txid":
                    this.checkDB();

                    txid = Util.parseUInt(splitted[1]);

                    this.writeToConsole(this.db.getDetailedTX(txid) + Environment.NewLine);

                    break;

                case "txrunconverter":
                case "txrunconvertermetric":
                    this.checkDB();

                    string[] txconvsplit = splitted[1].Split(new char[] { ' ' }, 2);
                    long     convdata    = 0;

                    txid     = Util.parseUInt(txconvsplit[0]);
                    convdata = Util.parseLong(txconvsplit[1]);

                    Table    txconvtable = this.db.tables[Database.TABLE_TRANSMIT];
                    TXRecord txconvrec   = (TXRecord)txconvtable.getRecord(txid);

                    string result = txconvrec.converter.processData(convdata, outputMetric: splitted[0].EndsWith("metric"));

                    this.writeToConsole(result + Environment.NewLine);

                    break;

                case "txsearch":
                    this.checkDB();

                    tofind = splitted[1].ToLower();
                    if (tofind.Contains(" && "))
                    {
                        tofindall = tofind.Split(new string[] { " && " }, StringSplitOptions.RemoveEmptyEntries);
                    }

                    this.writeBulkToConsoleStart();
                    for (uint u = 0x80000000; u < 0x80009000; ++u)
                    {
                        try
                        {
                            string temp = this.db.getTX(u);
                            if (temp != null)
                            {
                                string templower = temp.ToLower();

                                if (tofindall != null)
                                {
                                    foreach (string s in tofindall)
                                    {
                                        if (!templower.Contains(s))
                                        {
                                            goto SKIPTX;
                                        }
                                    }
                                    this.writeBulkToConsole(temp + "; 0x" + u.ToString("x"));
                                }
                                else if (templower.Contains(tofind))
                                {
                                    this.writeBulkToConsole(temp + "; 0x" + u.ToString("x"));
                                }
                            }
                        }
                        catch
                        {
                            continue;
                        }

SKIPTX:
                        continue;
                    }
                    this.writeBulkToConsoleEnd();

                    break;

                case "dumpstateconverter":
                    this.checkDB();

                    txid = Util.parseUInt(splitted[1]);

                    Table    dtcdumptxconvtable = this.db.tables[Database.TABLE_TRANSMIT];
                    TXRecord dtcdumptxconvrec   = (TXRecord)dtcdumptxconvtable.getRecord(txid);

                    if (dtcdumptxconvrec.converter is StateConverter)
                    {
                        StateConverter dtcdumpconv = (StateConverter)dtcdumptxconvrec.converter;
                        this.writeBulkToConsoleStart();
                        this.writeBulkToConsole("DFLT: " + dtcdumpconv.sdsRecord.defaultString);
                        foreach (KeyValuePair <ushort, string> kvp in dtcdumpconv.entries)
                        {
                            this.writeBulkToConsole("0x" + kvp.Key.ToString("X2") + ": " + kvp.Value);
                        }
                        this.writeBulkToConsoleEnd();
                    }
                    else
                    {
                        this.writeToConsole("Not a StateConverter." + Environment.NewLine);
                    }

                    break;

                case "convertertostring":
                    this.checkDB();

                    txid = Util.parseUInt(splitted[1]);

                    Table    ctsTable    = this.db.tables[Database.TABLE_TRANSMIT];
                    TXRecord ctsTxRecord = (TXRecord)ctsTable.getRecord(txid);

                    this.writeToConsole(ctsTxRecord.converter.ToString());

                    break;

                case "dumptableinfo":
                    this.checkDB();

                    ushort tableNum = Util.parseUShort(splitted[1]);

                    Table  t       = this.db.tables[tableNum];
                    string toPrint = "";

                    toPrint += "Table: " + tableNum + "; Columns: " + t.colCount + "; Rows: " + t.rowCount + ";" + Environment.NewLine;
                    toPrint += "ColSizes: " + BitConverter.ToString(t.colSizes) + "; RowSize: " + t.rowSize + ";" + Environment.NewLine;

                    this.writeToConsole(toPrint);

                    break;

                case "stringidfuzz":
                    this.checkDB();

                    string[] stringfuzzsplit = splitted[1].Split(new char[] { ' ' }, 2);

                    ushort stringfuzzTable    = Util.parseUShort(stringfuzzsplit[0]);
                    byte   stringfuzzTableCol = (byte)Util.parseUShort(stringfuzzsplit[1]);
                    Table  tt              = this.db.tables[stringfuzzTable];
                    int    stringfuzzhits  = 0;
                    int    stringfuzzzeros = 0;

                    foreach (Record stringfuzzrec in tt.records)
                    {
                        ushort stringfuzzfield  = (ushort)tt.readField(stringfuzzrec, stringfuzzTableCol);
                        string stringfuzzstring = this.db.getString(stringfuzzfield);
                        if (stringfuzzstring != "(null)")
                        {
                            ++stringfuzzhits;
                        }
                        if (stringfuzzfield == 0)
                        {
                            ++stringfuzzzeros;
                        }
                    }

                    this.writeToConsole("Records: " + tt.records.Length + "; Hits: " + stringfuzzhits + "; Zeros: " + stringfuzzzeros + Environment.NewLine);

                    break;

                case "genericidfuzz":
                    this.checkDB();

                    string[] fuzzsplit = splitted[1].Split(new char[] { ' ' }, 4);

                    ushort fuzzerTableId   = Util.parseUShort(fuzzsplit[0]);
                    byte   fuzzerTableCol  = (byte)Util.parseUShort(fuzzsplit[1]);
                    ushort fuzzingTableId  = Util.parseUShort(fuzzsplit[2]);
                    byte   fuzzingTableCol = (byte)Util.parseUShort(fuzzsplit[3]);
                    Table  fuzzerTable     = this.db.tables[fuzzerTableId];
                    Table  fuzzingTable    = this.db.tables[fuzzingTableId];
                    int    fuzzhits        = 0;
                    int    fuzzzeros       = 0;

                    foreach (Record fuzzingRec in fuzzingTable.records)
                    {
                        uint   fuzzingRecID = (uint)fuzzingTable.readField(fuzzingRec, fuzzingTableCol);
                        Record fuzzerRec    = fuzzerTable.getRecord(fuzzingRecID, idcol: fuzzerTableCol, sorted: false);
                        if (fuzzerRec != null)
                        {
                            ++fuzzhits;
                        }
                        if (fuzzingRecID == 0)
                        {
                            ++fuzzzeros;
                        }
                    }

                    this.writeToConsole("Records: " + fuzzingTable.records.Length + "; Hits: " + fuzzhits + "; Zeros: " + fuzzzeros + Environment.NewLine);

                    break;

                case "modid":
                    this.checkDB();

                    modid = Util.parseUShort(splitted[1]);

                    string modresult = this.db.getModule(modid);

                    if (modresult != null)
                    {
                        this.writeToConsole(modresult + Environment.NewLine);
                    }
                    else
                    {
                        this.writeToConsole("No such module ID." + Environment.NewLine);
                    }

                    this.txtConsoleInput.Focus();
                    this.txtConsoleInput.AppendText("modid " + splitted[1]);

                    break;

                case "modlist":
                case "modsearch":
                    this.checkDB();

                    if (splitted[0] != "modlist")
                    {
                        tofind = splitted[1].ToLower();
                        if (tofind.Contains(" && "))
                        {
                            tofindall = tofind.Split(new string[] { " && " }, StringSplitOptions.RemoveEmptyEntries);
                        }
                    }

                    this.writeBulkToConsoleStart();
                    for (ushort l = 0x0000; l < 0x2000; ++l)
                    {
                        try
                        {
                            string temp = this.db.getModule(l);

                            if (temp != null)
                            {
                                if (splitted[0] != "modlist")
                                {
                                    string templower = temp.ToLower();

                                    if (tofindall != null)
                                    {
                                        foreach (string s in tofindall)
                                        {
                                            if (!templower.Contains(s))
                                            {
                                                goto SKIPMOD;
                                            }
                                        }
                                        this.writeBulkToConsole(temp + "; 0x" + l.ToString("x"));
                                    }
                                    else if (templower.Contains(tofind))
                                    {
                                        this.writeBulkToConsole(temp + "; 0x" + l.ToString("x"));
                                    }
                                }
                                else
                                {
                                    this.writeBulkToConsole(temp + "; 0x" + l.ToString("x"));
                                }
                            }
                        }
                        catch
                        {
                            continue;
                        }

SKIPMOD:
                        continue;
                    }
                    this.writeBulkToConsoleEnd();

                    break;

                case "modtxlist":
                    this.checkDB();

                    modid = Util.parseUShort(splitted[1]);

                    Record rec = this.db.tables[Database.TABLE_MODULE].getRecord(modid);
                    if (rec != null)
                    {
                        ModuleRecord modrec = (ModuleRecord)rec;
                        this.writeBulkToConsoleStart();

                        foreach (TXRecord txrec in modrec.dataelements)
                        {
                            string temp = this.db.getTX(txrec.id);
                            this.writeBulkToConsole(temp + "; 0x" + txrec.id.ToString("x"));
                        }

                        this.writeBulkToConsoleEnd();
                    }
                    else
                    {
                        this.writeToConsole("No such module." + Environment.NewLine);
                    }

                    break;
                }
            }
            catch (Exception e)
            {
                this.writeToConsole("Exception: " + e.ToString() + Environment.NewLine);
            }
        }