static void Main(string[] args) { int[] houses = { 1, 2, 3, 4, 5 }; // var perms = Perm.GetAllPerm(houses); var perms = Perm.GetPermutations(houses, houses.Length); foreach (var perm in perms) { Console.Write("("); foreach (var value in perm) { Console.Write($"{value}, "); } Console.WriteLine("),"); Console.WriteLine($"{Color.Red} at index {perm.ToList().IndexOf((int)Color.Red)}"); } Console.WriteLine($"length of {perms.Count()}"); Console.WriteLine($"{Color.Blue}"); Console.WriteLine($"{(int)Color.Red}"); }
private int BitPattern(Perm p) { int idx = (int)p + 1; int pattern = (1 << idx); return(pattern); }
private void OnRequest(Req msg, Transition trans) { PerformancePermission permission; switch (stateMachine.State) { case State.Unknown: case State.Looser: case State.Inactive: permission = PerformancePermission.Accepted; break; case State.Winner: permission = PerformancePermission.Rejected; break; default: permission = PerformancePermission.Rejected; break; } var decision = new Perm() { SenderId = Id, ReceiversIds = new List <int>() { msg.SenderId }, PermissionToPerform = permission }; connection.InvokeAsync(nameof(Perm), decision); }
public override PreconditionResult Check(APIContext context) { if (Scope == "*" || Scope == null) { return(PreconditionResult.FromSuccess()); } if (context.Token == null) { throw new MustLoginException(); } var _scope = Scope; if (string.IsNullOrWhiteSpace(_scope)) { var path = context.Path.Split("/", StringSplitOptions.RemoveEmptyEntries); _scope = "html." + string.Join(".", path); } foreach (var scope in context.Token.Scopes) { if (Perm.IsMatch(scope, _scope, out _)) { return(PreconditionResult.FromSuccess()); } } return(PreconditionResult.FromError("Token is not authenticated for this endpoint")); }
static void Main(string[] args) { string[] arr = Console.ReadLine().Split(' '); //Array.Sort(arr); //Perm.PermWRep(arr, 0, arr.Length - 1); Perm.PermRepHash(arr, 0); }
public void ChangePrivacySetting(PrivacySetting setting, Perm value) { List <byte> bts = new List <byte>(); bts.AddRange(BitConverter.GetBytes((int)setting)); bts.AddRange(BitConverter.GetBytes((int)value)); SendCommand(new Command(Command.CommandType.ChangeUserPrivacy, bts.ToArray())); }
public void Find(double eps = 0) { region.Clear(); R.Coor size = new R.Coor(); // Размер области размещения. R.Coor coor = new R.Coor(); // Точка размещения объекта. for (int i = 1; i < rects.Length; i++) // 0-ой объект, с нулевыми координатами и размерами, необходим для поиска точек размещения связанных с областью размещения. { Rect rect = rects[i]; double obj_func = double.PositiveInfinity; // Значение функции цели при размещении текущего объекта. Perm perm = new Perm(Rect.Dim, i); do { #region Заполнение возможной точки размещения новыми координатами. for (int j = 0; j < Rect.Dim; j++) rect.Min(j, rects[perm[j]].Max(j)); #endregion #region Проверка попадания текущего объекта размещения в текущей точке размещения в область размещения. if (region.IsContaine(rect, eps)) #region Проверка непересечения текущего объекта размещения в текущей точке размещения со всеми размещёнными объектами. if (!rect.IsCollideWith(rects, i, eps)) { #region Определение функции цели в текущей точке размещения. double obj_func_temp = 1; for (int j = 0; j < Rect.Dim; j++) if (!region.Freez(j)) obj_func_temp *= Math.Max(region.Size(j), rect.Max(j)); #endregion #region Определение того, является ли текущая точка размещения лучше сохранённой (оптимальной). double delta = obj_func - obj_func_temp; for (int j = 0; j < Rect.Dim && Math.Abs(delta) <= eps; j++) delta = coor[j] - rect.Min(j); #endregion #region Сохранение лучших значения функции цели, точки размещения и размеров области размещения. if (delta - eps > 0) { obj_func = obj_func_temp; rect.CopyCoorTo(coor); for (int j = 0; j < Rect.Dim; j++) size[j] = Math.Max(region.Size(j), rect.Max(j)); } #endregion } #endregion #endregion } while (perm.NextPerm()); rect.CopyCoorFrom(coor); // Установка объекта в найденную точку. region.CopySizeFrom(size); // Установка новых размеров области. } }
public void perm_inc() { var p = Perm.Identity(16); for (var i = 0; i < 16; i++) { p.Inc(); } Claim.eq(p, Perm.Identity(16)); }
private void OnPerformancePermission(Perm msg, Transition trans) { Logger.Log(this, msg); AssignReceivedPermissionToNeighbour(msg.SenderId, msg.PermissionToPerform); if (DoAllNeighboursLetMePeform()) { stateMachine.Fire(Trigger.Win); } }
public DispetcherController() { Disps = from pr in Process.GetProcesses() where (long)pr.MainWindowHandle != 0 select new Disp { Id = pr.Id, Name = $"{pr.ProcessName}({pr.MainWindowTitle})", Memory = Perm.GetMemory(pr.ProcessName) }; }
public void Set(Perm p, bool include) { if (include) { Add(p); } else { Remove(p); } }
protected void Page_Load(object sender, EventArgs e) { if (GlobalVariables.loggedInUser == null) { Response.Redirect(GlobalVariables.starting); } if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0)) { string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName); string SaveLocation = Server.MapPath("..\\files") + "\\" + fn; File f = new File(fn, GlobalVariables.loggedInUser.id, File1.PostedFile.ContentLength); f.id = Database.Instance.insert(f); if (f.id > 0) { Perm p = new Perm(f.id, GlobalVariables.loggedInUser.id); Database.Instance.insert(p); try { File1.PostedFile.SaveAs(SaveLocation); Response.Write("The file has been uploaded."); } catch (Exception ex) { Response.Write("Error: " + ex.Message); //Note: Exception.Message returns detailed message that describes the current exception. //For security reasons, we do not recommend you return Exception.Message to end users in //production environments. It would be better just to put a generic error message. } } else { Response.Write("Exceeds Quota"); } } else { Response.Write("Please select a file to upload."); } List <File> lf = Database.Instance.getFiles(GlobalVariables.loggedInUser); List <string> ls = new List <string>(); foreach (File f in lf) { ls.Add(f.filename); } DataGrid.DataSource = ls; DataGrid.DataBind(); }
public static bool UpdatePerm(string permNameKey, Perm mIzin) { if (permNameKey.IsNullEmpty() || mIzin.PermName.IsNullEmpty()) { Mesaj.Uyari("İzin form adı boş yada geçersiz olamaz !"); return(false); } using (UserRoleDBDataContext Context = new UserRoleDBDataContext(ConStr)) { Context.ExecuteCommand("UPDATE usr.Perm SET PermName={0}, Active={1}, Type={2}, [Group]={3} WHERE PermName={4}", mIzin.PermName, mIzin.Active, mIzin.Type, mIzin.Group, permNameKey); } return(true); }
public static bool AddPerm(Perm izin) { if (izin.PermName.IsNullEmpty()) { Mesaj.Uyari("İzin form adı boş geçilemez !"); return(false); } using (UserRoleDBDataContext Context = new UserRoleDBDataContext(ConStr)) { Context.Perms.InsertOnSubmit(izin); Context.SubmitChanges(); } return(true); }
public async Task BlockWhole(SocketGuildUser user, IRole role) { var bUser = Program.GetUser(user); var perm = Perm.Parse($"-roles.{user.Guild.Id}.{role.Id}"); if (bUser.Permissions.RemoveAll(x => x.RawNode == perm.RawNode) > 0) { await ReplyAsync("Unblocked"); } else { bUser.Permissions.Add(perm); await ReplyAsync("Blocked."); } }
public IActionResult Post(Disp disp) { if (string.IsNullOrWhiteSpace(disp.Name)) { return(BadRequest()); } var s = Process.Start(disp.Name); var res = new Disp { Id = s.Id, Name = $"{s.ProcessName}({s.MainWindowTitle})", Memory = Perm.GetMemory(s.ProcessName) }; return(Ok(res)); }
public GroupObject(string file) { System.IO.StreamReader dis = new System.IO.StreamReader(file); Name = Path.GetFileNameWithoutExtension(file); parent = dis.ReadLine(); color = dis.ReadLine(); do { string line; line = dis.ReadLine(); try { Perm.Add(line); } catch (System.NullReferenceException) { continue; } }while (dis.Peek() >= 0); }
void perm_identity_check <N>(N rep = default) where N : ITypeNat, new() { var permA = Perm <N> .Identity; var n = nati <N>(); Claim.eq(n, permA.Length); Claim.eq(n, permA.Terms.Length); var terms = range(0, n - 1).ToArray(); Claim.eq(n, terms.Length); var permB = Perm.Define(new N(), terms); Claim.yea(permA == permB); }
void perform(BotUser user, ulong id, string e, ulong?criteria) { if (Situations.TryGetValue(id, out var actions) && actions.TryGetValue(e, out var sit)) { if (sit.State != null && sit.State != criteria) { return; } if (!string.IsNullOrWhiteSpace(sit.PermAdded)) { user.Permissions.Add(Perm.Parse(sit.PermAdded)); } if (!string.IsNullOrWhiteSpace(sit.PermRemoved)) { user.Permissions.RemoveAll(x => x.RawNode == sit.PermRemoved); } } }
public void insert(Perm perm) { SqlCommand cmd = new SqlCommand("insert into perm(fileid,ownerid) values(@fileid,@ownerid)", con); cmd.Parameters.AddWithValue("@fileid", perm.fileid); cmd.Parameters.AddWithValue("@ownerid", perm.ownerid); string log = GlobalVariables.GetIPAddress() + " added permission " + perm.ToString(); try { cmd.ExecuteNonQuery(); logger.Info(log); } catch (SqlException e) { logger.Error(e.GetType().ToString() + "Exception on " + log); logger.Error(e.StackTrace); } }
public static BotUser GetUser(IUser user) { var existing = GetUserOrDefault(user.Id); if (existing == null) { existing = new BotUser(user); Program.Users.Add(existing); } if (existing.Permissions.Count == 0 && Program.AppInfo != null && Program.AppInfo.Owner.Id == existing.Id ) { existing.Permissions.Add(Perm.Parse("bot.*")); } return(existing); }
public void perm32() { var p1 = Perm.Define(n32, (31, 0), (30, 1), (29, 2)); Claim.eq(p1[0], 31); Claim.eq(p1[1], 30); Claim.eq(p1[2], 29); Claim.eq(p1[3], 3); var bm = p1.ToBitMatrix(); Claim.eq(bm[0, 31], Bit.On); Claim.eq(bm[1, 30], Bit.On); Claim.eq(bm[2, 29], Bit.On); var v1 = BitVector32.Zero; var v2 = v1.Replicate(p1); Claim.eq(v1[31], v2[0]); Claim.eq(v1[30], v2[1]); Claim.eq(v1[29], v2[2]); }
private static int[] ToInt(Perm perm) => perm.Select(a => ((Scalar <int> .Const)a).Value).ToArray();
private Transpose(Tensor <T> x, int[] perm, Perm perm1) : base("DimShuffle", x, perm1) { this.Permutation = perm; Shape = new Dim[perm.Length]; perm.Apply(a => x.Shape[a], Shape); }
public async Task Approve(BotUser b) { b.IsApproved = true; b.Permissions.Add(Perm.Parse(Perms.Bot.User.All)); await ReplyAsync("User has been approved."); }
public PermProxy( World w, Player player, Perm perm ) { _world = w; _player = player; _perm = perm; }
public bool Contains(Perm p) { return((data & BitPattern(p)) != 0); }
public PermissionFailure( string msg, Perm p ) : base(msg) { _p = p; }
public void Remove(Perm p) { data = data & ~BitPattern(p); }
public void Add(Perm p) { data = data | BitPattern(p); }
public void Load(string uri, int vposShift, int startPos, int endPos) { XmlReader xr = XmlReader.Create(uri); List <Comment> result = new List <Comment>(); List <Perm> perms = new List <Perm>(); List <Vote> votes = new List <Vote>(); if (xr == null) { return; } int count = 0; Comment cmt = null; Vote vote = null; Perm perm = null; while (xr.Read()) { if (xr.ReadToFollowing("chat")) { int vpos = int.Parse(xr.GetAttribute("vpos")) - startPos + vposShift; if (vpos < -10 || vpos > endPos + 10) { continue; } int premium = int.Parse(xr.GetAttribute("premium") ?? "0"); string mail = xr.GetAttribute("mail") ?? ""; string[] mails = mail.ToLower().Split(' '); cmt = new Comment() { Count = count, //Number = int.Parse(xr.GetAttribute("no")), Vpos = vpos, //Mail = xr.GetAttribute("mail") ?? "", Mails = mails, Text = xr.ReadString() }; bool add = true; if (cmt.Text.StartsWith("/hb")) { continue; } if (cmt.Text.Contains("\n"))// Environment.NewLine { cmt.IsAA = true; } if (premium >= 3) { cmt.Text = Comment.StripHtmlTags(cmt.Text); add = false; if (cmt.Text.StartsWith("/clear") || cmt.Text.StartsWith("/cls")) { if (perm != null) { double endTime = cmt.Vpos / 100.0; if (perm.StartTime + 180.0 >= endTime) { perm.EndTime = endTime; } perm = null; } } else if (cmt.Text.StartsWith("/vote ")) { //start showresult stop cmt.IsVote = true; cmt.Text = cmt.Text.Substring(6); if (cmt.Text.StartsWith("start ")) { if (vote != null) { votes.Add(vote); } vote = new Vote(); vote.VoteComment = cmt; vote.StartTime = cmt.Vpos / 100.0; vote.ResultTime = (cmt.Vpos / 100.0) + 10.0; //temp vote.EndTime = (cmt.Vpos / 100.0) + 10.0; //temp } else if (cmt.Text.StartsWith("showresult ")) { if (vote != null) { vote.ResultComment = cmt; vote.ResultTime = (cmt.Vpos / 100.0); vote.EndTime = (cmt.Vpos / 100.0) + 10.0; //temp } } else if (cmt.Text.StartsWith("stop")) { if (vote != null) { vote.EndTime = cmt.Vpos / 100.0; votes.Add(vote); vote = null; } } } else { if (cmt.Text.StartsWith("/perm ")) { cmt.Text = cmt.Text.Substring(6); } cmt.IsPerm = true; perm = new Perm(); perm.Comment = cmt; perm.StartTime = cmt.Vpos / 100.0 - 3; //ちょっと早めに出す perm.EndTime = perm.StartTime + 12.0; //temp perms.Add(perm); } } if (add) { result.Add(cmt); } count++; } } if (vote != null) { votes.Add(vote); } result.Sort((a, b) => { return(a.Vpos >= b.Vpos ? 1 : -1); }); //逆順 votes.Sort((a, b) => { return(a.StartTime >= b.StartTime ? -1 : 1); }); perms.Sort((a, b) => { return(a.StartTime >= b.StartTime ? -1 : 1); }); Comments = result.ToArray(); Perms = perms.ToArray(); Votes = votes.ToArray(); }
public GitTeam(int id, string name, Perm perm = Perm.pull) { Id = id; Name = name; Permission = perm; }
public Task PerformancePermission(Perm message) { return(orchestrator.SendMessage(nameof(Perm), message)); }