Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 9 of 9 total
Thread Copy from filesystem to store and vice versa
Thu, Jun 28 2012 4:21 AMPermanent Link

Heiko Knuettel

It would be very nice if I could copy files from e.g "C:\LocalDocuments" to the store "ServerDocuments" and backwards, in cases when the users have no read/write permission for the folder on the server with the store "ServerDocuments".
Thu, Jun 28 2012 5:11 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Heiko


I would consider that bad news. Whilst I've had many a battle with security settings they exist for a reason and we shouldn't look for ways to circumvent them.

Roy Lambert
Thu, Jun 28 2012 6:25 AMPermanent Link

Heiko Knuettel

Roy

It could be your own security settings that you are trying to "circumvent". Just imagine you don't want users to read/write from/to a server folder with the windows explorer, but only your through your application. Basically the same with the database files on the server, you hide them from direct access too.
Thu, Jun 28 2012 8:45 AMPermanent Link

Raul

Team Elevate Team Elevate

Heiko,

The easiest way i think of this working would be to just create a local
store pointing to C:\LocalDocuments and then you can just copy files
between stores using normal edb commands (so either from your app or
helper utility). Creating/deleting a store could be done on demand just
for the duration of the file copy.

Raul




On 6/28/2012 4:21 AM, Heiko Knuettel wrote:
> It would be very nice if I could copy files from e.g "C:\LocalDocuments" to the store "ServerDocuments" and backwards, in cases when the users have no read/write permission for the folder on the server with the store "ServerDocuments".
>

Thu, Jun 28 2012 1:24 PMPermanent Link

Heiko Knuettel

Raul,

Ummm...when I am connected to a remote server and create a "local" store, it is created on the server machine.
Thu, Jun 28 2012 3:17 PMPermanent Link

Raul

Team Elevate Team Elevate


Yes, you would need to run a local edb engine session for the local
store (C:\LocalDocuments) and then in there create a remote store for
the store on the actual edb remote server.

You can run both local and remote sessions in the same app or depending
on your file copy requirements a small utility app might work as well.

Raul


On 6/28/2012 1:24 PM, Heiko Knuettel wrote:
> Raul,
>
> Ummm...when I am connected to a remote server and create a "local" store, it is created on the server machine.
>

Thu, Jun 28 2012 3:37 PMPermanent Link

Heiko Knuettel

Raul,

Sounds interesting...I'll try that, thanks!
Tue, Jul 3 2012 8:20 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Heiko,

<< It would be very nice if I could copy files from e.g "C:\LocalDocuments"
to the store "ServerDocuments" and backwards, in cases when the users have
no read/write permission for the folder on the server with the store
"ServerDocuments". >>

See these methods:

http://www.elevatesoft.com/manual?action=viewmethod&id=edb2&product=delphi&version=7&comp=TEDBSession&method=SaveStoreFileToStream

http://www.elevatesoft.com/manual?action=viewmethod&id=edb2&product=delphi&version=7&comp=TEDBSession&method=CalculateCRC32ForStream

http://www.elevatesoft.com/manual?action=viewmethod&id=edb2&product=delphi&version=7&comp=TEDBSession&method=SaveStreamToStoreFile

To modify a store file on the local machine, just execute the methods above.
You can use the CalculateCRC32ForStream method to determine if a file has
changed or not since being copied to the client application.  The EDB
Manager has code (main.pas) that shows how this is done using ShellExecute:

function TStoreFileObject.Alter: Boolean;
var
  TempFileName: TEDBString;
  TempFileStream: TFileStream;
  TempCRC32: LongWord;
  TempStoreName: TEDBString;
  TempRetry: Boolean;
