示例#1
0
        public ActionResult DeleteConnection(string Id)
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                AzureConnector           AzureConnector = new AzureConnector();
                IEnumerable <IConnector> connectors     = AzureConnector.GetConnectors(PortalSettings.PortalId);

                IConnector connector = connectors.FirstOrDefault(c => c.Id == Id);
                if (connector != null)
                {
                    connector.DeleteConnector(PortalSettings.PortalId);
                    actionResult.IsSuccess = true;
                    actionResult.Data      = Manager.ConnectorsManager.GetAll(PortalSettings.PortalId);
                    return(actionResult);
                }
                actionResult.AddError("ErrConnectorNotFound", Localization.GetString("ErrConnectorNotFound.Text", Constants.LocalResourceFile));
                return(actionResult);
            }
            catch (Exception ex)
            {
                actionResult.AddError("InternalServerError", "InternalServerError", ex);
                return(actionResult);
            }
        }
示例#2
0
        public static ActionResult Save(Connector postData, int PortalId)
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                string            name           = postData.Name;
                string            displayName    = postData.DisplayName;
                string            id             = postData.Id;
                AzureConnector    AzureConnector = new AzureConnector();
                List <IConnector> connectors     = AzureConnector.GetConnectors(PortalId).ToList();

                IConnector connector = connectors.FirstOrDefault(c => c.Id == id);

                if (connector == null && string.IsNullOrEmpty(id))
                {
                    connector = new AzureConnector
                    {
                        Id          = null,
                        DisplayName = null
                    };
                }
                if (connector != null && !string.IsNullOrEmpty(displayName) && connector.DisplayName != displayName)
                {
                    connector.DisplayName = string.IsNullOrEmpty(displayName) ? "" : displayName;
                }

                bool validated = false;
                if (connector != null)
                {
                    bool saved = connector.SaveConfig(PortalId, postData.Configurations, ref validated,
                                                      out string customErrorMessage);
                    if (!saved)
                    {
                        string Message = string.IsNullOrEmpty(customErrorMessage)
                                    ? Localization.GetString("ErrSavingConnectorSettings.Text", Components.Constants.LocalResourceFile)
                                    : customErrorMessage;
                        actionResult.AddError("ErrSavingConnectorSettings", Message);
                        return(actionResult);
                    }
                }
                actionResult.IsSuccess = true;
                actionResult.Data      = connector?.Id;
                return(actionResult);
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                actionResult.AddError("InternalServerError", "InternalServerError", ex);
                return(actionResult);
            }
        }
示例#3
0
        public async Task DeviceDiscovery_Exist()
        {
            _azureConnector = new AzureConnector(_azureSetup.ConnectionString, _azureSetup.ContainerName, "metadata.csv",
                                                 _csvService);
            var result = await _azureConnector.DeviceDiscovery();

            var sensors = _azureSetup.GetTestSensors().ToList().OrderBy(x => x);

            Assert.NotNull(result);
            Assert.AreEqual(1, result.Count, "Device count");
            Assert.AreEqual("dockan", result.First().Id, "Device Id");
            Assert.AreEqual(3, result.First().Sensors.Count, "Device Sensors count");
            Assert.AreEqual("dockan", result.First().Id, "Device Id");
            Assert.AreEqual(sensors, result.First().Sensors.OrderBy(x => x), "List of Sensors");
        }
示例#4
0
        public ActionResult GetAllContainers(int id)
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                List <string>       strs = new List <string>();
                AzureFolderProvider azureFolderProvider = new AzureFolderProvider();
                FolderMappingInfo   folderMappingInfo   = AzureConnector.FindAzureFolderMappingStatic(PortalSettings.PortalId, new int?(id), false);
                if (folderMappingInfo != null)
                {
                    strs = azureFolderProvider.GetAllContainers(folderMappingInfo);
                }
                List <StringValue> Containers = new List <StringValue>
                {
                    new StringValue {
                        Text = Localization.GetString("PleaseSelect.Text", Components.Constants.LocalResourceFile), Value = ""
                    }
                };
                foreach (string item in strs)
                {
                    Containers.Add(new StringValue {
                        Text = item, Value = item
                    });
                }
                actionResult.Data      = Containers;
                actionResult.IsSuccess = true;
            }
            catch (StorageException storageException1)
            {
                StorageException storageException = storageException1;
                Exceptions.LogException(storageException);
                string httpStatusMessage = storageException.RequestInformation.HttpStatusMessage ?? storageException.Message;
                actionResult.AddError("InternalServerError", httpStatusMessage);
            }
            catch (Exception exception)
            {
                Exceptions.LogException(exception);
                actionResult.AddError("InternalServerError", "An error has occurred connecting to the Azure account.");
            }
            return(actionResult);
        }
