コード例 #1
0
ファイル: PlansModule.cs プロジェクト: kib357/Ester2
        private BaseObject SavePlanObjectToDb(string id, BaseObject planObject)
        {
            BaseObject res;
            var        plan = new PlanObject();

            using (var context = new PlansDc(_esterConnectionString))
            {
                if (!string.IsNullOrEmpty(id))
                {
                    plan = GetPlanObjectById(id, context);
                }
                else
                {
                    context.PlanObjects.InsertOnSubmit(plan);
                }
                planObject.ExportToDbObject(plan, context);
                context.SubmitChanges();
                res = ServerExtensions.FromDbObject(plan);
            }
            if (_eventAggregator != null)
            {
                _eventAggregator.GetEvent <PlansModifiedEvent>().Publish(planObject);
            }
            return(res);
        }
コード例 #2
0
ファイル: PlansModule.cs プロジェクト: kib357/Ester2
        public Stream GetItemProperties(string id)
        {
            string responseBody;

            using (var context = new PlansDc(_esterConnectionString))
            {
                var res        = new List <BaseObjectProperty>();
                var plan       = GetPlanObjectById(id, context);
                var properties = context.PropertyTypes.Where(a => a.PlanObjectType == plan.PlanObjectType);
                foreach (var addressType in properties)
                {
                    var property =
                        context.Properties.FirstOrDefault(p => p.ObjectId == plan.Id && p.AddressTypeId == addressType.Id);
                    if (property != null)
                    {
                        res.Add(new BaseObjectProperty
                        {
                            Id       = property.Id,
                            Path     = property.Path,
                            TypeName = addressType.Title,
                            TypeId   = addressType.Id
                        });
                    }
                    else
                    {
                        res.Add(new BaseObjectProperty {
                            Id = 0, Path = "", TypeName = addressType.Title, TypeId = addressType.Id
                        });
                    }
                }
                responseBody = JsonConvert.SerializeObject(res, Formatting.Indented);
            }
            return(SerializeHelper.GetResponceFromString(responseBody));
        }
コード例 #3
0
        /// <summary>
        /// Процедура для обновления планов из БД
        /// </summary>
        private void OnPlansModified(BaseObject obj)
        {
            // прекращаем отправлять значения
            _pushValuesToClientTimer.Stop();

            // очищаем адреса и изменившиеся объекты
            _addresses.Clear();
            _changedValues.Clear();
            _planObjects.Clear();

            using (var plansDb = new PlansDc(_esterConnectionString))
            {
                // обновляем информцию из бд
                _rootObjects = plansDb.PlanObjects.Where(po => po.Parent == null).Select(p => ServerExtensions.FromDbObject(p)).ToList();
                foreach (var group in plansDb.Properties.GroupBy(g => g.Path))
                {
                    _addresses.Add(group.Key, group.ToList());
                }
            }

            FillPlanObjects(_planObjects, _rootObjects);

            // обновляем подписку на всех работающих провайдерах данных
            foreach (var dataProvider in _providers.Where(p => p.State == DataProviderState.Working))
            {
                dataProvider.UpdateSubscription(_addresses.Keys.ToList());
            }

            // возобновляем ход времени :)
            _pushValuesToClientTimer.Start();

            // уведомляем подписчиков о необходимости перечитать дерево целиком
            PushValuesToClients(true);
        }
コード例 #4
0
ファイル: PlansModule.cs プロジェクト: kib357/Ester2
 private void DeleteChilds(PlanObject plan, PlansDc context)
 {
     foreach (var child in plan.PlanObjects)
     {
         DeleteChilds(child, context);
         context.PlanObjects.DeleteOnSubmit(child);
     }
 }
