public void ModuleTypeKnower_WithFilledHub_turretOnly()
        {
            var go = new GameObject();

            go.AddComponent <ModuleTypeKnower>();
            var typeKnower = go.GetComponent <ModuleTypeKnower>();

            typeKnower.name  = "name";
            typeKnower.Types = new List <ModuleType>
            {
                ModuleType.Hub
            };

            var go2 = new GameObject();

            go2.AddComponent <ModuleTypeKnower>();
            var typeKnower2 = go2.GetComponent <ModuleTypeKnower>();

            typeKnower2.name  = "name2";
            typeKnower2.Types = new List <ModuleType>
            {
                ModuleType.Turret
            };

            var mr = new ModuleRecord(typeKnower, 42);

            mr.AddModule(typeKnower2, 2);

            Assert.AreEqual("42(2)", mr.ToString());
            Assert.AreEqual("name(name2)", mr.ToStringWithFullNames());
        }
Пример #2
0
    /// <summary>
    /// https://tc39.es/ecma262/#sec-modulenamespacecreate
    /// </summary>
    private static ObjectInstance CreateModuleNamespace(ModuleRecord module, List <string> unambiguousNames)
    {
        var m = new ModuleNamespace(module._engine, module, unambiguousNames);

        module._namespace = m;
        return(m);
    }
        private void ConditionControlDeleted(object sender, EventArgs e)
        {
            ModuleRecordControl control = (ModuleRecordControl)sender;
            ModuleRecord        cond    = control.ModuleRecord;

            if (cond.ItemId > 0 && MessageBox.Show("Do you really want to delete module record?", "Deleting confirmation", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                //если информация о состоянии сохранена в БД
                //и получен положительный ответ на ее удаление
                try
                {
                    GlobalObjects.CasEnvironment.NewKeeper.Delete(cond);
                }
                catch (Exception ex)
                {
                    Program.Provider.Logger.Log("Error while removing data", ex);
                }

                flowLayoutPanelMain.Controls.Remove(control);
                control.Deleted -= ConditionControlDeleted;
                control.Dispose();
            }
            else if (cond.ItemId <= 0)
            {
                flowLayoutPanelMain.Controls.Remove(control);
                control.Deleted -= ConditionControlDeleted;
                control.Dispose();
            }
        }
Пример #4
0
        public ActionResult Index()
        {
            Debug("Get ~/Administration/User/Index()");

            // Retrieve the user

            UserRecord user;

            if (int.Parse(HttpContext.User.Identity.Name) == -1)
            {
                user = UserRecord.CreateDefaultAdministrator();
            }
            else
            {
                user = _userManager.GetById(int.Parse(HttpContext.User.Identity.Name)) as UserRecord;
            }

            // If the login doesn't exist, it is the administrator by default (due to RoleFilter)

            if (user == null)
            {
                FormsAuthentication.SignOut();
                return(RedirectToAction("SignIn"));
            }

            // load ressources before designing the screen fitted to the user's profile

            LanguageDictionary ressources = new LanguageDictionary(Server.MapPath(LanguageDictionary.DIRECTORY_IMAGE), ConfigurationManager.DefaultLanguage);

            ressources.Load(_userManager.Database, user.CustomerId);

            // the user exists, check if it's already connected
            // In case of reloading page, the connection can't be disconnected as quick as expected ...

            if (DatabaseHub.IsAlreadyConnected(user.Id))
            {
                FormsAuthentication.SignOut();
                Debug($"The user '{user.Id}' is already connected on another support");
                return(View("AlreadyConnected", new UserViewModel(ressources, user, false)));
            }

            // Show the screen on depends on the user's profile

            if (user.CustomerId == 1)
            {
                return(RedirectToAction("Index", "Customer"));
            }

            // Look for the default functional module for the current user

            ModuleRecord module = _userManager.GetDefaultModule(user);

            if (module == null)
            {
                FormsAuthentication.SignOut();
                return(RedirectToAction("SignIn"));
            }

            return(RedirectToAction("Index", module.Module.ToString(), new { area = module.Module.ToString(), moduleId = module.Id }));
        }
        public void ModuleTypeKnower_ModuleNumberOnly()
        {
            var mr = new ModuleRecord(null, 42);

            Assert.AreEqual("42", mr.ToString());
            Assert.AreEqual("42", mr.ToStringWithFullNames());
        }
        public void WithEmptyHub()
        {
            var mr = new ModuleRecord(42, "name", true);

            Assert.AreEqual("42()", mr.ToString());
            Assert.AreEqual("name()", mr.ToStringWithFullNames());
            Assert.AreEqual("42", mr.ToSimpleString());
            Assert.AreEqual("name", mr.ToSimpleStringWithFullNames());
        }
Пример #7
0
        /// <summary>
        /// Retrieve the module on depends on the settings and rights of the current user
        /// </summary>
        /// <param name="user"></param>
        /// <param name="moduleId"></param>
        /// <returns></returns>
        public IModule GetModule(IUser user, int moduleId)
        {
            try
            {
                if (Database == null || user == null)
                {
                    return(null);
                }

                // Look for modules allowed for the current user

                UserModuleRecord userModuleFound = null;

                foreach (UserModuleRecord userModuleCurrent in (from userModule in Database.UserModule
                                                                where userModule.UserId == user.Id && userModule.ModuleId == moduleId
                                                                select userModule).ToList())
                {
                    InformationRecord information = Database._Information.Find("UserModule", userModuleCurrent.Id);

                    if (information == null || !information.IsDeleted)
                    {
                        userModuleFound = userModuleCurrent;
                        break;
                    }
                }

                if (userModuleFound == null)
                {
                    Warn($"No module '{moduleId}' found for the user '{user.Id}' ...");
                    return(null);
                }

                // Look for the module

                ModuleRecord module = Database.Module.Find(userModuleFound.ModuleId);

                if (module == null)
                {
                    Error($"Database inconsistency due to the missing of the module '{userModuleFound.ModuleId}' ...");
                    return(null);
                }

                if (!module.Enable)
                {
                    Warn($"The module '{module.Name}' is disabled!");
                    return(null);
                }

                Info($"The module is '{module.Name}'");
                return(module);
            }
            catch (System.Exception ex)
            {
                Exception($"Unable to retrieve the module '{moduleId}'", ex);
                return(null);
            }
        }
        public void ModuleNumberOnly()
        {
            var mr = new ModuleRecord(42);

            Assert.AreEqual("42", mr.ToString());
            Assert.AreEqual("42", mr.ToStringWithFullNames());
            Assert.AreEqual("42", mr.ToSimpleString());
            Assert.AreEqual("42", mr.ToSimpleStringWithFullNames());
        }
        public void ModuleNameDoesNotRemoveCloneIfItsTheWholeName()
        {
            var mr = new ModuleRecord(null, "(Clone)");

            Assert.IsEmpty(mr.ToString());
            Assert.AreEqual("Clone", mr.ToStringWithFullNames());
            Assert.IsEmpty(mr.ToSimpleString());
            Assert.AreEqual("Clone", mr.ToSimpleStringWithFullNames());
        }
        public void DefaultConstructor_givesBlankStrings()
        {
            var mr = new ModuleRecord();

            Assert.IsEmpty(mr.ToString());
            Assert.IsEmpty(mr.ToStringWithFullNames());
            Assert.IsEmpty(mr.ToSimpleString());
            Assert.IsEmpty(mr.ToSimpleStringWithFullNames());
        }
        public void ModuleNameRemovesClone()
        {
            var mr = new ModuleRecord(null, "name(Clone)");

            Assert.IsEmpty(mr.ToString());
            Assert.AreEqual("name", mr.ToStringWithFullNames());
            Assert.IsEmpty(mr.ToSimpleString());
            Assert.AreEqual("name", mr.ToSimpleStringWithFullNames());
        }
Пример #12
0
 public GenomeWrapper(string genome, float budget = DEFAULT_BUDGET, int geneLength = DEFAULT_GENE_LENGTH)
 {
     _genome              = genome;
     _geneLength          = geneLength;
     Budget               = budget;
     UsedLocations        = new List <Vector3>();
     ModuleTypeCounts     = new Dictionary <ModuleType, int>();
     _topModuleRecord     = new ModuleRecord();
     _currentModuleRecord = _topModuleRecord;
 }
Пример #13
0
        private ModuleRecord GetOrCreateRecord(string module)
        {
            ModuleRecord mr;

            if (this.moduleLookup.TryGetValue(module, out mr) == false)
            {
                mr = new ModuleRecord(module);
                this.moduleLookup.Add(module, mr);
            }

            return(mr);
        }
Пример #14
0
        public string getModule(ushort id)
        {
            Table  t         = this.tables[TABLE_MODULE];
            Record recordObj = t.getRecord(id);

            if (recordObj == null)
            {
                return(null);
            }
            ModuleRecord modrec = (ModuleRecord)recordObj;

            return(modrec.name + "; sc: " + modrec.scname);
        }
Пример #15
0
        public ModuleDataElemRecord(Table table, byte[] record) : base(table, record)
        {
            this.moduleForId = (ushort)this.table.readField(this, FIELD_MODULE_FOR_ID);

            this.txid = (uint)this.table.readField(this, FIELD_TXID);

            // Add TXRecord to corresponding ModuleRecord's List<TXRecord>
            Table        moduleTable = this.table.db.tables[Database.TABLE_MODULE];
            Table        txTable     = this.table.db.tables[Database.TABLE_TRANSMIT];
            ModuleRecord moduleRec   = (ModuleRecord)moduleTable.getRecord(this.moduleForId);
            TXRecord     txRec       = (TXRecord)txTable.getRecord(this.txid);

            moduleRec.dataelements.Add(txRec);
        }
        public void ModuleTypeKnower_ModuleNameOnly()
        {
            var go = new GameObject();

            go.AddComponent <ModuleTypeKnower>();
            var typeKnower = go.GetComponent <ModuleTypeKnower>();

            typeKnower.name = "name";

            var mr = new ModuleRecord(typeKnower);

            Assert.IsEmpty(mr.ToString());
            Assert.AreEqual("name", mr.ToStringWithFullNames());
        }
        public void WithFilledHub()
        {
            var mr = new ModuleRecord(42, "name", true);

            mr.AddModule(new ModuleRecord(2, "name2"));
            mr.AddModule(null);
            mr.AddModule(new ModuleRecord(3, "name3", true));

            Assert.AreEqual("42(2,-,3())", mr.ToString());
            Assert.AreEqual("name(name2,-,name3())", mr.ToStringWithFullNames());

            Assert.AreEqual("2,3,42", mr.ToSimpleString());
            Assert.AreEqual("name,name2,name3", mr.ToSimpleStringWithFullNames());
        }
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     for (int i = 0; i < 5; i++)
     {
         int j       = 1;
         var mRecord = new ModuleRecord();
         mRecord.Id         = j;
         mRecord.Operation1 = StateEnum.Pass;
         mRecord.Operation2 = StateEnum.Pass;
         mRecord.Operation3 = StateEnum.Pass;
         mRecord.Operation4 = StateEnum.Pass;
         ModuleRecords.Add(mRecord);
     }
     DataContext = this;
 }
        public void ModuleTypeKnower_WithEmptyHub()
        {
            var go = new GameObject();

            go.AddComponent <ModuleTypeKnower>();
            var typeKnower = go.GetComponent <ModuleTypeKnower>();

            typeKnower.name  = "name";
            typeKnower.Types = new List <ModuleType>
            {
                ModuleType.Hub
            };

            var mr = new ModuleRecord(typeKnower, 42);

            Assert.AreEqual("42()", mr.ToString());
            Assert.AreEqual("name()", mr.ToStringWithFullNames());
        }
        public void WithFilledHubWithDuplicates()
        {
            var mr = new ModuleRecord(42, "name", true);

            mr.AddModule(new ModuleRecord(2, "name2"));
            mr.AddModule(null);
            mr.AddModule(new ModuleRecord(3, "name3", true));
            mr.AddModule(new ModuleRecord(3, "name3", true));
            mr.AddModule(new ModuleRecord(4, "turret", false));
            mr.AddModule(new ModuleRecord(4, "turret", false));
            mr.AddModule(new ModuleRecord(4, "turret", false));
            mr.AddModule(new ModuleRecord(4, "turret", false));
            mr.AddModule(new ModuleRecord(4, "turret", false));

            Assert.AreEqual("42(2,-,3(),3(),4,4,4,4,4)", mr.ToString());
            Assert.AreEqual("name(name2,-,name3(),name3(),turret,turret,turret,turret,turret)", mr.ToStringWithFullNames());

            Assert.AreEqual("5*4,2*3,2,42", mr.ToSimpleString());
            Assert.AreEqual("5*turret,2*name3,name,name2", mr.ToSimpleStringWithFullNames());
        }