示例#5
0
        public static Connector Get(int PortalId, string Id)
        {
            AzureConnector AzureConnector = new AzureConnector();
            IConnector     Connector      = AzureConnector.GetConnectors(PortalId).Where(c => c.Id == Id).FirstOrDefault();
            Connector      Connect        = new Connector();

            if (Connector != null)
            {
                Connect.Id               = Connector.Id;
                Connect.Name             = Connector.Name;
                Connect.Type             = Connector.Type;
                Connect.DisplayName      = Connector.DisplayName;
                Connect.Connected        = Connector.HasConfig(PortalId);
                Connect.IconUrl          = Globals.ResolveUrl(Connector.IconUrl);
                Connect.PluginFolder     = Globals.ResolveUrl(Connector.PluginFolder);
                Connect.Configurations   = Connector.GetConfig(PortalId);
                Connect.SupportsMultiple = Connector.SupportsMultiple;
            }
            return(Connect);
        }
示例#6
0
        public static List <Connector> GetAll(int PortalId)
        {
            List <Connector> Connectors     = new List <Connector>();
            AzureConnector   AzureConnector = new AzureConnector();

            foreach (IConnector con in AzureConnector.GetConnectors(PortalId).ToList())
            {
                Connector connector = new Connector
                {
                    Id          = con.Id,
                    Name        = con.Name,
                    Type        = con.Type,
                    DisplayName = con.DisplayName,
                    Connected   = con.HasConfig(PortalId),
                    IconUrl     = Globals.ResolveUrl(con.IconUrl)
                };
                Connectors.Add(connector);
            }
            return(Connectors);
        }
示例#7
0
 public void Setup()
 {
     _azureSetup.Setup();
     _azureConnector = new AzureConnector(_azureSetup.ConnectionString, _azureSetup.ContainerName, null,
                                          _csvService);
 }
