Пример #1
0
        /// <summary>
        /// Begins the find request in asynchronous mode.
        /// </summary>
        /// <param name="clientAETitle">The client AE title.</param>
        /// <param name="remoteAE">The remote AE.</param>
        /// <param name="remoteHost">The remote host.</param>
        /// <param name="remotePort">The remote port.</param>
        /// <param name="requestDataset">The request attribute collection.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="asyncState">State of the async.</param>
        /// <returns></returns>
        public IAsyncResult BeginFind(string clientAETitle, string remoteAE, string remoteHost, int remotePort,
                                      DicomDataset requestDataset, AsyncCallback callback, object asyncState)
        {
            FindDelegate findDelegate = this.Find;

            return(findDelegate.BeginInvoke(clientAETitle, remoteAE, remoteHost, remotePort, requestDataset, callback,
                                            asyncState));
        }
Пример #2
0
 static CallbackHandler()
 {
     loadCallback = new LoadDelegate(load);
     unloadCallback = new UnloadDelegate(unload);
     openCallback = new OpenDelegate(open);
     listCallback = new ListDelegate(list);
     listFileInfoCallback = new ListFileInfoDelegate(listFileInfo);
     findCallback = new FindDelegate(find);
     findFileInfoCallback = new FindFileInfoDelegate(findFileInfo);
     existsCallback = new ExistsDelegate(exists);
 }
Пример #3
0
 public string Find(FindDelegate findDelegate)
 {
     foreach (string s in _Items)
     {
         if (findDelegate(s))
         {
             return(s);
         }
     }
     return(null);
 }
 public void NormalCases(FindDelegate findFunc)
 {
     Assert.AreEqual("a", findFunc("a"));
     Assert.AreEqual("aa", findFunc("aa"));
     Assert.AreEqual("a", findFunc("ab"));
     Assert.AreEqual("a", findFunc("abc"));
     Assert.AreEqual("aba", findFunc("aba"));
     Assert.AreEqual("aba", findFunc("abacd"));
     Assert.AreEqual("aba", findFunc("cdaba"));
     Assert.AreEqual("bab", findFunc("babad"));
     Assert.AreEqual("bb", findFunc("cbbd"));
 }
Пример #5
0
        /// <summary>
        /// Returns the first matching item identified by the find delegate.
        /// </summary>
        /// <typeparam name="ParamTy">Parameter type</typeparam>
        /// <param name="func">Delegate that should be called to chec
        /// for a matching object.</param>
        /// <param name="p">Parameter to the find delegate.</param>
        /// <returns>Returns the first matching item, or null
        /// if no item found.</returns>
        public ItemTy Find <ParamTy>(FindDelegate <ParamTy> func, ParamTy p)
        {
            foreach (ItemTy i in this)
            {
                if (func(i, p))
                {
                    return(i);
                }
            }

            return(null);
        }
Пример #6
0
        /// <summary>
        /// Ends the asynchronous find request.
        /// </summary>
        /// <param name="ar">The ar.</param>
        /// <returns></returns>
        public IList <DicomAttributeCollection> EndFind(IAsyncResult ar)
        {
            FindDelegate findDelegate = ((AsyncResult)ar).AsyncDelegate as FindDelegate;

            if (findDelegate != null)
            {
                return(findDelegate.EndInvoke(ar));
            }
            else
            {
                throw new InvalidOperationException("cannot get results, asynchresult is null");
            }
        }
Пример #7
0
        public RobotList <ItemTy> FindAll <ParamTy>(FindDelegate <ParamTy> func, ParamTy p)
        {
            RobotList <ItemTy> rval = new RobotList <ItemTy>();

            foreach (ItemTy i in this)
            {
                if (func(i, p))
                {
                    rval.Add(i);
                }
            }

            return(rval);
        }
Пример #8
0
        private XmlElement FindNode(XmlNodeList list, FindDelegate find)
        {
            XmlElement result = null;

            foreach (XmlNode node in list)
            {
                if (find(node))
                {
                    result = node as XmlElement;
                    break;
                }
            }
            return(result);
        }
