Exemplo n.º 1
0
 public bool CheckSecurity(int orgId, string[] keys, Models.Scope scope = Models.Scope.All, int scopeId = 0)
 {
     if (Keys.ContainsKey(orgId))
     {
         if (Keys[orgId].Any(a => (a.Key == "Owner" || a.Key == Security.Keys.OrgFullAccess.ToString()) && a.Enabled == true))
         {
             //full access to organization
             return(true);
         }
         foreach (var key in keys)
         {
             if (Keys[orgId].Any(a => a.Key == key))
             {
                 var orgkeys = Keys[orgId];
                 if (scope != Models.Scope.All)
                 {
                     //specific scope
                     return(orgkeys.Any(a => a.Key == key && a.Enabled == true && (a.Scope == Models.Scope.All || (a.Scope == scope && a.ScopeId == scopeId))));
                 }
                 else
                 {
                     //all scopes
                     return(orgkeys.Any(a => a.Key == key && a.Enabled == true));
                 }
             }
         }
     }
     //check if user has full access to Kandu application (if all else fails)
     if (Keys.Any(a => a.Value.Any(b => (b.Key == "AppOwner" || b.Key == "AppFullAccess") && b.Enabled == true)))
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
        private void OpenFile(string filename)
        {
            var file = new W3StringFile();

            try
            {
                var stream = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read));
                file.Read(stream);
                stream.Close();
            }
            catch (Exception)
            {
                //MessageBox.Show(string.Format("There was an error trying to open {0}.", filename), "Opening file failed.");
                return;
            }

            foreach (var item in file.block1)
            {
                if (!Lines.ContainsKey(item.str_id))
                {
                    Lines.Add(item.str_id, new List <W3StringBlock1>());
                }
                Lines[item.str_id].Add(item);
            }


            foreach (var item in file.block2)
            {
                if (!Keys.ContainsKey(item.str_id))
                {
                    Keys.Add(item.str_id, true);
                }
            }
        }
Exemplo n.º 3
0
        private void OpenFile(string filename)
        {
            var file = new W3StringFile();

            try
            {
                var stream = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read));
                file.Read(stream);
                stream.Close();
            }
            catch (Exception)
            {
                return;
            }

            foreach (var item in file.block1)
            {
                if (!Lines.ContainsKey(item.str_id))
                {
                    Lines.Add(item.str_id, new List <W3StringBlock1>());
                }
                Lines[item.str_id].Add(item);
            }


            foreach (var item in file.block2)
            {
                if (!Keys.ContainsKey(item.str_id))
                {
                    Keys.Add(item.str_id, true);
                }
            }
        }
Exemplo n.º 4
0
 public void Remove(float key)
 {
     if (Keys.ContainsKey(key))
     {
         Keys.Remove(key);
         RaisePropertyChanged("IsAnimated");
     }
 }
Exemplo n.º 5
0
        public void AddValue(string key, string value)
        {
            if (!Keys.ContainsKey(key))
            {
                Keys[key] = new List <string>();
            }

            Keys[key].Add(value);
        }
 public static void SetKeyDown(string name)
 {
     if (!Keys.ContainsKey(name.ToLower()))
     {
         Keys[name.ToLower()] = false;
     }
     if (!Keys[name.ToLower()])
     {
         KeyPresses[name.ToLower()] = true;
     }
     Keys[name.ToLower()] = true;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Sends the specified key, optionally indicating modifiers and duration.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="modifiers"></param>
        /// <param name="duration"></param>
        /// <returns></returns>
        public async Task SendKey(string key, KeyDirection direction = KeyDirection.PressAndRelease, IList <string> modifiers = null, Duration duration = null)
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            if (duration == null)
            {
                duration = AverageKeypressDuration;
            }

            // KeyNames of length == 1 are case-sensitive.
            if (key.Length > 1)
            {
                key = key.ToLowerInvariant();
            }

            if (!Keys.ContainsKey(key))
            {
                return;
            }

            var keyValue       = Keys[key];
            var modifiersValue = GetModifiers(keyValue.Item2, modifiers);

            switch (direction)
            {
            case KeyDirection.Press:
                SendKeyPress(keyValue.Item1, modifiersValue);
                break;

            case KeyDirection.Release:
                SendKeyRelease(keyValue.Item1, modifiersValue);
                break;

            case KeyDirection.PressAndRelease:
            default:
                SendKeyPress(keyValue.Item1, modifiersValue);
                await Util.Hesitate(duration);

                SendKeyRelease(keyValue.Item1, modifiersValue);
                break;
            }
        }
Exemplo n.º 8
0
 public IList <string> GetValues(string key)
 {
     return(Keys.ContainsKey(key) ? Keys[key] : new List <string>());
 }
