C# Sample
Demonstrates how to create a C# application using the VideoXpert SDK
SDKSampleApp.Source.Utilities Class Reference

Static Public Member Functions

static void BackgroundWorker_DoWork (object sender, DoWorkEventArgs args)
 The BackgroundWorker_DoWork method. More...
 
static void BackgroundWorker_ProgressChanged (object sender, ProgressChangedEventArgs args)
 The BackgroundWorker_ProgressChanged method. More...
 
static void BackgroundWorker_RunWorkerCompleted (object sender, RunWorkerCompletedEventArgs args)
 The BackgroundWorker_RunWorkerCompleted method. More...
 
static string EncodeToBase64 (string toEncode)
 The EncodeToBase64 method. More...
 
static string FormatFileSize (long byteValue, int decimalPlaces=1)
 The FormatFileSize method. More...
 
static Image RotateImage (Image image, float rotationAngle)
 The RotateImage method. More...
 
static async Task< HttpResponseMessage > SendRequest (Uri uri)
 The SendRequest method. More...
 

Static Private Member Functions

static int AddRowToGridView (object[] item)
 The AddRowToGridView method. More...
 
static void ChangeProgressViewState (bool isVisible)
 The ChangeProgressViewState method. More...
 

Detailed Description

Definition at line 17 of file Utilities.cs.

Member Function Documentation

static int SDKSampleApp.Source.Utilities.AddRowToGridView ( object[]  item)
inlinestaticprivate

The AddRowToGridView method.

Parameters
itemThe item to add to the list.

Definition at line 23 of file Utilities.cs.

24  {
25  var rowIndex = 0;
26  if (MainForm.Instance.dgvDataSources.InvokeRequired)
27  {
28  MainForm.Instance.dgvDataSources.Invoke(
29  new MethodInvoker(delegate { rowIndex = MainForm.Instance.dgvDataSources.Rows.Add(item); }));
30  }
31  else
32  rowIndex = MainForm.Instance.dgvDataSources.Rows.Add(item);
33 
34  return rowIndex;
35  }
static void SDKSampleApp.Source.Utilities.BackgroundWorker_DoWork ( object  sender,
DoWorkEventArgs  args 
)
inlinestatic

The BackgroundWorker_DoWork method.

Parameters
senderThe sender parameter.
argsThe args parameter.

Definition at line 42 of file Utilities.cs.

43  {
44  MainForm.Instance.dgvDataSources.Invoke(new MethodInvoker(delegate { MainForm.Instance.dgvDataSources.Rows.Clear(); }));
45 
46  if (MainForm.CurrentDevices != null)
47  MainForm.CurrentDevices.Clear();
48  MainForm.CurrentDevices = MainForm.CurrentSystem.GetDevices();
49 
50  if (MainForm.CurrentDataSources != null)
51  MainForm.CurrentDataSources.Clear();
52 
54  MainForm.CurrentDataSources = MainForm.CurrentSystem.GetDataSources();
55 
56  var dataSourceTotal = MainForm.CurrentDataSources.Count;
57  var dataSourceNum = 0;
58  foreach (var dataSource in MainForm.CurrentDataSources)
59  {
60  dataSourceNum++;
61  if (dataSource.Type != DataSource.Types.Video)
62  continue;
63 
64  var progress = ((decimal)dataSourceNum / dataSourceTotal) * 100;
65  MainForm.Instance.bgWorker.ReportProgress((int)progress, null);
66  Bitmap camIcon;
67  if (dataSource.DataInterfaces.Any(item => (int) item.RenderType > 0 && (int) item.RenderType <= 4))
68  {
69  camIcon = dataSource.State == DataSource.States.Offline ? Resources.cam_pano_offline : Resources.cam_pano;
70  }
71  else
72  {
73  if (dataSource.IsPTZ)
74  camIcon = dataSource.State == DataSource.States.Offline ? Resources.cam_ptz_offline : Resources.cam_ptz;
75  else
76  camIcon = dataSource.State == DataSource.States.Offline ? Resources.cam_fixed_offline : Resources.cam_fixed;
77  }
78 
79  object[] row = { camIcon, dataSource.Name, dataSource.Number.ToString() };
80  var index = AddRowToGridView(row);
81  var newRow = MainForm.Instance.dgvDataSources.Rows[index];
82  newRow.Tag = dataSource;
83  }
84 
85  MainForm.Instance.BeginInvoke((MethodInvoker)delegate
86  {
87  // If data source collection was successful enable the UI elements.
88  MainForm.Instance.eventsToolStripMenuItem.Enabled = true;
89  MainForm.Instance.manageToolStripMenuItem.Enabled = true;
90  MainForm.Instance.btnSeek.Enabled = true;
91  MainForm.Instance.btnPause.Enabled = true;
92  MainForm.Instance.btnPlay.Enabled = true;
93  MainForm.Instance.btnStop.Enabled = true;
94  MainForm.Instance.btnSnapshot.Enabled = true;
95  MainForm.Instance.btnRefreshDataSources.Enabled = true;
96  });
97  }
static void ChangeProgressViewState(bool isVisible)
The ChangeProgressViewState method.
Definition: Utilities.cs:124
static int AddRowToGridView(object[] item)
The AddRowToGridView method.
Definition: Utilities.cs:23
static void SDKSampleApp.Source.Utilities.BackgroundWorker_ProgressChanged ( object  sender,
ProgressChangedEventArgs  args 
)
inlinestatic