Пример #9
0
        public Node FindNode(T a_query, FindDelegate a_finder, float a_threshold = 0.0001f)
        {
            Node  best = null;
            float min  = 0;

            foreach (Node n in nodes)
            {
                float res = a_finder(a_query, n.data);
                if ((best == null || res < min) && res < a_threshold)
                {
                    best = n;
                    min  = res;
                }
            }
            return(best);
        }
Пример #10
0
        static void Main(string[] args)
        {
            //Instantiation of Delegates
            Multiplydelegate  mul_del   = new Multiplydelegate(Multiply);
            WriteNameDelegate write_del = new WriteNameDelegate(WriteName);
            DivisonDeletgate  div_del   = new DivisonDeletgate(Division);
            FunDelegate       fun_del   = new FunDelegate(fun);
            FindDelegate      feven_del = new FindDelegate(FindEven);
            FindDelegate      fmul5_del = new FindDelegate(FindMultipleof5);

            //Invoking The delegates
            int Result = mul_del.Invoke(5, 7);

            Console.WriteLine("Result is {0}", Result);

            string str = write_del("SWATI");

            Console.WriteLine(str);

            div_del.Invoke(10, 2);

            fun_del.Invoke();

            if (feven_del.Invoke(20))
            {
                Console.WriteLine("Number is EVEN");
            }
            else
            {
                Console.WriteLine("Number is ODD");
            }

            if (fmul5_del.Invoke(30))
            {
                Console.WriteLine("Multiple of 5");
            }
            else
            {
                Console.WriteLine("Not multiple of 5");
            }

            Console.ReadKey();
        }
Пример #11
0
            public Nodes FindNode(T a_query, FindDelegate a_finder, float a_threshold = 0.0001f)
            {
                Node  best = null;
                float min  = 0;

                for (int i = 0; i < nodes.Count; ++i)
                {
                    nodes[i];
                }
                foreach (Node n in nodes)
                {
                    float res = a_finder(a_query, n.data);
                    if (best == null || res < min && res < a_threshold)
                    {
                        best = n;
                        min  = res;
                    }
                }
                return(best);
            }
Пример #12
0
    public List <LuaValue> FindAll(FindDelegate condition)
    {
        List <LuaValue>  foundValues = new List <LuaValue>();
        Stack <LuaValue> stack       = new Stack <LuaValue>();

        stack.Push(_root);
        while (stack.Count > 0)
        {
            LuaValue val = stack.Pop();
            if (condition(val))
            {
                foundValues.Add(val);
            }
            if (val.LVT == LuaValueType.LVT_Table)
            {
                ICollection <LuaValue> pushVals = val.TableValue.Values;
                foreach (LuaValue v in pushVals)
                {
                    stack.Push(v);
                }
            }
        }
        return(foundValues);
    }
 /// <summary>
 /// Поиск положительных элементов через делегат.
 /// </summary>
 /// <param name="arr">Исходный массив.</param>
 /// <param name="findDelegate">Делегат для условия поиска.</param>
 /// <returns>Массив элементов, удовлетворяющих критерию поиска.</returns>
 public static int[] Find(this int[] arr, FindDelegate findDelegate)
 {
     return arr.Where(el => findDelegate(el)).ToArray();
 }