Пример #21
0
        /// <summary>
        /// Register that a module (of any type) has been added
        /// </summary>
        /// <param name="types">List of types that this module should be treated as.</param>
        /// <returns>boolean indicating if any more can be added</returns>
        public bool ConfigureAddedModule(IModuleTypeKnower knower, Vector3 usedLocation, int?moduleNumber)
        {
            if (knower != null)
            {
                foreach (var type in knower.ModuleTypes.Distinct())
                {
                    if (ModuleTypeCounts.ContainsKey(type))
                    {
                        ModuleTypeCounts[type]++;
                    }
                    else
                    {
                        ModuleTypeCounts[type] = 1;
                    }
                }
                ModulesAdded++;

                Cost += knower.ModuleCost;

                UsedLocations.Add(usedLocation);

                var nextMR = new ModuleRecord(knower, moduleNumber);
                _currentModuleRecord.AddModule(nextMR);
                _previousModuleRecords.Push(_currentModuleRecord);
                _currentModuleRecord = nextMR;

                //must be before module is configured, so the cost is updated before more modules are added.
                Jump();
                knower.Configure(this);
                ModuleFinished();
                JumpBack();
            }
            else
            {
                NoModuleAddedHere();
            }
            return(CanSpawn());
        }
Пример #22
0
    /// <summary>
    /// https://tc39.es/ecma262/#sec-getmodulenamespace
    /// </summary>
    public static ObjectInstance GetModuleNamespace(ModuleRecord module)
    {
        var ns = module._namespace;

        if (ns is null)
        {
            var exportedNames    = module.GetExportedNames();
            var unambiguousNames = new List <string>();
            for (var i = 0; i < exportedNames.Count; i++)
            {
                var name       = exportedNames[i];
                var resolution = module.ResolveExport(name);
                if (resolution is not null && resolution != ResolvedBinding.Ambiguous)
                {
                    unambiguousNames.Add(name);
                }
            }

            ns = CreateModuleNamespace(module, unambiguousNames);
        }

        return(ns);
    }
