Example #1
0
            public static bool DeletePropertyMap(Dashboard.PropertyMap newPropertyMap)
            {
                try
                {
                    var parent =
                        (from d in Client.Current.Dashboards where newPropertyMap.DashboardId == d.Id select d)
                        .FirstOrDefault();
                    if (parent == null)
                    {
                        return(false);
                    }

                    string         url     = "http://" + Settings.Current.Server + "/clent/dashboards/" + parent.PathUnit + "/visio/" + newPropertyMap.PathUnit;
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.ContentType     = "application/json";
                    request.Method          = "DELETE";
                    request.CookieContainer = _cookies;
                    request.Timeout         = 10000;
                    using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                    {
                        streamWriter.Write(JsonConvert.SerializeObject(newPropertyMap));
                    }
                    var httpResponse = (HttpWebResponse)request.GetResponse();
                    return(httpResponse.StatusCode == HttpStatusCode.OK || httpResponse.StatusCode == HttpStatusCode.Accepted);
                }
                catch { return(false); }
            }
Example #2
0
            public static Dashboard.PropertyMap CreatePropertyMap(Dashboard.PropertyMap newPropertyMap)
            {
                newPropertyMap.Id = null;
                try
                {
                    var parent =
                        (from d in Client.Current.Dashboards where newPropertyMap.DashboardId == d.Id select d)
                        .FirstOrDefault();
                    if (parent == null)
                    {
                        return(null);
                    }

                    string         url     = "http://" + Settings.Current.Server + "/clent/dashboards/" + parent.PathUnit + "/visio/";
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.ContentType = "application/json";
                    request.Method      = "POST";
                    request.Timeout     = 10000;
                    using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                    {
                        streamWriter.Write(JsonConvert.SerializeObject(newPropertyMap));
                    }
                    request.GetResponse();

                    url = url + newPropertyMap.PathUnit;

                    request = (HttpWebRequest)WebRequest.Create(url);
                    request.CookieContainer = _cookies;
                    request.Timeout         = 10000;
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    string          resp;
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                    {
                        resp = reader.ReadToEnd();
                    }
                    resp = WebUtility.HtmlDecode(resp);
                    if (string.IsNullOrWhiteSpace(resp))
                    {
                        throw new Exception("Can't get data from server");
                    }
                    return(JsonConvert.DeserializeObject <Dashboard.PropertyMap>(resp));
                }
                catch { return(null); }
            }
Example #3
0
        private static UIElement GetManagePropertyView(Property prop, Dashboard.PropertyMap plink)
        {
            var child = new StackPanel {
                Orientation = Orientation.Horizontal
            };
            var l = new Label {
                Content = prop.Name, HorizontalContentAlignment = HorizontalAlignment.Right, VerticalContentAlignment = VerticalAlignment.Center, FontSize = 14, Width = 130
            };

            l.SetResourceReference(Control.ForegroundProperty, "OnLightFontColor");
            child.Children.Add(l);
            switch ((TypeCode)prop.Type)
            {
            case TypeCode.Boolean:
                var tmp = new CheckBox {
                    Margin = new Thickness(5)
                };
                tmp.SetBinding(System.Windows.Controls.Primitives.ToggleButton.IsCheckedProperty, new Binding {
                    Source = prop, Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay
                });
                //tmp.Checked += async (s,e) =>
                //{

                //    await Task.Run(() =>
                //        { Network.IoTFactory.ModifyProperty(prop); });
                //};
                //tmp.Unchecked += async (s, e) => {
                //await Task.Run(() =>
                //{ Network.IoTFactory.ModifyProperty(prop);});
                //};
                child.Children.Add(tmp);
                break;

            case TypeCode.Int32:
            case TypeCode.Int16:
            case TypeCode.Int64:
            case TypeCode.UInt32:
            case TypeCode.UInt16:
            case TypeCode.UInt64:
                l = new Label {
                    Content = plink.Min, HorizontalContentAlignment = HorizontalAlignment.Right, VerticalContentAlignment = VerticalAlignment.Center, FontSize = 10, Margin = new Thickness(0, 0, -15, 0)
                };
                l.SetResourceReference(Control.ForegroundProperty, "OnLightFontColor");
                child.Children.Add(l);
                var sl = new Slider {
                    Minimum = plink.Min ?? 0, Maximum = plink.Max ?? 0, Width = 150, TickFrequency = 1, IsSnapToTickEnabled = true
                };
                sl.SetBinding(FrameworkElement.ToolTipProperty, new Binding("Value")
                {
                    Source = sl, Mode = BindingMode.OneWay
                });
                sl.SetBinding(System.Windows.Controls.Primitives.RangeBase.ValueProperty, new Binding {
                    Source = prop, Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay
                });
                //sl.ValueChanged+=(s,e)=> { Network.IoTFactory.ModifyProperty(prop); };
                child.Children.Add(sl);
                l = new Label {
                    Content = plink.Max, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center, FontSize = 10, Margin = new Thickness(-15, 0, 0, 0)
                };
                l.SetResourceReference(Control.ForegroundProperty, "OnLightFontColor");
                child.Children.Add(l);
                l = new Label {
                    HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center, FontSize = 12
                };
                l.SetResourceReference(Control.ForegroundProperty, "OnLightFontColor");
                l.SetBinding(ContentControl.ContentProperty, new Binding("Value")
                {
                    Source = sl, Mode = BindingMode.OneWay
                });
                child.Children.Add(l);
                break;

            case TypeCode.Double:
            case TypeCode.Decimal:
            case TypeCode.Single:
                if (plink.Min == null || plink.Max == null)
                {
                    break;
                }
                l = new Label {
                    Content = plink.Min, HorizontalContentAlignment = HorizontalAlignment.Right, VerticalContentAlignment = VerticalAlignment.Center, FontSize = 10
                };
                l.SetResourceReference(Control.ForegroundProperty, "OnLightFontColor");
                child.Children.Add(l);
                sl = new Slider {
                    Minimum = plink.Min ?? 0, Maximum = plink.Max ?? 0, Width = 150, TickFrequency = (plink.Max - plink.Min) / 100.0 ?? 0, IsSnapToTickEnabled = true
                };
                sl.SetBinding(FrameworkElement.ToolTipProperty, new Binding("Value")
                {
                    Source = sl, Mode = BindingMode.OneWay
                });
                sl.SetBinding(System.Windows.Controls.Primitives.RangeBase.ValueProperty, new Binding {
                    Source = prop, Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay
                });
                //sl.ValueChanged += (s, e) => { Network.IoTFactory.ModifyProperty(prop); };
                child.Children.Add(sl);
                l = new Label {
                    Content = plink.Max, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center, FontSize = 10, Margin = new Thickness(-15, 0, 0, 0)
                };
                l.SetResourceReference(Control.ForegroundProperty, "OnLightFontColor");
                child.Children.Add(l);
                l = new Label {
                    HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center, FontSize = 12
                };
                l.SetResourceReference(Control.ForegroundProperty, "OnLightFontColor");
                l.SetBinding(ContentControl.ContentProperty, new Binding("Value")
                {
                    Source = sl, Mode = BindingMode.OneWay
                });
                child.Children.Add(l);
                break;

            case TypeCode.String:
                var tmp1 = new TextBox {
                    Width = 100, HorizontalContentAlignment = HorizontalAlignment.Left, Margin = new Thickness(4), VerticalContentAlignment = VerticalAlignment.Center
                };
                tmp1.SetResourceReference(Control.ForegroundProperty, "OnLightFontColor");
                tmp1.SetBinding(TextBox.TextProperty, new Binding {
                    Source = prop, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay
                });

                /*
                 * TODO
                 * Придумать что-нибудь с уменьшением
                 * трафика мб на моазу лив и ентер повесить,
                 * замкнуть внешнюю переменную бул на изменение, поставить таймаут.
                 * завернуть все вызовы в другие потоки
                 */
                //tmp1.TextChanged += (s, e) => { Network.IoTFactory.ModifyProperty(prop); };
                child.Children.Add(tmp1);
                break;
            }
            return(child);
        }
