Beispiel #1
0
        public async Task <IActionResult> Create([Bind("Id,Username,Password,FirstName,SecondName,LastName,Egn,PhoneNumber,Email,IsActive,HireDate,LeaveDate")] User user)
        {
            if (ModelState.IsValid)
            {
                user.IsActive = true;
                user.HireDate = DateTime.Now;
                try
                {
                    SecurityChecker.CheckUser(user);
                }
                catch (InvalidEgnException)
                {
                    ViewData["message"] = "Egn is invalid";
                    user.Egn            = null;
                    return(View(user));
                }
                catch (Exception)
                {
                    return(View(user));
                }
                try
                {
                    AvailabilityChecker.CheckUserAvailabikity(user, _context);
                }
                catch (UsernameAlreadyExistsException)
                {
                    ViewData["message"] = "Username is taken";
                    user.Username       = null;
                    return(View(user));
                }
                catch (EmailAlreadyExistsException)
                {
                    ViewData["message"] = "Email is already registered";
                    user.Email          = null;
                    return(View(user));
                }
                catch (EgnAlreadyExistsException)
                {
                    ViewData["message"] = "EGN is already registered";
                    user.Egn            = null;
                    return(View(user));
                }
                catch (PhoneAlreadyExistsException)
                {
                    ViewData["message"] = "Phone is already registered";
                    user.PhoneNumber    = null;
                    return(View(user));
                }
                catch (Exception)
                {
                    return(View(user));
                }
                user.Password = Hasher.GetHash(user.Password);
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("Id,Capacity,roomTypes,IsAvailable,PriceAdult,PriceKid,roomNumber")] Room room)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    SecurityChecker.CheckRoom(room);
                }
                catch (Exception)
                {
                    return(View(room));
                }
                try
                {
                    AvailabilityChecker.CheckRoomAvailabikity(room, _context);
                }
                catch (RoomNumberExistsException)
                {
                    ViewData["message"] = "Room number already exists";
                    room.roomNumber     = 0;
                    return(View(room));
                }
                catch (Exception)
                {
                    return(View(room));
                }
                _context.Add(room);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(room));
        }
        private bool Init()
        {
            string ip = txt_drone_ip.Text;

            if (AvailabilityChecker.IsAddressAvailable(ip))
            {
                if (client == null)
                {
                    client = new TelloClient(ip, this);
                }
                txt_current_speed.Content = client.CurrentSpeed;
                return(true);
            }
            MessageBox.Show(String.Format("Drone host is not available: {0}", ip));
            return(false);
        }
