Click or drag to resize

SilverlightRemoteInvokeArguments Class

This class contains information passed to a remote invoke method.
This class contains information passed to a remote invoke method.
Inheritance Hierarchy
SystemObject
  Atalasoft.Imaging.SilverlightSilverlightRemoteInvokeArguments

Namespace:  Atalasoft.Imaging.Silverlight
Assembly:  Atalasoft.dotImage.Silverlight.Web (in Atalasoft.dotImage.Silverlight.Web.dll) Version: 11.0.0.0.0.297 (.NET 4.5.2, x86)
Syntax
public class SilverlightRemoteInvokeArguments

The SilverlightRemoteInvokeArguments type exposes the following members.

Properties
  NameDescription
Public propertyAllFiles
Gets a collection of ServerFileInformation for all images loaded in the Silverlight client.
Public propertyCode exampleArguments
Public propertyCode exampleSelectedFiles
Gets a collection of selected files.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodCode exampleUpdateImage
Notifies the SilverlightImageViewer control to reload all of the selected images.
Public methodCode exampleUpdateImage(ServerFileInformation)
Notifies the Silverlight control to reload a specific image.
Top
Examples
 Public Function ApplyMosaicCommand(ByVal e As SilverlightRemoteInvokeArguments) As String
    If e.SelectedFiles.Count = 0 Then
        Return "No image was selected."
    End If

    Dim cmd As New MosaicCommand()
    If e.Arguments.ContainsKey("SquareSize") Then
        cmd.SquareSize = Convert.ToInt32(e.Arguments("SquareSize"))
    End If

    Return ApplyCommand(cmd, e)
End Function

Private Function ApplyCommand(ByVal cmd As ImageCommand, ByVal e As SilverlightRemoteInvokeArguments) As String
    cmd.ApplyToAnyPixelFormat = True
    Try
        For Each file As ServerFileInformation In e.SelectedFiles
            Dim image As AtalaImage = Nothing
            Dim isTiff As Boolean = False

            Using fs As New FileStream(file.OriginalFile, FileMode.Open, FileAccess.Read, FileShare.Read)
                Dim decoder As ImageDecoder = RegisteredDecoders.GetDecoder(fs)
                fs.Seek(0, SeekOrigin.Begin)

                Dim md As MultiFramedImageDecoder = TryCast(decoder, MultiFramedImageDecoder)
                If md Is Nothing Then
                    image = decoder.Read(fs, Nothing)
                Else
                    isTiff = (Typeof decoder Is TiffDecoder)
                    image = md.Read(fs, file.FrameIndex, Nothing)
                End If
            End Using

            Dim results As ImageResults = cmd.Apply(image)

            If isTiff Then
                Dim tmp As String = Me.SilverlightWebHandler1.GetTemporaryFileName(e)
                File.Copy(file.OriginalFile, tmp, True)

                Using src As New FileStream(tmp, FileMode.Open, FileAccess.Read, FileShare.Read)
                    Dim doc As New TiffDocument(src)
                    If doc.Pages.Count <= file.FrameIndex Then
                        Return "error: Invalid index of "  file.FrameIndex.ToString()  "."
                    End If

                    doc.Pages(file.FrameIndex) = New TiffPage(results.Image)
                    doc.Save(file.OriginalFile)
                End Using

                File.Delete(tmp)
            Else
                results.Image.Save(file.OriginalFile, New PngEncoder(), Nothing)
            End If

            results.Image.Dispose()

            If (Not results.IsImageSourceImage) Then
                image.Dispose()
            End If

            e.UpdateImage(file)
        Next file
    Catch ex As Exception
        Return "There was an error applying the command."  Constants.vbCrLf  ex.Message
    End Try

    Return ""
End Function
 public string ApplyMosaicCommand(SilverlightRemoteInvokeArguments e)
{
  if (e.SelectedFiles.Count == 0)
      return "No image was selected.";

  MosaicCommand cmd = new MosaicCommand();
  if (e.Arguments.ContainsKey("SquareSize"))
      cmd.SquareSize = Convert.ToInt32(e.Arguments["SquareSize"]);

  return ApplyCommand(cmd, e);
}

private string ApplyCommand(ImageCommand cmd, SilverlightRemoteInvokeArguments e)
{
  cmd.ApplyToAnyPixelFormat = true;
  try
  {
      foreach (ServerFileInformation file in e.SelectedFiles)
      {
          AtalaImage image = null;
          bool isTiff = false;

          using (FileStream fs = new FileStream(file.OriginalFile, FileMode.Open, FileAccess.Read, FileShare.Read))
          {
              ImageDecoder decoder = RegisteredDecoders.GetDecoder(fs);
              fs.Seek(0, SeekOrigin.Begin);

              MultiFramedImageDecoder md = decoder as MultiFramedImageDecoder;
              if (md == null)
                  image = decoder.Read(fs, null);
              else
              {
                  isTiff = (decoder is TiffDecoder);
                  image = md.Read(fs, file.FrameIndex, null);
              }
          }

          ImageResults results = cmd.Apply(image);

          if (isTiff)
          {
              string tmp = this.SilverlightWebHandler1.GetTemporaryFileName(e);
              File.Copy(file.OriginalFile, tmp, true);

              using (FileStream src = new FileStream(tmp, FileMode.Open, FileAccess.Read, FileShare.Read))
              {
                  TiffDocument doc = new TiffDocument(src);
                  if (doc.Pages.Count <= file.FrameIndex)
                      return "error: Invalid index of " + file.FrameIndex.ToString() + ".";

                  doc.Pages[file.FrameIndex] = new TiffPage(results.Image);
                  doc.Save(file.OriginalFile);
              }

              File.Delete(tmp);
          }
          else
          {
              results.Image.Save(file.OriginalFile, new PngEncoder(), null);
          }

          results.Image.Dispose();

          if (!results.IsImageSourceImage)
              image.Dispose();

          e.UpdateImage(file);
      }
  }
  catch (Exception ex)
  {
      return "There was an error applying the command.\r\n" + ex.Message;
  }

  return "";
}
Examples
 Public Function ApplyMosaicCommand(ByVal e As SilverlightRemoteInvokeArguments) As String
    If e.SelectedFiles.Count = 0 Then
        Return "No image was selected."
    End If

    Dim cmd As New MosaicCommand()
    If e.Arguments.ContainsKey("SquareSize") Then
        cmd.SquareSize = Convert.ToInt32(e.Arguments("SquareSize"))
    End If

    Return ApplyCommand(cmd, e)