コード例 #5
0
 private void DeleteScheduleFromDb(ScheduleClass dataBaseSchedule)
 {
     using (var context = new PlansDc(ConfigurationManager.ConnectionStrings["Ester"].ConnectionString))
     {
         var dbSch = context.Schedules.Single(s => s.ObjectId == dataBaseSchedule.Id);
         context.Schedules.DeleteOnSubmit(dbSch);
         context.SubmitChanges();
     }
 }
コード例 #6
0
ファイル: PlansModule.cs プロジェクト: kib357/Ester2
 public void Delete(string id)
 {
     using (var context = new PlansDc(_esterConnectionString))
     {
         var plan = GetPlanObjectById(id, context);
         DeleteChilds(plan, context);
         context.PlanObjects.DeleteOnSubmit(plan);
         context.SubmitChanges();
     }
 }
コード例 #7
0
ファイル: PlansModule.cs プロジェクト: kib357/Ester2
        public Stream GetAlarmLevels()
        {
            string responseBody;

            using (var context = new PlansDc(_esterConnectionString))
            {
                var units = context.PropertyAlarmLevels.ToDictionary(u => u.Id, u => u.Name);
                responseBody = JsonConvert.SerializeObject(units, Formatting.Indented);
            }
            return(SerializeHelper.GetResponceFromString(responseBody));
        }
コード例 #8
0
ファイル: PlansModule.cs プロジェクト: kib357/Ester2
        public Stream GetItem(string id)
        {
            string responseBody;

            using (var context = new PlansDc(_esterConnectionString))
            {
                var plan = GetPlanObjectById(id, context);
                responseBody = JsonConvert.SerializeObject(ServerExtensions.FromDbObject(plan), Formatting.Indented);
            }
            return(SerializeHelper.GetResponceFromString(responseBody));
        }