Exemplo n.º 9
0
 public string GetValue(string key)
 {
     return(Keys.ContainsKey(key) && Keys[key].Count > 0 ? Keys[key][0] : string.Empty);
 }
Exemplo n.º 10
0
        public virtual TItem BorrowItem(TKey key, TimeSpan timeout)
        {
            if (timeout.Ticks < Timeout.Infinite)
            {
                throw new ArgumentException("Timeout must be greater than or equal to Timeout.Infinite", "timeout");
            }

            AssertOpen();

            DateTime startTime = DateTime.Now;

            TItem item;

            KeyLock.AcquireReaderLock(timeout);
            try
            {
                TimeSpan waitTime = NewWaitTime(timeout, startTime);

                if (!Keys.ContainsKey(key))
                {
                    LockCookie cookie = KeyLock.UpgradeToWriterLock(waitTime);
                    try
                    {
                        if (!Keys.ContainsKey(key))
                        {
                            Keys.Add(key, NewPool(key));
                        }

                        waitTime = NewWaitTime(timeout, startTime);
                    }
                    finally
                    {
                        KeyLock.DowngradeFromWriterLock(ref cookie);
                    }
                }

                TimeRecord <TItem> record = Keys[key].Poll(new TimeSpan(0));

                if (record == null)
                {
                    item = GrowPool(key);

                    if (item == null)
                    {
                        item = Keys[key].Poll(waitTime).Item;
                    }

                    if (item == null)
                    {
                        return(null);
                    }
                }
                else
                {
                    item = record.Item;
                }
            }
            finally
            {
                KeyLock.ReleaseReaderLock();
            }

            return(Borrow(key, item));
        }
Exemplo n.º 11
0
 public virtual bool Contains(TValue value) => Keys.ContainsKey(value);
