public GlobalStatMultTimesForm()
        {
            InitializeComponent();
            this.Node = new TreeNode();

            // Add each global item to the list
            foreach (KeyValuePair <string, string> I in StatsConstants.PythonGlobalVars)
            {
                StatName.Items.Add(new KeyValuePair(I.Key, I.Value));
            }

            StatName.SelectedIndex = 0;

            // Get our award ID from the main form
            IAward A = MedalDataEditor.SelectedAward;

            if (A is Award)
            {
                AwardId = ((Award)MedalDataEditor.SelectedAward).Id;
            }
            else
            {
                AwardId = ((Rank)MedalDataEditor.SelectedAward).Id.ToString();
            }
        }
        /// <summary>
        /// Restores the condition / criteria back to default (vanilla)
        /// </summary>
        private void RestoreToDefaultMenuItem_Click(object sender, EventArgs e)
        {
            // Make sure we have an award selected
            if (SelectedAwardNode == null || SelectedAwardNode.Parent == null)
            {
                MessageBox.Show("Please select an award!");
                return;
            }

            // Delay or tree redraw
            AwardConditionsTree.BeginUpdate();

            // Clear all Nodes
            AwardConditionsTree.Nodes.Clear();

            // Parse award conditions into tree view
            IAward SAward = AwardCache.GetAward(SelectedAwardNode.Name);

            SAward.RestoreDefaultConditions();
            AwardConditionsTree.Nodes.Add(SAward.ToTree());

            // Revalidate
            ValidateConditions(SelectedAwardNode, SAward.GetCondition());

            // Conditions tree's are to be expanded at all times
            AwardConditionsTree.ExpandAll();

            // Redraw the tree
            AwardConditionsTree.EndUpdate();
        }
Пример #3
0
        static async Task <IEnumerable <IJuror> > ImportJuryAsync(IAward award)
        {
            var result  = new List <IJuror>();
            var accMngr = new AccountManager();
            var login   = await accMngr.LogonAsync(SaEmail, SaPwd, string.Empty).ConfigureAwait(false);

            string filePath = Path.Combine(PAPath, JuryFolder, "Jurylist.txt");

            using var adapter = Adapters.Factory.Create <IJuror>(login.SessionToken);
            var lines = File.ReadAllLines(filePath).Where(l => string.IsNullOrEmpty(l) == false).ToArray();

            for (int i = 0; i < lines.Length;)
            {
                var entity = await adapter.CreateAsync();

                entity.AwardId     = award.Id;
                entity.Name        = lines[i++];
                entity.Position    = lines[i++];
                entity.Institution = lines[i++];
                entity.Email       = lines[i++];
                entity             = await adapter.InsertAsync(entity);

                result.Add(entity);
            }
            await accMngr.LogoutAsync(login.SessionToken).ConfigureAwait(false);

            return(result);
        }
Пример #4
0
        public void Add(IAward award)
        {
            var info = new AwardInfo {
                award = award
            };

            info.history.Add(award.Quality);
            this.AwardInfos.Add(info);
        }
        /// <summary>
        /// An event called everytime a new award is selected...
        /// It repaints the current award info
        /// </summary>
        private void AwardTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // Set our award globally
            SelectedAwardNode = e.Node;

            // Only proccess child Nodes
            if (SelectedAwardNode.Nodes.Count == 0)
            {
                // Set Award Image
                SetAwardImage(SelectedAwardNode.Name);

                // Set award name and type
                switch (Award.GetType(SelectedAwardNode.Name))
                {
                case AwardType.Badge:
                    AwardTypeBox.Text = "Badge";
                    AwardNameBox.Text = Award.GetName(SelectedAwardNode.Name);
                    break;

                case AwardType.Medal:
                    AwardTypeBox.Text = "Medal";
                    AwardNameBox.Text = Award.GetName(SelectedAwardNode.Name);
                    break;

                case AwardType.Ribbon:
                    AwardTypeBox.Text = "Ribbon";
                    AwardNameBox.Text = Award.GetName(SelectedAwardNode.Name);
                    break;

                case AwardType.Rank:
                    AwardTypeBox.Text = "Rank";
                    AwardNameBox.Text = Rank.GetName(Int32.Parse(SelectedAwardNode.Name));
                    break;
                }

                // Delay or tree redraw
                AwardConditionsTree.BeginUpdate();

                // Clear all Nodes
                AwardConditionsTree.Nodes.Clear();

                // Parse award conditions into tree view
                SelectedAward = AwardCache.GetAward(SelectedAwardNode.Name);
                TreeNode Conds = SelectedAward.ToTree();
                if (Conds != null)
                {
                    AwardConditionsTree.Nodes.Add(Conds);
                }

                // Conditions tree's are to be expanded at all times
                AwardConditionsTree.ExpandAll();

                // Redraw the tree
                AwardConditionsTree.EndUpdate();
            }
        }