Пример #14
0
        async Task <WifiNetworkDto> FindInternal(WifiNetworkDto nw, bool byBssIdOnly, FindDelegate findMethod)
        {
            WifiNetworkDto wifiDtoFromFile;
            var            delimiter = '\t';

            if (UseCachedNetworkLookup)
            {
                if (_CachedCSVNetworkList.Count == 0)
                {
                    #region Populate CSV cache
                    using (var fs = new FileStream(_filePathCSV, FileMode.Open, FileAccess.Read))
                    {
                        using (var fr = new StreamReader(fs, Constants.UNIVERSAL_ENCODING))
                        {
                            // skip header
                            var ss2 = fr.ReadLine();
                            while (!fr.EndOfStream)
                            {
                                var lineFromCSV = fr.ReadLine();
                                if (string.IsNullOrWhiteSpace(lineFromCSV))
                                {
                                    continue;
                                }
                                wifiDtoFromFile = WifiNetworkDto.GetWifiDtoFromString(lineFromCSV, delimiter);
                                _CachedCSVNetworkList.Add(wifiDtoFromFile);
                            }
                        }
                    }
                    #endregion
                }
                // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                // Refactor lookup code, also do the same for FindWifiInCSV()
                // Use FindDelegate
                var wifiDtoFromFileKVP = _CachedCSVNetworkList.FirstOrDefault(
                    (nwFromCache) => {
                    if (string.IsNullOrEmpty(nwFromCache.BssID))
                    {
                        return(nwFromCache.Name == nw.Name);
                    }
                    if (string.IsNullOrEmpty(nw.BssID))
                    {
                        return(nwFromCache.Name == nw.Name);
                    }
                    else
                    {
                        return(nwFromCache.BssID.ToUpper() == nw.BssID.ToUpper());
                    }
                });

                wifiDtoFromFile = wifiDtoFromFileKVP;
            }
            else
            {
                using (var fs = new FileStream(_filePathCSV, FileMode.Open, FileAccess.Read))
                {
                    using (var fr = new StreamReader(fs, Constants.UNIVERSAL_ENCODING))
                    {
                        // skip header
                        var ss2 = await fr.ReadLineAsync();

                        while (!fr.EndOfStream)
                        {
                            var lineFromCSV = await fr.ReadLineAsync();

                            if (string.IsNullOrWhiteSpace(lineFromCSV))
                            {
                                continue;
                            }
                            wifiDtoFromFile = WifiNetworkDto.GetWifiDtoFromString(lineFromCSV, delimiter);

                            if (findMethod(nw, wifiDtoFromFile))
                            {
                                return(wifiDtoFromFile);
                            }
                        }
                    }
                }
                wifiDtoFromFile = null;
            }

            return(wifiDtoFromFile);
        }
Пример #15
0
 private static extern IntPtr OgreManagedArchive_Create(String name, String archType, LoadDelegate loadCallback, UnloadDelegate unloadCallback, OpenDelegate openCallback, ListDelegate listCallback, ListFileInfoDelegate listFileInfoCallback, FindDelegate findCallback, FindFileInfoDelegate findFileInfoCallback, ExistsDelegate existsCallback
     #if FULL_AOT_COMPILE
     , IntPtr instanceHandle
     #endif
     );
Пример #16
0
 public Edge AddEdge(T a_start, T a_end, FindDelegate a_finder,
                     float a_threshold = 0.0001f, float a_weight = 1, bool undirected = true)
 {
     return(AddEdge(FindNode(a_start, a_finder, a_threshold),
                    FindNode(a_end, a_finder), a_weight, undirected));
 }
Пример #17
0
        static void Main(string[] args)
        {
            //instantiate the delegates
            Multiplydelegate mul_del = (x, y) =>        //lambda expression
            {
                return(x * y);
            };

            WriteNameDelegate write_del = name =>
            {
                return("My Name is " + name);
            };

            DivisonDeletgate div_del = (x, y) =>
            {
                Console.WriteLine("Divide Result is : {0}", x / y);
            };

            FunDelegate fun_del = () =>
            {
                Console.WriteLine("Programming is fun");
            };

            FindDelegate feven_del = x =>
            {
                if (x % 2 == 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            };


            FindDelegate fmul5_del = x =>
            {
                if (x % 5 == 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            };


            //Invoking The delegates

            int Result = mul_del.Invoke(5, 7);

            Console.WriteLine("Result is {0}", Result);

            string str = write_del("SWATI");

            Console.WriteLine(str);

            div_del.Invoke(10, 2);

            fun_del.Invoke();

            if (feven_del.Invoke(20))
            {
                Console.WriteLine("Number is EVEN");
            }
            else
            {
                Console.WriteLine("Number is ODD");
            }

            if (fmul5_del.Invoke(30))
            {
                Console.WriteLine("Multiple of 5");
            }
            else
            {
                Console.WriteLine("Not multiple of 5");
            }

            Console.ReadKey();
        }
 public void CornerCases(FindDelegate findFunc)
 {
     Assert.AreEqual("", findFunc(""));
     Assert.AreEqual("", findFunc(null));
 }