Exemplo n.º 12
0
        public static StringBuilder UpdateControlsInDB(System.Windows.Forms.Control.ControlCollection controlCollection, Int64 ModuleID, Hashtable Keys)
        {
            StringBuilder SB = new StringBuilder();

            if (Keys == null)
            {
                if (controlCollection.Count > 0)
                {
                    SB.AppendLine(controlCollection[0].FindForm().Name + "=" + controlCollection[0].FindForm().Text);
                }
                Keys = new Hashtable();
                var SControlCollection = SynapseControl.Load("WHERE FK_MODULE_ID = " + ModuleID.ToString());
                foreach (SynapseControl SC in SControlCollection)
                {
                    try
                    {
                        Keys.Add(SC.FORM_NAME + SC.CTRL_NAME + SC.CTRL_TYPE, SC);
                    }
                    // TODO: Catch more specific exception
                    catch (Exception ex)
                    {
                        SynapseForm.SynapseLogger.Error(ex.Message);
                    }
                }
            }
            foreach (Control C in controlCollection)
            {
                string formName    = C.FindForm().Name;
                string controlType = C.GetType().ToString();

                if (!Keys.ContainsKey(formName + C.Name + controlType))
                {
                    CreateControlInDB(ModuleID, formName, C.Name, controlType);
                }
                switch (controlType)
                {
                case "System.Windows.Forms.Label":
                    SB.AppendLine(C.FindForm().Name + "." + C.Name + "=" + C.Text);
                    break;

                case "System.Windows.Forms.Button":
                    SB.AppendLine(C.FindForm().Name + "." + C.Name + "=" + C.Text);
                    break;

                case "System.Windows.Forms.MenuStrip":
                    MenuStrip Menu = (MenuStrip)C;
                    SB.AppendLine(ListMenuStrip(Menu.Items, C.FindForm().Name, ModuleID, Keys).ToString());
                    break;

                case "System.Windows.Forms.TextBox":
                    break;

                case "System.Windows.Forms.FlowLayoutPanel":
                    FlowLayoutPanel FP = (FlowLayoutPanel)C;
                    SB.AppendLine(UpdateControlsInDB(FP.Controls, ModuleID, Keys).ToString());
                    break;

                case "System.Windows.Forms.GroupBox":
                    SB.AppendLine(C.FindForm().Name + "." + C.Name + "=" + C.Text);
                    GroupBox group = (GroupBox)C;
                    SB.AppendLine(UpdateControlsInDB(group.Controls, ModuleID, Keys).ToString());
                    break;

                case "System.Windows.Forms.CheckedListBox":
                    break;

                case "System.Windows.Forms.CheckBox":
                    SB.AppendLine(C.FindForm().Name + "." + C.Name + "=" + C.Text);
                    break;

                case "System.Windows.Forms.ToolStrip":
                    ToolStrip Tool = (ToolStrip)C;
                    SB.AppendLine(ListMenuStrip(Tool.Items, C.FindForm().Name, ModuleID, Keys).ToString());
                    break;

                case "System.Windows.Forms.StatusStrip":
                    StatusStrip Status = (StatusStrip)C;
                    SB.AppendLine(ListMenuStrip(Status.Items, C.FindForm().Name, ModuleID, Keys).ToString());
                    break;

                case "System.Windows.Forms.ToolStripPanel":
                    ContainerControl mycontainer = (ContainerControl)C;
                    SB.AppendLine(UpdateControlsInDB(mycontainer.Controls, ModuleID, Keys).ToString());
                    break;

                case "System.Windows.Forms.TabPage":
                    SB.AppendLine(C.FindForm().Name + "." + C.Name + "=" + C.Text);
                    Panel mytabpage = (Panel)C;
                    SB.AppendLine(UpdateControlsInDB(mytabpage.Controls, ModuleID, Keys).ToString());
                    break;

                case "System.Windows.Forms.Panel":
                case "System.Windows.Forms.SplitterPanel":
                case "System.Windows.Forms.ToolStripContentPanel":
                    Panel myPanel = (Panel)C;
                    SB.AppendLine(UpdateControlsInDB(myPanel.Controls, ModuleID, Keys).ToString());
                    break;

                case "System.Windows.Forms.ToolStripContainer":
                    System.Windows.Forms.ToolStripContainer tscontainer = (System.Windows.Forms.ToolStripContainer)C;
                    SB.AppendLine(UpdateControlsInDB(tscontainer.Controls, ModuleID, Keys).ToString());
                    break;

                case "System.Windows.Forms.SplitContainer":
                    System.Windows.Forms.SplitContainer mysplit = (System.Windows.Forms.SplitContainer)C;
                    SB.AppendLine(UpdateControlsInDB(mysplit.Controls, ModuleID, Keys).ToString());
                    break;

                case "System.Windows.Forms.TabControl":
                    TabControl tabControl = (TabControl)C;
                    SB.AppendLine(UpdateControlsInDB(tabControl.Controls, ModuleID, Keys).ToString());
                    break;

                case "System.Windows.Forms.ListView":
                    ListView liste = (ListView)C;
                    foreach (ColumnHeader Col in liste.Columns)
                    {
                        if (Col.Name != null && Col.Name != "")
                        {
                            SB.AppendLine(C.FindForm().Name + "." + C.Name + "." + Col.Name + "=" + Col.Text);
                            if (!Keys.ContainsKey(formName + C.Name + "." + Col.Name + Col.GetType().ToString()))
                            {
                                CreateControlInDB(ModuleID, formName, C.Name + "." + Col.Name, Col.GetType().ToString());
                            }
                        }
                        else
                        {
                            SynapseForm.SynapseLogger.Warn("Column with text '" + Col.Text + "' has no name or the default one");
                        }
                    }
                    break;

                case "SynapseAdvancedControls.ObjectListView":
                    ObjectListView oliste = (ObjectListView)C;
                    SB.AppendLine("ObjectListView.MenuLabelColumns=" + oliste.MenuLabelColumns);
                    SB.AppendLine("ObjectListView.MenuLabelGroupBy=" + oliste.MenuLabelGroupBy);
                    SB.AppendLine("ObjectListView.MenuLabelLockGroupingOn=" + oliste.MenuLabelLockGroupingOn);
                    SB.AppendLine("ObjectListView.MenuLabelSelectColumns=" + oliste.MenuLabelSelectColumns);
                    SB.AppendLine("ObjectListView.MenuLabelSortAscending=" + oliste.MenuLabelSortAscending);
                    SB.AppendLine("ObjectListView.MenuLabelSortDescending=" + oliste.MenuLabelSortDescending);
                    SB.AppendLine("ObjectListView.MenuLabelTurnOffGroups=" + oliste.MenuLabelTurnOffGroups);
                    SB.AppendLine("ObjectListView.MenuLabelUnlockGroupingOn=" + oliste.MenuLabelUnlockGroupingOn);
                    SB.AppendLine("ObjectListView.MenuLabelUnsort=" + oliste.MenuLabelUnsort);

                    foreach (OLVColumn Col in oliste.AllColumns)
                    {
                        if (Col.Text != null && Col.Text != "")
                        {
                            SB.AppendLine(C.FindForm().Name + "." + C.Name + "." + Col.Text.Replace(' ', '_').ToUpper() + "=" + Col.Text);
                            if (!Keys.ContainsKey(formName + C.Name + "." + Col.Text.Replace(' ', '_').ToUpper() + Col.GetType().ToString()))
                            {
                                CreateControlInDB(ModuleID, formName, C.Name + "." + Col.Text.Replace(' ', '_').ToUpper(), Col.GetType().ToString());
                            }
                        }
                        else
                        {
                            SynapseForm.SynapseLogger.Warn("Column with text '" + Col.Text + "' has no name or the default one");
                        }
                    }
                    break;

                case "SynapseCore.Controls.SynapseGraphic":
                    SynapseGraphic graph = (SynapseGraphic)C;
                    SB.AppendLine("SynapseGraphic.CopyMenu=" + graph.CopyMenu);
                    SB.AppendLine("SynapseGraphic.CurveOnlyMenu=" + graph.CurveOnlyMenu);
                    SB.AppendLine("SynapseGraphic.CurvesMenu=" + graph.CurvesMenu);
                    SB.AppendLine("SynapseGraphic.PageSetupMenu=" + graph.PageSetupMenu);
                    SB.AppendLine("SynapseGraphic.PrintMenu=" + graph.PrintMenu);
                    SB.AppendLine("SynapseGraphic.SaveAsMenu=" + graph.SaveAsMenu);
                    SB.AppendLine("SynapseGraphic.SetDefaultScaleMenu=" + graph.SetDefaultScaleMenu);
                    SB.AppendLine("SynapseGraphic.ShowAllCurvesMenu=" + graph.ShowAllCurvesMenu);
                    SB.AppendLine("SynapseGraphic.ShowHideCurveMenu=" + graph.ShowHideCurveMenu);
                    SB.AppendLine("SynapseGraphic.ShowHideLegendMenu=" + graph.ShowHideLegendMenu);
                    SB.AppendLine("SynapseGraphic.ShowPointValuesMenu=" + graph.ShowPointValuesMenu);
                    SB.AppendLine("SynapseGraphic.UndoAllZoomMenu=" + graph.UndoAllZoomMenu);
                    SB.AppendLine("SynapseGraphic.UnZoomMenu=" + graph.UnZoomMenu);

                    break;

                default:
                    if (C is UserControl)
                    {
                    }
                    break;
                }
                if (C.ContextMenuStrip != null)
                {
                    SynapseForm.SynapseLogger.Debug("Context menu found for control '" + C.Name + "' with menu name : '" + C.ContextMenuStrip.Name + "'");
                    controlType = C.ContextMenuStrip.GetType().ToString();
                    if (!Keys.ContainsKey(formName + C.ContextMenuStrip.Name + controlType))
                    {
                        CreateControlInDB(ModuleID, formName, C.ContextMenuStrip.Name, controlType);
                        Keys.Add(formName + C.ContextMenuStrip.Name + controlType, null);
                    }

                    SB.AppendLine(ListMenuStrip(C.ContextMenuStrip.Items, C.FindForm().Name, ModuleID, Keys).ToString());
                }
            }
            return(SB);
        }
