Пример #1
0
        public override bool Sync(bool CleanUp = false)
        {
            var rules = App.client.GetRules(new List <Guid>()
            {
                ProgSetId
            });

            List <FirewallRuleEx> list;

            if (rules == null || !rules.TryGetValue(ProgSetId, out list))
            {
                return(false);
            }

            Dictionary <string, SingleRule> oldRules = new Dictionary <string, SingleRule>(Rules);

            foreach (var rule in list)
            {
                if (Rules.ContainsKey(rule.guid))
                {
                    oldRules.Remove(rule.guid);
                }
                else
                {
                    Rules.Add(rule.guid, new SingleRule()
                    {
                        RuleId = rule.guid
                    });
                }
            }

            if (CleanUp)
            {
                foreach (string key in oldRules.Keys)
                {
                    Rules.Remove(key);
                }
            }

            List <ProgramSet> progs = App.client.GetPrograms(new List <Guid>()
            {
                ProgSetId
            });

            if (progs.Count == 0)
            {
                return(false);
            }
            ProgramSet progSet = progs[0];

            Name = progSet.config.Name;
            if (Icon.Length == 0)
            {
                Icon = progSet.GetIcon();
            }

            return(true);
        }
Пример #2
0
        public void DoUpdate()
        {
            SuspendChange++;

            ImgFunc.GetIconAsync(Program.GetIcon(), icon.Width, (ImageSource src) => {
                if (Application.Current != null)
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        icon.Source = src;
                    }));
                }
                return 0;
            });

            //name.Content = process.Name;
            name.Text = Program.config.Name;

            int blockedConnections = 0;
            int allowedConnections = 0;
            int socketCount = 0;
            UInt64 uploadRate = 0;
            UInt64 downloadRate = 0;
            foreach (Program prog in Program.Programs.Values)
            {
                blockedConnections += prog.countBlocked;
                allowedConnections += prog.countAllowed;

                socketCount += prog.SocketCount;

                uploadRate += prog.UploadRate;
                downloadRate += prog.DownloadRate;
            }
            info.Content = Translate.fmt("lbl_prog_info", blockedConnections, allowedConnections, socketCount, 
                FileOps.FormatSize((decimal)uploadRate), FileOps.FormatSize((decimal)downloadRate)); 

            WpfFunc.CmbSelect(category, Program.config.Category == null ? "" : Program.config.Category);

            if (Program.config.NetAccess == ProgramSet.Config.AccessLevels.Unconfigured)
            {
                cmbAccess.Background = GetAccessColor(Program.config.CurAccess);
                WpfFunc.CmbSelect(cmbAccess, Program.config.CurAccess.ToString());
            }
            else
            {
                if (Program.config.NetAccess != ProgramSet.Config.AccessLevels.Unconfigured && Program.config.NetAccess != Program.config.CurAccess)
                    cmbAccess.Background /*grid.Background*/ = FindResource("Stripes") as DrawingBrush;
                else
                    cmbAccess.Background = GetAccessColor(Program.config.NetAccess);

                WpfFunc.CmbSelect(cmbAccess, Program.config.NetAccess.ToString());
            }

            chkNotify.IsChecked = Program.config.GetNotify();

            progGrid.Items.Clear();

            foreach (Program prog in Program.Programs.Values)
                progGrid.Items.Insert(0, new ProgEntry(prog));

            btnSplit.IsEnabled = Program.Programs.Count > 1;
            SuspendChange--;
        }