Ejemplo n.º 1
0
        /// <summary>
        ///     递归绑定
        /// </summary>
        private static void Bind <TInfo>(this List <TInfo> lstCate, DropDownList ddl, int parentID, int tagNum, Func <TInfo, bool> where, bool isContainsSub, bool isUsePrefix) where TInfo : ICate, new()
        {
            List <TInfo> lst;

            lst = lstCate.FindAll(o => o.ParentID == parentID);
            if (lst == null || lst.Count == 0)
            {
                return;
            }

            if ((parentID == 0 || isContainsSub) && where != null)
            {
                lst = lst.Where(where).ToList();
            }
            if (lst == null || lst.Count == 0)
            {
                return;
            }

            foreach (var info in lst)
            {
                var text = isUsePrefix ? new string(' ', tagNum) + "├─" + info.Caption : info.Caption;

                ddl.Items.Add(new ListItem {
                    Value = info.ID.ToString(), Text = text
                });
                lstCate.Bind(ddl, info.ID.Value, tagNum + 1, where, isContainsSub, isUsePrefix);
            }
        }
        public void Flattening_nested_list_works()
        {
            // Arrange
            var neighbors = new List <Neighbor>
            {
                new Neighbor {
                    FirstName = "John", Pets = new List <string> {
                        "Fluffy", "Thor"
                    }
                },
                new Neighbor {
                    FirstName = "Tim"
                },
                new Neighbor {
                    FirstName = "Carl", Pets = new List <string> {
                        "Sybil"
                    }
                }
            };

            // Act
            var pets = neighbors.Bind(n => n.Pets);

            //var pets = neighbors.SelectMany(n => n.Pets);

            // Assert
            pets.Should().BeEquivalentTo(new List <string> {
                "Fluffy", "Thor", "Sybil"
            });
        }