Exemplo n.º 13
0
 public bool IsAppOwner()
 {
     return(UserId == 1 || (Keys.ContainsKey(0) && Keys[0].Any(a => a.Key == Security.Keys.AppOwner.ToString() && a.Enabled == true)));
 }
Exemplo n.º 14
0
 public bool IsInOrganization(int orgId)
 {
     return(Keys.ContainsKey(orgId));
 }
Exemplo n.º 15
0
        public void LogIn(int userId, int orgId, string email, string name, DateTime datecreated, string displayName = "", bool photo = false)
        {
            this.UserId      = userId;
            this.Email       = email;
            this.Photo       = photo;
            this.Name        = name;
            this.DisplayName = displayName;
            this.DateCreated = datecreated;

            //load security keys for user
            var keys = Query.Security.AllKeysForUser(userId);

            foreach (var key in keys)
            {
                if (Keys.ContainsKey(key.orgId))
                {
                    Keys[key.orgId].Add(new SecurityKey
                    {
                        Key     = key.key,
                        Enabled = key.enabled,
                        Scope   = Enum.Parse <Models.Scope>(key.scope.ToString()),
                        ScopeId = key.scopeId
                    });
                }
                else
                {
                    Keys.Add(key.orgId, new List <SecurityKey>()
                    {
                        new SecurityKey
                        {
                            Key     = key.key,
                            Enabled = key.enabled,
                            Scope   = Enum.Parse <Models.Scope>(key.scope.ToString()),
                            ScopeId = key.scopeId
                        }
                    });
                }
            }

            //load Kandu-specific properties for user from database
            var user = Query.Users.GetInfo(userId);

            KeepMenuOpen = user.keepmenu;
            AllColor     = user.allcolor;

            Boards = Query.Boards.GetBoardsForMember(userId);
            if (Boards == null)
            {
                Boards = new List <int>();
            }

            //create persistant cookie
            var auth    = Query.Users.CreateAuthToken(userId);
            var options = new CookieOptions()
            {
                Expires = DateTime.Now.AddMonths(1)
            };

            Context.Response.Cookies.Append("authId", auth, options);

            changed = true;
            Save();
        }
Exemplo n.º 16
0
 public static bool ContainsKey(ulong name) => Keys.ContainsKey(name);
Exemplo n.º 17
0
 public bool HasValue(string key)
 {
     return(Keys.ContainsKey(key));
 }