示例#1
0
        // GET: Units
        public ActionResult Index()
        {
            var unitDbInterface = new UnitDAO();
            var allUnits        = unitDbInterface.FetchAllUnits();

            return(View("UnitIndex", allUnits));
        }
示例#2
0
        public static ResoucesDAO CreateResouces(string resType)
        {
            ResoucesDAO resDao = null;

            switch (resType)
            {
            case "eqName":
                resDao = new EqNameDAO();
                break;

            case "eqType":
                resDao = new EqTypeDAO();
                break;

            case "addType":
                resDao = new AddTypeDAO();
                break;

            case "clearType":
                resDao = new ClearTypeDAO();
                break;

            case "keepPlace":
                resDao = new KeepPlaceDAO();
                break;

            case "unit":
                resDao = new UnitDAO();
                break;
            }
            return(resDao);
        }
示例#3
0
        public ActionResult ProcessUnitToCreate(Unit unitToAddToDb)
        {
            var unitDbInterface = new UnitDAO();

            unitDbInterface.AddUnitToDb(unitToAddToDb);
            var allUnits = unitDbInterface.FetchAllUnits();

            return(View("UnitIndex", allUnits));
        }
示例#4
0
        //unitsToUpdate[unitType] = modifier
        public void UnitUpdate(int kingdom, Field field, Dictionary <int, int> unitsToUpdate)
        {
            IList <Unit> units = new UnitDAO().GetFromArea(field.MapId, field.FieldX, field.FieldY, 1, 1);

            HashSet <int> done = new HashSet <int>();

            foreach (Unit u in units)
            {
                bool mod = false;

                if (u.KingdomId != kingdom)
                {
                    mod     = true;
                    u.Count = 0;
                }
                if (unitsToUpdate.ContainsKey(u.UnitTypeId))
                {
                    u.Count += unitsToUpdate[u.UnitTypeId];
                    done.Add(u.UnitTypeId);
                    mod = true;
                }

                //jesli zmodyfikowany to update
                if (mod)
                {
                    if (u.Count < 1)
                    {
                        new UnitDAO().Remove(u.UnitId);
                    }
                    else
                    {
                        new UnitDAO().Update(u);
                    }
                }
            }

            foreach (int ut in unitsToUpdate.Keys)
            {
                if (!done.Contains(ut))
                {
                    Unit newUnit = new Unit();
                    newUnit.Count      = unitsToUpdate[ut];
                    newUnit.FieldId    = field.FieldId;
                    newUnit.KingdomId  = kingdom;
                    newUnit.UnitName   = "Nie wiem po co jest to pole";
                    newUnit.UnitTypeId = ut;

                    new UnitDAO().Add(newUnit);
                }
            }
        }
示例#5
0
 public LessonService()
 {
     unitDao = new UnitDAO();
     service = new QuestionService();
 }
