예제 #1
0
        public static ReaderInfo Authorize(AuthorizeInfo request)
        {
            int          NumberReader = 0;
            ReaderInfo   result       = null;
            ReaderLoader loader       = new ReaderLoader();
            string       LoginType    = ReaderInfo.GetLoginType(request.login);

            if (LoginType == "NumberReader")
            {
                NumberReader = int.Parse(request.login);
                ReaderInfo reader = ReaderInfo.GetReader(NumberReader);
                if (reader == null)
                {
                    throw new Exception("R001");
                }
                request.password = ReaderInfo.HashPass(request.password, reader.Salt);
                result           = loader.Authorize(NumberReader, request.password);
            }
            else if (LoginType == "Email")
            {
                ReaderInfo reader = ReaderInfo.GetReader(request.login);
                if (reader == null)
                {
                    throw new Exception("R001");
                }
                request.password = ReaderInfo.HashPass(request.password, reader.Salt);
                result           = loader.Authorize(request.login, request.password);
            }
            if (result == null)
            {
                throw new Exception("R001");
            }
            return(result);
        }
예제 #2
0
파일: Form1.cs 프로젝트: infra-hdc/LIBFL
        private void ReadersAuthorize_Click(object sender, EventArgs e)
        {
            AuthorizeInfo request = new AuthorizeInfo();

            request.login    = "******";
            request.password = "******";
            string jsonData = JsonConvert.SerializeObject(request, ALISDateFormatJSONSettings);

            for (int i = 0; i < 100000; i++)
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                using (HttpClient client = new HttpClient())
                {
                    var response = client.PostAsync(ALIS_ADDRESS + "Readers/Authorize/", new StringContent(jsonData, Encoding.UTF8, "application/json"));
                    tbResponse.Text = response.Result.Content.ReadAsStringAsync().Result + " " + response.Result.StatusCode + sw.Elapsed.Milliseconds;
                    //tbResponse.Text = response.Result.Content.ToString();
                }
            }
        }
예제 #3
0
        public void UploadFile(byte[] content, string filename, string target)
        {
            ocl = DropboxClient.CreateOAuthClient(APP_KEY, APP_SECRET);
            ai  = ocl.GetAuthorizeInfo();

            RequestToken       = ai.RequestToken;
            RequestTokenSecret = ai.RequestTokenSecret;
            redirect_url       = ai.AuthorizeUrl;
            AccessTokenInfo t = ocl.GetAccessToken(RequestToken, RequestTokenSecret);

            Token       = t.Token;
            TokenSecret = t.TokenSecret;

            DropboxClient cl = new DropboxClient(APP_KEY, APP_SECRET, Token, TokenSecret);

            HigLabo.Net.Dropbox.UploadFileCommand ul = new HigLabo.Net.Dropbox.UploadFileCommand();
            ul.Root       = RootFolder.Sandbox;
            ul.FolderPath = target;
            ul.FileName   = filename;
            ul.LoadFileData(content);

            Metadata md = cl.UploadFile(ul);
        }
예제 #4
0
        public static void Register(HttpConfiguration config)
        {
            //// Uncomment the following to use the documentation from XML documentation file.
            config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/Documentation/documentation.xml")));

            //// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type.
            //// Also, the string arrays will be used for IEnumerable<string>. The sample objects will be serialized into different media type
            //// formats by the available formatters.
            //config.SetSampleObjects(new Dictionary<Type, object>
            //{
            //    {typeof(string), "sample string"},
            //    {typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
            //});

            // Extend the following to provide factories for types not handled automatically (those lacking parameterless
            // constructors) or for which you prefer to use non-default property values. Line below provides a fallback
            // since automatic handling will fail and GeneratePageResult handles only a single type.
#if Handle_PageResultOfT
            config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult);
