Пример #1
0
 public List <ListObject> GetAssignmentsByUser(string userID)
 {
     if (Itens == null)
     {
         return(null);
     }
     else
     {
         List <Item>       newItens   = Itens.FindAll(it => it.UserID == Int32.Parse(userID));
         List <ListObject> ListReturn = new List <ListObject>();
         ListObject        obj;
         if (newItens != null && newItens.Count > 0)
         {
             foreach (Item element in newItens)
             {
                 obj = new ListObject()
                 {
                     ItemDescription = element.Description, ItemID = element.ItemID
                 };
                 if (Assignments != null)
                 {
                     List <Assignment> ListAssignments = Assignments.FindAll(assi => assi.ItemID == element.ItemID);
                     foreach (Assignment assi in ListAssignments)
                     {
                         obj.Add(assi);
                     }
                 }
                 ListReturn.Add(obj);
             }
         }
         return(ListReturn);
     }
 }
Пример #2
0
        public bool AddObject(BaseContainer itemToAdd)
        {
            bool canJoin = CanObjectJoin(itemToAdd);

            if (canJoin)
            {
                ListObject.Add(itemToAdd);
            }
            return(canJoin);
        }
Пример #3
0
        /// <summary>
        /// 根据插件类型获取相同类型的所有插件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="models"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        public static List <T> CreateInstancesByPluginType <T>(this System.Reflection.Assembly[] models, string Type = "") where T : class
        {
            if (ListObject == null)
            {
                ListObject = new Dictionary <string, object>();
            }
            List <T> lstObject = new List <T>();

            foreach (var model in models)
            {
                //System.Threading.Tasks.Parallel.ForEach(models, model =>
                //{
                var types = model.GetTypesByType(Type);
                if (types != null && types.Count > 0)
                {
                    foreach (var type in types)
                    {
                        //System.Threading.Tasks.Parallel.ForEach(types, type =>
                        //{
                        string          assemblyPluginId = model.GetAssemblyPluginAttribute().ID;
                        PluginAttribute pluginAttribute  = type.GetPluginAttribute();
                        string          pluginId         = pluginAttribute.ID;
                        object          obj = null;
                        if (ListObject.ContainsKey(assemblyPluginId.ToLower() + pluginId.ToLower()))
                        {
                            obj = ListObject[assemblyPluginId.ToLower() + pluginId.ToLower()];
                        }
                        if (obj != null)
                        {
                            lstObject.Add(obj as T);
                        }
                        else
                        {
                            obj = type.GetConstructor(new Type[] { }).Invoke(null);
                            //obj = Activator.CreateInstance(type);
                            lstObject.Add(obj as T);
                            if (pluginAttribute.IsSingleInstance)
                            {
                                ListObject.Add(assemblyPluginId.ToLower() + pluginId.ToLower(), obj);
                            }
                        }
                        //});
                    }
                }
                //});
            }
            return(lstObject);
        }
Пример #4
0
        /// <summary>
        /// 根据ID创建对象
        /// </summary>
        /// <param name="models"></param>
        /// <param name="AssemblyId"></param>
        /// <param name="PluginId"></param>
        /// <returns></returns>
        public static object CreateInstanceByAssemblyIdAndPluginId(this System.Reflection.Assembly[] models, string AssemblyId, string PluginId = "")
        {
            object obj = null;

            if (ListObject == null)
            {
                ListObject = new Dictionary <string, object>();
            }
            var existModel = models.GetModelByAssemblyId(AssemblyId);

            if (existModel != null)
            {
                if (String.IsNullOrWhiteSpace(PluginId))
                {
                    PluginId = existModel.GetAssemblyPluginAttribute().DefaultPluginID;
                }
                if (String.IsNullOrWhiteSpace(PluginId))
                {
                    return(null);
                }
                if (ListObject.ContainsKey(AssemblyId.ToLower() + PluginId.ToLower()))
                {
                    obj = ListObject[AssemblyId.ToLower() + PluginId.ToLower()];
                }
                if (obj == null)
                {
                    Type existType = existModel.GetTypeByPluginId(PluginId);
                    if (existType != null)
                    {
                        obj = existType.GetConstructor(new Type[] { }).Invoke(null);
                        //obj = Activator.CreateInstance(existType);
                        if (existType.GetPluginAttribute().IsSingleInstance)
                        {
                            ListObject.Add(AssemblyId.ToLower() + PluginId.ToLower(), obj);
                        }
                    }
                }
            }
            return(obj);
        }
