public static AuthenticationData RetrieveAuthenticationData(String providerName)
 {
     using (var sess = new SessionScopeWrapper())
     {
         var prov = sess.CreateQuery("from OAuthProvider where ProviderName=?")
             .SetString(0, providerName)
             .List<IOAuthProvider>().FirstOrDefault();
         if (prov == null)
         {
             throw new Exception(String.Format("Unable to locate {0} provider in the configured OAuth providers", providerName));
         }
         var userToken = sess.CreateQuery("from UserOAuthToken where OAuthProvider.Id=? and User.Id=?")
             .SetString(0, prov.Id.ToString())
             .SetString(1, ApplicationContext.Current.Services.Get<IUserService>().UserId)
             .List<IUserOAuthToken>()
             .FirstOrDefault();
         if (userToken == null || userToken.AccessToken == null)
         {
             throw new Exception(String.Format("Unable to locate authorization token for current user under {0} provider", providerName));
         }
         if (userToken.ExpirationDate != null && userToken.ExpirationDate < DateTime.Now)
         {
             // TODO: refresh, if possible??  (Not applicable to either Twitter or Linked in, though)
             throw new Exception(String.Format("Authentication token for {0} provider has expired", providerName));
         }
         return new AuthenticationData
         {
             ConsumerKey = prov.ClientId,
             ConsumerSecret = prov.Secret,
             Token = userToken.AccessToken,
             TokenSecret = userToken.AccessTokenSecret,
             RefreshToken = userToken.RefreshToken
         };
     }
 }
Example #2
0
 public static AuthenticationData RetrieveAuthenticationData(String providerName)
 {
     using (var sess = new SessionScopeWrapper())
     {
         var prov = sess.CreateQuery("from OAuthProvider where ProviderName=?")
                    .SetString(0, providerName)
                    .List <IOAuthProvider>().FirstOrDefault();
         if (prov == null)
         {
             throw new Exception(String.Format("Unable to locate {0} provider in the configured OAuth providers", providerName));
         }
         var userToken = sess.CreateQuery("from UserOAuthToken where OAuthProvider.Id=? and User.Id=?")
                         .SetString(0, prov.Id.ToString())
                         .SetString(1, ApplicationContext.Current.Services.Get <IUserService>().UserId)
                         .List <IUserOAuthToken>()
                         .FirstOrDefault();
         if (userToken == null || userToken.AccessToken == null)
         {
             throw new Exception(String.Format("Unable to locate authorization token for current user under {0} provider", providerName));
         }
         if (userToken.ExpirationDate != null && userToken.ExpirationDate < DateTime.Now)
         {
             // TODO: refresh, if possible??  (Not applicable to either Twitter or Linked in, though)
             throw new Exception(String.Format("Authentication token for {0} provider has expired", providerName));
         }
         return(new AuthenticationData
         {
             ConsumerKey = prov.ClientId,
             ConsumerSecret = prov.Secret,
             Token = userToken.AccessToken,
             TokenSecret = userToken.AccessTokenSecret,
             RefreshToken = userToken.RefreshToken
         });
     }
 }
 public IEnumerable<IRecord> Read()
 {
     using (var sess = new SessionScopeWrapper())
     {
         var qry = sess.CreateQuery(_query);
         IList lst = qry.List();
         foreach (object o in lst)
             yield return new HqlRecordWrapper(o);
     }
 }
Example #4
0
        protected override void OnExecute()
        {
            IList <INotificationEvent> notificationEvents = null;

            // Get the list of Notification Events to process
            using (var session = new SessionScopeWrapper())
            {
                notificationEvents = session.QueryOver <INotificationEvent>()
                                     .Where(x => x.NextTimeToCheck <= DateTime.Now && x.Enabled == true)
                                     .List <INotificationEvent>();
            }

            if (notificationEvents != null)
            {
                foreach (INotificationEvent ne in notificationEvents)
                {
                    string   query   = ParseQueryForLiterals(ne);
                    DateTime now     = DateTime.UtcNow;
                    bool     bResult = false;

                    // Execute the query
                    using (var session = new SessionScopeWrapper())
                    {
                        Type entityType = typeof(Sage.SalesLogix.Entities.Account).Assembly.GetType(String.Format("Sage.SalesLogix.Entities.{0}", ne.EntityName));

                        IList <dynamic> payload = session.CreateQuery(query).List <dynamic>();

                        if (payload.Count > 0)
                        {
                            if (ne.Digest == true)
                            {
                                bResult = ProcessDigestEvent(ne, payload);
                            }
                            else
                            {
                                bResult = ProcessSingleEvent(ne, payload);
                            }
                        }
                        else
                        {
                            // Noting to process, but move the next time to check anyway.
                            bResult = true;
                        }
                    }
                    if (bResult)
                    {
                        // Update Notification Event
                        ne.LastChecked     = now;
                        ne.NextTimeToCheck = GetNextTimeToCheck(ne, now);
                        ne.Save();
                    }
                }
            }
        }