Ejemplo n.º 3
0
        public void List_Binds()
        {
            var values  = new[] { 1, 2, 3, 4, };
            var list    = new List <int>(values);
            var squares = list.Bind <int>(a => new List <int>(Helper(a))).Values.ToList();

            Assert.AreEqual(values.Sum(), squares.Count);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     绑定到DropDownList
        /// </summary>
        /// <param name="ddl">要绑定的ddl控件</param>
        /// <param name="selectedValue">默认选则值</param>
        /// <param name="where">筛选条件</param>
        /// <param name="isContainsSub">筛选条件是否包含子节点</param>
        /// <param name="isUsePrefix">是否需要加上前缀</param>
        /// <param name="lstCate">分类列表</param>
        public static void Bind <TInfo>(this List <TInfo> lstCate, DropDownList ddl, int selectedValue = 0, Func <TInfo, bool> where = null, bool isContainsSub = false, bool isUsePrefix = true) where TInfo : ICate, new()
        {
            ddl.Items.Clear();

            lstCate.Bind(ddl, 0, 0, where, isContainsSub, isUsePrefix);

            if (selectedValue > 0)
            {
                ddl.SelectedItems(selectedValue);
            }
        }
Ejemplo n.º 5
0
    {/// <summary>
        ///     绑定到DropDownList
        /// </summary>
        /// <param name="ddl">要绑定的ddl控件</param>
        /// <param name="selectedValue">默认选则值</param>
        /// <param name="parentID">所属上级节点</param>
        /// <param name="isUsePrefix">是否需要加上前缀</param>
        /// <param name="lstCate">分类列表</param>
        public static void Bind <TInfo>(this List <TInfo> lstCate, DropDownList ddl, int selectedValue, int parentID, bool isUsePrefix = true) where TInfo : ICate, new()
        {
            ddl.Items.Clear();

            lstCate.Bind(ddl, parentID, 0, null, false, isUsePrefix);

            if (selectedValue > 0)
            {
                ddl.SelectedItems(selectedValue);
            }
        }
Ejemplo n.º 6
0
        public async Task Start() {
            serviceSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);
            serviceSocket.Bind(new IPEndPoint(IPAddress.Parse(this.Host),this.Port));
            serviceSocket.Listen(64);
            
            while (true) {
                Socket newSocket = await serviceSocket.AcceptSocketAsync();
                this.clientSocket.Add(newSocket);

                Task.Run(async()=>await Listen(newSocket));
            }
        }
Ejemplo n.º 7
0
        public void TestShouldBindNeighborsPets()
        {
            // Given

            // When
            var result = _neighbors.Bind(neighbor => neighbor.Pets).ToList();

            // Then
            Assert.AreEqual(3, result.Count);
            Assert.IsTrue(result.Contains("Fluffy"));
            Assert.IsTrue(result.Contains("Thor"));
            Assert.IsTrue(result.Contains("Sybil"));
        }
Ejemplo n.º 8
0
 public static string BindTests(int[] values)
 {
     return(values
            .Reverse()
            .Aggregate(List.Empty <int>(), (xs, x) => List.Cons(x, xs))
            .Pipe(
                List.Bind <int, string>(
                    x => x
                    .ToString()
                    .Pipe(y => $"'{x}'")
                    .ToList()
                    .Repeat(List <string> .Empty, x)))
            .ToString());
 }
Ejemplo n.º 9
0
        public void List_Nondeterminism1()
        {
            var values = new[] { 1, 2, 3, 4, };
            Func <int, List <int> > unAbs = x => new List <int>(new[] { x, -x });
            var list          = new List <int> (values);
            var results       = list.Bind <int> (unAbs);
            var resultsValues = results.Values.ToArray();

            foreach (var x in values)
            {
                Assert.Contains(x, resultsValues);
                Assert.Contains(-x, resultsValues);
            }
        }
Ejemplo n.º 10
0
        public void List_Nondeterminism2()
        {
            var values = new[] { 1, 2, };

            var list    = new List <int> (values);
            var results = list
                          .Bind <int> (x => new List <int>(new [] { x, -x, }))
                          .Bind <int> (x => new List <int>(new [] { x, x + 7, }));
            var resultsValues = results.Values.ToArray();

            foreach (var x in new [] { 1, 2, 8, 9, -1, -2, 6, 5, })
            {
                Assert.Contains(x, resultsValues);
            }
        }
Ejemplo n.º 11
0
        public async Task Start()
        {
            serviceSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);
            serviceSocket.Bind(new IPEndPoint(IPAddress.Parse(this.Host), this.Port));
            serviceSocket.Listen(64);

            while (true)
            {
                Socket newSocket = await serviceSocket.AcceptSocketAsync();

                this.clientSocket.Add(newSocket);

                Task.Run(async() => await Listen(newSocket));
            }
        }
Ejemplo n.º 12
0
        public void ShouldBindAndSelectManyBeIdentical()
        {
            IEnumerable <Subject> population = new List <Subject>()
            {
                new Subject()
                {
                    Age = Age.Of(20)
                },
                new Subject()
                {
                },
                new Subject()
                {
                    Age = Age.Of(30)
                }
            };

            var manyItems = population.SelectMany(p => p.Age.AsEnumerable()).ToArray();
            var bindItems = population.Bind(x => x.Age).ToArray();

            Assert.Equal(manyItems.Count(), bindItems.Count());

            manyItems.ForEach((item, index) => Assert.Equal(item, bindItems[index]));
        }
Ejemplo n.º 13
0
        // 4 Use Bind to implement AverageYearsWorkedAtTheCompany, shown below (only
        // employees who have left should be included).

        static double AverageYearsWorkedAtTheCompany(List <Employee> employees)
        => employees
        .Bind(e => e.LeftOn.Map(leftOn => YearsBetween(e.JoinedOn, leftOn)))
        .Average();
Ejemplo n.º 14
0
        // 4 Use Bind to implement AverageYearsWorkedAtTheCompany, shown below (only
        // employees who have left should be included).

        static double AverageYearsWorkedAtTheCompany(List <Employee> employees)
        {
            // your implementation here...
            return(employees.Bind(e => e.LeftOn.Select(left => YearsBetween(e.JoinedOn, left)))
                   .Average());
        }
