Esempio n. 1
0
 public static string GetTextResponse(string method, IDictionary par)
 {
     using (var reader = new StreamReader(GetWebResponse(method, "json", par).GetResponseStream(), Encoding.UTF8))
     {
         string res = reader.ReadToEnd();
         SessionTrace.Add(res);
         return(res);
     }
 }
Esempio n. 2
0
    public static void Reset()
    {
        SessionTrace err = Current;

        lock (err.lockObj)
        {
            err.TraceList = new List <string>();
            HttpContext.Current.Session.Remove(Key);
        }
    }
Esempio n. 3
0
 public static void Add(string error)
 {
     if (Allowed)
     {
         SessionTrace err = Current;
         lock (err.lockObj)
         {
             err.TraceList.Add(error);
             err.Update();
         }
     }
 }
Esempio n. 4
0
    public static HttpWebResponse GetWebResponse(string serviceName, string format, IDictionary par)
    {
        string paramString = "{";

        if (par != null)
        {
            bool first = true;
            foreach (var key in par.Keys)
            {
                paramString += (first ? "" : ",") + "\"" + key + "\":" + JsonConvert.SerializeObject(par[key], Newtonsoft.Json.Formatting.None);
                first        = false;
            }
        }
        paramString += "}";

        var webRequest = (HttpWebRequest)WebRequest.Create(string.Format(@"http://{0}/{1}?format={2}", WebConfigurationManager.AppSettings[InstallHelpers.UltimaWebServiceURL], serviceName, format));

        webRequest.Method          = "POST";
        webRequest.ContentType     = "text/json";
        webRequest.UserAgent       = "Mozilla/5.0 (Windows NT 5.1; rv:28.0) Gecko/20100101 Firefox/28.0";
        webRequest.ContentLength   = Encoding.UTF8.GetBytes(paramString).Length;
        webRequest.CookieContainer = cookieCont;

        string autorization = "bitrix" + ":" + "bitrix";

        byte[] binaryAuthorization = System.Text.Encoding.UTF8.GetBytes(autorization);
        autorization = Convert.ToBase64String(binaryAuthorization);
        autorization = "Basic " + autorization;
        webRequest.Headers.Add("AUTHORIZATION", autorization);

        SessionTrace.Add(paramString);
        webRequest.CookieContainer = cookieCont;
        try
        {
            using (var streamWriter = new StreamWriter(webRequest.GetRequestStream()))
            {
                streamWriter.Write(paramString);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var webResponse = (HttpWebResponse)webRequest.GetResponse();
            return(webResponse);
        }
        catch (Exception ex)
        {
            string msg = Log(ex, webRequest.RequestUri.ToString(), paramString);
            throw new Exception(msg, ex);
        }
    }
    public static bool SignIn(string user, string password)
    {
        bool isSignedIn = UltimaWebService.SignInAgent(user, password);

        if (isSignedIn)
        {
            CClientInfo info = SessionClient.GetClientInfo(true);

            if (info != null)
            {
                bool   isPersistent = false;
                string userData     = info.Id.ToString();

                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                    1,                                                         // ticket version
                    info.FirstName,                                            // authenticated username
                    DateTime.Now,                                              // issueDate
                    DateTime.Now.AddMinutes(30),                               // expiryDate
                    isPersistent,                                              // true to persist across browser sessions
                    userData,                                                  // can be used to store additional user data
                    FormsAuthentication.FormsCookiePath);                      // the path for the cookie

                string encryptedTicket = FormsAuthentication.Encrypt(ticket);

                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                cookie.HttpOnly = true;
                HttpContext.Current.Response.Cookies.Add(cookie);
                return(true);
            }
            else
            {
                SessionTrace.Add("ClientInfo is null");
            }
        }
        else
        {
            SessionTrace.Add("Not signed in - signing out..");
        }

        SignOut();

        return(false);
    }
Esempio n. 6
0
 public void AddSession(SessionTrace session)
 {
     _sessionTraceRepository.Add(session);
 }
 public void AddSession(SessionTrace session)
 {
     _sessionTraceDomain.AddSession(session);
 }