getAllEntries() of NotesView in Domino To Go for Titanium returns null - titanium

If you have for example this code:
var db = new NotesDatabase("https://address.com/mobile.nsf", "Database");
var view = db.getView("PolicyData");
var vec = view.getAllEntries();
if(!vec) {
alert("nothing in view");
return;
}
var ve = vec.getFirstEntry();
it will fail because vec is null. Why?

The reason is that you need to synchronize the view with the Domino backend first, so that it's data is in the the local SQLite database of the device.
This would work:
var db = new NotesDatabase("https://address.com/mobile.nsf", "Database");
var view = db.getView("PolicyData");
var callback = function() {
var vec = view.getAllEntries();
if(!vec) {
alert("nothing in view");
return;
}
var ve = vec.getFirstEntry();
}
view.update(callback);
See http://www.youatnotes.com/web/youatnotes/wiki-dtg.nsf/dx/NotesView#Methods for more details about the update method.

Related

c# Copy SQL table data to another DB with Where clause filter using Data Factory

I am in a process to copy data from one SQL database (Source) and move to another SQL Database (destination) through data factory using c# code.
I am able to copy all the data from a source table to destination table, but i want to move filtered data only, like SELECT * FROM Source.tbl WHERE Category = 5. There would be around 10-15 table that i would move data. Can you provide me sample code which may help me?
My code for moving single table all data..
// Authenticate and create a data factory management client
var context = new AuthenticationContext("https://login.windows.net/" + tenantID);
ClientCredential cc = new ClientCredential(AppID, AuthKey);
AuthenticationResult result = context.AcquireTokenAsync("https://management.azure.com/", cc).Result;
ServiceClientCredentials cred = new TokenCredentials(result.AccessToken);
var client = new DataFactoryManagementClient(cred) { SubscriptionId = SubscriptionID };
// Create data factory
Factory dataFactory = new Factory { Location = Region, Identity = new FactoryIdentity() };
// This line throws error, we cannot proceed further. unless we get access of creating DF or update or access.
client.Factories.CreateOrUpdate(ResourceGroup, DataFactoryName, dataFactory);
var DF = client.Factories.Get(ResourceGroup, DataFactoryName);
while (DF.ProvisioningState == "PendingCreation")
{
System.Threading.Thread.Sleep(1000);
}
LinkedServiceResource storageLinkedService = new LinkedServiceResource(
new AzureSqlDatabaseLinkedService
{
ConnectionString = new SecureString(SourceSQLConnString)
}
);
client.LinkedServices.CreateOrUpdate(ResourceGroup, DataFactoryName, SourceSQLLinkedServiceName, storageLinkedService);
LinkedServiceResource sqlDbLinkedService = new LinkedServiceResource(
new AzureSqlDatabaseLinkedService
{
ConnectionString = new SecureString(DestSQLConnString)
}
);
client.LinkedServices.CreateOrUpdate(ResourceGroup, DataFactoryName, DestSQLLinkedServiceName, sqlDbLinkedService);
DatasetResource SourceSQLDataSet = new DatasetResource(
new AzureSqlTableDataset
{
LinkedServiceName = new LinkedServiceReference
{
ReferenceName = SourceSQLLinkedServiceName
},
TableName = Table,
}
);
client.Datasets.CreateOrUpdate(ResourceGroup, DataFactoryName, SourceSQLDataSetName, SourceSQLDataSet);
// Create a Azure SQL Database dataset
DatasetResource DestSQLDataSet = new DatasetResource(
new AzureSqlTableDataset
{
LinkedServiceName = new LinkedServiceReference
{
ReferenceName = DestSQLLinkedServiceName
},
TableName = Table
}
);
client.Datasets.CreateOrUpdate(ResourceGroup, DataFactoryName, DestSQLDataSetName, DestSQLDataSet);
PipelineResource pipeline = new PipelineResource
{
Activities = new List<Activity>
{
new CopyActivity
{
Name = "CopyFromSQLToSQL",
Inputs = new List<DatasetReference>
{
new DatasetReference()
{
ReferenceName = SourceSQLDataSetName
}
},
Outputs = new List<DatasetReference>
{
new DatasetReference
{
ReferenceName = DestSQLDataSetName
}
},
Source = new SqlSource(),
Sink = new SqlSink { }
}
}
};
client.Pipelines.CreateOrUpdate(ResourceGroup, DataFactoryName, PipelineName, pipeline);
// Create a pipeline run
CreateRunResponse runResponse = client.Pipelines.CreateRunWithHttpMessagesAsync(ResourceGroup, DataFactoryName, PipelineName).Result.Body;
// Monitor the pipeline run
PipelineRun pipelineRun;
while (true)
{
pipelineRun = client.PipelineRuns.Get(ResourceGroup, DataFactoryName, runResponse.RunId);
if (pipelineRun.Status == "InProgress")
System.Threading.Thread.Sleep(15000);
else
break;
}
You could put your query into the SqlReaderQuery property of your sql Source.
I talked to the Data Factory support, they said we have not implemented yet,
Create Data Factory,
Create linked services
In loop create datasets and Create copy activity