The BackgroundWorker_ProgressChanged method.

Parameters
senderThe sender parameter.
argsThe args parameter.

Definition at line 104 of file Utilities.cs.

105  {
106  MainForm.Instance.pbLoadCameras.Invoke(
107  new MethodInvoker(delegate { MainForm.Instance.pbLoadCameras.Value = args.ProgressPercentage; }));
108  }
static void SDKSampleApp.Source.Utilities.BackgroundWorker_RunWorkerCompleted ( object  sender,
RunWorkerCompletedEventArgs  args 
)
inlinestatic

The BackgroundWorker_RunWorkerCompleted method.

Parameters
senderThe sender parameter.
argsThe args parameter.

Definition at line 115 of file Utilities.cs.

116  {
118  }
static void ChangeProgressViewState(bool isVisible)
The ChangeProgressViewState method.
Definition: Utilities.cs:124
static void SDKSampleApp.Source.Utilities.ChangeProgressViewState ( bool  isVisible)
inlinestaticprivate

The ChangeProgressViewState method.

Parameters
isVisibleThe value to set the visible property to.

Definition at line 124 of file Utilities.cs.

125  {
126  if (MainForm.Instance.pbLoadCameras.InvokeRequired)
127  {
128  MainForm.Instance.pbLoadCameras.Invoke(
129  new MethodInvoker(delegate { MainForm.Instance.pbLoadCameras.Visible = isVisible; }));
130  }
131  else
132  MainForm.Instance.pbLoadCameras.Visible = isVisible;
133 
134  if (MainForm.Instance.lblAddingCameras.InvokeRequired)
135  {
136  MainForm.Instance.lblAddingCameras.Invoke(
137  new MethodInvoker(delegate { MainForm.Instance.lblAddingCameras.Visible = isVisible; }));
138  }
139  else
140  MainForm.Instance.lblAddingCameras.Visible = isVisible;
141 
142  if (MainForm.Instance.btnRefreshDataSources.InvokeRequired)
143  {
144  MainForm.Instance.btnRefreshDataSources.Invoke(
145  new MethodInvoker(delegate { MainForm.Instance.btnRefreshDataSources.Visible = !isVisible; }));
146  }
147  else
148  MainForm.Instance.btnRefreshDataSources.Visible = !isVisible;
149  }
static string SDKSampleApp.Source.Utilities.EncodeToBase64 ( string  toEncode)
inlinestatic

The EncodeToBase64 method.