示例#6
0
    public MapModel GetMapModel()
    {
        User    user        = CurrentUser.Current;
        Kingdom userKingdom = new KingdomDAO().GetByUserId(user.UserId);

        IList <Kingdom> kingdoms = new KingdomDAO().GetByMapId(userKingdom.MapId);

        List <Owner> players = new List <Owner>();

        Random random = new Random();



        foreach (Kingdom k in kingdoms)
        {
            if (k.KingdomId == userKingdom.KingdomId)
            {
                players.Add(new Owner(userKingdom.KingdomId, userKingdom.KingdomName, "#FF0000"));
            }
            else
            {
                players.Add(new Owner(k.KingdomId, k.KingdomName, String.Format("#{0:X6}", random.Next(0x1000000))));
            }
        }



        List <TileInfo> tiles = new List <TileInfo>();

        IList <Field> fields = new FieldDAO().GetByMapId(userKingdom.MapId);


        foreach (Field field in fields)
        {
            IList <Unit> units     = new UnitDAO().GetFromArea(field.MapId, field.FieldX, field.FieldY, 1, 1);
            int          unitCount = 0;
            foreach (Unit u in units)
            {
                unitCount += u.Count;
            }

            tiles.Add(new TileInfo(field.FieldId, field.FieldX, field.FieldY, field.FieldName, field.KingdomId, unitCount));
        }


        //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Orders need to be taken away from the database too !!!!!!!!!!!!!!!!!!1
        List <OrderInfo> orders   = new List <OrderInfo>();
        IList <Order>    ordersDB = new OrderDAO().GetByKingdomEpoch(userKingdom.KingdomId, new EpochDAO().GetCurrentByMapId(userKingdom.MapId).EpochId);

        Dictionary <int, UnitType> unitTypes = new Dictionary <int, UnitType>();

        IList <UnitType> unitTypesAll = new UnitTypeDAO().GetAll();

        foreach (UnitType ut in unitTypesAll)
        {
            unitTypes.Add(ut.UnitTypeId, ut);
        }

        foreach (Order o in ordersDB)
        {
            if (o.OrderTypeName.Equals("Buy"))
            {
                orders.Add(new OrderInfo(o.OrderTypeName, o.FieldId, o.FieldIdDestination, o.Count, unitTypes[o.UnitTypeId].UnitTypeCost * o.Count));
            }
            else
            {
                orders.Add(new OrderInfo(o.OrderTypeName, o.FieldId, o.FieldIdDestination, o.Count, 0));
            }
        }

        //orders.Add(new OrderInfo("Defend",1,1,5,0));
        //int rice = 1000;

        //List<Owner> players = new List<Owner>();

        //Owner owner1 = new Owner(1, "Moose", "#ff0000");
        //Owner owner2 = new Owner(2, "Lucas", "#00ff00");

        //players.Add(owner1);
        //players.Add(owner2);

        //List<TileInfo> tiles = new List<TileInfo>();

        //tiles.Add(new TileInfo(1,1,1,"Krwawe wzgórza", owner1.playerId, 5));
        //tiles.Add(new TileInfo(2,2,1,"MooseVille", owner1.playerId, 5));
        //tiles.Add(new TileInfo(3,2,2,"Grunwald", owner1.playerId, 5));
        //tiles.Add(new TileInfo(4,1,2,"Bździochy dolne", null, 5));
        //tiles.Add(new TileInfo(5,3,4,"Cukierkowa Dolina", owner2.playerId, 10));
        //tiles.Add(new TileInfo(6,5,5,"Wilczy Szaniec", owner2.playerId, 10));
        //List<OrderInfo> orders = new List<OrderInfo>();


        //orders.Add(new OrderInfo("Defend",1,1,5,0));
        return(new MapModel(userKingdom.KingdomResources, tiles, players, orders));
    }
 public Unit()
 {
     lUnitDAO = new UnitDAO();
 }
示例#8
0
	public MapModel GetMapModel() 
	{
        User user = CurrentUser.Current;
        Kingdom userKingdom = new KingdomDAO().GetByUserId(user.UserId);

        IList<Kingdom> kingdoms = new KingdomDAO().GetByMapId(userKingdom.MapId);

        List<Owner> players = new List<Owner>();

        Random random = new Random();

        

        foreach (Kingdom k in kingdoms)
        {
            if (k.KingdomId == userKingdom.KingdomId)
            {
                players.Add(new Owner(userKingdom.KingdomId, userKingdom.KingdomName, "#FF0000"));
            }
            else
            {
                players.Add(new Owner(k.KingdomId, k.KingdomName, String.Format("#{0:X6}", random.Next(0x1000000))));
            }
        }

        

        List<TileInfo> tiles = new List<TileInfo>();

        IList<Field> fields = new FieldDAO().GetByMapId(userKingdom.MapId);


        foreach (Field field in fields)
        {
            IList<Unit> units = new UnitDAO().GetFromArea(field.MapId, field.FieldX, field.FieldY, 1, 1);
            int unitCount = 0;
            foreach (Unit u in units)
            {
                unitCount += u.Count;
            }

            tiles.Add(new TileInfo(field.FieldId, field.FieldX, field.FieldY, field.FieldName, field.KingdomId, unitCount));
        }
	
	
		//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Orders need to be taken away from the database too !!!!!!!!!!!!!!!!!!1
		List<OrderInfo> orders = new List<OrderInfo>();
        IList<Order> ordersDB = new OrderDAO().GetByKingdomEpoch(userKingdom.KingdomId, new EpochDAO().GetCurrentByMapId(userKingdom.MapId).EpochId);

        Dictionary<int,UnitType> unitTypes = new Dictionary<int,UnitType>();
         
        IList<UnitType> unitTypesAll = new UnitTypeDAO().GetAll();

        foreach (UnitType ut in unitTypesAll)
        {
           unitTypes.Add(ut.UnitTypeId,ut);
        }

        foreach (Order o in ordersDB)
        {     
            if (o.OrderTypeName.Equals("Buy"))
            {
                orders.Add(new OrderInfo(o.OrderTypeName, o.FieldId, o.FieldIdDestination, o.Count, unitTypes[o.UnitTypeId].UnitTypeCost * o.Count));
            }
            else
            {
                orders.Add(new OrderInfo(o.OrderTypeName, o.FieldId, o.FieldIdDestination, o.Count, 0));
            }
        }

        //orders.Add(new OrderInfo("Defend",1,1,5,0));
        //int rice = 1000;

        //List<Owner> players = new List<Owner>();
		
        //Owner owner1 = new Owner(1, "Moose", "#ff0000");
        //Owner owner2 = new Owner(2, "Lucas", "#00ff00");

        //players.Add(owner1);
        //players.Add(owner2);

        //List<TileInfo> tiles = new List<TileInfo>();

        //tiles.Add(new TileInfo(1,1,1,"Krwawe wzgórza", owner1.playerId, 5));
        //tiles.Add(new TileInfo(2,2,1,"MooseVille", owner1.playerId, 5));
        //tiles.Add(new TileInfo(3,2,2,"Grunwald", owner1.playerId, 5));
        //tiles.Add(new TileInfo(4,1,2,"Bździochy dolne", null, 5));
        //tiles.Add(new TileInfo(5,3,4,"Cukierkowa Dolina", owner2.playerId, 10));
        //tiles.Add(new TileInfo(6,5,5,"Wilczy Szaniec", owner2.playerId, 10));
        //List<OrderInfo> orders = new List<OrderInfo>();


        //orders.Add(new OrderInfo("Defend",1,1,5,0));
		return new MapModel(userKingdom.KingdomResources, tiles, players, orders);
	}