begin
  Result:=False;
  MainForm.BeginExecution('Opening...',True,True);
  try
     with SessionObject.Session do
        begin
        TempFileName:=IncludeTrailingBackslash(Engine.Handle.Environment.TempDirectory)+FName;
        try
           TempFileStream:=TFileStream.Create(TempFileName,(fmCreate or
fmShareExclusive));
           try
              SaveStoreFileToStream(ParentName,FName,TempFileStream);
              TempCRC32:=CalculateCRC32ForStream(TempFileStream);
           finally
              FreeAndNil(TempFileStream);
           end;
           ShellOpenFile(MainForm.Handle,TempFileName,Engine.Handle.Environment.TempDirectory);
           TempFileStream:=TFileStream.Create(TempFileName,(fmOpenRead or
fmShareExclusive));
           try
              if (CalculateCRC32ForStream(TempFileStream) <> TempCRC32)
then
                 begin
                 if (MessageDlg('Would you like to propogate the changes
made to '+FName+' back to '+
                                'the source file in the '+ParentName+'
store ?',mtConfirmation,[mbYes,mbNo],0)=mrYes) then
                    begin
                    TempRetry:=True;
                    TempStoreName:=ParentName;
                    while TempRetry do
                       begin
                       TempRetry:=False;
                       try
                          SaveStreamToStoreFile(TempStoreName,FName,TempFileStream);
                          Result:=True;
                       except
                          on E: Exception do
                             begin
                             TempRetry:=True;
                             if (MessageDlg('The following error occurred
while propogating the changes '+
                                            'made to '+FName+' back to the
source file in the '+TempStoreName+' store: '+CRLF+CRLF+
                                            E.Message+CRLF+CRLF+
                                            'Would you like to save the
file to a different store until the problem can '+
                                            'be resolved
?',mtError,[mbYes,mbNo],0)=mrYes) then
                                begin
                                SelectStoreDialog:=TSelectStoreDialog.Create(nil);
                                try
                                   with SelectStoreDialog do
                                      begin
                                      CurStoreName:=TempStoreName;
                                      CurObject:=Self;
                                      Setup;
                                      if (ShowModal=mrOk) then
                                         TempStoreName:=FileStoreComboBox.Text;
                                      end;
                                finally
                                   SelectStoreDialog.Release;
                                end;
                                end;
                             end;
                       end;
                       end;
                    end;
                 end;
           finally
              FreeAndNil(TempFileStream);
           end;
        finally
           DeleteFile(TempFileName);
        end;
        end;
     MainForm.EndExecution('Opened');
  except
     MainForm.CancelExecution('Error opening');
     raise;
  end;
end;

The ShellOpenFile procedure (edbutilcomps.pas in the \utilcomps subdirectory
of the EDB-ADD download) looks like this:

procedure ShellOpenFile(ParentWindow: HWND; const FileName: TEDBString;
                       const DefaultDirectory: TEDBString);
var
  {$IFDEF EDB_UNICODE}
  ExecuteInfo: TShellExecuteInfoW;
  {$ELSE}
  ExecuteInfo: TShellExecuteInfoA;
  {$ENDIF}
  TempResult: Boolean;
begin
  with ExecuteInfo do
     begin
     cbSize:=SizeOf(ExecuteInfo);
     fMask:=(SEE_MASK_FLAG_DDEWAIT   or SEE_MASK_NOCLOSEPROCESS or
SEE_MASK_FLAG_NO_UI);
     Wnd:=ParentWindow;
     lpVerb:='open';
     lpFile:=pEDBChar(FileName);
     lpParameters:=nil;
     lpDirectory:=pEDBChar(DefaultDirectory);
     nShow:=SW_SHOW;
     hInstApp:=0;
     end;
  {$IFDEF EDB_UNICODE}
  TempResult:=ShellExecuteExW(@ExecuteInfo);
  {$ELSE}
  TempResult:=ShellExecuteExA(@ExecuteInfo);
  {$ENDIF}
  if TempResult then
     begin
     try
        Windows.WaitForSingleObject(ExecuteInfo.hProcess,INFINITE);
     finally
        Windows.CloseHandle(ExecuteInfo.hProcess);
     end;
     end
  else
     raise Exception.Create(SysErrorMessage(GetLastError));
end;

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Jul 18 2012 7:35 AMPermanent Link

Heiko Knuettel

Tim,

so it's already there...great! Thank you!
Image