Пример #23
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":
                case "dumpconverter":
                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() + Environment.NewLine);

                    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);
            }
        }
Пример #24
0
 /// <summary>
 /// Контрол редактирует данные о залитом масле для одного агрегата
 /// </summary>
 public ModuleRecordControl(ModuleRecord runup)
     : this()
 {
     AttachedObject = runup;
 }
Пример #25
0
        public static void Main(string [] args)
        {
            var path = ProcessArguments(args);

            if (args.Length == 1)
            {
                Modules = Types = Methods = true;
            }

            var         reader = new ProfileReader();
            ProfileData pd     = null;

            if (path == null)
            {
                if (Port < 0)
                {
                    Error($"You should specify path or -p PORT to read the profile.");
                    Environment.Exit(4);
                }
                else
                {
                    try {
                        pd = ReadProfileFromPort(reader);
                    } catch (Exception e) {
                        Error($"Unable to read profile through local port: {Port}.\n{e}");
                        Environment.Exit(5);
                    }
                }
            }
            else if (!File.Exists(path))
            {
                Error($"'{path}' doesn't exist.");
                Environment.Exit(3);
            }
            else
            {
                using (var stream = new FileStream(path, FileMode.Open)) {
                    if (Verbose)
                    {
                        ColorWriteLine($"Reading '{path}'...", ConsoleColor.Yellow);
                    }

                    pd = reader.ReadAllData(stream);
                }
            }

            List <MethodRecord>        methods = new List <MethodRecord> (pd.Methods);
            ICollection <TypeRecord>   types   = new List <TypeRecord> (pd.Types);
            ICollection <ModuleRecord> modules = new List <ModuleRecord> (pd.Modules);

            if (FilterMethod != null || FilterType != null || FilterModule != null)
            {
                methods = new List <MethodRecord> ();
                types   = new HashSet <TypeRecord> ();
                modules = new HashSet <ModuleRecord> ();

                foreach (var method in pd.Methods)
                {
                    var type   = method.Type;
                    var module = type.Module;

                    if (FilterModule != null)
                    {
                        var match = FilterModule.Match(module.ToString());

                        if (!match.Success)
                        {
                            continue;
                        }
                    }

                    if (FilterType != null)
                    {
                        var match = FilterType.Match(method.Type.ToString());

                        if (!match.Success)
                        {
                            continue;
                        }
                    }

                    if (FilterMethod != null)
                    {
                        var match = FilterMethod.Match(method.ToString());

                        if (!match.Success)
                        {
                            continue;
                        }
                    }

                    methods.Add(method);
                    types.Add(type);
                    modules.Add(module);
                }
            }

            if (FilterMethod == null && FilterType != null)
            {
                foreach (var type in pd.Types)
                {
                    if (types.Contains(type))
                    {
                        continue;
                    }

                    var match = FilterType.Match(type.ToString());

                    if (!match.Success)
                    {
                        continue;
                    }

                    types.Add(type);
                }
            }

            if (Modules)
            {
                ColorWriteLine($"Modules:", ConsoleColor.Green);

                foreach (var module in modules)
                {
                    WriteLine($"\t{module.Mvid} {module.ToString ()}");
                }
            }

            if (Types)
            {
                ColorWriteLine($"Types:", ConsoleColor.Green);

                foreach (var type in types)
                {
                    WriteLine($"\t{type}");
                }
            }

            if (Methods)
            {
                ColorWriteLine($"Methods:", ConsoleColor.Green);

                foreach (var method in methods)
                {
                    WriteLine($"\t{method}");
                }
            }

            if (Summary)
            {
                ColorWriteLine($"Summary:", ConsoleColor.Green);
                WriteLine($"\tModules: {modules.Count.ToString ("N0"),10}{(modules.Count != pd.Modules.Length ? $"  (of {pd.Modules.Length})" : "" )}");
                WriteLine($"\tTypes:   {types.Count.ToString ("N0"),10}{(types.Count != pd.Types.Length ? $"  (of {pd.Types.Length})" : "")}");
                WriteLine($"\tMethods: {methods.Count.ToString ("N0"),10}{(methods.Count != pd.Methods.Length ? $"  (of {pd.Methods.Length})" : "")}");
            }

            if (!string.IsNullOrEmpty(Output))
            {
                if (Verbose)
                {
                    ColorWriteLine($"Going to write the profile to '{Output}'", ConsoleColor.Yellow);
                }
                var modulesArray = new ModuleRecord [modules.Count];
                modules.CopyTo(modulesArray, 0);
                var typesArray = new TypeRecord [types.Count];
                types.CopyTo(typesArray, 0);
                var updatedPD = new ProfileData(modulesArray, typesArray, methods.ToArray());

                using (var stream = new FileStream(Output, FileMode.Create)) {
                    var writer = new ProfileWriter();
                    writer.WriteAllData(stream, updatedPD);
                }
            }
        }
Пример #26
0
 public TypeRecord(int id, ModuleRecord module, string name, GenericInstRecord ginst) : base(id)
 {
     Module      = module;
     Name        = name;
     GenericInst = ginst;
 }
Пример #27
0
 public ModuleNamespace(Engine engine, ModuleRecord module, List <string> exports) : base(engine)
 {
     _module  = module;
     _exports = new HashSet <string>(exports);
 }
Пример #28
0
        public ActionResult Add(string name, string login, string email, string address, string comment)
        {
            Debug($"Get ~/Administration/Customer/Add(name={name}, login={login}, email={email}, address={address}, comment={comment})");

            // Only for administrator from the first customer (Syncytium)

            if (!(_userManager.GetById(int.Parse(HttpContext.User.Identity.Name)) is UserRecord user) || user.CustomerId != 1)
            {
                return(HttpNotFound());
            }

            // check the value by itself

            Errors errors = new Errors();

            // no name set

            if (string.IsNullOrWhiteSpace(name))
            {
                errors.AddField("Name", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_NAME}" });
            }
            name = name.Trim();

            // no login set

            if (string.IsNullOrWhiteSpace(login))
            {
                errors.AddField("Login", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_LOGIN}" });
            }
            login = login.Trim();

            // no email set

            if (string.IsNullOrWhiteSpace(email))
            {
                errors.AddField("Email", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_EMAIL}" });
            }
            email = email.Trim();

            // check if the name already exists

            if (_userManager.Database.Customer.Where(c => c.Name.Equals(name)).Any())
            {
                errors.AddField("Name", "ERR_FIELD_UNIQUE", new object[] { "{CUSTOMER_NAME}" });
            }

            // check if the login already exists

            bool loginExist = false;

            foreach (UserRecord record in _userManager.Database.User.Where(u => u.Login.Equals(login)).ToList())
            {
                // User deleted ?

                InformationRecord information = _userManager.Database._Information.FirstOrDefault(info => info.Id == record.Id && info.Table.Equals("User"));
                if (information == null || information.DeleteTick == null)
                {
                    loginExist = true;
                    break;
                }
            }

            if (loginExist)
            {
                errors.AddField("Name", "ERR_FIELD_UNIQUE", new object[] { "{CUSTOMER_LOGIN}" });
            }

            // load ressources before designing the screen fitted to the user's profile

            LanguageDictionary ressources = new LanguageDictionary(Server.MapPath(LanguageDictionary.DIRECTORY_IMAGE), ConfigurationManager.DefaultLanguage);

            ressources.Load(_userManager.Database, user.CustomerId);

            if (errors.HasError)
            {
                // update ModelState on depends on errors

                SetModelState(ModelState, ressources, errors);
                return(View(new CustomerViewModel(ressources, user)));
            }

            // Create a new customer

            Info($"Creating of a new customer ('{name}', '{login}', '{email}', '{address}', '{comment}') ...");

            CustomerRecord newCustomer = new CustomerRecord()
            {
                Name    = name,
                Login   = login,
                Email   = email,
                Address = address,
                Comment = comment
            };

            _userManager.Database.Customer.Add(newCustomer);
            _userManager.Database.SaveChanges();

            Info($"Customer created {newCustomer}");

            // Add the parameter "Language.Tick.<customerId>" into the parameter table

            _userManager.Database._Parameter.Add(new ParameterRecord()
            {
                Key = $"Language.Tick.{newCustomer.Id}", Value = "0"
            });

            // Duplicate multilanguage dictionary (from the customer 1 to the new one)

            Info($"Duplicating multilanguage labels ...");

            int nbLabels = 0;

            foreach (LanguageRecord languageRecord in _userManager.Database.Language.Where(l => l.CustomerId == 1).ToList())
            {
                LanguageRecord newLanguageRecord = LanguageRecord.Copy(languageRecord) as LanguageRecord;
                newLanguageRecord.CustomerId = newCustomer.Id;
                _userManager.Database.Language.Add(newLanguageRecord);
                nbLabels++;
            }

            Info($"{nbLabels} labels duplicated");

            // Create the administrator for this new customer

            UserRecord newUser = new UserRecord()
            {
                Login        = login,
                Registration = name,
                Name         = name,
                Email        = email,
                Language     = user.Language,
                CustomerId   = newCustomer.Id
            };

            _userManager.Database.User.Add(newUser);
            _userManager.Database.SaveChanges();
            Info($"Creating a new user {newUser} ...");

            ModuleRecord newModule = new ModuleRecord()
            {
                Name       = "Administration",
                Module     = ModuleRecord.EModule.Administration,
                Profile    = UserProfile.EUserProfile.Administrator,
                Enable     = true,
                CustomerId = newCustomer.Id
            };

            _userManager.Database.Module.Add(newModule);
            _userManager.Database.SaveChanges();
            Info($"Module({newModule.Id}) created");

            UserModuleRecord newUserModule = new UserModuleRecord()
            {
                UserId     = newUser.Id,
                ModuleId   = newModule.Id,
                Default    = true,
                CustomerId = newCustomer.Id
            };

            _userManager.Database.UserModule.Add(newUserModule);
            _userManager.Database.SaveChanges();
            Info($"UserModule({newUserModule.Id}) created");

            // send a mail for the new user

            Info($"Sending an email to create the password ...");

            using (UserController controller = new UserController(_userManager))
                controller.SendNewPassword(newUser.Login);

            Info($"Customer created ...");

            return(RedirectToAction("Index"));
        }
Пример #29
0
        public void readRecords()
        {
            int readOffset = (int)this.offset;

            // NOTE: loop unrolled purposely
            switch (this.id)
            {
            case Database.TABLE_STATE_DATA_SPECIFIER:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new SDSRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_BINARY_DATA_SPECIFIER:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new BDSRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_NUMERIC_DATA_SPECIFIER:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new NDSRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_CONVERTERS_STATE:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new SCRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_CONVERTERS_NUMERIC:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new NCRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_STATE_ENTRY:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new StateEntryRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_STRINGS:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new StringRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_DATA_ACQUISITION_DESCRIPTION:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new DADRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_DES_INFO:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new DESRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_SERIVCE_CAT_STUFFS:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new ServiceCatRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_TRANSMIT:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new TXRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_MODULE_DATAELEMENT:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new ModuleDataElemRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_MODULE:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new ModuleRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_DRB_MENU:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new MenuRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;

            case Database.TABLE_UNKNOWN_3:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new RecordUnknownWithString(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize), 2);
                }
                break;

            case Database.TABLE_UNKNOWN_21:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new RecordUnknownWithString(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize), 3);
                }
                break;

            default:
                for (ushort i = 0; i < this.rowCount; ++i)
                {
                    records[i] = new Record(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize));
                }
                break;
            }
        }
Пример #30
0
        public ActionResult Update(int id, string name, string login, string email, string address, string comment)
        {
            Debug($"Get ~/Administration/Customer/Update(id={id}, name={name}, login={login}, email={email}, address={address}, comment={comment})");

            // Only for administrator from the first customer (Syncytium)

            if (!(_userManager.GetById(int.Parse(HttpContext.User.Identity.Name)) is UserRecord user) || user.CustomerId != 1)
            {
                return(HttpNotFound());
            }

            // The customer has to exist

            CustomerRecord customer = _userManager.Database.Customer.Find(id);

            if (customer == null)
            {
                return(HttpNotFound());
            }

            // check the value by itself

            Errors errors = new Errors();

            // no name set

            if (string.IsNullOrWhiteSpace(name))
            {
                errors.AddField("Name", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_NAME}" });
            }
            name = name.Trim();

            // no login set

            if (string.IsNullOrWhiteSpace(login))
            {
                errors.AddField("Login", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_LOGIN}" });
            }
            login = login.Trim();

            // no email set

            if (string.IsNullOrWhiteSpace(email))
            {
                errors.AddField("Email", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_EMAIL}" });
            }
            email = email.Trim();

            // check if the name already exists

            if (_userManager.Database.Customer.Where(c => c.Name.Equals(name) && c.Id != customer.Id).Any())
            {
                errors.AddField("Name", "ERR_FIELD_UNIQUE", new object[] { "{CUSTOMER_NAME}" });
            }

            if (!customer.Login.Equals(login))
            {
                // check if the new login already exists

                bool loginExist = false;
                foreach (UserRecord record in _userManager.Database.User.Where(u => u.Login.Equals(login) && u.CustomerId != customer.Id).ToList())
                {
                    // User deleted ?

                    InformationRecord information = _userManager.Database._Information.FirstOrDefault(info => info.Id == record.Id && info.Table.Equals("User"));
                    if (information == null || information.DeleteTick == null)
                    {
                        loginExist = true;
                        break;
                    }
                }

                if (loginExist)
                {
                    errors.AddField("Name", "ERR_FIELD_UNIQUE", new object[] { "{CUSTOMER_LOGIN}" });
                }
            }

            // load ressources before designing the screen fitted to the user's profile

            LanguageDictionary ressources = new LanguageDictionary(Server.MapPath(LanguageDictionary.DIRECTORY_IMAGE), ConfigurationManager.DefaultLanguage);

            ressources.Load(_userManager.Database, user.CustomerId);

            if (errors.HasError)
            {
                // update ModelState on depends on errors

                SetModelState(ModelState, ressources, errors);
                return(View(new CustomerViewModel(ressources, user, new CustomerRecord {
                    Name = name, Login = login, Email = email, Address = address, Comment = comment
                })));
            }

            // Update the customer

            Info($"Updating the customer ({customer}) within ('{name}', '{login}', '{email}', '{address}', '{comment}') ...");

            // look for the administrator exists

            UserRecord administrator = null;

            foreach (UserRecord record in _userManager.Database.User.Where(u => u.Login.Equals(customer.Login) && u.CustomerId == customer.Id).ToList())
            {
                // User deleted ?

                InformationRecord information = _userManager.Database._Information.FirstOrDefault(info => info.Id == record.Id && info.Table.Equals("User"));
                if (information == null || information.DeleteTick == null)
                {
                    administrator = record;
                    break;
                }
            }

            bool sendEmail = false;

            if (administrator == null)
            {
                Info($"The administrator '{customer.Login}' was removed!");

                administrator = new UserRecord()
                {
                    Login        = login,
                    Registration = name,
                    Name         = name,
                    Email        = email,
                    Language     = user.Language,
                    CustomerId   = customer.Id
                };
                Info($"Creating a new administrator {administrator} ...");

                _userManager.Database.User.Add(administrator);
                _userManager.Database.SaveChanges();

                sendEmail = true;
            }
            else if (!administrator.Login.Equals(login) || !administrator.Email.Equals(email))
            {
                Info($"The administrator '{administrator}' has to be updated!");

                if (!administrator.Login.Equals(login))
                {
                    administrator.Login = login;
                }

                if (administrator.Registration.Equals(customer.Name))
                {
                    administrator.Registration = name;
                }

                if (administrator.Name.Equals(customer.Name))
                {
                    administrator.Name = name;
                }

                if (!administrator.Email.Equals(email))
                {
                    administrator.Email = email;
                    sendEmail           = administrator.Password == null;
                }

                _userManager.Database.SaveChanges();

                Info($"The administrator '{administrator}' is updated!");
            }
            else
            {
                Debug($"The administrator {administrator} doesn't change");
            }

            // check if the administration module is defined and assigned to the user

            ModuleRecord moduleAdministration = null;

            foreach (ModuleRecord record in _userManager.Database.Module.Where(m => m.Module == ModuleRecord.EModule.Administration &&
                                                                               m.Profile == UserProfile.EUserProfile.Administrator &&
                                                                               m.CustomerId == customer.Id).ToList())
            {
                // Module deleted ?

                InformationRecord information = _userManager.Database._Information.Find("Module", record.Id);

                if (information != null && information.IsDeleted)
                {
                    continue;
                }

                moduleAdministration = record;
                if (!moduleAdministration.Enable)
                {
                    Info($"The module administrator '{moduleAdministration}' is enabled!");
                    moduleAdministration.Enable = true;
                    _userManager.Database.SaveChanges();
                }
            }

            if (moduleAdministration == null)
            {
                Debug($"Creation of the module administrator");
                moduleAdministration = new ModuleRecord()
                {
                    Name       = "Administration",
                    Module     = ModuleRecord.EModule.Administration,
                    Profile    = UserProfile.EUserProfile.Administrator,
                    Enable     = true,
                    CustomerId = customer.Id
                };
                _userManager.Database.Module.Add(moduleAdministration);
                _userManager.Database.SaveChanges();
                Info($"Module({moduleAdministration.Id}) created");
            }

            // check if the module administration is assigned to the administrator

            UserModuleRecord userModuleAdministration = null;

            foreach (UserModuleRecord record in _userManager.Database.UserModule.Where(a => a.ModuleId == moduleAdministration.Id &&
                                                                                       a.UserId == administrator.Id &&
                                                                                       a.CustomerId == customer.Id).ToList())
            {
                // Module deleted ?

                InformationRecord information = _userManager.Database._Information.Find("UserModule", record.Id);

                if (information != null && information.IsDeleted)
                {
                    continue;
                }

                userModuleAdministration = record;
            }

            if (userModuleAdministration == null)
            {
                Debug($"Creation of the association between the user and the module administration");
                userModuleAdministration = new UserModuleRecord()
                {
                    ModuleId   = moduleAdministration.Id,
                    UserId     = administrator.Id,
                    CustomerId = customer.Id
                };
                _userManager.Database.UserModule.Add(userModuleAdministration);
                _userManager.Database.SaveChanges();
                Info($"UserModule({userModuleAdministration.Id}) created");
            }

            // update the customer

            customer.Name    = name;
            customer.Login   = login;
            customer.Email   = email;
            customer.Address = address;
            customer.Comment = comment;

            _userManager.Database.SaveChanges();

            if (sendEmail)
            {
                // send a mail for the new user

                Info($"Sending an email to create the password ...");

                using (UserController controller = new UserController(_userManager))
                    controller.SendNewPassword(administrator.Login);
            }

            Info($"Customer updated ...");

            return(RedirectToAction("Index"));
        }