Example #5
0
 /// <summary>
 /// True if specified user is in specified team (or department).
 /// Note that this will return true whether the user is a direct member of the team,
 /// or manager of someone who is.
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="teamName"></param>
 /// <returns></returns>
 public static bool IsUserInTeam(String userId, String teamName)
 {
     using (var sess = new SessionScopeWrapper())
     {
         return(0 < sess.CreateQuery("select count(*) from OwnerRights sr where sr.User.Id=? and sr.Owner.OwnerDescription=?")
                .SetString(0, userId)
                .SetString(1, teamName)
                .SetCacheable(true)
                .UniqueResult <long>());
     }
 }
        public IEnumerable<IRecord> Read(WorkItem workItem)
        {
            String query = String.Format("from {0} where {1}", _entity, workItem.EvaluateLiterals(_where, this));

            using (var sess = new SessionScopeWrapper())
            {
                var qry = sess.CreateQuery(query);
                IList lst = qry.List();
                foreach (object o in lst)
                    yield return new EntityRecordWrapper(o);
            }
        }
    private IPickListView GetPickListView()
    {
        IPickListView plv = this.BindingSource.Current as IPickListView;

        using (ISession session = new SessionScopeWrapper(true))
        {
            IQuery query = session.CreateQuery("select p1 from PickListView p1 where p1.Id = :PickListId");
            query
            .SetAnsiString("PickListId", plv.Id.ToString())
            .SetCacheable(false);
            return(query.UniqueResult <IPickListView>());
        }
    }
Example #8
0
 /// <summary>
 /// Handles the Click event of the GetPasswordHint control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected void GetPasswordHint_Click(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(slxLogin.UserName))
     {
         HintText.Text = GetLocalResourceObject("PasswordHintUserNameRequired").ToString();
     }
     else
     {
         IList<IContact> contacts = null;
         using (ISession session = new SessionScopeWrapper())
         {
             contacts = session.CreateQuery("from Contact c where c.WebUserName = :value")
                .SetAnsiString("value", slxLogin.UserName)
                .List<IContact>();
         }
         if ((contacts != null) && (contacts.Count > 0))
         {
             HintText.Text = (contacts[0].WebPasswordHint);
         }
     }
     HintTextDiv.Style.Add(HtmlTextWriterStyle.Display, "inline");
 }
    private IList <IPickListItemView> GetItems(IPickListView pickList)
    {
        using (ISession session = new SessionScopeWrapper(true))
        {
            if (string.IsNullOrEmpty(_sortExpression))
            {
                _sortExpression = "OrderSeq";
            }
            if (string.IsNullOrEmpty(_sortDirection))
            {
                _sortDirection = "Asc";
            }

            string hql = string.Format("select P1 from PickListItemView P1 where (P1.UserId =:UserId And P1.PickListId = :PickListId) order by {0} {1} ", _sortExpression, _sortDirection);
            //string hql = string.Format("select P1 from PickListItemView P1 where (P1.PickListId = :PickListId) order by {0} {1} ", _sortExpression, _sortDirection);
            IQuery query = session.CreateQuery(hql);
            query
            .SetAnsiString("PickListId", pickList.Id.ToString())
            .SetAnsiString("UserId", "ADMIN")
            .SetCacheable(false);
            return(query.List <IPickListItemView>());
        }
    }
