Esempio n. 1
0
    public NewModule GetModuleData(string code, string lang, string age)
    {
        NewModule x = new NewModule();

        try {
            string[] translations = T.Translations(lang);
            string   sql          = null;
            lang = string.IsNullOrEmpty(lang) ? "hr" : lang;
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + Server.MapPath("~/App_Data/" + appDataBase))) {
                connection.Open();
                /***** Modules *****/
                sql = string.Format(@"SELECT code, title, description, meals, perc FROM modules WHERE code = '{0}'", code);
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            x.code             = reader.GetValue(0) == DBNull.Value ? null : reader.GetString(0);
                            x.title            = reader.GetValue(1) == DBNull.Value ? null : T.Tran(reader.GetString(1), translations, lang);
                            x.desc             = reader.GetValue(2) == DBNull.Value ? null : T.Tran(reader.GetString(2), translations, lang);
                            x.meals            = JsonConvert.DeserializeObject <List <Meals.NewMeal> >(reader.GetValue(3) == DBNull.Value ? null : reader.GetString(3));
                            x.meals            = TranslateMeals(x.meals, lang);
                            x.perc             = reader.GetValue(4) == DBNull.Value ? 0 : Convert.ToDouble(reader.GetString(4));
                            x.saturatedFatsMax = GetSaturatedFatsMaxPerModuleData(x.code, age, lang);
                        }
                    }
                }
                /***** Modules *****/
            }
            return(x);
        } catch (Exception e) {
            L.SendErrorLog(e, null, null, "NutritionStandards", "GetModuleData");
            return(x);
        }
    }
Esempio n. 2
0
    public string Init(string lang)
    {
        try {
            Data resp = new Data();
            resp.nutritionStandards = new List <CodeTitle>();
            resp.modules            = new List <NewModule>();
            string[] translations = T.Translations(lang);
            string   sql          = null;
            lang = string.IsNullOrEmpty(lang) ? "hr" : lang;
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + Server.MapPath("~/App_Data/" + appDataBase))) {
                connection.Open();

                /***** Nutrition Standards *****/
                sql = string.Format(@"SELECT code, title FROM nutritionStandards WHERE country = '{0}' ORDER BY listOrder", lang);
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            CodeTitle x = new CodeTitle();
                            x.code  = reader.GetValue(0) == DBNull.Value ? null : reader.GetString(0);
                            x.title = reader.GetValue(1) == DBNull.Value ? null : T.Tran(reader.GetString(1), translations, lang);
                            resp.nutritionStandards.Add(x);
                        }
                    }
                }
                /***** Nutrition Standards *****/

                /***** Modules *****/
                sql = @"SELECT code, title, description, meals, perc, country FROM modules";
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            NewModule x = new NewModule();
                            x.code    = reader.GetValue(0) == DBNull.Value ? null : reader.GetString(0);
                            x.title   = reader.GetValue(1) == DBNull.Value ? null : T.Tran(reader.GetString(1), translations, lang);
                            x.desc    = reader.GetValue(2) == DBNull.Value ? null : T.Tran(reader.GetString(2), translations, lang);
                            x.meals   = JsonConvert.DeserializeObject <List <Meals.NewMeal> >(reader.GetValue(3) == DBNull.Value ? null : reader.GetString(3));
                            x.meals   = TranslateMeals(x.meals, lang);
                            x.perc    = reader.GetValue(4) == DBNull.Value ? 0 : Convert.ToDouble(reader.GetString(4));
                            x.country = reader.GetValue(5) == DBNull.Value ? null : reader.GetString(5);
                            resp.modules.Add(x);
                        }
                    }
                }
                /***** Modules *****/
            }
            return(JsonConvert.SerializeObject(resp, Formatting.None));
        } catch (Exception e) {
            L.SendErrorLog(e, null, null, "NutritionStandards", "Init");
            return(JsonConvert.SerializeObject(e.Message, Formatting.None));
        }
    }