Parameters
toEncodeThe string to encode to Base64.
Returns
The Base64 encoded string.

Definition at line 156 of file Utilities.cs.

157  {
158  var toEncodeAsBytes = Encoding.ASCII.GetBytes(toEncode);
159  var returnValue = Convert.ToBase64String(toEncodeAsBytes);
160  return returnValue;
161  }
static string SDKSampleApp.Source.Utilities.FormatFileSize ( long  byteValue,
int  decimalPlaces = 1 
)
inlinestatic

The FormatFileSize method.

Parameters
byteValueThe size of the file in bytes.
decimalPlacesThe amount of decimal places to use.
Returns
The file size formatted as a readable string.

Definition at line 169 of file Utilities.cs.

170  {
171  string[] sizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
172  if (byteValue < 0) { return "-" + FormatFileSize(-byteValue); }
173  if (byteValue == 0) { return "0.0 bytes"; }
174 
175 
176  var mag = (int)Math.Log(byteValue, 1024);
177  var adjustedSize = (decimal)byteValue / (1L << (mag * 10));
178  if (Math.Round(adjustedSize, decimalPlaces) < 1000)
179  return string.Format("{0:n" + decimalPlaces + "} {1}", adjustedSize, sizeSuffixes[mag]);
180 
181  mag += 1;
182  adjustedSize /= 1024;
183  return string.Format("{0:n" + decimalPlaces + "} {1}", adjustedSize, sizeSuffixes[mag]);
184  }
static string FormatFileSize(long byteValue, int decimalPlaces=1)
The FormatFileSize method.
Definition: Utilities.cs:169
static Image SDKSampleApp.Source.Utilities.RotateImage ( Image  image,
float  rotationAngle 
)
inlinestatic

The RotateImage method.

Parameters
imageThe image to be rotated.
rotationAngleThe angle (in degrees).
Returns
The rotated image.

Definition at line 192 of file Utilities.cs.

193  {
194  if (image == null)
195  return null;
196 
197  // Create an empty image.
198  var bitmap = new Bitmap(image.Width, image.Height);
199  bitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution);
200 
201  // Turn the bitmap into a graphics object.
202  var graphics = Graphics.FromImage(bitmap);
203 
204  // Set the rotation point to the center of the image.
205  graphics.TranslateTransform((float)bitmap.Width / 2, (float)bitmap.Height / 2);
206 
207  // Rotate the image.
208  graphics.RotateTransform(rotationAngle);
209  graphics.TranslateTransform(-(float)bitmap.Width / 2, -(float)bitmap.Height / 2);
210 
211  // Set the InterpolationMode to HighQualityBicubic to ensure a high
212  // quality image once it is transformed to the specified size.
213  graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
214 
215  // Draw the new image onto the graphics object.
216  graphics.DrawImage(image, new Point(0, 0));
217 
218  // Dispose of the graphics object.
219  graphics.Dispose();
220 
221  // Return the image.
222  return bitmap;
223  }
static async Task<HttpResponseMessage> SDKSampleApp.Source.Utilities.SendRequest ( Uri  uri)
inlinestatic

The SendRequest method.

Parameters
uriThe request Uri.
Returns
The response message.

Definition at line 230 of file Utilities.cs.

231  {
232  // Create a new WebClient instance.
233  var client = new HttpClient();
234 
235  // Supply the username and password that was used to create the VideoXpert system.
236  var request = new HttpRequestMessage(HttpMethod.Get, uri);
237  request.Headers.Add("X-Serenity-User", EncodeToBase64(MainForm.CurrentUserName));
238  request.Headers.Add("X-Serenity-Password", EncodeToBase64(MainForm.CurrentPassword));
239 
240  // Forces the WebClient to trust the security certificate handed back from the VideoXpert server.
241  ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
242 
243  var response = await client.SendAsync(request);
244  return response;
245  }
static string EncodeToBase64(string toEncode)
The EncodeToBase64 method.
Definition: Utilities.cs:156

The documentation for this class was generated from the following file: