Beispiel #1
0
        public void CellReaction(object sender, RoutedEventArgs e)
        {
            type = Map.brush;
            switch (type)
            {
            case objects.wall:
                Background = new SolidColorBrush(Colors.Black);
                break;

            case objects.player:
                Background = new SolidColorBrush(Colors.Green);
                break;

            case objects.exit:
                Background = new SolidColorBrush(Colors.Red);
                break;

            case objects.empty:
                Background = new SolidColorBrush(Colors.White);
                break;

            default:
                break;
            }
        }
Beispiel #2
0
        public void AddAuto()
        {
            var nums = (from a in db.auto
                        select a.num).ToList();

            foreach (string num in nums)
            {
                if (num == this.num.ToUpper())
                {
                    throw new Exception("Данный автомобиль уже зарегестрирован в базе");
                }
            }
            int     new_id = db.objects.Max(n => n.id_o) + 1;
            objects obj    = new objects {
                id_o = new_id, type_o = "a"
            };
            auto auto = new auto
            {
                id_a   = new_id,
                model  = model,
                num    = num.ToUpper(),
                year_a = year
            };

            db.objects.Add(obj);
            db.auto.Add(auto);
            db.SaveChanges();
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                ofd.InitialDirectory = _lastPath;
                ofd.Filter = "iSpy Files (*.ispy)|*.ispy|XML Files (*.xml)|*.xml";
                if (ofd.ShowDialog(this) == DialogResult.OK)
                {
                    string fileName = ofd.FileName;
                    try
                    {
                        var fi = new FileInfo(fileName);
                        _lastPath = fi.DirectoryName;
                    }
                    catch
                    {
                    }

                    if (fileName.Trim() != "")
                    {

                        try
                        {
                            _c = MainForm.GetObjects(fileName.Trim());
                            ListObjects(_c);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, LocRm.GetString("Error"));
                        }
                    }
                }
            }
        }
Beispiel #4
0
 public objects.Card Defence(objects.Card card, objects.Suits suit)
 {
     if (card.Suit == suit)
     {
         foreach (objects.Card c in _hand)
         {
             if (c.Suit == suit && c.Number > card.Number)
             {
                 _hand.Remove(c);
                 return c;
             }
         }
         return null;
     }
     else
     {
         foreach (objects.Card c in _hand)
         {
             if ((c.Suit == card.Suit && c.Number > card.Number) || (c.Suit == suit))
             {
                 _hand.Remove(c);
                 return c;
             }
         }
         return null;
     }
 }
Beispiel #5
0
 private void ListObjects(objects c)
 {
     clbAdd.Items.Clear();
     foreach (var cam in c.cameras)
     {
         clbAdd.Items.Add(new clb(cam));
     }
 }
Beispiel #6
0
 public VisibleObject(int x, int y, objects t)
 {
     coordX            = x;
     coordY            = y;
     type              = t;
     Click            += CellReaction;
     PreviewMouseDown += methodeMouseDown;
     PreviewMouseUp   += methodeMouseUp;
 }
 AddOperations(objects, bulkUpdateSelector, o => new BulkUpdateDescriptor <T, TPartialDocument>().IdFrom(o));
        public string Delete(string token)
        {
            //int objectId, int userId, bool final

            string message = "";



            token = TokenManager.readToken(HttpContext.Current.Request);
            var strP = TokenManager.GetPrincipal(token);

            if (strP != "0") //invalid authorization
            {
                return(TokenManager.GenerateToken(strP));
            }
            else
            {
                int  objectId = 0;
                int  userId   = 0;
                bool final    = false;

                IEnumerable <Claim> claims = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "objectId")
                    {
                        objectId = int.Parse(c.Value);
                    }
                    else if (c.Type == "userId")
                    {
                        userId = int.Parse(c.Value);
                    }
                    else if (c.Type == "final")
                    {
                        final = bool.Parse(c.Value);
                    }
                }

                if (final)
                {
                    try
                    {
                        using (incposdbEntities entity = new incposdbEntities())
                        {
                            objects Deleterow = entity.objects.Find(objectId);
                            entity.objects.Remove(Deleterow);
                            message = entity.SaveChanges().ToString();
                            //  return Ok("OK");
                            return(TokenManager.GenerateToken(message));

                            // return Ok("OK");
                        }
                    }
                    catch
                    {
                        return(TokenManager.GenerateToken("0"));
                    }
                }
                else
                {
                    try
                    {
                        using (incposdbEntities entity = new incposdbEntities())
                        {
                            objects Obj = entity.objects.Find(objectId);
                            Obj.isActive     = 0;
                            Obj.updateUserId = userId;
                            Obj.updateDate   = DateTime.Now;
                            message          = entity.SaveChanges().ToString();
                            //  return Ok("OK");
                            return(TokenManager.GenerateToken(message));
                        }
                    }
                    catch
                    {
                        return(TokenManager.GenerateToken("0"));
                    }
                }
            }



            //var re = Request;
            //var headers = re.Headers;
            //string token = "";
            //if (headers.Contains("APIKey"))
            //{
            //    token = headers.GetValues("APIKey").First();
            //}

            //Validation validation = new Validation();
            //bool valid = validation.CheckApiKey(token);
            //if (valid)
            //{

            //    if (final)
            //    {
            //        try
            //        {
            //            using (incposdbEntities entity = new incposdbEntities())
            //            {

            //                objects Deleterow = entity.objects.Find(objectId);
            //                entity.objects.Remove(Deleterow);
            //                entity.SaveChanges();
            //                return Ok("OK");
            //            }
            //        }
            //        catch
            //        {
            //            return NotFound();
            //        }
            //    }
            //    else
            //    {
            //        try
            //        {
            //            using (incposdbEntities entity = new incposdbEntities())
            //            {

            //                objects Obj = entity.objects.Find(objectId);
            //                Obj.isActive = 0;
            //                Obj.updateUserId = userId;
            //                Obj.updateDate = DateTime.Now;
            //                entity.SaveChanges();
            //                return Ok("Ok");
            //            }
            //        }
            //        catch
            //        {
            //            return NotFound();
            //        }
            //    }



            //}
            //else
            //    return NotFound();
        }
        public String Save(string token)
        {
            //string Object
            string message = "";



            token = TokenManager.readToken(HttpContext.Current.Request);
            var strP = TokenManager.GetPrincipal(token);

            if (strP != "0") //invalid authorization
            {
                return(TokenManager.GenerateToken(strP));
            }
            else
            {
                string              Object    = "";
                objects             newObject = null;
                IEnumerable <Claim> claims    = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "Object")
                    {
                        Object    = c.Value.Replace("\\", string.Empty);
                        Object    = Object.Trim('"');
                        newObject = JsonConvert.DeserializeObject <objects>(Object, new IsoDateTimeConverter {
                            DateTimeFormat = "dd/MM/yyyy"
                        });
                        break;
                    }
                }
                if (newObject != null)
                {
                    //   bondes tmpObject = null;


                    try
                    {
                        if (newObject.updateUserId == 0 || newObject.updateUserId == null)
                        {
                            Nullable <int> id = null;
                            newObject.updateUserId = id;
                        }
                        if (newObject.createUserId == 0 || newObject.createUserId == null)
                        {
                            Nullable <int> id = null;
                            newObject.createUserId = id;
                        }
                        using (incposdbEntities entity = new incposdbEntities())
                        {
                            var sEntity = entity.Set <objects>();
                            if (newObject.objectId == 0)
                            {
                                newObject.createDate   = DateTime.Now;
                                newObject.updateDate   = DateTime.Now;
                                newObject.updateUserId = newObject.createUserId;
                                sEntity.Add(newObject);
                                entity.SaveChanges();
                                message = newObject.objectId.ToString();
                            }
                            else
                            {
                                var tmps = entity.objects.Where(p => p.objectId == newObject.objectId).FirstOrDefault();

                                tmps.objectId = newObject.objectId;
                                tmps.name     = newObject.name;
                                tmps.note     = newObject.note;
                                tmps.note     = newObject.note;

                                tmps.createDate     = newObject.createDate;
                                tmps.updateDate     = DateTime.Now;// server current date
                                tmps.parentObjectId = newObject.parentObjectId;
                                tmps.objectType     = newObject.objectType;
                                tmps.updateUserId   = newObject.updateUserId;
                                entity.SaveChanges();
                                message = tmps.objectId.ToString();
                            }
                        }
                        // return message; ;
                        return(TokenManager.GenerateToken(message));
                    }
                    catch
                    {
                        message = "0";
                        return(TokenManager.GenerateToken(message));
                    }
                }

                return(TokenManager.GenerateToken(message));
            }


            //var re = Request;
            //var headers = re.Headers;
            //string token = "";
            //string message ="";
            //if (headers.Contains("APIKey"))
            //{
            //    token = headers.GetValues("APIKey").First();
            //}
            //Validation validation = new Validation();
            //bool valid = validation.CheckApiKey(token);

            //if (valid)
            //{
            //    newObject = newObject.Replace("\\", string.Empty);
            //    newObject = newObject.Trim('"');
            //    objects Object = JsonConvert.DeserializeObject<objects>(newObject, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None });
            //    try
            //    {


            //        if (Object.updateUserId == 0 || Object.updateUserId == null)
            //        {
            //            Nullable<int> id = null;
            //            Object.updateUserId = id;
            //        }
            //        if (Object.createUserId == 0 || Object.createUserId == null)
            //        {
            //            Nullable<int> id = null;
            //            Object.createUserId = id;
            //        }
            //        using (incposdbEntities entity = new incposdbEntities())
            //        {
            //            var sEntity = entity.Set<objects>();
            //            if (Object.objectId == 0)
            //            {
            //                Object.createDate = DateTime.Now;
            //                Object.updateDate = DateTime.Now;
            //                Object.updateUserId = Object.createUserId;
            //                sEntity.Add(Object);
            //                entity.SaveChanges();
            //                 message = Object.objectId.ToString();
            //            }
            //            else
            //            {

            //                var tmps = entity.objects.Where(p => p.objectId == Object.objectId).FirstOrDefault();

            //                tmps.objectId=Object.objectId;
            //                tmps.name = Object.name;
            //                tmps.note = Object.note;
            //                tmps.note=Object.note;

            //                tmps.createDate=Object.createDate;
            //                tmps.updateDate = DateTime.Now;// server current date
            //                tmps.parentObjectId = Object.parentObjectId;
            //                tmps.objectType = Object.objectType;
            //                tmps.updateUserId = Object.updateUserId;
            //                entity.SaveChanges();
            //                message = tmps.objectId.ToString();
            //            }


            //        }
            //        return message; ;
            //    }

            //    catch
            //    {
            //        return "-1";
            //    }
            //}
            //else
            //    return "-1";
        }
Beispiel #10
0
 public static void WriteComponent(List <object> objects, byte *memory, in T component) => _writeComponentAction(objects, memory, component);
Beispiel #11
0
 private void ListObjects(objects c)
 {
     clbAdd.Items.Clear();
     foreach (var cam in c.cameras)
     {
         clbAdd.Items.Add(new clb(cam));
     }
 }
Beispiel #12
0
        private void SaveObjects(string fileName)
        {
            if (_shuttingDown)
                return;

            if (fileName == "")
                fileName = Program.AppDataPath + @"XML\objects.xml";
            var c = new objects { Version = Convert.ToInt32(Application.ProductVersion.Replace(".", "")), actions = new objectsActions {entries = _actions.ToArray()} };
            foreach (objectsCamera oc in Cameras)
            {
                CameraWindow occ = GetCameraWindow(oc.id);
                if (occ != null)
                {
                    oc.width = occ.Width;
                    oc.height = occ.Height;
                    oc.x = occ.Location.X;
                    oc.y = occ.Location.Y;
                }
            }
            c.cameras = Cameras.ToArray();
            foreach (objectsMicrophone om in Microphones)
            {
                VolumeLevel omc = GetVolumeLevel(om.id);
                if (omc != null)
                {
                    om.width = omc.Width;
                    om.height = omc.Height;
                    om.x = omc.Location.X;
                    om.y = omc.Location.Y;
                }
            }
            c.microphones = Microphones.ToArray();
            foreach (objectsFloorplan of in FloorPlans)
            {
                FloorPlanControl fpc = GetFloorPlan(of.id);
                if (fpc != null)
                {
                    of.width = fpc.Width;
                    of.height = fpc.Height;
                    of.x = fpc.Location.X;
                    of.y = fpc.Location.Y;
                }
            }
            c.floorplans = FloorPlans.ToArray();
            c.remotecommands = RemoteCommands.ToArray();
            lock (ThreadLock)
            {
                var s = new XmlSerializer(typeof(objects));
                var sb = new StringBuilder();
                using (var writer = new StringWriter(sb))
                {
                    try
                    {
                        s.Serialize(writer, c);
                        File.WriteAllText(fileName, sb.ToString(), Encoding.UTF8);
                    }
                    catch (Exception e)
                    {
                        LogExceptionToFile(e);
                    }
                }
            }
        }
Beispiel #13
0
        private void SaveObjects(string fileName)
        {
            if (fileName == "")
                fileName = Program.AppDataPath + @"XML\objects.xml";
            var c = new objects();
            foreach (objectsCamera oc in Cameras)
            {
                CameraWindow occ = GetCameraWindow(oc.id);
                if (occ != null)
                {
                    oc.width = occ.Width;
                    oc.height = occ.Height;
                    oc.x = occ.Location.X;
                    oc.y = occ.Location.Y;
                    //occ.SaveFileList();
                }
            }
            c.cameras = Cameras.ToArray();
            foreach (objectsMicrophone om in Microphones)
            {
                VolumeLevel omc = GetMicrophone(om.id);
                if (omc != null)
                {
                    om.width = omc.Width;
                    om.height = omc.Height;
                    om.x = omc.Location.X;
                    om.y = omc.Location.Y;
                    //omc.SaveFileList();
                }
            }
            c.microphones = Microphones.ToArray();
            foreach (objectsFloorplan of in FloorPlans)
            {
                FloorPlanControl fpc = GetFloorPlan(of.id);
                if (fpc != null)
                {
                    of.width = fpc.Width;
                    of.height = fpc.Height;
                    of.x = fpc.Location.X;
                    of.y = fpc.Location.Y;
                }
            }
            c.floorplans = FloorPlans.ToArray();
            c.remotecommands = RemoteCommands.ToArray();

            var s = new XmlSerializer(typeof(objects));
            using (var fs = new FileStream(fileName, FileMode.Create))
            {
                using (TextWriter writer = new StreamWriter(fs))
                {
                    fs.Position = 0;
                    s.Serialize(writer, c);

                    writer.Close();
                }
                fs.Close();
            }
        }
Beispiel #14
0
 public void CardToHand(objects.Card card)
 {
     _hand.Add(card);
 }
Beispiel #15
0
 public void OnDone(objects sender, string result)
 {
     Console.WriteLine(result);
 }
Beispiel #16
0
        public void Delete(DataGridView dataGridView, int activeTable)
        {
            try
            {
                if (dataGridView.SelectedCells.Count == 1)
                {
                    switch (activeTable)
                    {
                    case (1):
                    case (2):
                    {
                        List <users> query = (from us in db.users
                                              select us).ToList();
                        users   item = query.First(n => n.id_u.ToString() == dataGridView.SelectedCells[0].OwningRow.Cells[0].Value.ToString());
                        objects obj  = (from o in db.objects
                                        where o.id_o == item.id_u
                                        select o).First();
                        if (MessageBox.Show("Вы уверены?", "Удаление", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            db.users.Remove(item);
                            db.objects.Remove(obj);
                            db.SaveChanges();
                        }
                        break;
                    }

                    case (3):
                    {
                        List <auto> query = (from au in db.auto
                                             select au).ToList();
                        auto    item = query.First(n => n.id_a.ToString() == dataGridView.SelectedCells[0].OwningRow.Cells[0].Value.ToString());
                        objects obj  = (from o in db.objects
                                        where o.id_o == item.id_a
                                        select o).First();
                        if (MessageBox.Show("Вы уверены?", "Удаление", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            db.auto.Remove(item);
                            db.objects.Remove(obj);
                            db.SaveChanges();
                        }
                        break;
                    }

                    case (4):
                    {
                        List <payment> query = (from p in db.payment
                                                select p).ToList();
                        payment item = query.First(n => n.id_p.ToString() == dataGridView.SelectedCells[0].OwningRow.Cells[0].Value.ToString());
                        if (MessageBox.Show("Вы уверены?", "Удаление", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            db.payment.Remove(item);
                            db.SaveChanges();
                        }
                        break;
                    }
                    }
                }
            }
            catch
            {
                MessageBox.Show("Ошибка удаления данных");
            }
        }
Beispiel #17
0
 objects[index].SetParent(objects[parent], false);
    static void Main()
    {
        int width = 22;
        int height = 13;
        Console.SetWindowSize(width, height);
        Console.SetBufferSize(width, height);

        int playground = width - 1;

        List<objects> rocks = new List<objects>();
        List<objects> moreRocks = new List<objects>();
        Random rocksGenerator = new Random();
        char[] rockChars = "^@*&+%$#!.;".ToCharArray();

        objects dwarf = new objects();
        dwarf.x = playground / 2;
        dwarf.y = height - 1;
        dwarf.c = '0';


        while (true)
        {
            for (int i = 0; i < rocks.Count; i++)
            {
                objects newRock = rocks[i];
                newRock.y++;
                rocks.Remove(rocks[i]);
                moreRocks.Add(newRock);
            }

            int rocksNumber = rocksGenerator.Next(1, 8);
            for (int j = 0; j < rocksNumber; j++)
            {
                objects newRock = new objects();
                newRock.y = 0;
                newRock.x = rocksGenerator.Next(0, playground);
                int r = rocksGenerator.Next(rockChars.Length);
                newRock.c = rockChars[r];
                rocks.Add(newRock);
            }

            while (Console.KeyAvailable)
            {
                ConsoleKeyInfo key = Console.ReadKey(true);
                while (Console.KeyAvailable)
                {
                    Console.ReadKey(true);
                }
                if ((key.Key == ConsoleKey.LeftArrow) && (dwarf.x != 0))
                {
                    dwarf.x--;
                }
                else if ((key.Key == ConsoleKey.RightArrow) && (dwarf.x != playground - 1))
                {
                    dwarf.x++;
                }
            }
            Console.Clear();
            PrintOnPosition(dwarf.x, dwarf.y, dwarf.c);

            foreach (objects newRock in moreRocks)
            {
                PrintOnPosition(newRock.x, newRock.y, newRock.c);
            }

            moreRocks.Clear();

            Thread.Sleep(500);

            
        }









    //    // fortmat the console
        //int width = 41;
        //int height = 13;
        //Console.SetWindowSize(width, height);
        //Console.SetBufferSize(width, height + 2);
        //Console.CursorVisible = false;
        //Console.SetCursorPosition(0, 0);
    //    //-----

    //    string hero = "                    0                    ";
    //    Console.Write("\n\n\n\n\n\n\n\n\n\n\n\n\n" + hero);

    //    //while (true)
    //    //{
    //    //    ConsoleKeyInfo key = Console.ReadKey(true);
    //    //    int action = (int)key.Key;
    //    //    if (action == 37)
    //    //    {
    //    //        hero = hero.Remove(0, 1);
    //    //        hero = hero + " ";
    //    //        Console.Clear();
    //    //        Console.Write("\n\n\n\n\n\n\n\n\n\n\n\n\n" + hero);
    //    //    }
    //    //    if (action == 39)
    //    //    {
    //    //        hero = hero.Remove(40, 1);
    //    //        hero = " " + hero;
    //    //        Console.Clear();
    //    //        Console.Write("\n\n\n\n\n\n\n\n\n\n\n\n\n" + hero);
    //    //    }
    //    //}

    //    //generator-rocks, gravity: on
    //    string[] rocks = new string[15];
    //    var chars = "^@*&+%$#!.;                                                                                                                        ";
    //    var stringChars = new char[41];
    //    var random = new Random();

    //    while (true)
    //    {
    //        for (int i = 0; i < stringChars.Length; i++)
    //        {
    //            stringChars[i] = chars[random.Next(chars.Length)];
    //        }

    //        rocks[0] = new String(stringChars);

    //        for (int i = 12; i >= 1; i--)
    //        {
    //            rocks[i] = rocks[i - 1];
    //        }
    //        for (int i = 1; i <= 12; i++)
    //        {
    //            Console.Write(rocks[i]);
    //        }
    //        Thread.Sleep(150);
    //        Console.Clear();

    //        //ConsoleKeyInfo key = Console.ReadKey(true);
    //        //int action = (int)key.Key;
    //        //if (action == 37)
    //        //{
    //        //    hero = hero.Remove(0, 1);
    //        //    hero = hero + " ";
    //        //    Console.Clear();
    //        //    Console.Write(hero);
    //        //}
    //        //if (action == 39)
    //        //{
    //        //    hero = hero.Remove(40, 1);
    //        //    hero = " " + hero;
    //        //    Console.Clear();
    //        //    Console.Write(hero);
    //        //}
    //    }
    //    //-----


    }
Beispiel #19
0
        public static objects GetObjects(string path)
        {
            var c = new objects();
            try
            {
                lock (ThreadLock)
                {
                    using (var fs = new FileStream(path, FileMode.Open))
                    {
                        var s = new XmlSerializer(typeof (objects));
                        using (TextReader reader = new StreamReader(fs))
                        {
                            fs.Position = 0;
                            c = (objects) s.Deserialize(reader);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogExceptionToFile(ex);
                switch (MessageBox.Show($"Error loading file ({ex.Message}) Try again?", "Error", MessageBoxButtons.YesNo))
                {
                    case DialogResult.Yes:
                        return GetObjects(path);
                }
            }

            if (c.cameras==null)
                c.cameras = new objectsCamera[] {};

            bool addActions = c.actions?.entries == null;
            if (addActions)
                c.actions = new objectsActions {entries = new objectsActionsEntry[] {}};

            if (c.cameras.Select(oc => oc.settings.desktopresizewidth).Any(rw => rw == 0))
            {
                throw new Exception("err_old_config");
            }

            if (c.microphones==null)
                c.microphones = new objectsMicrophone[] {};
            if (c.floorplans == null)
                c.floorplans = new objectsFloorplan[] {};

            if (c.remotecommands == null)
                c.remotecommands = new objectsCommand[] {};

            if (c.remotecommands.Length == 0)
            {
                c.remotecommands = GenerateRemoteCommands();
            }

            bool bVlc = VlcHelper.VlcInstalled;

            bool bAlertVlc = false;
            int camid = 0;
            string path2;
            //load non clones first
            c.cameras = c.cameras.ToList().OrderByDescending(p => p.settings.sourceindex != 10).ToArray();
            c.microphones = c.microphones.ToList().OrderByDescending(p => p.settings.typeindex != 5).ToArray();

            foreach (objectsCamera cam in c.cameras)
            {
                if (cam.id >= camid)
                    camid = cam.id + 1;

                path2 = Helper.GetMediaDirectory(cam.settings.directoryIndex) + "video\\" + cam.directory + "\\";
                if (cam.settings.sourceindex == 5 && !bVlc)
                {
                    bAlertVlc = true;
                }
                if (cam.settings.youtube == null)
                {
                    cam.settings.youtube = new objectsCameraSettingsYoutube
                            {
                                category = Conf.YouTubeDefaultCategory,
                                tags = "iSpy, Motion Detection, Surveillance",
                                @public = true
                            };
                }
                if (cam.ptzschedule == null)
                {
                    cam.ptzschedule = new objectsCameraPtzschedule
                            {
                                active = false,
                                entries = new objectsCameraPtzscheduleEntry[] {}
                            };
                }
                if (cam.settings.storagemanagement == null)
                {
                    cam.settings.storagemanagement = new objectsCameraSettingsStoragemanagement
                            {
                                enabled = false,
                                maxage = 72,
                                maxsize = 1024

                            };
                }
                bool migrate = false;
                if (cam.alertevents == null)
                {
                    cam.alertevents = new objectsCameraAlertevents();
                    migrate = true;
                }

                if (cam.settings.cloudprovider==null)
                    cam.settings.cloudprovider = new objectsCameraSettingsCloudprovider();

                if (cam.alertevents.entries == null)
                    cam.alertevents.entries = new objectsCameraAlerteventsEntry[] {};

                if (migrate)
                {
                    var l = new List<objectsCameraAlerteventsEntry>();
                    if (!string.IsNullOrEmpty(cam.alerts.executefile))
                    {
                        l.Add(new objectsCameraAlerteventsEntry
                                {
                                    type = "Exe",
                                    param1 = cam.alerts.executefile,
                                    param2 = cam.alerts.arguments
                                });
                    }
                    if (cam.notifications.sendemail)
                    {
                        l.Add(new objectsCameraAlerteventsEntry
                                {
                                    type = "E",
                                    param1 = cam.settings.emailaddress,
                                    param2 = "True"
                                });
                    }
                    if (cam.notifications.sendsms)
                    {
                        l.Add(new objectsCameraAlerteventsEntry {type = "SMS", param1 = cam.settings.smsnumber});
                    }
                    if (cam.alerts.maximise)
                    {
                        l.Add(new objectsCameraAlerteventsEntry {type = "M"});
                    }
                    if (!string.IsNullOrEmpty(cam.alerts.playsound))
                    {
                        l.Add(new objectsCameraAlerteventsEntry {type = "S", param1 = cam.alerts.playsound});
                    }

                    string[] alertOptions = cam.alerts.alertoptions.Split(','); //beep,restore

                    if (Convert.ToBoolean(alertOptions[0]))
                        l.Add(new objectsCameraAlerteventsEntry {type = "B"});
                    if (Convert.ToBoolean(alertOptions[1]))
                        l.Add(new objectsCameraAlerteventsEntry {type = "SW"});

                    if (cam.notifications.sendtwitter)
                    {
                        l.Add(new objectsCameraAlerteventsEntry {type = "TM"});
                    }

                    if (!string.IsNullOrEmpty(cam.alerts.trigger))
                    {
                        l.Add(new objectsCameraAlerteventsEntry {type = "TA", param1 = cam.alerts.trigger});
                    }
                    cam.alertevents.entries = l.ToArray();

                }

                if (addActions)
                {
                    var l = c.actions.entries.ToList();
                    l.AddRange(cam.alertevents.entries.Select(a => new objectsActionsEntry
                                                                    {
                                                                        mode = "alert",
                                                                        objectid = cam.id,
                                                                        objecttypeid = 2,
                                                                        type = a.type,
                                                                        param1 = a.param1,
                                                                        param2 = a.param2,
                                                                        param3 = a.param3,
                                                                        param4 = a.param4
                                                                    }));
                    if (!string.IsNullOrEmpty(cam.settings.emailondisconnect))
                    {
                        l.Add(new objectsActionsEntry
                        {
                            mode = "disconnect",
                            objectid = cam.id,
                            objecttypeid = 2,
                            type = "E",
                            param1 = cam.settings.emailondisconnect,
                            param2 = "False"
                        });
                    }
                    c.actions.entries = l.ToArray();
                }

                cam.newrecordingcount = 0;
                if (cam.settings.maxframerate == 0)
                    cam.settings.maxframerate = 10;
                if (cam.settings.maxframeraterecord == 0)
                    cam.settings.maxframeraterecord = 10;
                if (cam.settings.timestampfontsize == 0)
                    cam.settings.timestampfontsize = 10;
                if (cam.recorder.timelapsesave == 0)
                    cam.recorder.timelapsesave = 60;

                if (cam.x < 0)
                    cam.x = 0;
                if (cam.y < 0)
                    cam.y = 0;

                if (cam.detector.minwidth == 0)
                {
                    cam.detector.minwidth = 20;
                    cam.detector.minheight = 20;
                    cam.detector.highlight = true;
                    cam.settings.reconnectinterval = 0;
                }
                if (cam.settings.accessgroups == null)
                    cam.settings.accessgroups = "";
                if (cam.settings.ptztimetohome == 0)
                    cam.settings.ptztimetohome = 100;
                if (cam.settings.ptzautohomedelay == 0)
                    cam.settings.ptzautohomedelay = 30;
                if (cam.settings.ptzurlbase == null)
                    cam.settings.ptzurlbase = "";
                if (cam.settings.audioport <= 0)
                    cam.settings.audioport = 80;
                if (cam.ftp.intervalnew < 0)
                    cam.ftp.intervalnew = cam.ftp.interval;

                if (cam.ftp.server.Length>10)
                {
                    var ftp = Conf.FTPServers.FirstOrDefault(p => p.name == cam.ftp.server && p.username==cam.ftp.username);
                    if (ftp == null)
                    {
                        ftp = new configurationServer
                                {
                                    ident = Guid.NewGuid().ToString(),
                                    name=cam.ftp.server,
                                    password = cam.ftp.password,
                                    port = cam.ftp.port,
                                    rename = cam.ftp.rename,
                                    server = cam.ftp.server,
                                    usepassive = cam.ftp.usepassive,
                                    username = cam.ftp.username
                                };
                        var l = Conf.FTPServers.ToList();
                        l.Add(ftp);
                        Conf.FTPServers = l.ToArray();
                        cam.ftp.ident = ftp.ident;
                        cam.ftp.server = "";
                    }
                }

                if (Conf.MediaDirectories.FirstOrDefault(p => p.ID == cam.settings.directoryIndex) == null)
                    cam.settings.directoryIndex = Conf.MediaDirectories.First().ID;

                if (string.IsNullOrEmpty(cam.settings.emailondisconnect))
                {
                    if (cam.settings.notifyondisconnect)
                    {
                        cam.settings.emailondisconnect = cam.settings.emailaddress;
                    }
                }

                cam.detector.type = cam.detector.type.Replace("Modelling", "Modeling");//fix typo

                if (cam.recorder.quality == 0)
                    cam.recorder.quality = 8;
                if (cam.recorder.timelapseframerate == 0)
                    cam.recorder.timelapseframerate = 5;

                if (cam.detector.movementintervalnew < 0)
                    cam.detector.movementintervalnew = cam.detector.movementinterval;

                if (cam.detector.nomovementintervalnew < 0)
                    cam.detector.nomovementintervalnew = cam.detector.nomovementinterval;

                if (cam.directory == null)
                    throw new Exception("err_old_config");

                if (string.IsNullOrEmpty(cam.settings.ptzpelcoconfig))
                    cam.settings.ptzpelcoconfig = "COM1|9600|8|One|Odd|1";

                if (cam.savelocal == null)
                {
                    cam.savelocal = new objectsCameraSavelocal
                                    {
                                        counter = cam.ftp.counter,
                                        countermax = cam.ftp.countermax,
                                        mode = cam.ftp.mode,
                                        enabled = cam.ftp.savelocal,
                                        filename = cam.ftp.localfilename,
                                        intervalnew = cam.ftp.intervalnew,
                                        minimumdelay = cam.ftp.minimumdelay,
                                        quality = cam.ftp.quality,
                                        text = cam.ftp.text

                                    };
                }

                if (cam.alerts.processmode == null)
                    cam.alerts.processmode = "continuous";
                if (cam.alerts.pluginconfig == null)
                    cam.alerts.pluginconfig = "";
                if (cam.ftp.quality == 0)
                    cam.ftp.quality = 75;

                if (cam.ftp.countermax == 0)
                    cam.ftp.countermax = 20;

                if (cam.settings.audiousername == null)
                {
                    cam.settings.audiousername = "";
                    cam.settings.audiopassword = "";
                }

                if (string.IsNullOrEmpty(cam.settings.timestampforecolor) || cam.settings.timestampforecolor == "0")
                {
                    cam.settings.timestampforecolor = "255,255,255";
                }

                if (string.IsNullOrEmpty(cam.settings.timestampbackcolor) || cam.settings.timestampbackcolor == "0")
                {
                    cam.settings.timestampbackcolor = "70,70,70";
                }

                if (Math.Abs(cam.detector.minsensitivity - 0) < double.Epsilon)
                {
                    cam.detector.maxsensitivity = 100;
                    //fix for old setting conversion
                    cam.detector.minsensitivity = 100 - cam.detector.sensitivity;

                    if (Math.Abs(cam.detector.minsensitivity - 100) < double.Epsilon)
                    {
                        cam.detector.minsensitivity = 20;
                    }
                }

                if (cam.detector.minsensitivity > cam.detector.maxsensitivity)
                {
                    //reset
                    cam.detector.maxsensitivity = 100;
                    cam.detector.minsensitivity = 20;
                }

                if (!Directory.Exists(path2))
                {
                    try
                    {
                        Directory.CreateDirectory(path2);
                    }
                    catch (IOException e)
                    {
                        LogExceptionToFile(e);
                    }
                }

                if (string.IsNullOrEmpty(cam.ftp.localfilename))
                {
                    cam.ftp.localfilename = "{0:yyyy-MM-dd_HH-mm-ss_fff}.jpg";
                }

                if (string.IsNullOrEmpty(cam.settings.audiomodel))
                    cam.settings.audiomodel = "None";

                if (string.IsNullOrEmpty(cam.settings.timestampfont))
                {
                    cam.settings.timestampfont = FontXmlConverter.ConvertToString(Drawfont);
                    cam.settings.timestampshowback = true;
                }

                path2 = Helper.GetMediaDirectory(cam.settings.directoryIndex) + "video\\" + cam.directory + "\\thumbs\\";
                if (!Directory.Exists(path2))
                {
                    try
                    {
                        Directory.CreateDirectory(path2);
                    }
                    catch
                    {
                        // ignored
                    }
                }

                path2 = Helper.GetMediaDirectory(cam.settings.directoryIndex) + "video\\" + cam.directory + "\\grabs\\";
                if (!Directory.Exists(path2))
                {
                    try
                    {
                        Directory.CreateDirectory(path2);
                    }
                    catch
                    {
                        // ignored
                    }
                }
                if (cam.alerts.trigger == null)
                    cam.alerts.trigger = "";

                if (string.IsNullOrEmpty(cam.rotateMode))
                {
                    cam.rotateMode = "RotateNoneFlipNone";
                    if (cam.rotate90)
                    {
                        cam.rotateMode = RotateFlipType.Rotate90FlipNone.ToString();
                    }
                    if (cam.flipx)
                    {
                        cam.rotateMode = RotateFlipType.RotateNoneFlipX.ToString();
                    }
                    if (cam.flipy)
                    {
                        cam.rotateMode = RotateFlipType.RotateNoneFlipY.ToString();
                    }
                    if (cam.flipx && cam.flipy)
                    {
                        cam.rotateMode = RotateFlipType.RotateNoneFlipXY.ToString();
                    }
                }
                if (cam.settings.pip == null)
                {
                    cam.settings.pip = new objectsCameraSettingsPip {enabled = false, config = ""};
                }
            }
            int micid = 0;
            foreach (objectsMicrophone mic in c.microphones)
            {
                if (mic.id >= micid)
                    micid = mic.id + 1;
                if (mic.directory == null)
                    throw new Exception("err_old_config");
                mic.newrecordingcount = 0;
                path2 = Helper.GetMediaDirectory(mic.settings.directoryIndex) + "audio\\" + mic.directory + "\\";
                if (!Directory.Exists(path2))
                    Directory.CreateDirectory(path2);

                if (mic.settings.accessgroups == null)
                    mic.settings.accessgroups = "";

                if (mic.settings.storagemanagement == null)
                {
                    mic.settings.storagemanagement = new objectsMicrophoneSettingsStoragemanagement
                    {
                        enabled = false,
                        maxage = 72,
                        maxsize = 1024

                    };
                }
                if (Math.Abs(mic.detector.minsensitivity - (-1)) < double.Epsilon)
                {
                    mic.detector.minsensitivity = mic.detector.sensitivity;
                    mic.detector.maxsensitivity = 100;
                }
                if (mic.detector.minsensitivity > mic.detector.maxsensitivity)
                {
                    //reset
                    mic.detector.maxsensitivity = 100;
                    mic.detector.minsensitivity = 20;
                }

                if (Conf.MediaDirectories.FirstOrDefault(p => p.ID == mic.settings.directoryIndex) == null)
                    mic.settings.directoryIndex = Conf.MediaDirectories.First().ID;

                bool migrate = false;
                if (mic.alertevents == null)
                {
                    mic.alertevents = new objectsMicrophoneAlertevents();
                    migrate = true;
                }
                if (mic.alertevents.entries == null)
                {
                    mic.alertevents.entries = new objectsMicrophoneAlerteventsEntry[] { };
                }

                if (migrate)
                {
                    var l = new List<objectsMicrophoneAlerteventsEntry>();
                    if (!string.IsNullOrEmpty(mic.alerts.executefile))
                    {
                        l.Add(new objectsMicrophoneAlerteventsEntry { type = "Exe", param1 = mic.alerts.executefile, param2 = mic.alerts.arguments });
                    }
                    if (mic.notifications.sendemail)
                    {
                        l.Add(new objectsMicrophoneAlerteventsEntry { type = "E", param1 = mic.settings.emailaddress, param2 = "True" });
                    }
                    if (mic.notifications.sendsms)
                    {
                        l.Add(new objectsMicrophoneAlerteventsEntry { type = "SMS", param1 = mic.settings.smsnumber });
                    }

                    string[] alertOptions = mic.alerts.alertoptions.Split(','); //beep,restore

                    if (Convert.ToBoolean(alertOptions[0]))
                        l.Add(new objectsMicrophoneAlerteventsEntry { type = "B" });
                    if (Convert.ToBoolean(alertOptions[1]))
                        l.Add(new objectsMicrophoneAlerteventsEntry { type = "SW" });

                    if (mic.notifications.sendtwitter)
                    {
                        l.Add(new objectsMicrophoneAlerteventsEntry { type = "TM" });
                    }

                    if (!string.IsNullOrEmpty(mic.alerts.trigger))
                    {
                        l.Add(new objectsMicrophoneAlerteventsEntry { type = "TA", param1 = mic.alerts.trigger });
                    }
                    mic.alertevents = new objectsMicrophoneAlertevents() {entries = l.ToArray()};
                }

                if (string.IsNullOrEmpty(mic.settings.emailondisconnect))
                {
                    if (mic.settings.notifyondisconnect)
                    {
                        mic.settings.emailondisconnect = mic.settings.emailaddress;
                    }
                }

                if (addActions)
                {
                    var l = c.actions.entries.ToList();
                    l.AddRange(mic.alertevents.entries.Select(a => new objectsActionsEntry
                    {
                        mode = "alert",
                        objectid = mic.id,
                        objecttypeid = 1,
                        type = a.type,
                        param1 = a.param1,
                        param2 = a.param2,
                        param3 = a.param3,
                        param4 = a.param4
                    }));
                    if (!string.IsNullOrEmpty(mic.settings.emailondisconnect))
                    {
                        l.Add(new objectsActionsEntry
                                {
                                    mode = "disconnect",
                                    objectid = mic.id,
                                    objecttypeid = 1,
                                    type = "E",
                                    param1 = mic.settings.emailondisconnect,
                                    param2 = "False"
                                });
                    }
                    c.actions.entries = l.ToArray();
                }

                if (mic.x < 0)
                    mic.x = 0;
                if (mic.y < 0)
                    mic.y = 0;

                if (mic.settings.gain <= 0)
                    mic.settings.gain = 1;

                if (mic.alerts.trigger == null)
                    mic.alerts.trigger = "";
            }
            int fpid = 0;
            foreach (objectsFloorplan ofp in c.floorplans)
            {
                if (ofp.id >= fpid)
                    fpid = ofp.id + 1;

                if (ofp.x < 0)
                    ofp.x = 0;
                if (ofp.y < 0)
                    ofp.y = 0;
                if (ofp.accessgroups == null)
                    ofp.accessgroups = "";
            }
            int rcid = 0;
            foreach (objectsCommand ocmd in c.remotecommands)
            {
                if (ocmd.id >= rcid)
                    rcid = ocmd.id + 1;
            }

            if (bAlertVlc)
            {
                MessageBox.Show(Program.Platform == "x64"
                    ? LocRm.GetString("InstallVLCx64")
                        .Replace("[DIR]", Environment.NewLine + Program.AppPath + "VLC64" + Environment.NewLine)
                    : LocRm.GetString("InstallVLCx86"));
                OpenUrl(Program.Platform == "x64" ? VLCx64 : VLCx86);
            }
            SaveConfig();
            NeedsSync = true;
            LogMessageToFile("Loaded " + c.cameras.Length + " cameras, " + c.microphones.Length + " mics and " + c.floorplans.Length + " floorplans");
            return c;
        }
Beispiel #20
0
        private void SaveObjects(string fileName)
        {
            if (fileName == "")
                fileName = Program.AppPath + @"XML\objects.xml";
            var c = new objects();
            foreach (objectsCamera oc in Cameras)
            {
                CameraWindow occ = GetCameraWindow(oc.id);
                if (occ != null)
                {
                    oc.width = occ.Width;
                    oc.height = occ.Height;
                    oc.x = occ.Location.X;
                    oc.y = occ.Location.Y;
                }
            }
            c.cameras = Cameras.ToArray();
            foreach (objectsMicrophone om in Microphones)
            {
                VolumeLevel omc = GetMicrophone(om.id);
                if (omc != null)
                {
                    om.width = omc.Width;
                    om.height = omc.Height;
                    om.x = omc.Location.X;
                    om.y = omc.Location.Y;
                }
            }
            c.microphones = Microphones.ToArray();

            var s = new XmlSerializer(typeof (objects));
            var fs = new FileStream(fileName, FileMode.Create);
            TextWriter writer = new StreamWriter(fs);
            fs.Position = 0;
            s.Serialize(writer, c);
            fs.Close();
        }