Example #4
0
        private static UIElement GetPropertyView(Property prop, Dashboard.PropertyMap plink)
        {
            var child = new StackPanel {
                Orientation = Orientation.Horizontal
            };
            var l = new Label {
                Content = prop.Name, HorizontalContentAlignment = HorizontalAlignment.Right, VerticalContentAlignment = VerticalAlignment.Center, FontSize = 14, Width = 200
            };

            l.SetResourceReference(Control.ForegroundProperty, "OnLightFontColor");
            child.Children.Add(l);
            switch (prop.Type)
            {
            case 3:
                var checkBox = new CheckBox
                {
                    Style  = Application.Current.FindResource("StaticCheckBox") as Style,
                    Width  = 20,
                    Height = 20,
                    Margin = new Thickness(8)
                };
                checkBox.SetBinding(System.Windows.Controls.Primitives.ToggleButton.IsCheckedProperty,
                                    new Binding {
                    Source = prop, Path = new PropertyPath("Value"), Mode = BindingMode.OneWay
                });
                child.Children.Add(checkBox);
                break;

            case 9:
            case 7:
            case 11:
            case 10:
            case 8:
            case 12:
            case 14:
            case 15:
            case 13:
                var pb = new ProgressBar
                {
                    Width           = 150,
                    Minimum         = plink.Min ?? 0,
                    Maximum         = plink.Max ?? 0,
                    Margin          = new Thickness(4),
                    IsIndeterminate = false
                };
                pb.SetBinding(System.Windows.Controls.Primitives.RangeBase.ValueProperty,
                              new Binding {
                    Source = prop, Path = new PropertyPath("Value"), Mode = BindingMode.OneWay
                });
                pb.SetResourceReference(Control.ForegroundProperty, "MainColor");
                l = new Label
                {
                    Content = double.Parse(prop.Value),
                    HorizontalContentAlignment = HorizontalAlignment.Center,
                    VerticalContentAlignment   = VerticalAlignment.Center,
                    FontSize   = 20,
                    FontFamily = new FontFamily("Consolas")
                };
                l.SetResourceReference(Control.ForegroundProperty, "MainColor");
                l.SetBinding(ContentControl.ContentProperty,
                             new Binding {
                    Source = prop, Path = new PropertyPath("Value"), Mode = BindingMode.OneWay
                });
                child.Children.Add(pb);
                child.Children.Add(l);
                break;

            case 18:
                l = new Label
                {
                    Content = "\"" + prop.Value + "\"",
                    HorizontalContentAlignment = HorizontalAlignment.Center,
                    VerticalContentAlignment   = VerticalAlignment.Center,
                    FontSize   = 12,
                    FontFamily = new FontFamily("Consolas")
                };
                l.SetResourceReference(Control.ForegroundProperty, "OnLightFontColor");
                l.SetBinding(ContentControl.ContentProperty,
                             new Binding {
                    Source = prop, Path = new PropertyPath("Value"), Mode = BindingMode.OneWay
                });
                child.Children.Add(l);
                break;
            }
            return(child);
        }