Example #10
0
    private void ExportPickListData(IList<string> selections, string format)
    {
        if (selections == null)
        {
            using (ISession session = new SessionScopeWrapper())
            {
                IQuery query = session.CreateQuery("select P.ItemId from PickList P where P.PickListId = :id order by P.Text");
                query
                    .SetAnsiString("id", "PICKLISTLIST")
                    .SetCacheable(true);
                selections = query.List<string>();
            }
        }

        DataTable dt = new DataTable("PickLists");
        DataColumn dc = dt.Columns.Add();
        dc.ColumnName = "PickListName";
        dc.DataType = typeof(string);
        dc.AllowDBNull = true;

        dc = dt.Columns.Add();
        dc.ColumnName = "Text";
        dc.DataType = typeof(string);
        dc.AllowDBNull = true;

        dc = dt.Columns.Add();
        dc.ColumnName = "Code";
        dc.DataType = typeof(string);
        dc.AllowDBNull = true;

        dc = dt.Columns.Add();
        dc.ColumnName = "Order";
        dc.DataType = typeof(int);
        dc.AllowDBNull = true;

        dc = dt.Columns.Add();
        dc.ColumnName = "IsDefault";
        dc.DataType = typeof(bool);
        dc.AllowDBNull = true;

        dc = dt.Columns.Add();
        dc.ColumnName = "PickListId";
        dc.DataType = typeof(string);
        dc.AllowDBNull = true;

        dc = dt.Columns.Add();
        dc.ColumnName = "ItemId";
        dc.DataType = typeof(string);
        dc.AllowDBNull = true;

        IDictionary<string, Layout> layout = new Dictionary<string, Layout>();

        Layout item = new Layout();
        item = new Layout();
        item.ColumnName = "PickListName";
        item.ColumnCaption = "PickListName";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        item = new Layout();
        item.ColumnName = "Text";
        item.ColumnCaption = "Text";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        item = new Layout();
        item.ColumnName = "Code";
        item.ColumnCaption = "Code";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        item = new Layout();
        item.ColumnName = "Order";
        item.ColumnCaption = "Order";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        item = new Layout();
        item.ColumnName = "IsDefault";
        item.ColumnCaption = "IsDefault";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        item = new Layout();
        item.ColumnName = "PickListId";
        item.ColumnCaption = "PickListId";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        item = new Layout();
        item.ColumnName = "ItemId";
        item.ColumnCaption = "ItemId";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        foreach (string pickListId in selections)
        {
            PickList pl = PickList.GetPickListById(pickListId);
            if (pl != null)
            {
                PickList defaultItem = PickList.GetDefaultItem(pickListId);
                IList<PickList> Items = PickList.GetPickListItems(pickListId, false);
                if ((items != null) || (Items.Count > 0))
                {
                    foreach (PickList pitem in Items)
                    {
                        DataRow row = dt.NewRow();
                        row["PickListId"] = pickListId;
                        row["ItemId"] = pitem.ItemId;
                        row["PickListName"] = pl.Text;
                        row["Text"] = pitem.Text;
                        row["Code"] = pitem.Shorttext;
                        row["Order"] = pitem.Id;
                        if ((defaultItem != null) && (defaultItem.ItemId == pitem.ItemId))
                        {
                            row["IsDefault"] = true;
                        }
                        else
                        {
                            row["IsDefault"] = false;
                        }
                        dt.Rows.Add(row);
                    }
                }
                else
                {
                    DataRow row = dt.NewRow();
                    row["PickListId"] = pickListId;
                    row["ItemId"] = "NOITEMS";
                    row["PickListName"] = pl.Text;
                    row["Text"] = "";
                    row["Code"] = "";
                    row["Order"] = -1;
                    row["IsDefault"] = false;
                    dt.Rows.Add(row);
                }
            }
        }

        switch (format)
        {
            case "csv":
                ToCSV(dt, layout);
                break;
            case "tab":
                ToTab(dt, layout);
                break;
        }
    }
    protected void LoadUrls()
    {
        ddlUrls.Items.Clear();

        IUserService userService = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Security.IUserService>();
        string currentUserId = userService.UserId;

        using (NHibernate.ISession session = new SessionScopeWrapper())
        {
            StringBuilder hql = new StringBuilder();
            hql.Append("select w.Name, w.Id, w.CreateUser from WebInfo w ");
            hql.Append("where w.CreateUser = :cUser ");
            hql.Append("and w.Entity = 'Account' ");
            hql.Append("or w.Share = 'Y' ");
            hql.Append("and w.Entity = 'Account' ");
            hql.Append("order by w.Name");

            NHibernate.IQuery newQuery = session.CreateQuery(hql.ToString());
            newQuery.SetAnsiString("cUser", currentUserId);

            System.Collections.IList tempList = newQuery.List();
            ArrayList results = new ArrayList();

            foreach (object data in tempList)
            {
                Array al = (Array)data;
                ArrayList fields = new ArrayList();
                foreach (object field in al)
                {
                    fields.Add((string)field);
                }
                results.Add(fields);
            }

            for (int i = 0; i < results.Count; i++)
            {
                ArrayList itemList = new ArrayList();

                itemList = results[i] as ArrayList;

                ListItem listItem = new ListItem();

                if (currentUserId == itemList[2].ToString())
                {
                    listItem.Text = itemList[0].ToString() + "*";
                }
                else
                {
                    listItem.Text = itemList[0].ToString();
                }

                listItem.Value = itemList[1].ToString();
                ddlUrls.Items.Add(listItem);
            }
        }

        if (ddlUrls.Items.Count > 0)
        {
            SetDisplay(ddlUrls.Items[0].Value);
        }
    }