End Function

Private Function ApplyCommand(ByVal cmd As ImageCommand, ByVal e As SilverlightRemoteInvokeArguments) As String
    cmd.ApplyToAnyPixelFormat = True
    Try
        For Each file As ServerFileInformation In e.SelectedFiles
            Dim image As AtalaImage = Nothing
            Dim isTiff As Boolean = False

            Using fs As New FileStream(file.OriginalFile, FileMode.Open, FileAccess.Read, FileShare.Read)
                Dim decoder As ImageDecoder = RegisteredDecoders.GetDecoder(fs)
                fs.Seek(0, SeekOrigin.Begin)

                Dim md As MultiFramedImageDecoder = TryCast(decoder, MultiFramedImageDecoder)
                If md Is Nothing Then
                    image = decoder.Read(fs, Nothing)
                Else
                    isTiff = (Typeof decoder Is TiffDecoder)
                    image = md.Read(fs, file.FrameIndex, Nothing)
                End If
            End Using

            Dim results As ImageResults = cmd.Apply(image)

            If isTiff Then
                Dim tmp As String = Me.SilverlightWebHandler1.GetTemporaryFileName(e)
                File.Copy(file.OriginalFile, tmp, True)

                Using src As New FileStream(tmp, FileMode.Open, FileAccess.Read, FileShare.Read)
                    Dim doc As New TiffDocument(src)
                    If doc.Pages.Count <= file.FrameIndex Then
                        Return "error: Invalid index of "  file.FrameIndex.ToString()  "."
                    End If

                    doc.Pages(file.FrameIndex) = New TiffPage(results.Image)
                    doc.Save(file.OriginalFile)
                End Using

                File.Delete(tmp)
            Else
                results.Image.Save(file.OriginalFile, New PngEncoder(), Nothing)
            End If

            results.Image.Dispose()

            If (Not results.IsImageSourceImage) Then
                image.Dispose()
            End If

            e.UpdateImage(file)
        Next file
    Catch ex As Exception
        Return "There was an error applying the command."  Constants.vbCrLf  ex.Message
    End Try

    Return ""
End Function
 public string ApplyMosaicCommand(SilverlightRemoteInvokeArguments e)
{
  if (e.SelectedFiles.Count == 0)
      return "No image was selected.";

  MosaicCommand cmd = new MosaicCommand();
  if (e.Arguments.ContainsKey("SquareSize"))
      cmd.SquareSize = Convert.ToInt32(e.Arguments["SquareSize"]);

  return ApplyCommand(cmd, e);
}

private string ApplyCommand(ImageCommand cmd, SilverlightRemoteInvokeArguments e)
{
  cmd.ApplyToAnyPixelFormat = true;
  try
  {
      foreach (ServerFileInformation file in e.SelectedFiles)
      {
          AtalaImage image = null;
          bool isTiff = false;

          using (FileStream fs = new FileStream(file.OriginalFile, FileMode.Open, FileAccess.Read, FileShare.Read))
          {
              ImageDecoder decoder = RegisteredDecoders.GetDecoder(fs);
              fs.Seek(0, SeekOrigin.Begin);

              MultiFramedImageDecoder md = decoder as MultiFramedImageDecoder;
              if (md == null)
                  image = decoder.Read(fs, null);
              else
              {
                  isTiff = (decoder is TiffDecoder);
                  image = md.Read(fs, file.FrameIndex, null);
              }
          }

          ImageResults results = cmd.Apply(image);

          if (isTiff)
          {
              string tmp = this.SilverlightWebHandler1.GetTemporaryFileName(e);
              File.Copy(file.OriginalFile, tmp, true);

              using (FileStream src = new FileStream(tmp, FileMode.Open, FileAccess.Read, FileShare.Read))
              {
                  TiffDocument doc = new TiffDocument(src);
                  if (doc.Pages.Count <= file.FrameIndex)
                      return "error: Invalid index of " + file.FrameIndex.ToString() + ".";

                  doc.Pages[file.FrameIndex] = new TiffPage(results.Image);
                  doc.Save(file.OriginalFile);
              }

              File.Delete(tmp);
          }
          else
          {
              results.Image.Save(file.OriginalFile, new PngEncoder(), null);
          }

          results.Image.Dispose();

          if (!results.IsImageSourceImage)
              image.Dispose();

          e.UpdateImage(file);
      }
  }
  catch (Exception ex)
  {
      return "There was an error applying the command.\r\n" + ex.Message;
  }

  return "";
}
See Also