Ejemplo n.º 15
0
        // 4 Use Bind to implement AverageYearsWorkedAtTheCompany, shown below (only
        // employees who have left should be included).

        // f : (IEnumerable<Employee>) -> f : (Employee -> Option<Double>) -> IEnumerable<Double>
        // f : (IEnumerable<Double> -> Double
        static double AverageYearsWorkedAtTheCompany(List <Employee> employees)
        {
            return(employees.Bind(employee => employee.LeftOn.Map(leftOn => YearsAtCompaby(employee.JoinedOn, leftOn)))
                   .Average());
        }
 public static double AverageYearsWorkedAtTheCompany(List <Employee> employees)
 {
     return(employees.Bind(x => x.LeftOn.Map(e => e.YearDiff(x.JoinedOn)))
            .Average());
 }
Ejemplo n.º 17
0
        // 4 Use Bind to implement AverageYearsWorkedAtTheCompany, shown below (only
        // employees who have left should be included).

        static double AverageYearsWorkedAtTheCompany(List <Employee> employees)
        => employees
        .Bind(GetWorkingDuration)
        .Average((x) => x.TotalDays / 365);
Ejemplo n.º 18
0
        private static void Main(string[] args)
        {
            var streamInsightAppName = ConfigurationManager.AppSettings["streamInsightAppName"];
            var streamInsightServerName = ConfigurationManager.AppSettings["streamInsightServerName"];

            var streamInsightPort = ConfigurationManager.AppSettings["streamInsightPort"];

            var serverName = ConfigurationManager.AppSettings["serverName"];

            using (var server = Microsoft.ComplexEventProcessing.Server.Create(streamInsightServerName))
            {

                var host = new ServiceHost(server.CreateManagementService());

                var managementUri = String.Format(@"http://{1}:{0}/StreamInsight/wcf/Management/", streamInsightPort, serverName);
                host.AddServiceEndpoint(typeof(IManagementService), new WSHttpBinding(SecurityMode.Message), managementUri);

                Console.WriteLine("Management URI: {0}", managementUri);
                host.Open();

                //удаляем приложение, если оно уже создано было ранее кем-то.
                if (server.Applications.ContainsKey(streamInsightAppName))
                {
                    server.Applications[streamInsightAppName].Delete();
                }
                var app = server.CreateApplication(streamInsightAppName);

                string wcfSourceUrl = String.Format(@"http://{1}:{0}/StreamInsight/wcf/Source/", streamInsightPort, serverName);

                Console.WriteLine("WCF URI: {0}", wcfSourceUrl);

                //определяем средство доставки данных клиентам.
                string signalRHubUrl = ConfigurationManager.AppSettings["signalRHubUrl"];
                var observableSink = app.DefineObserver(() => new SignalRObserver(signalRHubUrl));

                var sources = new List<IQStreamable<DiagramModelCollection>>();

                var appFabricEventQueue = new QStremableSourceNonValueEventQueue().Get(app, wcfSourceUrl);
                sources.Add(appFabricEventQueue);

                var appFabricEventValueQueue = new QStremableSourceValueEventQueue().Get(app, wcfSourceUrl);
                sources.Add(appFabricEventValueQueue);

                // var observableExceptionEventWcfSource = app.DefineObservable(() => new WCFObservable<SerializableException>(wcfSourceUrl + "ExceptionEventService", "ExceptionEventService"));

                //var query2 = from x in observableExceptionEventWcfSource
                //    .ToPointStreamable(i => PointEvent.CreateInsert<SerializableException>(DateTime.UtcNow, i), AdvanceTimeSettings.IncreasingStartTime)
                //    .TumblingWindow(TimeSpan.FromMilliseconds(30000))
                //             select x.MapEventOnDiagrams();

                //связываем источник и получатель данных
                sources.Bind(observableSink);

                host.Close();
            }
        }
Ejemplo n.º 19
0
        // 4 Use Bind to implement AverageYearsWorkedAtTheCompany, shown below (only
        // employees who have left should be included).

        static double AverageYearsWorkedAtTheCompany(List <Employee> employees)
        {
            return(employees
                   .Bind(x => x.LeftOn.Map(leaveDate => (leaveDate - x.JoinedOn).Days / 365))
                   .Average());
        }