Example #12
0
 /// <summary>
 /// True if specified user is in specified team (or department).
 /// Note that this will return true whether the user is a direct member of the team,
 /// or manager of someone who is.
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="teamName"></param>
 /// <returns></returns>
 public static bool IsUserInTeam(String userId, String teamName)
 {
     using (var sess = new SessionScopeWrapper())
     {
         return 0 < sess.CreateQuery("select count(*) from OwnerRights sr where sr.User.Id=? and sr.Owner.OwnerDescription=?")
             .SetString(0, userId)
             .SetString(1, teamName)
             .SetCacheable(true)
             .UniqueResult<long>();
     }
 }
Example #13
0
 private IPickListView GetPickListView()
 {
     IPickListView plv =  this.BindingSource.Current as IPickListView;
     using (ISession session = new SessionScopeWrapper(true))
     {
         IQuery query = session.CreateQuery("select p1 from PickListView p1 where p1.Id = :PickListId");
         query
             .SetAnsiString("PickListId", plv.Id.ToString())
             .SetCacheable(false);
         return query.UniqueResult<IPickListView>();
     }
 }
Example #14
0
    private IList<IPickListItemView> GetItems(IPickListView pickList)
    {
        using (ISession session = new SessionScopeWrapper(true))
        {

            if(string.IsNullOrEmpty(_sortExpression))
            {
               _sortExpression = "OrderSeq";
            }
            if(string.IsNullOrEmpty(_sortDirection))
            {
              _sortDirection = "Asc";
            }

                string hql = string.Format("select P1 from PickListItemView P1 where (P1.UserId =:UserId And P1.PickListId = :PickListId) order by {0} {1} ", _sortExpression, _sortDirection);
                //string hql = string.Format("select P1 from PickListItemView P1 where (P1.PickListId = :PickListId) order by {0} {1} ", _sortExpression, _sortDirection);
                IQuery query = session.CreateQuery(hql);
                query
                    .SetAnsiString("PickListId", pickList.Id.ToString())
                    .SetAnsiString("UserId", "ADMIN")
                    .SetCacheable(false);
                return query.List<IPickListItemView>();

        }
    }
    private void AddAction(string actionName, string desription, IRole role)
    {
        using (ISession session = new SessionScopeWrapper())
        {

            IList<ISecuredAction> actions = null;

            IQuery query = session.CreateQuery("from SecuredAction s where s.Name = :name");
            query
             .SetAnsiString("name", actionName);
            actions = query.List<ISecuredAction>();
            if (actions.Count < 1)
            {

                ISecuredAction newAction = Sage.Platform.EntityFactory.Create<ISecuredAction>();
                newAction.Name = actionName;
                newAction.Description = desription;
                newAction.Save();
                ISecuredActionRole newActionRole = Sage.Platform.EntityFactory.Create<ISecuredActionRole>();
                newActionRole.Role = role;
                newActionRole.SecuredAction = newAction;
                newActionRole.Save();
            }
            else
            { }

        }
    }