Esempio n. 3
0
        protected static int ProcessArguments(string[] args)
        {
            int iReturn = -1; // -1=Nothing done; 0=Failed; 1=Success

            bool   bVersion    = false;
            bool   bHelp       = false;
            bool   bScan       = false;
            bool   bDumpConfig = false;
            bool   bDaemon     = false;
            byte   iSoftReset  = 0;
            byte   iHardReset  = 0;
            byte   iGetIdent   = 0;
            byte   iSetAddr    = 0;
            byte   iSetType    = 0;
            byte   iSetDesc    = 0;
            string sSetDesc    = null;

            if (args.Length > 0)
            {
                int i = 0;
                int l = 0;
                while (i < args.Length)
                {
                    if (args[i] == "--version")
                    {
                        bVersion = true;
                    }
                    else if (args[i] == "--help")
                    {
                        bVersion = true;
                        bHelp    = true;
                    }
                    else if (args[i] == "--scan")
                    {
                        bScan = true;
                    }
                    else if (args[i] == "--dumpconfig")
                    {
                        bDumpConfig = true;
                    }
                    else if (args[i] == "--daemon")
                    {
                        bDaemon = true;
                    }
                    else if ((l = CheckArgumentGetByte(args, i, "--ident", 1, ref iGetIdent)) != 0)
                    {
                        if (l > 0)
                        {
                            i++;
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else if ((l = CheckArgumentGetByte(args, i, "--setaddr", 1, ref iSetAddr)) != 0)
                    {
                        if (l > 0)
                        {
                            i++;
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else if ((l = CheckArgumentGetByte(args, i, "--settype", 1, ref iSetType)) != 0)
                    {
                        if (l > 0)
                        {
                            i++;
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else if ((l = CheckArgumentGetByte(args, i, "--setdesc", 2, ref iSetDesc)) != 0)
                    {
                        if (l > 0)
                        {
                            sSetDesc = args[i + 2];
                            if (sSetDesc.Length > ICCConstants.DESCSIZE)
                            {
                                Console.WriteLine(string.Format("Description too long in argument passed to {0} {1} {2}\n", args[i], args[i + 1], args[i + 2]));
                                return(0);
                            }
                            i += 2;
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else if ((l = CheckArgumentGetByte(args, i, "--softreset", 1, ref iSoftReset)) != 0)
                    {
                        if (l > 0)
                        {
                            i++;
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else if ((l = CheckArgumentGetByte(args, i, "--hardreset", 1, ref iHardReset)) != 0)
                    {
                        if (l > 0)
                        {
                            i++;
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Unknown argument %s\n", args[i]);
                        return(0);
                    }
                    i++;
                }
            }

            if (bVersion && args.Length > 2)
            {
                Console.WriteLine("Argument --version should be used alone.\n");
                return(0);
            }
            if (bHelp && args.Length > 2)
            {
                Console.WriteLine("Argument --help should be used alone.\n");
                return(0);
            }
            if (bScan && args.Length > 2)
            {
                Console.WriteLine("Argument --scan should be used alone.\n");
                return(0);
            }
            if (bDumpConfig && args.Length > 2)
            {
                Console.WriteLine("Argument --dumpconfig should be used alone.\n");
                return(0);
            }
            if (bDaemon && args.Length > 2)
            {
                Console.WriteLine("Argument --daemon should be used alone.\n");
                return(0);
            }

            if (bVersion)
            {
                PrintVersion();
                iReturn = 1;
            }

            if (bHelp)
            {
                PrintHelp(args[0]);
                iReturn = 1;
            }

            if (bScan)
            {
                PrintModuleList();
                iReturn = 1;
            }

            if (bDumpConfig)
            {
                var sw = new StreamWriter(Console.OpenStandardOutput());
                sw.AutoFlush = true;
                Console.SetOut(sw);
                Conf.Display(sw);
                iReturn = 1;
            }

            if (bDaemon)
            {
                var d = new DaemonManager(Biccp, Conf, Log);
                return(d.Start() ? 1 : 0);
            }

            if (iGetIdent != 0)
            {
                if (Conf.Modules.ContainsKey(iGetIdent))
                {
                    var ccMod = Conf.Modules[iGetIdent];
                    Console.WriteLine("\n");
                    Console.WriteLine(string.Format("    Version     : {0}.{1}.{2}", ccMod.Major, ccMod.Minor, ccMod.Build));
                    Console.WriteLine(string.Format("    Address     : 0x{0:x2}", iGetIdent));
                    Console.WriteLine(string.Format("    Type        : 0x{0:x2} - {1}", ccMod.Type, ccMod.TypeDescription));
                    Console.WriteLine(string.Format("    Description : {0}", ccMod.Description));
                    Console.WriteLine("\n");
                }
                iReturn = 1;
            }
            if (iSetAddr != 0)
            {
                var mod = new NewModule()
                {
                    ID = 0x77, Log = Log
                };
                mod.ActionRaised += Mod_ActionRaised;
                mod.SetAddress(iSetAddr);
                iReturn = 1;
            }
            if (iSetType != 0)
            {
                var mod = new NewModule()
                {
                    ID = 0x77, Log = Log
                };
                mod.ActionRaised += Mod_ActionRaised;
                mod.SetType(iSetType);
                iReturn = 1;
            }
            if (iSetDesc != 0)
            {
                var mod = new NewModule()
                {
                    ID = iSetDesc, Log = Log
                };
                mod.ActionRaised += Mod_ActionRaised;
                mod.SetDescription(sSetDesc);
                iReturn = 1;
            }
            if (iSoftReset != 0)
            {
                var mod = new NewModule()
                {
                    ID = iSoftReset, Log = Log
                };
                mod.ActionRaised += Mod_ActionRaised;
                mod.SoftReset();
                iReturn = 1;
            }
            if (iHardReset != 0)
            {
                var mod = new NewModule()
                {
                    ID = iHardReset, Log = Log
                };
                mod.ActionRaised += Mod_ActionRaised;
                mod.HardReset();
                iReturn = 1;
            }

            return(iReturn);
        }
Esempio n. 4
0
 public CreateNewModule(string moduleName, NewModule module)
 {
     this.moduleName = moduleName;
     this.module     = module;
 }