Пример #6
0
 public BaseAward(IAward award)
 {
     StringId        = award.StringId;
     Title           = award.Title;
     Description     = award.Description;
     Status          = award.Status;
     Date            = award.Date;
     Value           = award.Value;
     ComplaintPeriod = award.ComplaintPeriod;
 }
Пример #7
0
 public Award(IAward award)
     : base(award)
 {
     if (Value == null)
     {
         Value = new Value();
     }
     if (ComplaintPeriod == null)
     {
         ComplaintPeriod = new Period();
     }
 }
Пример #8
0
        public IAward Run(IAward award)
        {
            var step = this.PreExpiration_QualityStep;

            if (award.IsExpired)
            {
                step = this.PostExpiration_QualityStep;
            }

            award.ChangeQuality(step);
            return(award);
        }
Пример #9
0
        static async Task <IEnumerable <IProject> > ImportProgramAsync(IAward award, List <IMember> members)
        {
            var result  = new List <IProject>();
            var accMngr = new AccountManager();
            var login   = await accMngr.LogonAsync(SaEmail, SaPwd, string.Empty).ConfigureAwait(false);

            string filePath = Path.Combine(PAPath, ProgramFolder);

            using var adapter = Adapters.Factory.Create <IProject>(login.SessionToken);

            members ??= new List <IMember>();

            foreach (var item in new DirectoryInfo(filePath).GetDirectories())
            {
                var data = item.Name.Split(' ');

                if (data.Length == 5)
                {
                    var entity = await adapter.CreateAsync();

                    var fileDescription = Path.Combine(filePath, item.Name, "Description.txt");
                    var fileLogo        = Path.Combine(filePath, item.Name, "Logo.png");
                    var fileMembers     = Path.Combine(filePath, item.Name, "Members.txt");

                    entity.AwardId     = award.Id;
                    entity.From        = TimeSpan.ParseExact(data[0], "hhmm", null);
                    entity.To          = TimeSpan.ParseExact(data[1], "hhmm", null);
                    entity.Title       = data[2];
                    entity.School      = $"{data[3]} - {data[4]}";
                    entity.Description = File.Exists(fileDescription) ? File.ReadAllText(fileDescription) : "No description";
                    entity.Logo        = File.Exists(fileLogo) ? File.ReadAllBytes(fileLogo) : null;
                    entity             = await adapter.InsertAsync(entity);

                    result.Add(entity);

                    if (File.Exists(fileMembers))
                    {
                        members.AddRange(await ImportMembersAsync(login.SessionToken, entity, fileMembers));
                    }
                }
            }
            await accMngr.LogoutAsync(login.SessionToken).ConfigureAwait(false);

            return(result);
        }
Пример #10
0
        /// <summary>
        /// Creates the award update view.
        /// </summary>
        /// <param name="awardInfo">The award information.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">awardInfo</exception>
        public IAwardView CreateAwardUpdateView(IAward awardInfo)
        {
            if (awardInfo == null)
            {
                throw new ArgumentNullException(nameof(awardInfo));
            }

            var awardView = new AwardView
            {
                AwardId     = awardInfo.AwardId,
                UserId      = awardInfo.UserId,
                AwardName   = awardInfo.AwardName,
                AwardYear   = awardInfo.AwardYear,
                DateCreated = awardInfo.DateCreated,
                IsActive    = awardInfo.IsActive,
            };

            return(awardView);
        }
