Exemplo n.º 1
0
 private void ModifyBlindsStart()
 {
     if (reference.Count == 0)
     {
         return;
     }
     for (int i = 0; i < reference.Count; i++)
     {
         Context con = Server.getContext(reference[i]);
         if (con == null)
         {
             continue;
         }
         if (con.Type != Util.TypeContext.Blinds)
         {
             continue;
         }
         Blind bl = (Blind)con.defContext;
         if (bl == null)
         {
             continue;
         }
         bl.Flag = true;
     }
 }
Exemplo n.º 2
0
        }                                                               // переменная сущность как флаг состояния
        static public void  appendBlind(string name, string description, Blind blind)
        {
            Context con = new Context(name, description, Util.TypeContext.Blinds, blind);

            Server.appendContext(con);
            Server.appendChaild(Server.PointBlinds);
        }
Exemplo n.º 3
0
        public void Run()
        {
            Util.message("Запустили поток по формулам");
            Context blcon = Server.getContext(Server.PointBlinds);

            do
            {
                tm          = DateTime.Now;
                Util.time   = tm;
                this.intime = tm.Ticks;
                int count = 0;
                for (int i = 0; i < blcon.Count; i++)
                {
                    //Util.message("i=" + i.ToString());
                    Context bc = Server.getContext(blcon.getChaild(i));
                    if (bc == null)
                    {
                        Util.errorMessage("Нет контеста формулы ", i.ToString()); return;
                    }
                    if (bc.Type != Util.TypeContext.Blinds)
                    {
                        Util.errorMessage("В контексте не формула ", i.ToString()); return;
                    }
                    Blind bb = (Blind)bc.defContext;
                    count += (bb.goBlind(intime))?1:0;
                }
                DateTime tmnow = DateTime.Now;
                int      st    = (int)((tmnow.Ticks - tm.Ticks) / 10000); // если превышено время обхода в 100 миллисекунд генерируется предупреждение с указанием колличества циклов
                if (st > steptime)
                {
                    Util.errorMessage(
                        "Предупреждение!!! Время цикла обработки [" +
                        st.ToString() +
                        "] превысило нормальное значение работы цикла [" +
                        steptime + "]; колличество циклов " + count + "\r\n", "MainLoop"); st = 0;
                }
                else
                {
                    st = steptime - st;
                }
                //Util.message("Ждем "+st.ToString());
                if (st > 0)
                {
                    Thread.Sleep(st);
                }
                Util.blink = !Util.blink;
            } while (true);
        }
Exemplo n.º 4
0
        public static void BuildBlind() // Построение состояний лампочек
        {
            // вычислим примерные размеры массива
            SortedList <string, int> sl = null;

            sl = new SortedList <string, int>(Server.Count);
            Context con = null;

            con = Server.getContext(Server.PointVariables);

            for (int i = 0; i < con.Count; i++)
            {
                int     index = con.getChaild(i);
                Context var   = Server.getContext(index);
                sl.Add(var.Name, index);
            }
            con = Server.getContext(Server.PointModels);

            for (int i = 0; i < con.Count; i++)
            {
                int     index = con.getChaild(i);
                Context var   = Server.getContext(index);
                sl.Add(var.Name, index);
            }
            con = Server.getContext(Server.PointConstants);

            for (int i = 0; i < con.Count; i++)
            {
                int     index = con.getChaild(i);
                Context var   = Server.getContext(index);
                sl.Add(var.Name, index);
            }

            DateTime tm = DateTime.Now;

            long bazatime = tm.Ticks;

            for (int i = 0; i < defBlind.Count; i++)
            {
                int        numFunction;
                SmallBlind sBl  = defBlind[i];
                string     name = "Blind" + string.Format("{0:0000}", i);

                string description = sBl.nameFunction + "( ";
                for (int j = 0; j < sBl.nameParamIn.Count; j++)
                {
                    description += j == 0 ? "" : ",";
                    description += sBl.nameParamIn[j] + " in";
                    if (sBl.ups[j])
                    {
                        description += " up";
                    }
                }
                for (int j = 0; j < sBl.nameParamOut.Count; j++)
                {
                    description += "," + sBl.nameParamOut[j] + " out";
                }
                description += " )";
                numFunction  = Function.NameToInt(sBl.nameFunction);

                if (numFunction < 0)
                {
                    Util.errorMessage("Отсутствует функция ", description); Util.work = false;
                }
                Blind BL = new Blind(numFunction, sBl.onstart);
                if (sBl.steptimer > 0)
                {
                    BL.setOnTimer(bazatime, sBl.steptimer);
                }
                for (int j = 0; j < sBl.nameParamIn.Count; j++)
                {
                    int ip = sl.IndexOfKey(sBl.nameParamIn[j]);
                    if (ip < 0)
                    {
                        Util.errorMessage("Нет " + sBl.nameParamIn[j], description); Util.work = false; ip = 1;
                    }
                    else
                    {
                        ip = sl[sBl.nameParamIn[j]];
                        if (sBl.ups[j])
                        {
                            Context  cont = Server.getContext(ip);
                            Variable var  = (Variable)cont.defContext;
                            if (var != null)
                            {
                                var.appendReference(Server.Count);
                                var.blinds.Add(Server.Count);
                                Server.setContext(ip, cont);
                            }
                        }
                        else
                        {
                            Context  cont = Server.getContext(ip);
                            Variable var  = (Variable)cont.defContext;
                            var.blinds.Add(Server.Count);
                            Server.setContext(ip, cont);
                        }
                        BL.listParamIn.Add(ip);
                    }
                }
                for (int j = 0; j < sBl.nameParamOut.Count; j++)
                {
                    int ip = sl.IndexOfKey(sBl.nameParamOut[j]);
                    if (ip < 0)
                    {
                        Util.errorMessage("Нет " + sBl.nameParamIn[j], description); Util.work = false; ip = 1;
                    }
                    else
                    {
                        ip = sl[sBl.nameParamOut[j]];
                        Context  cont = Server.getContext(ip);
                        Variable var  = (Variable)cont.defContext;
                        var.blinds.Add(Server.Count);
                        Server.setContext(ip, cont);
                        BL.listParamOut.Add(ip);
                    }
                }
                if (!Function.isCorrect(numFunction, BL.listParamIn, BL.listParamOut))
                {
                    Util.errorMessage("Ошибки в параметрах вызова ", description); Util.work = false;
                }
                ;
                Blind.appendBlind(name, description, BL);
                Util.message(name + " " + description + " добавлено ");
            }
            sl = null;
        }