示例#9
0
        //unitsToUpdate[unitType] = modifier
        public void UnitUpdate(int kingdom, Field field, Dictionary<int, int> unitsToUpdate)
        {
            IList<Unit> units = new UnitDAO().GetFromArea(field.MapId, field.FieldX, field.FieldY, 1, 1);

            HashSet<int> done = new HashSet<int>();

            foreach (Unit u in units)
            {
                bool mod = false;

                if (u.KingdomId != kingdom)
                {
                    mod = true;
                    u.Count = 0;
                }
                if (unitsToUpdate.ContainsKey(u.UnitTypeId))
                {
                    u.Count += unitsToUpdate[u.UnitTypeId];
                    done.Add(u.UnitTypeId);
                    mod = true;
                }

                //jesli zmodyfikowany to update
                if (mod)
                {
                    if (u.Count < 1)
                    {
                        new UnitDAO().Remove(u.UnitId);
                    }
                    else
                    {
                        new UnitDAO().Update(u);
                    }
                }
            }

            foreach (int ut in unitsToUpdate.Keys)
            {
                if (!done.Contains(ut))
                {
                    Unit newUnit = new Unit();
                    newUnit.Count = unitsToUpdate[ut];
                    newUnit.FieldId = field.FieldId;
                    newUnit.KingdomId = kingdom;
                    newUnit.UnitName = "Nie wiem po co jest to pole";
                    newUnit.UnitTypeId = ut;

                    new UnitDAO().Add(newUnit);
                }
            }

        }
示例#10
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public UnitBLL(LoggingSessionInfo pUserInfo)
 {
     this._currentDAO     = new UnitDAO(pUserInfo);
     this.CurrentUserInfo = pUserInfo;
 }
示例#11
0
 public QuestionService()
 {
     unitDao = new UnitDAO();
 }