#endif

            // Extend the following to use a preset object directly as the sample for all actions that support a media
            // type, regardless of the body parameter or return type. The lines below avoid display of binary content.
            // The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object.
            config.SetSampleForMediaType(
                new TextSample("Binary JSON content. See http://bsonspec.org for details."),
                new MediaTypeHeaderValue("application/bson"));

            //// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format
            //// and have IEnumerable<string> as the body parameter or return type.
            //config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));

            //// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
            //// and action named "Put".
            //config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");

            //// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
            //// on the controller named "Values" and action named "Get" with parameter "id".
            //config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");

            //// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
            //// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
            //config.SetActualRequestType(typeof(string), "Values", "Get");

            //// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
            //// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
            //config.SetActualResponseType(typeof(string), "Values", "Post");


            ReaderInfo reader = ReaderInfo.GetReader(189245);
            //Readers.Get
            ReaderSimpleView rsv  = ReaderViewFactory.GetReaderSimpleView(reader);
            string           json = JsonConvert.SerializeObject(rsv, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Readers", "Get");


            //Readers.GetByOauthToken
            AccessToken token = new AccessToken();
            token.TokenValue = "jhgfjfg*%&$*FKGfkfKfI^(*&^5&^TGVfjtgfdtre$E65r86T87t)(*7goYGV986T98^&Go8yg";
            json             = JsonConvert.SerializeObject(token, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Readers", "GetByOauthToken");

            json = JsonConvert.SerializeObject(rsv, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Readers", "GetByOauthToken");

            ////Readers.ChangePasswordLocalReader
            //ChangePasswordLocalReader password = new ChangePasswordLocalReader();
            //password.DateBirth = "1984-02-14";// new DateTime(1984, 2, 14);
            //password.NewPassword = "******";
            //password.NumberReader = 189245;
            //json = JsonConvert.SerializeObject(password, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            //config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Readers", "ChangePasswordLocalReader");

            //Readers.GetLoginType
            LoginType ltype = new LoginType();
            ltype.LoginTypeValue = "Email";
            json = JsonConvert.SerializeObject(ltype, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Readers", "GetLoginType");
            UserLogin ul = new UserLogin();
            ul.Login = "******";
            json     = JsonConvert.SerializeObject(ul, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Readers", "GetLoginType");


            //Readers.ByEmail
            UserEmail ue = new UserEmail();
            ue.Email = "*****@*****.**";
            json     = JsonConvert.SerializeObject(ue, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Readers", "ByEmail");
            json = JsonConvert.SerializeObject(rsv, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Readers", "ByEmail");



            //Readers.Authorize
            AuthorizeInfo aut = new AuthorizeInfo();
            aut.login    = "******";
            aut.password = "******";
            json         = JsonConvert.SerializeObject(aut, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Readers", "Authorize");
            config.SetSampleForType(aut, new MediaTypeHeaderValue("application/json"), typeof(AuthorizeInfo));
            config.SetActualRequestType(typeof(AuthorizeInfo), "Readers", "Authorize");
            json = JsonConvert.SerializeObject(rsv, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Readers", "Authorize");

            //Readers / IsBirthDateMatchReaderId
            BirthDateMatchReaderId match = new BirthDateMatchReaderId();
            match.DateBirth = "1984-02-14";
            match.ReaderId  = 189245;
            BooleanResponse br = new BooleanResponse();
            br.Result = true;
            json      = JsonConvert.SerializeObject(match, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Readers", "IsBirthDateMatchReaderId");
            json = JsonConvert.SerializeObject(br, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Readers", "IsBirthDateMatchReaderId");

            //Readers/SetPasswordLocalReader
            SetPasswordLocalReader spwd = new SetPasswordLocalReader();
            spwd.NewPassword = "******";
            spwd.ReaderId    = 189245;
            json             = JsonConvert.SerializeObject(spwd, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Readers", "SetPasswordLocalReader");


            //Books.Get
            BookSimpleView book;
            book = ViewFactory.GetBookSimpleView("BJVVV_1411951");
            json = JsonConvert.SerializeObject(book, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Books", "Get");

            //Circulation.InsertIntoUserBasket
            ImpersonalBasket basket = new ImpersonalBasket();
            basket.BookIdArray = new List <string>();
            basket.BookIdArray.AddRange(new string[] { "BJVVV_1299121", "BJVVV_1304618", "REDKOSTJ_31866", "REDKOSTJ_43090" });
            basket.ReaderId = 189245;
            json            = JsonConvert.SerializeObject(basket, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Circulation", "InsertIntoUserBasket");

            //Circulation.Basket
            CirculationInfo   circ       = new CirculationInfo();
            List <BasketInfo> UserBasket = circ.GetBasket(888);
            json = JsonConvert.SerializeObject(UserBasket, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Circulation", "Basket");

            //Circulation.Order
            circ = new CirculationInfo();
            MakeOrder mo = new MakeOrder();
            mo.BookId      = "BJVVV_1078762";
            mo.ReaderId    = 100000;
            mo.OrderTypeId = 2;
            json           = JsonConvert.SerializeObject(mo, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Circulation", "Order");


            //Circulation.Orders
            List <OrderInfo> UserOrders = circ.GetOrders(155);
            json = JsonConvert.SerializeObject(UserOrders, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Circulation", "Orders");
            //Circulation.Basket    Delete
            BasketDelete bd = new BasketDelete();
            bd.BooksToDelete.Add("BJVVV_1299121");
            bd.BooksToDelete.Add("BJVVV_1491232");
            bd.ReaderId = 200500;
            json        = JsonConvert.SerializeObject(bd, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Circulation", "DeleteFromBasket");

            //Circulation.OrdersHistory
            List <OrderHistoryInfo> UserOrdersHistory = circ.GetOrdersHistory(100000);
            json = JsonConvert.SerializeObject(UserOrdersHistory, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Circulation", "OrdersHistory");


            //Readers.PreRegisterRemoteReader
            PreRegisterRemoteReader re = new PreRegisterRemoteReader();
            re.BirthDate   = "1975-05-05";//new DateTime(1975, 05, 05);
            re.CountryId   = 137;
            re.Email       = "*****@*****.**";
            re.FamilyName  = "Иванов";
            re.FatherName  = "Иванович";
            re.MobilePhone = "89551234567";
            re.Name        = "Иван";
            re.Password    = "******";
            json           = JsonConvert.SerializeObject(re, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Readers", "PreRegisterRemoteReader");

            //Readers.ConfirmRegistrationRemoteReader
            ConfirmRegistrationRemoteReader c = new ConfirmRegistrationRemoteReader();
            c.Url = "https://oauth.libfl.ru/activate/<activation code>";
            json  = JsonConvert.SerializeObject(c, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Readers", "ConfirmRegistrationRemoteReader");

            //Readers.ChangePasswordByEmail
            ChangePasswordByEmail em = new ChangePasswordByEmail();
            em.Email = "*****@*****.**";
            json     = JsonConvert.SerializeObject(em, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Readers", "ChangePasswordByEmail");

            //Readers.SetPasswordRemoteReader
            SetPasswordRemoteReader set = new SetPasswordRemoteReader();
            set.Url      = "https://oauth.libfl.ru/recovery/<recovery code>";
            set.Password = "******";
            json         = JsonConvert.SerializeObject(set, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Readers", "SetPasswordRemoteReader");

            //Readers.CheckPasswordUrl
            CheckPasswordUrl check = new CheckPasswordUrl();
            check.Url = "https://oauth.libfl.ru/recovery/<recovery code>";
            json      = JsonConvert.SerializeObject(check, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleRequest(json, new MediaTypeHeaderValue("application/json"), "Readers", "CheckPasswordUrl");

            //GET Litres/Account/{ReaderId}
            LitresInfo li = new LitresInfo();
            li.Login    = "******";
            li.Password = "******";
            json        = JsonConvert.SerializeObject(li, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Litres", "LitresAccount");
            //POST Litres/AssignAccount/{ReaderId}
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Litres", "AssignLitresAccount");


            //Circulation / Orders / ById /{ OrderId}
            OrderInfo oi = circ.GetOrder(22);
            json = JsonConvert.SerializeObject(oi, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Circulation", "OrdersById");

            //Books/ElectronicCopy/{id}
            ElectronicCopyFullView ec = ViewFactory.GetElectronicCopyFullView("BJVVV_138023");
            json = JsonConvert.SerializeObject(ec, Formatting.Indented, ALISSettings.ALISDateFormatJSONSettings);
            config.SetSampleResponse(json, new MediaTypeHeaderValue("application/json"), "Books", "GetElectronicCopyFullView");
        }
예제 #5
-1
        public void UploadFile(byte[] content, string filename, string target)
        {
            ocl = DropboxClient.CreateOAuthClient(APP_KEY, APP_SECRET);
            ai = ocl.GetAuthorizeInfo();

            RequestToken = ai.RequestToken;
            RequestTokenSecret = ai.RequestTokenSecret;
            redirect_url = ai.AuthorizeUrl;
            AccessTokenInfo t = ocl.GetAccessToken(RequestToken, RequestTokenSecret);

            Token = t.Token;
            TokenSecret = t.TokenSecret;

            DropboxClient cl = new DropboxClient(APP_KEY, APP_SECRET, Token, TokenSecret);

            HigLabo.Net.Dropbox.UploadFileCommand ul = new HigLabo.Net.Dropbox.UploadFileCommand();
            ul.Root = RootFolder.Sandbox;
            ul.FolderPath = target;
            ul.FileName = filename;
            ul.LoadFileData(content);

            Metadata md = cl.UploadFile(ul);


        }