Пример #11
0
        public void SaveAward(SaveAwardPostData postData)
        {
            Campaign campaign = CampaignService.Instance.Get(postData.StoreId, postData.CampaignId);

            if (campaign == null)
            {
                return;
            }

            IAward award = campaign.Awards.SingleOrDefault(i => i.Id == postData.AwardId);

            if (award == null)
            {
                return;
            }

            award.Settings = postData.Settings;
            award.SaveSettings();
        }
        public IAward Run(IAward award)
        {
            if (award.IsExpired)
            {
                award.ChangeQuality(-1 * award.Quality);
                return(award);
            }
            var qualityStep = 1;

            if (award.DaysUntilExpiration <= 5)
            {
                qualityStep = 3;
            }
            else if (award.DaysUntilExpiration <= 10)
            {
                qualityStep = 2;
            }

            award.ChangeQuality(qualityStep);
            return(award);
        }
Пример #13
0
        public HttpResponseMessage AddAward(AddAwardPostData postData)
        {
            Campaign campaign = CampaignService.Instance.Get(postData.StoreId, postData.CampaignId);

            if (campaign == null)
            {
                return(null);
            }

            IAward award = AwardService.Instance.Get(postData.AwardAlias);

            if (award == null)
            {
                return(null);
            }

            campaign.Awards.Add(award);
            campaign.Save();

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new StringContent(award.ToJson(), Encoding.UTF8, "application/json");
            return(response);
        }
Пример #14
0
        /// <summary>
        /// Creates the edit award view.
        /// </summary>
        /// <param name="awardInfo">The award information.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">awardInfo</exception>
        public IAwardView CreateEditAwardView(IAward awardInfo)
        {
            if (awardInfo == null)
            {
                throw new ArgumentNullException(nameof(awardInfo));
            }

            //if (awardCollection == null) throw new ArgumentNullException(nameof(awardCollection));

            //var departmentDDL =
            //    GetDropDownList.DepartmentListItems(departmentCollection, departmentInfo.ParentDepartmentId);


            var returnAward = new AwardView
            {
                AwardId   = awardInfo.AwardId,
                UserId    = awardInfo.UserId,
                AwardName = awardInfo.AwardName,
                AwardYear = awardInfo.AwardYear,
                IsActive  = awardInfo.IsActive
            };

            return(returnAward);
        }
Пример #15
0
        /// <summary>
        /// An event called everytime a new award is selected...
        /// It repaints the current award info
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AwardTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode N = e.Node;

            // Only proccess child Nodes
            if (N.Nodes.Count == 0)
            {
                // Set Award Image
                SetAwardImage(N.Name);

                // Set award name and type
                AwardNameBox.Text = N.Text;
                switch (Award.GetType(N.Name))
                {
                    case AwardType.Badge:
                        AwardTypeBox.Text = "Badge";
                        break;
                    case AwardType.Medal:
                        AwardTypeBox.Text = "Medal";
                        break;
                    case AwardType.Ribbon:
                        AwardTypeBox.Text = "Ribbon";
                        break;
                    case AwardType.Rank:
                        AwardTypeBox.Text = "Rank";
                        break;
                }

                // Delay or tree redraw
                AwardConditionsTree.BeginUpdate();

                // Clear all Nodes
                AwardConditionsTree.Nodes.Clear();

                // Parse award conditions into tree view
                SelectedAward = AwardCache.GetAward(N.Name);
                AwardConditionsTree.Nodes.Add(SelectedAward.ToTree());

                // Conditions tree's are to be expanded at all times
                AwardConditionsTree.ExpandAll();

                // Redraw the tree
                AwardConditionsTree.EndUpdate();
            }
        }