示例#12
0
        private IDictionary <string, Unit> loadUnits(Component c)
        {
            IDictionary <string, Unit> units = new Dictionary <string, Unit>();

            AbstractComponentFunctorApplication absCapp_ = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve(c.Id_functor_app);
            AbstractComponentFunctorApplication absCapp  = null;

            while (absCapp_ != null)
            {
                absCapp  = absCapp_;
                absCapp_ = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve_next(absCapp_.Id_functor_app);
            }

            int id_abstract = absCapp.Id_abstract;

            // for each unit ...
            foreach (UnitType u in unit)
            {
                string uref            = u.uRef;
                string iRef            = u.iRef;
                int    partition_index = u.replicaSpecified ? u.replica : 0;

                string uRefSuper = u.super.Length == 0 ? "" : u.super[0].uRef;
                for (int j = 1; j < u.super.Length; j++)
                {
                    uRefSuper += "+" + u.super[j].uRef;
                }


                Interface i = br.ufc.pargo.hpe.backend.DGAC.BackEnd.idao.retrieve(id_abstract, uref);

                InterfaceType ui = lookForInterface(iRef);

                Unit uu = new Unit();
                uu.Id_concrete   = c.Id_concrete;
                uu.Id_unit       = uref;
                uu.Id_abstract   = id_abstract;
                uu.Id_interface  = uref;
                uu.Id_unit_super = uRefSuper;
                //  uu.Unit_replica = partition_index;
                uu.Class_name      = xc.header.packagePath + "." + xc.header.name + "." + iRef;
                uu.Class_nargs     = i.Class_nargs;
                uu.Assembly_string = uu.Class_name + ", Culture=neutral, Version=0.0.0.0"; // In the current implementation, the name of the dll is the name of the class of the unit.
                uu.Order           = i.Order;

                units.Add(uu.Id_unit, uu);

                //Console.WriteLine("ui.sources={0}",ui.sources);
                //Console.WriteLine("ui.protocol={0}",ui.protocol);
                //Console.WriteLine("{0}={1}", c.Kind, Constants.KIND_COMPUTATION_NAME);

                if (ui.sources == null && (c.Kind.Equals(Constants.KIND_COMPUTATION_NAME) ||
                                           c.Kind.Equals(Constants.KIND_SYNCHRONIZER_NAME)))
                {
                    Console.WriteLine("ENTER WRAPPER GENERATOR " + c.Library_path);

                    IWrapperGenerator wg           = new WrapperGenerator();
                    string[]          dependencies = null;
                    CodeCompileUnit   compile_unit = wg.create_wrapper(c.Library_path, ui.iRef, uu.Id_abstract, uu.Id_interface, out dependencies);
                    string            source_code  = wg.generate_source_code(ui.iRef, compile_unit);

                    Console.WriteLine(source_code);

                    SourceCode ss = new SourceCode();
                    ss.Type_owner         = 'u';
                    ss.Id_owner_container = uu.Id_concrete;
                    ss.Id_owner           = uu.Id_unit;
                    ss.Contents           = source_code;
                    ss.File_type          = "dll";
                    ss.File_name          = ui.iRef + ".cs";
                    ss.Order = 0;
                    br.ufc.pargo.hpe.backend.DGAC.BackEnd.scdao.insert(ss);
                }
                else if (ui.sources != null)
                {
                    int order = 0;
                    foreach (SourceFileType sft in ui.sources[ui.sources.Length - 1].file)
                    {
                        if (sft.srcType.Equals("user") || sft.srcType.Equals("base"))
                        {
                            Console.WriteLine("loadUnits - 1 " + sft.name);
                            SourceCode ss = new SourceCode();
                            ss.Type_owner         = 'u';
                            ss.Id_owner_container = uu.Id_concrete;
                            ss.Id_owner           = uu.Id_unit;
                            ss.Contents           = sft.contents;
                            ss.File_type          = "dll";
                            ss.File_name          = sft.name;
                            ss.Order = order++;
                            br.ufc.pargo.hpe.backend.DGAC.BackEnd.scdao.insert(ss);
                            Console.WriteLine("loadUnits - 2");

                            int size = (sft.externalDependency == null ? 0 : sft.externalDependency.Length) +
                                       (ui.externalReferences == null ? 0 : ui.externalReferences.Length);

                            Console.WriteLine("loadUnits - 3");

                            if (size > 0)
                            {
                                Console.WriteLine("loadUnits - 4");
                                string[] allRefs = new string[size];
                                if (ui.externalReferences != null)
                                {
                                    ui.externalReferences.CopyTo(allRefs, 0);
                                }

                                if (sft.externalDependency != null)
                                {
                                    sft.externalDependency.CopyTo(allRefs, ui.externalReferences == null ? 0 : ui.externalReferences.Length);
                                }

                                Console.WriteLine("loadUnits - 5");

                                foreach (string extRef in allRefs)
                                {
                                    Console.WriteLine("loadUnits - 6 - " + extRef);
                                    SourceCodeReference ssr = new SourceCodeReference();
                                    ssr.Type_owner         = ss.Type_owner;
                                    ssr.Id_owner_container = ss.Id_owner_container;
                                    ssr.Id_owner           = ss.Id_owner;
                                    ssr.File_name          = ss.File_name;
                                    ssr.Reference          = extRef;
                                    if (br.ufc.pargo.hpe.backend.DGAC.BackEnd.scrdao.retrieve(ssr) == null)
                                    {
                                        br.ufc.pargo.hpe.backend.DGAC.BackEnd.scrdao.insert(ssr);
                                    }
                                    Console.WriteLine("loadUnits - 7 - " + extRef);
                                }
                            }
                        }
                        else if (sft.srcType.Equals("platform.settings"))
                        {
                            SourceCode ss = new SourceCode();
                            ss.Type_owner         = 'u';
                            ss.Id_owner_container = uu.Id_concrete;
                            ss.Id_owner           = uu.Id_unit;
                            ss.Contents           = sft.contents;
                            ss.File_type          = "platform.settings";
                            ss.File_name          = sft.name;
                            ss.Order = order++;
                            br.ufc.pargo.hpe.backend.DGAC.BackEnd.scdao.insert(ss);
                        }
                    }
                }
                else
                {
                    throw new Exception("Unit " + uu.Id_unit + " neither has a source code nor is a connector.");
                }

                UnitDAO udao = new UnitDAO();
                udao.insert(uu);
            }

            return(units);
        }
示例#13
0
 public CourseService()
 {
     unitDao = new UnitDAO();
     service = new LessonService();
 }