Пример #5
0
        public override void OnNavigatedTo(INavigationParameters parameters)
        {
            MessagingCenter.Unsubscribe <CreateItemViewModel, Item>(this, "ItemCreated");
            MessagingCenter.Subscribe <CreateItemViewModel, Item>(this, "ItemCreated", (sender, args) =>
            {
                ListObject objeto = new ListObject()
                {
                    ItemID = args.ItemID, ItemDescription = args.Description
                };
                AssignmentsAgrupados.Add(objeto);
                if (Itens == null)
                {
                    Itens = new List <Item>();
                }
                Itens.Add(args);
            });

            MessagingCenter.Unsubscribe <CreateAssignmentViewModel, Assignment>(this, "AssignmentCreated");
            MessagingCenter.Subscribe <CreateAssignmentViewModel, Assignment>(this, "AssignmentCreated", (sender, args) =>
            {
                ListObject objectList = AssignmentsAgrupados.Where(obj => obj.ItemID == args.ItemID).FirstOrDefault();
                objectList.Add(args);
            });
        }
Пример #6
0
 public void AddObject(AbstractObject obj)
 {
     ListObject.Add(obj);
     obj.Position = this;
 }
Пример #7
0
        private async void PeriodChanged()
        {
            AssignmentsAgrupados.Clear();
            ListObject listaObj;


            if (Itens != null)
            {
                bool useWCF = Preferences.Get("UseWCF", false);
                if (!useWCF)
                {
                    foreach (Item element in Itens)
                    {
                        listaObj = new ListObject()
                        {
                            ItemDescription = element.Description, ItemID = element.ItemID
                        };

                        List <Assignment> ListAssignments = null;

                        ListAssignments = await App.SQLiteDb.GetAssignmentsByItemAsync(element.ItemID);

                        foreach (Assignment assi in ListAssignments)
                        {
                            assi.AssignmentDate = Convert.ToDateTime(assi.DateString);
                            if (SelectedPeriod.Value == 2 && DatesAreInTheSameWeek(assi.AssignmentDate, DateTime.Now))
                            {
                                listaObj.Add(assi);
                            }
                            else if (SelectedPeriod.Value == 1 && DatesAreInTheSameDay(assi.AssignmentDate, DateTime.Now))
                            {
                                listaObj.Add(assi);
                            }
                            else if (SelectedPeriod.Value == 3 && assi.AssignmentDate.Month == DateTime.Now.Month && assi.AssignmentDate.Year == DateTime.Now.Year)
                            {
                                listaObj.Add(assi);
                            }
                            else if (SelectedPeriod.Value == 4 && assi.AssignmentDate.CompareTo(DateTime.Today) >= 0)
                            {
                                listaObj.Add(assi);
                            }
                        }
                        listaObj.ItemID          = element.ItemID;
                        listaObj.ItemDescription = element.Description;
                        AssignmentsAgrupados.Add(listaObj);
                    }
                }
                else
                {
                    if (Itens != null && Itens.Count > 0)
                    {
                        var client = new HttpClient
                        {
                            Timeout     = TimeSpan.FromMilliseconds(15000),
                            BaseAddress = new Uri(GetUrlBase())
                        };

                        var json    = JsonConvert.SerializeObject(Itens);
                        var content = new StringContent(json, Encoding.UTF8, "application/json");
                        using (var response2 = await client.PostAsync("GetAssignmentsByItem", content))
                        {
                            if (response2 != null)
                            {
                                if (response2.IsSuccessStatusCode)
                                {
                                    var respStr2 = await response2.Content.ReadAsStringAsync();

                                    if (!String.IsNullOrEmpty(respStr2))
                                    {
                                        List <Assignment> ListAssignments = JsonConvert.DeserializeObject <List <Assignment> >(respStr2);
                                        foreach (Item element in Itens)
                                        {
                                            listaObj = new ListObject()
                                            {
                                                ItemDescription = element.Description, ItemID = element.ItemID
                                            };
                                            foreach (Assignment assi in ListAssignments)
                                            {
                                                if (assi.ItemID == element.ItemID)
                                                {
                                                    assi.AssignmentDate = Convert.ToDateTime(assi.DateString);
                                                    if (SelectedPeriod.Value == 2 && DatesAreInTheSameWeek(assi.AssignmentDate, DateTime.Now))
                                                    {
                                                        listaObj.Add(assi);
                                                    }
                                                    else if (SelectedPeriod.Value == 1 && DatesAreInTheSameDay(assi.AssignmentDate, DateTime.Now))
                                                    {
                                                        listaObj.Add(assi);
                                                    }
                                                    else if (SelectedPeriod.Value == 3 && assi.AssignmentDate.Month == DateTime.Now.Month && assi.AssignmentDate.Year == DateTime.Now.Year)
                                                    {
                                                        listaObj.Add(assi);
                                                    }
                                                    else if (SelectedPeriod.Value == 4 && assi.AssignmentDate.CompareTo(DateTime.Today) >= 0)
                                                    {
                                                        listaObj.Add(assi);
                                                    }
                                                }
                                            }
                                            listaObj.ItemID          = element.ItemID;
                                            listaObj.ItemDescription = element.Description;
                                            AssignmentsAgrupados.Add(listaObj);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                await DialogService.DisplayAlertAsync("Warning", "Connection Failed", "OK");
                            }
                        }
                    }
                }
            }
        }
Пример #8
0
        public override async void Initialize(INavigationParameters parameters)
        {
            try
            {
                UserDialogs.Instance.ShowLoading("Loading...");

                bool useWCF = Preferences.Get("UseWCF", false);
                AssignmentsAgrupados = new ObservableCollection <ListObject>();
                if (!useWCF)
                {
                    Itens = await App.SQLiteDb.GetItensByUserAsync(Preferences.Get("LoggedUserID", 0));

                    //AssignmentsAgrupados = new ObservableCollection<ListObject>();

                    ListObject listaObj;
                    foreach (Item element in Itens)
                    {
                        listaObj = new ListObject()
                        {
                            ItemDescription = element.Description, ItemID = element.ItemID
                        };
                        List <Assignment> ListAssignments = await App.SQLiteDb.GetAssignmentsByItemAsync(element.ItemID);

                        foreach (Assignment assi in ListAssignments)
                        {
                            listaObj.Add(assi);
                        }
                        AssignmentsAgrupados.Add(listaObj);
                    }
                }
                else
                {
                    // AssignmentsAgrupados = new ObservableCollection<ListObject>();
                    var client = new HttpClient
                    {
                        Timeout     = TimeSpan.FromMilliseconds(15000),
                        BaseAddress = new Uri(GetUrlBase())
                    };
                    using (var response = await client.GetAsync("GetItensByUser/" + Preferences.Get("LoggedUserID", 0)))
                    {
                        if (response != null)
                        {
                            if (response.IsSuccessStatusCode)
                            {
                                var respStr = await response.Content.ReadAsStringAsync();

                                if (!String.IsNullOrEmpty(respStr))
                                {
                                    Itens = JsonConvert.DeserializeObject <List <Item> >(respStr);
                                    if (Itens.Count > 0)
                                    {
                                        using (var response2 = await client.GetAsync("GetAssignmentsByUser/" + Preferences.Get("LoggedUserID", 0)))
                                        {
                                            if (response2 != null)
                                            {
                                                if (response2.IsSuccessStatusCode)
                                                {
                                                    var respStr2 = await response2.Content.ReadAsStringAsync();

                                                    if (!String.IsNullOrEmpty(respStr2))
                                                    {
                                                        AssignmentsAgrupados = JsonConvert.DeserializeObject <ObservableCollection <ListObject> >(respStr2);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                await DialogService.DisplayAlertAsync("Warning", "Connection Failed", "OK");
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                await DialogService.DisplayAlertAsync("Warning", "Connection Failed", "OK");
                            }
                        }
                        else
                        {
                            await DialogService.DisplayAlertAsync("Warning", "Connection Failed", "OK");
                        }
                    }
                }


                Periods = new List <DatePickerObject>
                {
                    new DatePickerObject {
                        Value = 1, Label = "Today"
                    },
                    new DatePickerObject {
                        Value = 2, Label = "This Week"
                    },
                    new DatePickerObject {
                        Value = 3, Label = "This Month"
                    },
                    new DatePickerObject {
                        Value = 4, Label = "Open-Ended"
                    }
                };
                SelectedPeriod = Periods[0];
            }
            catch (Exception e)
            {
                await DialogService.DisplayAlertAsync("Warning", "Something went wrong", "OK");
            }
            finally
            {
                UserDialogs.Instance.HideLoading();
            }
        }
Пример #9
0
        override public AbstractArea ChoiceNextArea(List <AbstractArea> listArea)
        {
            var home = (Anthill)listArea[0].Environment;

            if (Life <= 25 && Life >= 10 || StayHome)
            {
                IsGoingHome = true;
            }

            if (Position.Environment?.GetType() == typeof(Anthill) && Position.Environment != home)
            {
                var homeEnemy = (Anthill)Position.Environment;
                IsStoping = true;
                var food = homeEnemy.ListObject.Count < 5 ? null : homeEnemy.ListObject.Where(o => o.GetType() == typeof(Food)).First();
                if (food != null || ListObject.Count < MaxCapacityCarry)
                {
                    homeEnemy.ListObject.Remove(food);
                    ListObject.Add(food);
                }
                else
                {
                    IsStoping = false;
                }
            }

            if (IsWalking && ListObject.Count > 0 &&
                (int)Math.Round(Position.X % 1) == 0 &&
                (int)Math.Round(Position.Y % 1) == 0)
            {
                var PositionCurrent = listArea[1];
                if (PositionCurrent.ListObject.Count < 7)
                {
                    PositionCurrent.AddObject(new Pheromone());
                }
                else
                {
                    ((Pheromone)(from p in PositionCurrent.ListObject
                                 where p.GetType() == typeof(Pheromone)
                                 select p).First()).Duration = 200;
                }
            }

            if (IsGoingHome == true && _position.X == home.Position.X && _position.Y == home.Position.Y)
            {
                home.ListObject.AddRange(ListObject);
                ListObject.RemoveAll(e => true == true);

                while (Life <= 100)
                {
                    var foods = (from f in home.ListObject
                                 where f.GetType() == typeof(Food)
                                 select f);

                    if (foods.Count() <= 10)
                    {
                        break;
                    }
                    Life += ((Food)foods.First()).GetRemaningPiece();
                    home.ListObject.Remove(foods.First());
                }

                _destination = null;
                IsGoingHome  = false;
                IsWalking    = false;
                _isWalkingForFoodAtPosition = null;
            }

            if (_isWalkingForFoodAtPosition != null)
            {
                if (_destination == null)
                {
                    _destination = _isWalkingForFoodAtPosition;
                }

                if (IsStoping)
                {
                    Food food = (Food)(from f in _isWalkingForFoodAtPosition.ListObject
                                       where f.GetType() == typeof(Food)
                                       select f).FirstOrDefault();

                    if (food != null && ListObject.Count < MaxCapacityCarry && food.GetRemaningPiece() > 0)
                    {
                        ListObject.Add(food.TakeAPiece());
                    }
                    else
                    {
                        IsGoingHome = true;
                        IsStoping   = false;
                        _isWalkingForFoodAtPosition = null;
                    }
                }
                else if (Math.Abs(Math.Round(_isWalkingForFoodAtPosition.X - _position.X, 1)) <= 1 &&
                         Math.Abs(Math.Round(_isWalkingForFoodAtPosition.Y - _position.Y)) <= 1 &&
                         IsInCenterField())
                {
                    IsStoping = true;
                }
                else
                {
                }
            }
            else
            {
                for (var i = 1; i < listArea.Count && IsGoingHome == false; i++)
                {
                    var area = listArea[i];
                    foreach (AbstractObject obj in area.ListObject)
                    {
                        if (obj.GetType() == typeof(Food))
                        {
                            _isWalkingForFoodAtPosition = (Field)obj.Position;
                            _destination = obj.Position;
                            break;
                        }
                    }
                }
            }
            if (ListObject.Count > 0)
            {
                return(base.ChoiceNextArea(listArea));
            }
            else if (Life <= 25)
            {
                return(base.ChoiceNextArea(new List <AbstractArea>()
                {
                    listArea[0]
                }));
            }
            else
            {
                var listPheromone = IsGoingHome ? new List <AbstractArea>() : GetAreaWithPheromone(listArea);
                if (listPheromone.Count > 0 &&
                    listPheromone.First().X != Position.X &&
                    listPheromone.First().Y != Position.Y)
                {
                    return(base.ChoiceNextArea(new List <AbstractArea>()
                    {
                        listPheromone.First()
                    }));
                }
                else
                {
                    if (listPheromone.Count > 0)
                    {
                        IsGoingHome = false;
                        listArea.Remove(listArea[0]);
                    }

                    foreach (AbstractArea area in listPheromone)
                    {
                        listArea.Remove(area);
                    }

                    return(base.ChoiceNextArea(listArea));
                }
            }
        }