Пример #16
0
 public IAward Run(IAward award)
 {
     return(award);
 }
        /// <summary>
        /// Saves the medal data to a file
        /// </summary>
        private void SaveButton_Click(object sender, EventArgs e)
        {
            // ============ Check For Condition Errors and Alert User of Any
            string Profile    = ProfileSelector.SelectedItem.ToString();
            int    CondErrors = 0;

            // Check for condition errors on badges
            TreeNode BadgeNode = AwardTree.Nodes[0];

            for (int i = 0; i < BadgeNode.Nodes.Count; i++)
            {
                foreach (TreeNode N in BadgeNode.Nodes[i].Nodes)
                {
                    IAward    t    = AwardCache.GetAward(N.Name);
                    Condition Cond = t.GetCondition();
                    if (Cond is ConditionList)
                    {
                        ConditionList Clist = Cond as ConditionList;
                        if (Clist.HasConditionErrors)
                        {
                            CondErrors++;
                        }
                    }
                    else if (Cond.Returns() != ReturnType.Bool)
                    {
                        CondErrors++;
                    }
                }
            }

            // Check for condition errors on the rest of the awards
            for (int i = 1; i < 4; i++)
            {
                foreach (TreeNode N in AwardTree.Nodes[i].Nodes)
                {
                    IAward    t    = AwardCache.GetAward(N.Name);
                    Condition Cond = t.GetCondition();
                    if (Cond is ConditionList)
                    {
                        ConditionList Clist = Cond as ConditionList;
                        if (Clist.HasConditionErrors)
                        {
                            CondErrors++;
                        }
                    }
                    else if (Cond.Returns() != ReturnType.Bool)
                    {
                        CondErrors++;
                    }
                }
            }

            // Warn the user of any condition errors, and verify if we wanna save anyways
            if (CondErrors > 0)
            {
                DialogResult Res = MessageBox.Show(
                    "A total of " + CondErrors + " award condition errors were found."
                    + Environment.NewLine + Environment.NewLine
                    + "Are you sure you want to save these changes without fixing these issues?",
                    "Condition Errors Found", MessageBoxButtons.YesNo, MessageBoxIcon.Warning
                    );

                if (Res != DialogResult.Yes)
                {
                    return;
                }
            }

            // ============ Begin applying Medal Data Update

            // Add base medal data functions
            StringBuilder MedalData = new StringBuilder();

            MedalData.AppendLine(Program.GetResourceAsString("BF2Statistics.MedalData.PyFiles.functions.py"));
            MedalData.AppendLine("medal_data = (");

            // Add Each Award (except ranks) to the MedalData Array
            foreach (Award A in AwardCache.GetBadges())
            {
                MedalData.AppendLine("\t" + A.ToPython());
            }

            foreach (Award A in AwardCache.GetMedals())
            {
                MedalData.AppendLine("\t" + A.ToPython());
            }

            foreach (Award A in AwardCache.GetRibbons())
            {
                MedalData.AppendLine("\t" + A.ToPython());
            }

            // Append Rank Data
            MedalData.AppendLine(")");
            MedalData.AppendLine("rank_data = (");
            foreach (Rank R in AwardCache.GetRanks())
            {
                MedalData.AppendLine("\t" + R.ToPython());
            }

            // Close off the Rank Data Array
            MedalData.AppendLine(")#end");


            // ============ Save Medal Data
            try
            {
                // Write to file
                File.WriteAllText(
                    Path.Combine(PythonPath, "medal_data_" + Profile + ".py"),
                    MedalData.ToString().TrimEnd()
                    );

                // Update variables, and display success
                ChangesMade = false;
                Notify.Show("Medal Data Saved Successfully!", "Operation Successful", AlertType.Success);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "An exception was thrown while trying to save medal data. Medal data has NOT saved."
                    + Environment.NewLine + Environment.NewLine
                    + "Message: " + ex.Message,
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
            }
        }
Пример #18
0
 public AwardDTO(IAward award)
     : base(award)
 {
 }