示例#8
0
 public StateController()
 {
     _azureConnector = new AzureConnector();
 }
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        static void Main()
        {
            try
            {
                Console.WriteLine("*** STT stating ***");
                DBConnector     dbConnector     = new DBConnector();
                GoogleConnector googleConnector = new GoogleConnector();

                string AZURE_TEMP_FOLDER_PATH = ConfigurationManager.AppSettings["AZURE_TEMP_FOLDER_PATH"];
                var    groups = dbConnector.AllBlobNotProcessed((int)MediaExtensions.WAV, ApiSourceId.Both).GroupBy(i => i.InterviewID).ToList();
                Console.WriteLine("Not processed wavs groups count : " + groups.Count());
                if (groups.Count() > 0)
                {
                    AzureConnector azureConnector = new AzureConnector();
                    foreach (var group in groups)
                    {
                        if (group.Count() > 0)
                        {
                            var tempPath = String.Empty;
                            foreach (var item in group)
                            {
                                Console.WriteLine("-----------------------------------------------------");
                                Console.WriteLine(item.MediaURL);
                                List <Microsoft.CognitiveServices.Speech.SpeechRecognitionResult> recognizedItems = new List <Microsoft.CognitiveServices.Speech.SpeechRecognitionResult>();

                                var tempFolderName = Guid.NewGuid().ToString();
                                tempPath = System.IO.Path.Combine(AZURE_TEMP_FOLDER_PATH, item.InterviewID.ToString());

                                Console.WriteLine("Interviw LanguageID :" + item.LanguageID);
                                Console.WriteLine("InterviwID : " + item.InterviewID);
                                Console.WriteLine("MediaShortName : ", item.MediaShortName);

                                var apisource = dbConnector.GetInterviewApiSource(item.InterviewID, item.LanguageID);
                                if (apisource != null)
                                {
                                    List <SpeechToText> list = new List <SpeechToText>();
                                    if (apisource.SourceID.Equals(ApiSourceId.Azure))
                                    {
                                        if (item.ApiSourceID == ApiSourceId.Azure)
                                        {
                                            #region STT Microsoft
                                            //Only select Question Order
                                            var questionOrder = item.MediaShortName.Substring(item.MediaShortName.Length - 5, 1);

                                            Stream stream = azureConnector.GetMediaBlob(item.MediaURL);

                                            var temp_audio_file = SharedHelper.CreateFileLocaly(stream, tempFolderName, tempPath);

                                            SpeechRecognitionMS.ContinuousRecognitionWithFileAsync(temp_audio_file, item.LanguageID, recognizedItems).Wait();

                                            foreach (var recognitionResult in recognizedItems)
                                            {
                                                var text   = recognitionResult.Text;
                                                var result = SharedHelper.BuildSentimentKeyWordsScoreAsync(text, item.LanguageID);
                                                var sTT    = new SpeechToText()
                                                {
                                                    Confidence     = "Microsoft",
                                                    Text           = text,
                                                    SentimentScore = result.Result.Score,
                                                    KeyWords       = result.Result.KeyWords,
                                                };
                                                list.Add(sTT);
                                            }

                                            var jsonResult = Newtonsoft.Json.JsonConvert.SerializeObject(list);

                                            int quest = 0;
                                            if (int.TryParse(questionOrder, out quest))
                                            {
                                                dbConnector.AddSpeechToText(item.InterviewID, quest, jsonResult);
                                            }
                                            #endregion
                                        }
                                    }
                                    else
                                    {
                                        if (item.ApiSourceID == ApiSourceId.Google)
                                        {
                                            #region STT Google
                                            //STT Google to be tested , then delete the old web Job
                                            //Only select Question Order

                                            var questionOrder = item.MediaShortName.Substring(item.MediaShortName.Length - 5, 1);
                                            Console.WriteLine("QuestionOrder : " + questionOrder);
                                            Console.WriteLine("Media Url : " + item.MediaURL);

                                            var response = SpeechRecognitionGoogle.stt_google(item.MediaShortName, item.LanguageID);
                                            if (response != null)
                                            {
                                                foreach (var result in response.Results)
                                                {
                                                    foreach (var alternative in result.Alternatives)
                                                    {
                                                        var text      = alternative.Transcript;
                                                        var result_ms = SharedHelper.BuildSentimentKeyWordsScoreAsync(text, String.IsNullOrEmpty(item.LanguageID) ? System.Configuration.ConfigurationManager.AppSettings["LanguageCode"] : item.LanguageID);
                                                        Console.WriteLine($"currrent google speech to text : {alternative.Transcript}");
                                                        var sTT = new SpeechToText()
                                                        {
                                                            Confidence     = "google",
                                                            Text           = text,
                                                            SentimentScore = result_ms.Result.Score,
                                                            Order          = int.Parse(questionOrder),
                                                            KeyWords       = result_ms.Result.KeyWords,
                                                        };
                                                        list.Add(sTT);
                                                    }
                                                }
                                            }

                                            var jsonResult = Newtonsoft.Json.JsonConvert.SerializeObject(list);
                                            Console.WriteLine($"Json google speech: {jsonResult}");
                                            dbConnector.AddSpeechToText(item.InterviewID, int.Parse(questionOrder), jsonResult, (int)ApiSourceId.Google);
                                            #endregion
                                        }
                                    }
                                }

                                dbConnector.UpdateInterviewMediaStatus(item.MediaURL, 1);
                                //TODO::Delete  wavs from google storage at the end of the process
                                googleConnector.DeleteObject(item.MediaShortName);

                                var _result = dbConnector.AllBlobProcessed(item.InterviewID, (int)MediaExtensions.WAV);
                                if (_result == "TRUE")
                                {
                                    dbConnector.InsertOrUpdateAVTaskTracker(DBOperationType.Update.ToString(), "", item.InterviewID, TaskLabel.texte.ToString(), (int)StatusId.Finished, 0);
                                }
                            }
                            DeleteTempFiles_If_All_Files_Are_treated(dbConnector, ApiSourceId.Azure, group.FirstOrDefault().InterviewID, tempPath);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                SharedHelper.GetFullException(e);
            }
            Console.WriteLine("***GoogleRecognizeSST Finished ***");
        }