SEC_ERROR_REVOKED_CERTIFICATE error while accesing the url in browser

Hi i am getting below error while trying to access the website which is hosted in IIS 8 for which the SSL certificate had got expired and i installed the new SSL certificate provided by GoDaddy, it was all working fine for 2 days and now it shows the below error. Let me know if anyone can figure out what is the issue
using Microsoft.CognitiveServices.Speech;
using Newtonsoft.Json;
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace SPT
{
class Program
{
public static async Task RecognizeSpeechAsync()
{
// Creates an instance of a speech config with specified subscription key and service region.
// Replace with your own subscription key // and service region (e.g., "westus").
var config = SpeechConfig.FromSubscription(" 7cf359266c964dc789960abe063cc65b", "westus");
// Creates a speech recognizer.
using (var recognizer = new SpeechRecognizer(config))
{
Console.WriteLine("Say something...");
// Starts speech recognition, and returns after a single utterance is recognized. The end of a
// single utterance is determined by listening for silence at the end or until a maximum of 15
// seconds of audio is processed. The task returns the recognition text as result.
// Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single
// shot recognition like command or query.
// For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead.
var result = await recognizer.RecognizeOnceAsync();
// Checks result.
if (result.Reason == ResultReason.RecognizedSpeech)
{
Console.WriteLine($"We recognized: {result.Text}");
}
else if (result.Reason == ResultReason.NoMatch)
{
Console.WriteLine($"NOMATCH: Speech could not be recognized.");
}
else if (result.Reason == ResultReason.Canceled)
{
var cancellation = CancellationDetails.FromResult(result);
Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");
if (cancellation.Reason == CancellationReason.Error)
{
Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
Console.WriteLine($"CANCELED: Did you update the subscription info?");
}
}
}
}
public static async Task SynthesisToSpeakerAsync()
{
// Creates an instance of a speech config with specified subscription key and service region.
// Replace with your own subscription key and service region (e.g., "westus").
// The default language is "en-us".
var config = SpeechConfig.FromSubscription("7cf359266c964dc789960abe063cc65b", "westus");
// Creates a speech synthesizer using speaker as audio output.
using (var synthesizer = new SpeechSynthesizer(config))
{
// Receive a text from console input and synthesize it to speaker.
Console.WriteLine("Type some text that you want to speak...");
Console.Write("> ");
string text = Console.ReadLine();
using (var result = await synthesizer.SpeakTextAsync(text))
{
if (result.Reason == ResultReason.SynthesizingAudioCompleted)
{
Console.WriteLine($"Speech synthesized to speaker for text [{text}]");
}
else if (result.Reason == ResultReason.Canceled)
{
var cancellation = SpeechSynthesisCancellationDetails.FromResult(result);
Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");
if (cancellation.Reason == CancellationReason.Error)
{
Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
Console.WriteLine($"CANCELED: ErrorDetails=[{cancellation.ErrorDetails}]");
Console.WriteLine($"CANCELED: Did you update the subscription info?");
}
}
}
// This is to give some time for the speaker to finish playing back the audio
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
public static async Task SynthesisToVideoAsync()
{
var apiUrl = "https://api.videoindexer.ai";
var accountId = "56fbb8f8-b9a8-4119-b46a-fa5fb6668ddd";
var location = "westus2";
var apiKey = "6f354f730bc141f9bc3e57e73c6001b0";
System.Net.ServicePointManager.SecurityProtocol = System.Net.ServicePointManager.SecurityProtocol | System.Net.SecurityProtocolType.Tls12;
// create the http client
var handler = new HttpClientHandler();
handler.AllowAutoRedirect = false;
var client = new HttpClient(handler);
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", apiKey);
// obtain account access token
var accountAccessTokenRequestResult = client.GetAsync($"{apiUrl}/auth/{location}/Accounts/{accountId}/AccessToken?allowEdit=true").Result;
var accountAccessToken = accountAccessTokenRequestResult.Content.ReadAsStringAsync().Result.Replace("\"", "");
client.DefaultRequestHeaders.Remove("Ocp-Apim-Subscription-Key");
// upload a video
var content = new MultipartFormDataContent();
Debug.WriteLine("Uploading...");
// get the video from URL
var videoUrl = "VIDEO_URL"; // replace with the video URL
// as an alternative to specifying video URL, you can upload a file.
// remove the videoUrl parameter from the query string below and add the following lines:
//FileStream video =File.OpenRead(Globals.VIDEOFILE_PATH);
//byte[] buffer =newbyte[video.Length];
//video.Read(buffer, 0, buffer.Length);
//content.Add(newByteArrayContent(buffer));
var uploadRequestResult = client.PostAsync($"{apiUrl}/{location}/Accounts/{accountId}/Videos?accessToken={accountAccessToken}&name=some_name&description=some_description&privacy=private&partition=some_partition&videoUrl={videoUrl}", content).Result;
var uploadResult = uploadRequestResult.Content.ReadAsStringAsync().Result;
// get the video id from the upload result
var videoId = JsonConvert.DeserializeObject<dynamic>(uploadResult)["id"];
Debug.WriteLine("Uploaded");
Debug.WriteLine("Video ID: " + videoId);
// obtain video access token
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", apiKey);
var videoTokenRequestResult = client.GetAsync($"{apiUrl}/auth/{location}/Accounts/{accountId}/Videos/{videoId}/AccessToken?allowEdit=true").Result;
var videoAccessToken = videoTokenRequestResult.Content.ReadAsStringAsync().Result.Replace("\"", "");
client.DefaultRequestHeaders.Remove("Ocp-Apim-Subscription-Key");
// wait for the video index to finish
while (true)
{
Thread.Sleep(10000);
var videoGetIndexRequestResult = client.GetAsync($"{apiUrl}/{location}/Accounts/{accountId}/Videos/{videoId}/Index?accessToken={videoAccessToken}&language=English").Result;
var videoGetIndexResult = videoGetIndexRequestResult.Content.ReadAsStringAsync().Result;
var processingState = JsonConvert.DeserializeObject<dynamic>(videoGetIndexResult)["state"];
Debug.WriteLine("");
Debug.WriteLine("State:");
Debug.WriteLine(processingState);
// job is finished
if (processingState != "Uploaded" && processingState != "Processing")
{
Debug.WriteLine("");
Debug.WriteLine("Full JSON:");
Debug.WriteLine(videoGetIndexResult);
break;
}
}
// search for the video
var searchRequestResult = client.GetAsync($"{apiUrl}/{location}/Accounts/{accountId}/Videos/Search?accessToken={accountAccessToken}&id={videoId}").Result;
var searchResult = searchRequestResult.Content.ReadAsStringAsync().Result;
Debug.WriteLine("");
Debug.WriteLine("Search:");
Debug.WriteLine(searchResult);
// get insights widget url
var insightsWidgetRequestResult = client.GetAsync($"{apiUrl}/{location}/Accounts/{accountId}/Videos/{videoId}/InsightsWidget?accessToken={videoAccessToken}&widgetType=Keywords&allowEdit=true").Result;
var insightsWidgetLink = insightsWidgetRequestResult.Headers.Location;
Debug.WriteLine("Insights Widget url:");
Debug.WriteLine(insightsWidgetLink);
// get player widget url
var playerWidgetRequestResult = client.GetAsync($"{apiUrl}/{location}/Accounts/{accountId}/Videos/{videoId}/PlayerWidget?accessToken={videoAccessToken}").Result;
var playerWidgetLink = playerWidgetRequestResult.Headers.Location;
Debug.WriteLine("");
Debug.WriteLine("Player Widget url:");
Debug.WriteLine(playerWidgetLink);
}
static void Main()
{
RecognizeSpeechAsync().Wait();
SynthesisToSpeakerAsync().Wait();
SynthesisToVideoAsync().Wait();
Console.WriteLine("Please press a key to continue.");
Console.ReadLine();
}
}
}

FileStream openAsync throws Error #1009

hi I have a problem regarding FileStream openAsync read file, I have a listener and waiting on complete
var file:File = File.applicationStorageDirectory.resolvePath(fName+'.'+EXT);
var fileStream:FileStream = new FileStream();
if (!file.exists) {
this.dispatchEvent(new AppEvent(AppEvent.DATA, null, false));
}else {
fileStream.addEventListener(Event.COMPLETE, fileReadCompleteHandler);
fileStream.openAsync(file, FileMode.READ);
fileStream.addEventListener(Event.CLOSE, fileClosedHandler);
fileStream.addEventListener(IOErrorEvent.IO_ERROR, IOErrorHandler);
}
private function fileReadCompleteHandler(event:Event):void {
var ob:Object;
var fileStream:FileStream = FileStream(event.currentTarget);
try {
ob.source = fileStream.readObject();
}catch (e:Error) {
trace('error:' + e.message)
}
fileStream.removeEventListener(Event.COMPLETE, fileReadCompleteHandler);
fileStream.close();
}
on fileReadCompleteHandler I get error: "Error #1009: Cannot access a property or method of a null object reference."
what I am missing, how can I read object from openAsync?
thanks
You never initialize object ob, of course accessing fields of a null object gives you #1009:
var ob:Object;
var fileStream:FileStream = FileStream(event.currentTarget);
try {
ob.source = fileStream.readObject();
You need to:
var ob:Object = new Object;
var fileStream:FileStream = FileStream(event.currentTarget);
try {
ob.source = fileStream.readObject();

Windows Phone 8.1 Media Capture Rotated Incorrectly

I'm having great difficulty getting my captured image to be rotated correctly, the bitmapencoder class doesn't seem to be doing anything.
private async Task CapturePhoto()
{
ImageEncodingProperties pIEPEncoder = ImageEncodingProperties.CreateJpeg();
InMemoryRandomAccessStream pIMSCapture = new InMemoryRandomAccessStream();
using (pIMSCapture)
{
await cMCeCapture.CapturePhotoToStreamAsync(pIEPEncoder, pIMSCapture);
pIMSCapture.Seek(0);
BitmapDecoder pBDrDecoder = await BitmapDecoder.CreateAsync(pIMSCapture);
BitmapEncoder pBErEncoder = await BitmapEncoder.CreateForTranscodingAsync(pIMSCapture, pBDrDecoder);
pBErEncoder.BitmapTransform.InterpolationMode = BitmapInterpolationMode.Fant;
pBErEncoder.BitmapTransform.Rotation = ConvertDegreesToBitmapRotation(cIntRotationDegrees);
await pBErEncoder.FlushAsync();
BitmapImage pBIeCapture = new BitmapImage();
pIMSCapture.Seek(0);
await pBIeCapture.SetSourceAsync(pIMSCapture);
CaptureImage.Source = pBIeCapture;
CaptureImage.Stretch = Stretch.Uniform;
CaptureImage.Width = LayoutRoot.ActualWidth;
CaptureImage.Height = LayoutRoot.ActualHeight;
}
await CleanupCameraAsync();
}
Any ideas how to fix this? The camera API seems to be my nemesis as of late, so frustrating to get anything working how I would like.
I have found an alternative solution and that's to use the WritableBitmapEx class obtained from here,
https://writeablebitmapex.codeplex.com/
This actually does what it's supposed to do, unlike the BitmapEncoder class for some reason. Plus it's super easy to use. Although flipping Horizontal seems to flip Vertical instead, not entirely sure why but it works anyway. I just switched Horizontal and Vertical over.
private async Task CapturePhoto()
{
ImageEncodingProperties pIEPEncoder = ImageEncodingProperties.CreateJpeg();
InMemoryRandomAccessStream pIMSCapture = new InMemoryRandomAccessStream();
using (pIMSCapture)
{
await cMCeCapture.CapturePhotoToStreamAsync(pIEPEncoder, pIMSCapture);
if(!cBlnExternalCamera)
{
pIMSCapture.Seek(0);
BitmapImage pBIeCapture = new BitmapImage();
await pBIeCapture.SetSourceAsync(pIMSCapture);
pIMSCapture.Seek(0);
WriteableBitmap pWBpBitmap = new WriteableBitmap(pBIeCapture.PixelWidth, pBIeCapture.PixelHeight);
await pWBpBitmap.SetSourceAsync(pIMSCapture);
if (cIntRotationDegrees != 0)
pWBpBitmap = pWBpBitmap.Rotate(cIntRotationDegrees);
if (cBlnMirroringPreview)
pWBpBitmap = pWBpBitmap.Flip(cDInDisplayInformation.CurrentOrientation == DisplayOrientations.Landscape || cDInDisplayInformation.CurrentOrientation == DisplayOrientations.LandscapeFlipped ? WriteableBitmapExtensions.FlipMode.Vertical : WriteableBitmapExtensions.FlipMode.Horizontal);
CaptureImage.Source = pWBpBitmap;
CaptureImage.Stretch = Stretch.Uniform;
CaptureImage.Width = LayoutRoot.ActualWidth;
CaptureImage.Height = LayoutRoot.ActualHeight;
}
else
{
pIMSCapture.Seek(0);
BitmapImage pBIeCapture = new BitmapImage();
await pBIeCapture.SetSourceAsync(pIMSCapture);
CaptureImage.Source = pBIeCapture;
CaptureImage.Stretch = Stretch.Uniform;
CaptureImage.Width = LayoutRoot.ActualWidth;
CaptureImage.Height = LayoutRoot.ActualHeight;
}
}
await CleanupCameraAsync();
}

How to get profile picture(Image) from People App

I'm tring to get the profile picture from People App. I used
Windows.ApplicationModel.Contacts.Contact contact = new Contact();
I got Thumbnail from propety contact.Thumbnail.
I need to convert this Thumbnail to StorageFile. Could you please give inputs to solve this issue?
And, while using the following code:
IRandomAccessStreamWithContentType stream = awaitcontactInfo.Thumbnail.OpenReadAsync();
if(stream != null && stream.Size > 0)
{
//
}
Sometimes I'm getting RPC Server is unavailable Exception. Sometimes the streamSize is Zero.
You are creating new instance of Contact class. You don't have to do that to pick contact from people. You should use ContactPicker.
var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker();
contactPicker.CommitButtonText = "Select";
ContactInformation contact = await contactPicker.PickSingleContactAsync();
if (contact != null)
{
IRandomAccessStreamWithContentType stream = await contact.GetThumbnailAsync();
if (stream != null && stream.Size > 0)
{
var file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("MyContactThumb.png", CreationCollisionOption.GenerateUniqueName);
// You can also use FileSavePicker to save file in user defined location.
Windows.Storage.Streams.Buffer MyBuffer = new Windows.Storage.Streams.Buffer(Convert.ToUInt32(stream.Size));
IBuffer iBuf = await stream.ReadAsync(MyBuffer, MyBuffer.Capacity, InputStreamOptions.None);
await FileIO.WriteBufferAsync(file, iBuf);
}
}