コード例 #1
0
        /// <summary>
        /// Parse transmission torrents data.
        /// </summary>
        /// <param name="data"></param>
        private void ProcessParsingTransmissionResponse(TransmissionTorrents data)
        {
            if (!IsConnected)
            {
                return;
            }

            lock (_syncTorrentList)
            {
                //1: 'check pending',
                //2: 'checking',

                //5: 'seed pending',
                //6: 'seeding',
                switch (_filterCategory)
                {
                //3: 'download pending',
                //4: 'downloading',
                case Enums.Categories.Downloading:
                    data.Torrents = data.Torrents.Where(x => x.Status == 3 || x.Status == 4).ToArray();
                    break;

                //4: 'downloading',
                //6: 'seeding',
                //2: 'checking',
                case Enums.Categories.Active:
                    data.Torrents = data.Torrents.Where(x => x.Status == 4 || x.Status == 6 || x.Status == 2)
                                    .ToArray();
                    data.Torrents = data.Torrents.Where(x => x.RateDownload > 1 || x.RateUpload > 1).ToArray();
                    break;

                //0: 'stopped' and is error,
                case Enums.Categories.Stopped:
                    data.Torrents = data.Torrents.Where(x => x.Status == 0 && string.IsNullOrEmpty(x.ErrorString))
                                    .ToArray();
                    break;

                case Enums.Categories.Error:
                    data.Torrents = data.Torrents.Where(x => !string.IsNullOrEmpty(x.ErrorString)).ToArray();
                    break;


                //6: 'seeding',
                //1: 'checking queue',
                case Enums.Categories.Inactive:
                    //var array1 = data.Torrents.Where(x=> x.Status == 1).ToArray();
                    var array2 = data.Torrents.Where(x => x.RateDownload <= 0 && x.RateUpload <= 0 && x.Status != 2)
                                 .ToArray();

                    //int array1OriginalLength = array1.Length;
                    //Array.Resize<TorrentInfo>(ref array1, array1OriginalLength + array2.Length);
                    //Array.Copy(array2, 0, array1, array1OriginalLength, array2.Length);
                    data.Torrents = array2;
                    break;

                //6: 'seeding',
                case Enums.Categories.Ended:
                    data.Torrents = data.Torrents.Where(x => x.Status == 6).ToArray();
                    break;
                }

                if (!string.IsNullOrEmpty(FilterText))
                {
                    //var txtfilter = FilterText;
                    if (FilterText.Contains("{p}:"))
                    {
                        var splited   = FilterText.Split("{p}:");
                        var filterKey = splited[^ 1];
コード例 #2
0
        /// <summary>
        /// Populates the list of filter vars with those that match the VarNames found in the provided list of questions.
        /// </summary>
        /// <param name="questions"></param>
        private void GetFilterVars(List <SurveyQuestion> questions)
        {
            string filterVar;

            int filterVarPos = 0;
            int filterVarLen;

            string filterExp; // the filter expression of the variable e.g. [varname]=1, 2, 8 or 9.

            string[] filterOptionsList;
            string   options;

            Regex           rx;
            MatchCollection results;

            while (!FilterText.Equals(""))
            {
                FilterVar fv;
                foreach (SurveyQuestion q in questions)
                {
                    filterVar = q.VarName.RefVarName;

                    if (!FilterText.Contains(filterVar))
                    {
                        continue;
                    }

                    rx = new Regex(filterVar + "(=|<|>|<>)" +
                                   "(([0-9]+(,\\s[0-9]+)+\\sor\\s[0-9]+)" +
                                   "|([0-9]+\\sor\\s[0-9]+)" +
                                   "|([0-9]+\\-[0-9]+)" +
                                   "|([0-9]+))");

                    filterVarPos = FilterText.IndexOf(filterVar);
                    filterVarLen = filterVar.Length;

                    results = rx.Matches(FilterText);

                    if (results.Count > 0)
                    {
                        filterExp = results[0].Value;
                        options   = filterExp.Substring(filterVarLen + 1);
                        options   = Regex.Replace(options, "[^0-9 <->]", "");

                        filterOptionsList = GetOptionList(options).Split(' ');

                        fv         = new FilterVar();
                        fv.Varname = filterVar;
                        if (filterOptionsList.Length != 0)
                        {
                            fv.ResponseCodes = filterOptionsList.Select(Int32.Parse).ToList();
                        }
                        // add to the list of filter vars if it is not already there
                        if (!FilterVars.Contains(fv))
                        {
                            FilterVars.Add(fv);
                        }
                    }
                    else
                    {
                        filterVarPos = 0;
                        continue;
                    }
                    filterVarPos = 0;
                    // trim the filterText to the point after this VarName
                    FilterText = FilterText.Substring(filterVarPos + filterVarLen);
                }
                if (filterVarPos == 0)
                {
                    break;
                }
            }
        }