Browse Source

Merge branch 'develop'

Unknown 6 years ago
parent
commit
f73d84b05c
5 changed files with 100 additions and 9 deletions
  1. 4 4
      Quick.Commons.pas
  2. 37 0
      Quick.HttpClient.pas
  3. 49 0
      Quick.RTTI.Utils.pas
  4. 9 4
      Quick.Threads.pas
  5. 1 1
      QuickLib.inc

+ 4 - 4
Quick.Commons.pas

@@ -7,7 +7,7 @@
   Author      : Kike Pérez
   Version     : 1.7
   Created     : 14/07/2017
-  Modified    : 20/02/2019
+  Modified    : 27/02/2019
 
   This file is part of QuickLib: https://github.com/exilon/QuickLib
 
@@ -949,7 +949,7 @@ end;
           BuildStr := TNSString.Wrap(AppBundle.infoDictionary.objectForKey(AppKey));
           Result := UTF8ToString(BuildStr.UTF8String);
         except
-          Result := 'N/A';
+          Result := '';
         end;
       end;
       {$ENDIF}
@@ -1067,7 +1067,7 @@ end;
       end;
       {$ELSE}
         begin
-          Result := 'N/A';
+          Result := '';
         end;
       {$ENDIF}
     {$ENDIF}
@@ -1099,7 +1099,7 @@ begin
   FmtSettings.DateSeparator := '-';
   FmtSettings.TimeSeparator := ':';
   FmtSettings.ShortDateFormat := 'YYYY-MM-DD"T"HH:NN:SS.ZZZ" GMT"';
-  Result := DateTimeToStr(aDate,FmtSettings);
+  Result := DateTimeToStr(aDate,FmtSettings).Trim;
 end;
 
 function GMTToDateTime(aDate : string) : TDateTime;

+ 37 - 0
Quick.HttpClient.pas

@@ -103,6 +103,7 @@ type
     property HandleRedirects : Boolean read fHandleRedirects write SetHandleRedirects;
     function Get(const aURL : string) : IHttpRequestResponse;
     function Post(const aURL, aInContent : string) : IHttpRequestResponse; overload;
+    function Post(const aURL : string; aInContent : TStream) : IHttpRequestResponse; overload;
     function Post(const aURL : string; aJsonContent : TJsonObject) : IHttpRequestResponse; overload;
     function Put(const aURL, aInContent : string) : IHttpRequestResponse;
   end;
@@ -207,6 +208,42 @@ begin
   end;
 end;
 
+function TJsonHttpClient.Post(const aURL : string; aInContent : TStream) : IHttpRequestResponse;
+var
+  {$IFDEF DELPHIXE8_UP}
+  resp : IHTTPResponse;
+  {$ELSE}
+  resp : TIdHTTPResponse;
+  {$ENDIF}
+  responsecontent : TStringStream;
+begin
+  //postcontent.WriteString(aInContent);
+  responsecontent := TStringStream.Create;
+  try
+    {$IFDEF DELPHIXE8_UP}
+    resp := fHTTPClient.Post(aURL,aInContent,responsecontent);
+    {$ELSE}
+      {$IFDEF FPC}
+      try
+         fHTTPClient.Post(aURL,aInContent,responsecontent);
+         fHTTPClient.Disconnect(False);
+      except
+        on E : Exception do
+        begin
+          if e.ClassType <> EIdConnClosedGracefully then raise e;
+        end;
+      end;
+      {$ELSE}
+      fHTTPClient.Post(aURL,aInContent,responsecontent);
+      {$ENDIF}
+    resp := fHTTPClient.Response;
+    {$ENDIF}
+    Result := THttpRequestResponse.Create(resp,responsecontent.DataString);
+  finally
+    responsecontent.Free;
+  end;
+end;
+
 function TJsonHttpClient.Post(const aURL : string; aJsonContent : TJsonObject) : IHttpRequestResponse;
 begin
   {$IFDEF DELPHIXE8_UP}

+ 49 - 0
Quick.RTTI.Utils.pas

@@ -1,5 +1,36 @@
+{ ***************************************************************************
+
+  Copyright (c) 2016-2019 Kike Pérez
+
+  Unit        : Quick.RTTI.Utils
+  Description : Files functions
+  Author      : Kike Pérez
+  Version     : 1.5
+  Created     : 09/03/2018
+  Modified    : 20/02/2019
+
+  This file is part of QuickLib: https://github.com/exilon/QuickLib
+
+ ***************************************************************************
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+ *************************************************************************** }
+
 unit Quick.RTTI.Utils;
 
+{$i QuickLib.inc}
+
 interface
 
 uses
@@ -23,6 +54,7 @@ type
     class function PropertyExists(aTypeInfo : Pointer; const aPropertyName : string) : Boolean;
     class function GetPropertyValue(aInstance : TObject; const aPropertyName : string) : TValue; overload;
     class function GetPropertyValue(aTypeInfo : Pointer; const aPropertyName : string) : TValue; overload;
+    class function FindClass(const aClassName: string): TClass;
   end;
 
   ERTTIError = class(Exception);
@@ -114,5 +146,22 @@ begin
   Result := fCtx.GetType(aTypeInfo).GetProperty(aPropertyName) <> nil;
 end;
 
+class function TRTTI.FindClass(const aClassName: string): TClass;
+var
+  rType : TRttiType;
+  rList : TArray<TRttiType>;
+begin
+  Result := nil;
+  rList := fCtx.GetTypes;
+  for rType in rList do
+  begin
+    if (rType.IsInstance) and (aClassName.EndsWith(rType.Name)) then
+      begin
+        Result := rType.AsInstance.MetaClassType;
+        Break;
+      end;
+  end;
+end;
+
 
 end.

+ 9 - 4
Quick.Threads.pas

@@ -7,7 +7,7 @@
   Author      : Kike Pérez
   Version     : 1.4
   Created     : 09/03/2018
-  Modified    : 18/02/2019
+  Modified    : 28/02/2019
 
   This file is part of QuickLib: https://github.com/exilon/QuickLib
 
@@ -1402,9 +1402,14 @@ begin
         tmMinutes : fNextExecution := IncMinute(fNextExecution,fTimeInterval);
         tmSeconds : fNextExecution := IncSecond(fNextExecution,fTimeInterval);
       end;
-      fLastExecution := Now();
-      Inc(fExecutionTimes);
-      Result := True;
+
+      if Now() > fNextExecution then Result := False //avoid execution if system time was altered
+      else
+      begin
+        fLastExecution := Now();
+        Inc(fExecutionTimes);
+        Result := True;
+      end;
     end;
   end;
 end;

+ 1 - 1
QuickLib.inc

@@ -1,7 +1,7 @@
 {
     This file is part of QuickLib: https://github.com/exilon/QuickLib
 
-    QuickLibs. Copyright (C) 2018 Kike Pérez
+    QuickLibs. Copyright (C) 2019 Kike Pérez
       Exilon - https://www.exilon.es
 
      ***************************************************************************