Beispiel #4
0
        private void BtnStartCheck_Click(object sender, EventArgs e)
        {
            if (CheckService.DomainList.Count > 0)
            {
                BtnStartCheck.Enabled = false;
                BtnStopCheck.Enabled  = true;
                cancelToken           = new CancellationTokenSource();

                new Thread(async() =>
                {
                    try
                    {
                        await AvailabilityChecker.CheckAll(cancelToken.Token);
                        IOHelper.WriteToDomains(Setting.SavePath);
                    }
                    catch (OperationCanceledException)
                    {
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + (ex.InnerException != null ? "\nAyrıntılar: " + ex.InnerException.Message : ""), "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        synCtx.Send(delegate
                        {
                            BtnStartCheck.Enabled = true;
                            BtnStopCheck.Enabled  = false;
                        }, null);
                    }
                })
                {
                    IsBackground = true
                }.Start();
            }
            else
            {
                MessageBox.Show("Domain eklemediniz!", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,PhoneNumber,Email,IsMinor")] Client client)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    SecurityChecker.CheckClient(client);
                }
                catch (Exception)
                {
                    return(View(client));
                }
                try
                {
                    AvailabilityChecker.CheckClientAvailabikity(client, _context);
                }
                catch (EmailAlreadyExistsException)
                {
                    ViewData["message"] = "Email is already registered";
                    client.Email        = null;
                    return(View(client));
                }
                catch (PhoneAlreadyExistsException)
                {
                    ViewData["message"] = "Phone is already registered";
                    client.PhoneNumber  = null;
                    return(View(client));
                }
                catch (Exception)
                {
                    return(View(client));
                }
                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
        public static MacroSpec CompileData(DeviceProfile profile)
        {
            var res = new MacroSpec();

            foreach (var op in MacroOpManager.FindAll())
            {
                var xmlOp = new MacroOperationSpec()
                {
                    Id = op.Key.ToString()
                };
                res.Operations.Add(xmlOp);

                IEnumerable <PropertyInfo> props = op.Value.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                                                   .Where(prop => prop.GetCustomAttribute <NoSerializeAttribute>() == null)
                                                   .OrderBy(prop => prop.GetCustomAttribute <SerializeAttribute>()?.StartByte ?? 999);

                foreach (PropertyInfo prop in props)
                {
                    var fieldAttr = prop.GetCustomAttribute <MacroFieldAttribute>();
                    if (fieldAttr == null)
                    {
                        continue;
                    }

                    var xmlField = new MacroFieldSpec()
                    {
                        Id   = fieldAttr.Id,
                        Name = fieldAttr.Name,
                        IsId = prop.GetCustomAttribute <CommandIdAttribute>() != null
                    };
                    xmlOp.Fields.Add(xmlField);

                    if (prop.GetCustomAttribute <BoolAttribute>() != null)
                    {
                        xmlField.Type = MacroFieldType.Bool;
                    }
                    else if (prop.GetCustomAttribute <Enum8Attribute>() != null || prop.GetCustomAttribute <Enum16Attribute>() != null || prop.GetCustomAttribute <Enum32Attribute>() != null)
                    {
                        xmlField.Type = prop.PropertyType.GetCustomAttribute <FlagsAttribute>() != null ? MacroFieldType.Flags : MacroFieldType.Enum;

                        string mappedTypeName = TypeMappings.MapType(prop.PropertyType.FullName);
                        Type   mappedType     = prop.PropertyType;
                        if (mappedTypeName != mappedType.FullName && mappedTypeName.IndexOf("System.") != 0)
                        {
                            mappedType = GetType(mappedTypeName);
                        }


                        foreach (object val in Enum.GetValues(mappedType))
                        {
                            string id      = val.ToString();
                            var    xmlAttr = mappedType.GetMember(val.ToString())[0].GetCustomAttribute <XmlEnumAttribute>();
                            if (xmlAttr != null)
                            {
                                id = xmlAttr.Name;
                            }

                            if (!AvailabilityChecker.IsAvailable(profile, val))
                            {
                                continue;
                            }

                            // TODO check value is available for usage location
                            xmlField.Values.Add(new MacroFieldValueSpec()
                            {
                                Id   = id,
                                Name = val.ToString(),
                            });
                        }
                    }
                    else
                    {
                        SetNumericProps(profile, op.Key, xmlField, prop);
                    }
                }
            }

            return(res);
        }
 private static T GetDefaultForField <T>(DeviceProfile profile, MacroOperationType op, MacroFieldSpec field)
 {
     return((T)AvailabilityChecker.GetMaxForProperty(profile, string.Format("{0}.{1}", op.ToString(), field.Name)));
 }
Beispiel #8
0
        public void AutoTestMacroOps()
        {
            using (var helper = new AtemComparisonHelper(Client, Output))
            {
                IBMDSwitcherMacroControl ctrl = GetMacroControl();

                var failures = new List <string>();

                Assembly           assembly = typeof(ICommand).GetTypeInfo().Assembly;
                IEnumerable <Type> types    = assembly.GetTypes().Where(t => typeof(SerializableCommandBase).GetTypeInfo().IsAssignableFrom(t));
                foreach (Type type in types)
                {
                    if (type == typeof(SerializableCommandBase))
                    {
                        continue;
                    }

/*
 *                  if (type != typeof(AuxSourceSetCommand))
 *                      continue;*/

                    try
                    {
                        Output.WriteLine("Testing: {0}", type.Name);
                        for (int i = 0; i < 10; i++)
                        {
                            SerializableCommandBase   raw         = (SerializableCommandBase)RandomPropertyGenerator.Create(type, (o) => AvailabilityChecker.IsAvailable(helper.Profile, o)); // TODO - wants to be ICommand
                            IEnumerable <MacroOpBase> expectedOps = raw.ToMacroOps(ProtocolVersion.Latest);
                            if (expectedOps == null)
                            {
                                Output.WriteLine("Skipping");
                                break;
                            }

                            using (new StopMacroRecord(ctrl)) // Hopefully this will stop recording if it exceptions
                            {
                                ctrl.Record(0, string.Format("record-{0}-{1}", type.Name, i), "");
                                helper.SendCommand(raw);
                                helper.Sleep(20);
                            }

                            helper.Sleep(40);
                            byte[] r = DownloadMacro(0);
                            if (r.Length == 0)
                            {
                                throw new Exception("Macro has no operations");
                            }

                            MacroOpBase decoded = MacroOpManager.CreateFromData(r, false); // This is assuming that there is a single macro op
                            RandomPropertyGenerator.AssertAreTheSame(expectedOps.Single(), decoded);
                        }
                    }
                    catch (Exception e)
                    {
                        var msg = string.Format("{0}: {1}", type.Name, e.Message);
                        Output.WriteLine(msg);
                        failures.Add(msg);
                    }
                }

                Assert.Empty(failures);
            }
        }
        private async Task <Response> ScheduleRun(string key)
        {
            if (key.Equals(JobNames.PlexCacher, StringComparison.CurrentCultureIgnoreCase))
            {
                PlexContentCacher.CacheContent();
            }

            if (key.Equals(JobNames.WatcherCacher, StringComparison.CurrentCultureIgnoreCase))
            {
                WatcherCacher.Queued();
            }

            if (key.Equals(JobNames.SonarrCacher, StringComparison.CurrentCultureIgnoreCase))
            {
                SonarrCacher.Queued();
            }
            if (key.Equals(JobNames.RadarrCacher, StringComparison.CurrentCultureIgnoreCase))
            {
                RadarrCacher.Queued();
            }
            if (key.Equals(JobNames.CpCacher, StringComparison.CurrentCultureIgnoreCase))
            {
                CpCacher.Queued();
            }
            if (key.Equals(JobNames.StoreBackup, StringComparison.CurrentCultureIgnoreCase))
            {
                StoreBackup.Start();
            }
            if (key.Equals(JobNames.SrCacher, StringComparison.CurrentCultureIgnoreCase))
            {
                SrCacher.Queued();
            }
            if (key.Equals(JobNames.PlexChecker, StringComparison.CurrentCultureIgnoreCase))
            {
                AvailabilityChecker.Start();
            }
            if (key.Equals(JobNames.StoreCleanup, StringComparison.CurrentCultureIgnoreCase))
            {
                StoreCleanup.Start();
            }
            if (key.Equals(JobNames.RequestLimitReset, StringComparison.CurrentCultureIgnoreCase))
            {
                RequestLimit.Start();
            }
            if (key.Equals(JobNames.EpisodeCacher, StringComparison.CurrentCultureIgnoreCase))
            {
                EpisodeCacher.Start();
            }
            if (key.Equals(JobNames.RecentlyAddedEmail, StringComparison.CurrentCultureIgnoreCase))
            {
                RecentlyAdded.Start();
            }
            if (key.Equals(JobNames.FaultQueueHandler, StringComparison.CurrentCultureIgnoreCase))
            {
                FaultQueueHandler.Start();
            }
            if (key.Equals(JobNames.PlexUserChecker, StringComparison.CurrentCultureIgnoreCase))
            {
                RequestLimit.Start();
            }


            return(Response.AsJson(new JsonResponseModel {
                Result = true
            }));
        }
Beispiel #10
0
 private static T GetDefaultForField <T>(DeviceProfile profile, Type cmdType, CommandProperty field)
 {
     return((T)AvailabilityChecker.GetMaxForCommandProperty(profile, $"{cmdType.Name}.{field.Name}"));
 }
Beispiel #11
0
        public static CommandsSpec CompileData(DeviceProfile profile)
        {
            var res = new CommandsSpec();

            foreach (var cmdSet in CommandManager.GetAllTypes())
            {
                foreach (var cmd in cmdSet.Value)
                {
                    var spec = res.Commands[cmd.Item2.FullName] = new CommandSpec
                    {
                        FullName       = cmd.Item2.FullName,
                        Name           = cmd.Item2.Name,
                        InitialVersion = cmd.Item1,
                        ToServer       = false,
                        ToClient       = false
                    };

                    var nameAttr = cmd.Item2.GetCustomAttribute <CommandNameAttribute>();
                    if (nameAttr != null)
                    {
                        spec.ToClient = nameAttr.Direction.HasFlag(CommandDirection.ToClient);
                        spec.ToServer = nameAttr.Direction.HasFlag(CommandDirection.ToServer);
                    }

                    if (typeof(SerializableCommandBase).GetTypeInfo().IsAssignableFrom(cmd.Item2))
                    {
                        spec.IsValid = true;

                        foreach (PropertyInfo prop in cmd.Item2.GetProperties(
                                     BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                        {
                            // If prop cannot be serialized, then ignore
                            if (!prop.CanWrite || prop.GetSetMethod() == null)
                            {
                                continue;
                            }

                            if (prop.GetCustomAttribute <NoSerializeAttribute>() != null)
                            {
                                continue;
                            }

                            var resProp = new CommandProperty
                            {
                                Name = prop.Name,
                                IsId = prop.GetCustomAttributes <CommandIdAttribute>().Any()
                            };

                            if (prop.GetCustomAttribute <BoolAttribute>() != null)
                            {
                                resProp.Type = CommandPropertyType.Bool;
                            }
                            else if (prop.GetCustomAttribute <Enum8Attribute>() != null ||
                                     prop.GetCustomAttribute <Enum16Attribute>() != null ||
                                     prop.GetCustomAttribute <Enum32Attribute>() != null)
                            {
                                resProp.Type = prop.PropertyType.GetCustomAttribute <FlagsAttribute>() != null
                                    ? CommandPropertyType.Flags
                                    : CommandPropertyType.Enum;

                                var options = new List <CommandEnumOption>();
                                foreach (object val in Enum.GetValues(prop.PropertyType))
                                {
                                    if (!AvailabilityChecker.IsAvailable(profile, val))
                                    {
                                        continue;
                                    }

                                    // TODO check value is available for usage location
                                    options.Add(new CommandEnumOption
                                    {
                                        Id   = (int)val,
                                        Name = val.ToString(),
                                    });
                                }

                                resProp.Options = options;
                            }
                            else if (prop.GetCustomAttribute <StringAttribute>() != null)
                            {
                                resProp.Type = CommandPropertyType.String;
                            }
                            else if (prop.GetCustomAttribute <StringLengthAttribute>() != null)
                            {
                                resProp.Type = CommandPropertyType.String;
                                resProp.Max  = (int)prop.GetCustomAttribute <StringLengthAttribute>().MaxLength;
                            }
                            else if (prop.GetCustomAttribute <ByteArrayAttribute>() != null)
                            {
                                resProp.Type = CommandPropertyType.ByteArray;
                                resProp.Max  = (int)prop.GetCustomAttribute <ByteArrayAttribute>().Size;
                            }
                            else if (prop.GetCustomAttribute <UInt16ListAttribute>() != null)
                            {
                                resProp.Type = CommandPropertyType.IntArray;
                                //resProp.Count = (int)prop.GetCustomAttribute<UInt16ListAttribute>().Count;
                            }
                            else if (prop.GetCustomAttribute <UInt32ListAttribute>() != null)
                            {
                                resProp.Type = CommandPropertyType.IntArray;
                                //resProp.Count = (int)prop.GetCustomAttribute<UInt32ListAttribute>().Count;
                            }
                            else if (prop.GetCustomAttribute <HyperDeckTimeAttribute>() != null)
                            {
                                resProp.Type = CommandPropertyType.Timestamp;
                            }
                            else if (prop.GetCustomAttribute <IpAddressAttribute>() != null)
                            {
                                resProp.Type = CommandPropertyType.IpAddress;
                            }
                            else
                            {
                                SetNumericProps(profile, cmd.Item2, resProp, prop);
                            }

                            spec.Properties.Add(resProp);
                        }
                    }
                }
            }

            return(res);
        }