コード例 #9
0
ファイル: CustomAuthentication.cs プロジェクト: kib357/Ester2
 public static bool ValidateUser(string username, string password)
 {
     using (var context = new PlansDc(EsterConnectionString))
     {
         if (context.Users.Any(u => u.Login == username && u.Password == password))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #10
0
ファイル: CustomAuthentication.cs プロジェクト: kib357/Ester2
 public static bool IsUserExist(string username)
 {
     using (var context = new PlansDc(EsterConnectionString))
     {
         if (context.Users.Any(u => u.Login == username))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #11
0
 public static bool IsValidAPIKey(string key)
 {
     using (var classes = new PlansDc(EsterConnectionString))
     {
         Guid apiKey;
         if (Guid.TryParse(key, out apiKey) && classes.Users.Any(s => s.ApiKey == apiKey))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #12
0
ファイル: NewBacNetServer.cs プロジェクト: kib357/Ester2
        public NewBacNetServer(IUnityContainer container)
        {
            _container = container;

            _addresses     = new Dictionary <string, List <Address> >();
            _planObjects   = new Dictionary <int, BaseObject>();
            _changedValues = new List <BaseObject>();

            _pushValuesToClientTimer          = new Timer(5000);
            _pushValuesToClientTimer.Elapsed += PushValuesToClientTimerTick;

            _plansDb = new PlansDc(@"Data Source=192.168.0.160\SQLEXPRESS;Initial Catalog=Ester;Persist Security Info=True;User ID=sa;Password=6*!vb9%q");

            State = BacNetServerStates.Initializing;

            _rootObjects = _plansDb.PlanObjects.Where(po => po.Parent == null).Select(p => BaseObject.FromDbObject(p)).ToList();
            FillPlanObjects(_planObjects, _rootObjects);

            try
            {
                Network = new BacNet(_configSource.Configs["BacNet"].Get("Ip"));
            }
            catch (Exception)
            {
                State            = BacNetServerStates.Fault;
                StateDescription = "Cannot initialize BACnet provider, check ip address configuration.";
                return;
            }

            State = BacNetServerStates.Normal;

            foreach (var group in _plansDb.Addresses.GroupBy(g => g.Path))
            {
                if (!group.Key.Contains('.'))
                {
                    continue;
                }

                var  objAddr = group.Key.Split('.')[1].Trim();
                uint instance;
                instance = uint.TryParse(group.Key.Split('.')[0].Trim(), out instance) ? instance : 0;

                if (instance != 0 && !string.IsNullOrEmpty(objAddr))
                {
                    Network[instance].Objects[objAddr].ValueChangedEvent += OnBacnetValueChanged;
                }

                _addresses.Add(group.Key, group.ToList());
            }
            _pushValuesToClientTimer.Start();
        }
コード例 #13
0
        private List <ScheduleClass> GetSchedulesFromDataBase()
        {
            var dataBaseSchedules = new List <ScheduleClass>();

            using (var context = new PlansDc(ConfigurationManager.ConnectionStrings["Ester"].ConnectionString))
            {
                foreach (var dbSchedule in context.Schedules)
                {
                    var schedule = ConvertDbScheduleToScheduleClass(dbSchedule);
                    dataBaseSchedules.Add(schedule);
                }
            }
            return(dataBaseSchedules);
        }
コード例 #14
0
        private void EditScheduleInDataBase(ScheduleClass controllerSchedule)
        {
            Schedule newDbSchedule = ConvertScheduleClassToDbSchedule(controllerSchedule);

            using (var context = new PlansDc(ConfigurationManager.ConnectionStrings["Ester"].ConnectionString))
            {
                var dbSchedule = context.Schedules.Single(s => s.ObjectId == newDbSchedule.ObjectId);
                dbSchedule.Title = newDbSchedule.Title;
                dbSchedule.OverrideController            = newDbSchedule.OverrideController;
                dbSchedule.DeleteOnSync                  = newDbSchedule.DeleteOnSync;
                dbSchedule.SchedulesContents             = newDbSchedule.SchedulesContents;
                dbSchedule.SchedulesControlledProperties = newDbSchedule.SchedulesControlledProperties;
                context.SubmitChanges();
            }
        }
コード例 #15
0
ファイル: PlansModule.cs プロジェクト: kib357/Ester2
        private static PlanObject GetPlanObjectById(string id, PlansDc context)
        {
            int intId;

            if (!int.TryParse(id, out intId))
            {
                throw new BadRequestException("Unknown identifier format");
            }
            var plan = context.PlanObjects.FirstOrDefault(p => p.Id == intId);

            if (plan == null)
            {
                throw new BadRequestException("Object not found");
            }
            return(plan);
        }
コード例 #16
0
        private void AddScheduleToDataBase(ScheduleClass controllerSchedule)
        {
            //добавление расписания в бд
            Schedule sch = ConvertScheduleClassToDbSchedule(controllerSchedule);

            using (var context = new PlansDc(ConfigurationManager.ConnectionStrings["Ester"].ConnectionString))
            {
                var dbSch = context.Schedules.FirstOrDefault(s => s.ObjectId == sch.ObjectId);
                if (dbSch != null)
                {
                    context.Schedules.DeleteOnSubmit(dbSch);
                }
                context.Schedules.InsertOnSubmit(sch);
                context.SubmitChanges();
            }
        }
コード例 #17
0
ファイル: PlansModule.cs プロジェクト: kib357/Ester2
        public Stream GetTypeProperties(string id)
        {
            string responseBody;

            using (var context = new PlansDc(_esterConnectionString))
            {
                int intId;
                if (!int.TryParse(id, out intId))
                {
                    throw new BadRequestException("Unknown identifier format");
                }
                var res = context.PropertyTypes.Where(a => a.TypeId == intId).ToDictionary(p1 => p1.Id, p2 => p2.Title);
                responseBody = JsonConvert.SerializeObject(res, Formatting.Indented);
            }
            return(SerializeHelper.GetResponceFromString(responseBody));
        }
コード例 #18
0
ファイル: NewBacNetServer.cs プロジェクト: kib357/Ester2
        public NewBacNetServer(IUnityContainer container)
        {
            _container = container;

            _addresses = new Dictionary<string, List<Address>>();
            _planObjects = new Dictionary<int, BaseObject>();
            _changedValues = new List<BaseObject>();

            _pushValuesToClientTimer = new Timer(5000);
            _pushValuesToClientTimer.Elapsed += PushValuesToClientTimerTick;

            _plansDb = new PlansDc(@"Data Source=192.168.0.160\SQLEXPRESS;Initial Catalog=Ester;Persist Security Info=True;User ID=sa;Password=6*!vb9%q");

            State = BacNetServerStates.Initializing;

            _rootObjects = _plansDb.PlanObjects.Where(po => po.Parent == null).Select(p => BaseObject.FromDbObject(p)).ToList();
            FillPlanObjects(_planObjects, _rootObjects);

            try
            {
                Network = new BacNet(_configSource.Configs["BacNet"].Get("Ip"));
            }
            catch (Exception)
            {
                State = BacNetServerStates.Fault;
                StateDescription = "Cannot initialize BACnet provider, check ip address configuration.";
                return;
            }

            State = BacNetServerStates.Normal;

            foreach (var group in _plansDb.Addresses.GroupBy(g => g.Path))
            {
                if (!group.Key.Contains('.'))
                    continue;

                var objAddr = group.Key.Split('.')[1].Trim();
                uint instance;
                instance = uint.TryParse(group.Key.Split('.')[0].Trim(), out instance) ? instance : 0;

                if (instance != 0 && !string.IsNullOrEmpty(objAddr))
                    Network[instance].Objects[objAddr].ValueChangedEvent += OnBacnetValueChanged;

                _addresses.Add(group.Key, group.ToList());
            }
            _pushValuesToClientTimer.Start();
        }
コード例 #19
0
 public void DeleteSchedule(string id)
 {
     try
     {
         int intId = int.Parse(id);
         using (var context = new PlansDc(ConfigurationManager.ConnectionStrings["Ester"].ConnectionString))
         {
             var dbSchedule = context.Schedules.Single(s => s.ObjectId == intId);
             dbSchedule.DeleteOnSync = true;
             context.SubmitChanges();
         }
     }
     catch
     {
         throw new BadRequestException();
     }
 }
コード例 #20
0
ファイル: PlansModule.cs プロジェクト: kib357/Ester2
        public Stream Get()
        {
            string responseBody;

            using (var context = new PlansDc(_esterConnectionString))
            {
                var plans = context.PlanObjects.Where(p => p.ParentId == null);

                var res = new List <IContainerObject>();
                foreach (var planObject in plans)
                {
                    res.Add(ServerExtensions.FromDbObject(planObject) as IContainerObject);
                }
                responseBody = JsonConvert.SerializeObject(res, Formatting.Indented);
            }
            return(SerializeHelper.GetResponceFromString(responseBody));
        }
コード例 #21
0
        private int GetFreeIdForType(ScheduleTypes type)
        {
            using (var context = new PlansDc(ConfigurationManager.ConnectionStrings["Ester"].ConnectionString))
            {
                int minId = 0, maxId = 0;
                switch (type)
                {
                case ScheduleTypes.SKUD:
                    minId = (int)ScheduleClass.MinScudTypeNumber;
                    maxId = (int)ScheduleClass.MaxScudTypeNumber;
                    break;

                case ScheduleTypes.Heat:
                    minId = (int)ScheduleClass.MinHeatTypeNumber;
                    maxId = (int)ScheduleClass.MaxHeatTypeNumber;
                    break;

                case ScheduleTypes.Light:
                    minId = (int)ScheduleClass.MinLightTypeNumber;
                    maxId = (int)ScheduleClass.MaxLightTypeNumber;
                    break;

                case ScheduleTypes.AC:
                    minId = (int)ScheduleClass.MinACTypeNumber;
                    maxId = (int)ScheduleClass.MaxACTypeNumber;
                    break;

                case ScheduleTypes.Ventilation:
                    minId = (int)ScheduleClass.MinVentialtionTypeNumber;
                    maxId = (int)ScheduleClass.MaxVentialtionTypeNumber;
                    break;
                }
                var schedules = context.Schedules.Where(s => s.ObjectId >= minId && s.ObjectId <= maxId).ToList();
                for (var i = minId; i <= maxId; i++)
                {
                    if (schedules.All(s => s.ObjectId != i))
                    {
                        return(i);
                    }
                }
                return(0);
            }
        }
コード例 #22
0
 public Stream GetScheduleById(string id)
 {
     try
     {
         int intId = int.Parse(id);
         using (var context = new PlansDc(ConfigurationManager.ConnectionStrings["Ester"].ConnectionString))
         {
             var dbSchedule     = context.Schedules.Single(s => s.ObjectId == intId);
             var schedule       = ConvertDbScheduleToScheduleClass(dbSchedule);
             var myResponseBody = JsonConvert.SerializeObject(schedule);
             if (WebOperationContext.Current != null)
             {
                 WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8";
             }
             return(new MemoryStream(Encoding.UTF8.GetBytes(myResponseBody)));
         }
     }
     catch
     {
         throw new BadRequestException();
     }
 }
コード例 #23
0
ファイル: ServerExtensions.cs プロジェクト: kib357/Ester2
        public static void ExportToDbObject(this BaseObject baseObject, PlanObject dbObject, PlansDc context, int order = 0)
        {
            dbObject.Id = baseObject.Id >= 0 ? baseObject.Id : GetNewPlanObjectId(context);

            if (baseObject.ParentId != null && baseObject.ParentId >= 0)
            {
                dbObject.ParentId = baseObject.ParentId;
            }

            dbObject.Order       = order;
            dbObject.Name        = baseObject.Name;
            dbObject.Description = baseObject.Description;
            dbObject.Left        = baseObject.Left;
            dbObject.Top         = baseObject.Top;
            dbObject.Width       = baseObject.Width;
            dbObject.Height      = baseObject.Height;
            dbObject.TypeId      = baseObject.TypeId;
            if (baseObject.Path != null)
            {
                dbObject.Geometry = baseObject.Path.ToSvg();
            }

            if (baseObject.Properties != null)
            {
                dbObject.Properties.Clear();
                foreach (var baseObjectProperty in baseObject.Properties.Where(p => !string.IsNullOrWhiteSpace(p.Path)))
                {
                    var newProperty = new Property
                    {
                        AddressTypeId = baseObjectProperty.TypeId,
                        Path          = baseObjectProperty.Path
                    };
                    dbObject.Properties.Add(newProperty);
                }
            }

            if (!baseObject.IsContainer)
            {
                return;
            }

            var baseContainer = baseObject as IContainerObject;

            if (baseContainer == null)
            {
                throw new BadRequestException("Children cannot be null in ContainerObject");
            }

            for (var i = dbObject.PlanObjects.Count - 1; i >= 0; i--)
            {
                if (baseContainer.Children.All(s => s.Id != dbObject.PlanObjects[i].Id))
                {
                    dbObject.PlanObjects.RemoveAt(i);
                }
            }
            var childOrder = 0;

            foreach (var childObject in baseContainer.Children)
            {
                var dbChildObject = dbObject.PlanObjects.FirstOrDefault(p => p.Id == childObject.Id);
                if (dbChildObject == null)
                {
                    dbChildObject = new PlanObject();
                    dbObject.PlanObjects.Add(dbChildObject);
                }
                childObject.ExportToDbObject(dbChildObject, context, childOrder++);
            }
        }
コード例 #24
0
ファイル: MainWindow.xaml.cs プロジェクト: kib357/Ester2
        //private void MainWindow_OnKeyUp(object sender, KeyEventArgs e)
        //{
        //	if (e.Key == Key.F5)
        //	{
        //		var db = new PlansDc();

        //		var plan = db.PlanObjects.FirstOrDefault(w => w.Parent == null);

        //		Plan viewPlan = (Plan)BaseObject.FromDbObject(plan);
        //		DataContext = viewPlan;
        //	}
        //}

        private void LoadfromSvgClick(object sender, RoutedEventArgs e)
        {
            //Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            //dlg.DefaultExt = ".svg";
            //dlg.Filter = "SVG files (.svg)|*.svg";

            //Nullable<bool> result = dlg.ShowDialog();
            //if (result == true)
            //{
            //	// Open document
            //	string filename = dlg.FileName;
            //	var document = XDocument.Load(filename);



            //}

            var db = new PlansDc();

            #region rooms

            var r = db.PlanObjects.Single(o => o.Id == 13);
            r.Geometry = XElement.Parse("<path fill=\"none\" stroke=\"#000000\" d=\"M121.666,142.587H57.333V48.917h145.333v33 M150,142.587h52.667v-28.669 M202.667,190.418v25.666H57.333v-73.667l64.333,0.169 M202.667,163.751v-21.164H150 M202.667,81.917v-33h134.667v27M202.667,113.917v28.669h134.667v-36.336 M337.33,75.75V48.92h64v167.16h-73.12 M202.67,190.42v25.66h91.58 M337.33,106.08v36.34H202.67v21.16 M289.73,273.115c-10.943-2.66-22.605-8.908-34.397-20.7c0-21,0-36.331,0-36.331h38.917 M328.208,216.084h25.125v36.331c0,0-13.468,14.125-33.604,19.89\"/>");

            var grass = new PlanObject
            {
                Geometry =
                    XElement.Parse(
                        "<path fill=\"#52AC62\" stroke=\"#52AC62\" d=\"M0,40.654C2.667-2.635,38.667,0.032,38.667,0.032L436,0c0,0,52.667,8.033,52.667,38.032s0,284,0,284H342v-38.667l92,0.667V22.699H41.333l-1.333,250l220,0.667v48.667H0C0,322.032,0,82.699,0,40.654z\"/>"),
                Name   = "Травка",
                Parent = r,
                TypeId = 5
            };
            var r1 = new PlanObject
            {
                Geometry =
                    XElement.Parse(
                        "<path fill=\"#6CA9E0\" d=\"M337.333,142.417H202.667v-93.5h134.667V142.417z\"/>"),
                Name   = "101",
                Parent = r
                ,
                TypeId = 6
            };
            var r2 = new PlanObject
            {
                Geometry =
                    XElement.Parse(
                        "<path fill=\"#6CA9E0\" d=\"M202.667,142.587H57.333V48.917h145.333V142.587z\"/>"),
                Name   = "102",
                Parent = r,
                TypeId = 6
            };
            var r3 = new PlanObject
            {
                Geometry =
                    XElement.Parse(
                        "<path fill=\"#6CA9E0\" d=\"M202.667,216.084H57.333v-73.498h145.333V216.084z\"/>"),
                Name   = "103",
                Parent = r,
                TypeId = 6
            };
            var r4 = new PlanObject
            {
                Geometry =
                    XElement.Parse(
                        "<path fill=\"#6CA9E0\" d=\"M202.67,216.08V143h134.663l-0.003-94.08h64v167.16H202.67\"/>"),
                Name   = "104",
                Parent = r,
                TypeId = 6
            };
            var r5 = new PlanObject
            {
                Geometry =
                    XElement.Parse(
                        "<path fill=\"#6CA9E0\" d=\"M319.729,272.305l-29.998,0.81c0,0-15.23-1.99-34.397-20.7c0-17.165,0-36.331,0-36.331h98c0,0,0,22.479,0,36.331C337.063,268.188,319.729,272.305,319.729,272.305\"/>"),
                Name   = "105",
                Parent = r,
                TypeId = 6
            };

            #endregion

            db.PlanObjects.InsertOnSubmit(r1);
            db.PlanObjects.InsertOnSubmit(r2);
            db.PlanObjects.InsertOnSubmit(r3);
            db.PlanObjects.InsertOnSubmit(r4);
            db.PlanObjects.InsertOnSubmit(r5);

            //db.SubmitChanges();
        }
コード例 #25
0
 private List <ScheduleClass> GetSchedulesFromDataBase()
 {
     using (var context = new PlansDc(ConfigurationManager.ConnectionStrings["Ester"].ConnectionString))
         return(context.Schedules.Select(dbSchedule => ConvertDbScheduleToScheduleClass(dbSchedule)).ToList());
 }
コード例 #26
0
        public DataManager(IUnityContainer container)
        {
            // подписываемся на событие обновления планов через редактор
            var eventAggregator = container.Resolve <EventAggregator>();
            var eve             = eventAggregator.GetEvent <PlansModifiedEvent>();

            eve.Subscribe(OnPlansModified);

            // инициализируем переменные
            _addresses     = new Dictionary <string, List <Property> >();
            _planObjects   = new Dictionary <int, BaseObject>();
            _providers     = new List <IDataProvider>();
            _changedValues = new List <BaseObject>();

            _pushValuesToClientTimer = new Timer(PushValuesInterval)
            {
                AutoReset = true
            };
            _pushValuesToClientTimer.Elapsed += PushValuesToClientTimerOnElapsed;

            using (var plansDb = new PlansDc(_esterConnectionString))
            {
                // получаем необходимые значения из бд
                _rootObjects = plansDb.PlanObjects.Where(po => po.Parent == null).Select(p => ServerExtensions.FromDbObject(p)).ToList();
                foreach (var group in plansDb.Properties.GroupBy(g => g.Path))
                {
                    _addresses.Add(group.Key, group.ToList());
                }
            }

            FillPlanObjects(_planObjects, _rootObjects);

            // Регистрируем все имеющиеся провайдеры данных
            RegisterDataProviders();

            // формируем конфигурацию для провайдеров данных
            var config = new Dictionary <string, object>
            {
                {
                    "ConfigSource",
                    new XmlConfigSource(Path.Combine(HttpRuntime.AppDomainAppPath, @"Resources\ServerConfig.xml"))
                    {
                        AutoSave = true
                    }
                },
                {
                    "Addresses",
                    _addresses.Keys.ToList()
                }
            };

            // инициализируем провайдеры
            foreach (var dataProvider in _providers)
            {
                dataProvider.DataProviderInitializedEvent += OnDataProviderInitializedEvent;
                dataProvider.Initialize(config);
            }

            // запускаем таймер
            _pushValuesToClientTimer.Start();
        }
コード例 #27
0
ファイル: MainWindow.xaml.cs プロジェクト: kib357/Ester2
        //private void MainWindow_OnKeyUp(object sender, KeyEventArgs e)
        //{
        //    if (e.Key == Key.F5)
        //    {
        //        var db = new PlansDc();
        //        var plan = db.PlanObjects.FirstOrDefault(w => w.Parent == null);
        //        Plan viewPlan = (Plan)BaseObject.FromDbObject(plan);
        //        DataContext = viewPlan;
        //    }
        //}
        private void LoadfromSvgClick(object sender, RoutedEventArgs e)
        {
            //Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            //dlg.DefaultExt = ".svg";
            //dlg.Filter = "SVG files (.svg)|*.svg";

            //Nullable<bool> result = dlg.ShowDialog();
            //if (result == true)
            //{
            //	// Open document
            //	string filename = dlg.FileName;
            //	var document = XDocument.Load(filename);

            //}

            var db = new PlansDc();
            #region rooms

            var r = db.PlanObjects.Single(o => o.Id == 13);
            r.Geometry = XElement.Parse("<path fill=\"none\" stroke=\"#000000\" d=\"M121.666,142.587H57.333V48.917h145.333v33 M150,142.587h52.667v-28.669 M202.667,190.418v25.666H57.333v-73.667l64.333,0.169 M202.667,163.751v-21.164H150 M202.667,81.917v-33h134.667v27M202.667,113.917v28.669h134.667v-36.336 M337.33,75.75V48.92h64v167.16h-73.12 M202.67,190.42v25.66h91.58 M337.33,106.08v36.34H202.67v21.16 M289.73,273.115c-10.943-2.66-22.605-8.908-34.397-20.7c0-21,0-36.331,0-36.331h38.917 M328.208,216.084h25.125v36.331c0,0-13.468,14.125-33.604,19.89\"/>");

            var grass = new PlanObject
            {
                Geometry =
                    XElement.Parse(
                        "<path fill=\"#52AC62\" stroke=\"#52AC62\" d=\"M0,40.654C2.667-2.635,38.667,0.032,38.667,0.032L436,0c0,0,52.667,8.033,52.667,38.032s0,284,0,284H342v-38.667l92,0.667V22.699H41.333l-1.333,250l220,0.667v48.667H0C0,322.032,0,82.699,0,40.654z\"/>"),
                Name = "Травка",
                Parent = r,
                TypeId = 5
            };
            var r1 = new PlanObject
            {
                Geometry =
                    XElement.Parse(
                        "<path fill=\"#6CA9E0\" d=\"M337.333,142.417H202.667v-93.5h134.667V142.417z\"/>"),
                Name = "101",
                Parent = r
                ,
                TypeId = 6
            };
            var r2 = new PlanObject
            {
                Geometry =
                    XElement.Parse(
                        "<path fill=\"#6CA9E0\" d=\"M202.667,142.587H57.333V48.917h145.333V142.587z\"/>"),
                Name = "102",
                Parent = r,
                TypeId = 6
            };
            var r3 = new PlanObject
            {
                Geometry =
                    XElement.Parse(
                        "<path fill=\"#6CA9E0\" d=\"M202.667,216.084H57.333v-73.498h145.333V216.084z\"/>"),
                Name = "103",
                Parent = r,
                TypeId = 6
            };
            var r4 = new PlanObject
            {
                Geometry =
                    XElement.Parse(
                        "<path fill=\"#6CA9E0\" d=\"M202.67,216.08V143h134.663l-0.003-94.08h64v167.16H202.67\"/>"),
                Name = "104",
                Parent = r,
                TypeId = 6
            };
            var r5 = new PlanObject
            {
                Geometry =
                    XElement.Parse(
                        "<path fill=\"#6CA9E0\" d=\"M319.729,272.305l-29.998,0.81c0,0-15.23-1.99-34.397-20.7c0-17.165,0-36.331,0-36.331h98c0,0,0,22.479,0,36.331C337.063,268.188,319.729,272.305,319.729,272.305\"/>"),
                Name = "105",
                Parent = r,
                TypeId = 6
            };

            #endregion

            db.PlanObjects.InsertOnSubmit(r1);
            db.PlanObjects.InsertOnSubmit(r2);
            db.PlanObjects.InsertOnSubmit(r3);
            db.PlanObjects.InsertOnSubmit(r4);
            db.PlanObjects.InsertOnSubmit(r5);

            //db.SubmitChanges();
        }
コード例 #28
0
ファイル: ServerExtensions.cs プロジェクト: kib357/Ester2
        private static int GetNewPlanObjectId(PlansDc context)
        {
            var lastPlanObject = context.PlanObjects.OrderByDescending(p => p.Id).FirstOrDefault();

            return(lastPlanObject == null ? 0 : lastPlanObject.Id + 1);
        }