public static void MyClassInitialize(TestContext testContext)
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            currentTable = tableClient.GetTableReference(GenerateRandomTableName());
            currentTable.CreateIfNotExists();

            // Populate Entities (This will add 1500 entities to a new table, enough to test continuations 
            TableServiceContext ctx = tableClient.GetTableServiceContext();
            
            for (int l = 0; l < totalTestEntities / 100; l++)
            {
                for (int m = 0; m < 100; m++)
                {
                    BaseEntity ent = new BaseEntity("partition" + l, m.ToString());
                    ent.Randomize();
                    ent.A = ent.RowKey;
                    ctx.AddObject(currentTable.Name, ent);
                }

                ctx.SaveChangesWithRetries(SaveChangesOptions.Batch);
            }
        }
Exemplo n.º 2
0
        public static void go()
        {
            const String partitionName = "Video_Partition";

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureStorage"].ToString());
            CloudTableClient    tableClient    = storageAccount.CreateCloudTableClient();
            CloudTable          table          = tableClient.GetTableReference("Videos");

            // If table doesn't already exist in storage then create and populate it with some initial values, otherwise do nothing
            if (!table.Exists())
            {
                // Create table if it doesn't exist already
                table.CreateIfNotExists();

                // Create the batch operation.
                TableBatchOperation batchOperation = new TableBatchOperation();

                // Create a video entity and add it to the table.
                VideoEntity video1 = new VideoEntity(partitionName, "1");
                video1.Title       = "bee.mp4";
                video1.CreatedDate = DateTime.Now;

                // Create another video entity and add it to the table.
                VideoEntity video2 = new VideoEntity(partitionName, "2");
                video2.Title       = "bunny.mp4";
                video2.CreatedDate = DateTime.Now;


                // Create another video entity and add it to the table.
                VideoEntity video3 = new VideoEntity(partitionName, "3");
                video3.Title       = "giraffes.mp4";
                video3.CreatedDate = DateTime.Now;
                //video3.SampleDate = null;


                // Create another video entity and add it to the table.
                VideoEntity video4 = new VideoEntity(partitionName, "4");
                video4.Title       = "ostrich.mp4";
                video4.CreatedDate = DateTime.Now;


                // Create another video entity and add it to the table.
                VideoEntity video5 = new VideoEntity(partitionName, "5");
                video5.Title       = "sintel.mp4";
                video5.CreatedDate = DateTime.Now;


                // Create another video entity and add it to the table.
                VideoEntity video6 = new VideoEntity(partitionName, "6");
                video6.Title       = "swann.mp4";
                video6.CreatedDate = DateTime.Now;

                // Create another video entity and add it to the table.
                VideoEntity video7 = new VideoEntity(partitionName, "7");
                video7.Title       = "swann.mp4";
                video7.CreatedDate = DateTime.Now;


                // Add video entities to the batch insert operation.
                batchOperation.Insert(video1);
                batchOperation.Insert(video2);
                batchOperation.Insert(video3);
                batchOperation.Insert(video4);
                batchOperation.Insert(video5);
                batchOperation.Insert(video6);
                batchOperation.Insert(video7);

                // Execute the batch operation.
                table.ExecuteBatch(batchOperation);
            }
        }
Exemplo n.º 3
0
 internal void CreateTableIfNotExists()
 {
     table = tableClient.GetTableReference(TableName);
     table.CreateIfNotExists();
 }
        public static void Run([TimerTrigger("0 10 3/3 1/1 * *", RunOnStartup = true)] TimerInfo myTimer,
                               [Queue("downloadandunpacksnodas", Connection = "AzureWebJobsStorage")] ICollector <FileReadyToDownloadQueueMessage> outputQueueItem,
                               TraceWriter log)
        {
            log.Info($"C# Timer trigger function executed at: {DateTime.Now}");

            string partitionName = "snodas-westus-v1";

            log.Info($"DetectSnodasReadyForDownload Timer trigger function executed at UTC: {DateTime.UtcNow}");
#if DEBUG
            int numberOfDaysToCheck = 67;
#else
            int numberOfDaysToCheck = 5;
#endif

            // Retrieve storage account from connection string.
            var storageAccount           = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("AzureWebJobsStorage"));
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
            CloudTable       table       = tableClient.GetTableReference("snodasdownloadtracker");
            table.CreateIfNotExists();

            //look back eight days and fill in any missing values; I beleive they store files on this server for 7 days
            TableQuery <FileProcessedTracker> dateQuery = new TableQuery <FileProcessedTracker>().Where(
                TableQuery.CombineFilters(
                    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionName),
                    TableOperators.And,
                    TableQuery.GenerateFilterConditionForDate("ForecastDate", QueryComparisons.GreaterThan, DateTime.UtcNow.AddDays(-1 * numberOfDaysToCheck))
                    )
                );

            var results = table.ExecuteQuery(dateQuery);
            //1. Are there any missing dates for the last n days we should backfill
            var currentDate           = DateTime.UtcNow.AddDays(-1 * numberOfDaysToCheck);
            var checkDate             = currentDate;
            var listOfDatesToDownload = new List <DateTime>();
            while (checkDate < DateTime.UtcNow)
            {
                string fileName = checkDate.ToString("yyyyMMdd") + "Snodas.csv";
                if (results.Where(r => r.RowKey == fileName).Count() == 0)
                {
                    //If file doesn't exist enter a new item
                    log.Info($"snodas backfill: adding item {fileName} to download queue");
                    listOfDatesToDownload.Add(checkDate.Date);
                }
                else
                {
                    log.Info($"Skipping item {fileName} as it already exists");
                }
                checkDate = checkDate.AddDays(1);
            }

            foreach (var date in listOfDatesToDownload)
            {
                // Get the object used to communicate with the server.
                var urlBase = @"ftp://sidads.colorado.edu/pub/DATASETS/NOAA/G02158/masked/";
                urlBase += date.ToString("yyyy/");
                urlBase += date.ToString("MM_MMM/");
                urlBase += "SNODAS_" + date.ToString("yyyyMMdd") + ".tar";
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(urlBase);
                request.Method = WebRequestMethods.Ftp.GetDateTimestamp;

                // This FTP site uses anonymous logon.
                request.Credentials = new NetworkCredential("anonymous", "");
                try
                {
                    FtpWebResponse response = (FtpWebResponse)request.GetResponse();
                    //file exists; add to download queue
                    log.Info($"Adding snodas file with {date} to download queue.");
                    //enter a new queue item
                    outputQueueItem.Add(new FileReadyToDownloadQueueMessage {
                        FileName = "SNODAS_" + date.ToString("yyyyMMdd") + "tar",
                        FileDate = date.ToString("yyyyMMdd"), Url = urlBase,
                        Filetype = partitionName
                    });
                }
                catch (WebException ex)
                {
                    FtpWebResponse response = (FtpWebResponse)ex.Response;
                    if (response.StatusCode ==
                        FtpStatusCode.ActionNotTakenFileUnavailable)
                    {
                        log.Info($"SNODAS File for date {date} not available, skipping.");
                        //Does not exist
                        continue;
                    }
                    else
                    {
                        log.Error($"Error attempting to see if snodas file with date {date} exists on ftp server.");
                    }
                }
            }
        }
        /// <summary>
        /// Helper to get the cloud table associated with the supplied appender name
        /// </summary>
        /// <param name="appenderName">unique name to identify a log4net Azure TableAppender</param>
        /// <returns></returns>
        internal CloudTable GetCloudTable(string appenderName)
        {
            if (!this.appenderCloudTables.ContainsKey(appenderName))
            {
                // attempt to get at table from the appender details
                TableAppender tableAppender = LogManager
                                              .GetLogger(typeof(TableAppender))
                                              .Logger
                                              .Repository
                                              .GetAppenders()
                                              .Where(x => x is TableAppender)
                                              .Cast <TableAppender>()
                                              .SingleOrDefault(x => x.Name == appenderName);

                if (tableAppender != null)
                {
                    string connectionString;

                    // attempt to find connection string in web.config
                    if (ConfigurationManager.ConnectionStrings[tableAppender.ConnectionString] != null)
                    {
                        connectionString = ConfigurationManager.ConnectionStrings[tableAppender.ConnectionString].ConnectionString;
                    }
                    else
                    {
                        // fallback to assuming tableAppender has the full connection string
                        connectionString = tableAppender.ConnectionString;
                    }

                    CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(connectionString);

                    CloudTableClient cloudTableClient = cloudStorageAccount.CreateCloudTableClient();

                    CloudTable cloudTable = cloudTableClient.GetTableReference(tableAppender.TableName);

                    bool cloudTableReady = false;

                    //bool retry;
                    //do
                    //{
                    //    retry = false;
                    try
                    {
                        cloudTable.CreateIfNotExists();

                        cloudTableReady = true;
                    }
                    catch     //(StorageException exception)
                    {
                        //if (exception.RequestInformation.HttpStatusCode == 409 &&
                        //    exception.RequestInformation.ExtendedErrorInformation.ErrorCode.Equals(TableErrorCodeStrings.TableBeingDeleted))
                        //{
                        //    retry = true;
                        //}
                    }
                    //} while (retry);

                    if (cloudTableReady)
                    {
                        this.appenderCloudTables[appenderName] = cloudTable;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(this.appenderCloudTables[appenderName]);
        }
Exemplo n.º 6
0
        public static async Task <object> Run([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, TraceWriter log, Microsoft.Azure.WebJobs.ExecutionContext execContext)
        {
            // Variables
            int taskindex               = 0;
            int OutputMES               = -1;
            int OutputPremium           = -1;
            int OutputIndex1            = -1;
            int OutputIndex2            = -1;
            int OutputOCR               = -1;
            int OutputFaceDetection     = -1;
            int OutputFaceRedaction     = -1;
            int OutputMotion            = -1;
            int OutputSummarization     = -1;
            int OutputMesThumbnails     = -1;
            int OutputVideoAnnotation   = -1;
            int OutputContentModeration = -1;

            int    id               = 0;
            string programid        = "";
            string programName      = "";
            string channelName      = "";
            string programUrl       = "";
            string programState     = "";
            string lastProgramState = "";

            IJob  job             = null;
            ITask taskEncoding    = null;
            int   NumberJobsQueue = 0;

            int intervalsec = 60; // Interval for each subclip job (sec). Default is 60

            TimeSpan starttime = TimeSpan.FromSeconds(0);
            TimeSpan duration  = TimeSpan.FromSeconds(intervalsec);

            log.Info($"Webhook was triggered!");
            string triggerStart = DateTime.UtcNow.ToString("o");

            string jsonContent = await req.Content.ReadAsStringAsync();

            dynamic data = JsonConvert.DeserializeObject(jsonContent);

            log.Info(jsonContent);

            if (data.channelName == null || data.programName == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new
                {
                    error = "Please pass channel name and program name in the input object (channelName, programName)"
                }));
            }

            if (data.intervalSec != null)
            {
                intervalsec = (int)data.intervalSec;
            }

            MediaServicesCredentials amsCredentials = new MediaServicesCredentials();

            log.Info($"Using Azure Media Service Rest API Endpoint : {amsCredentials.AmsRestApiEndpoint}");

            try
            {
                AzureAdTokenCredentials tokenCredentials = new AzureAdTokenCredentials(amsCredentials.AmsAadTenantDomain,
                                                                                       new AzureAdClientSymmetricKey(amsCredentials.AmsClientId, amsCredentials.AmsClientSecret),
                                                                                       AzureEnvironments.AzureCloudEnvironment);

                AzureAdTokenProvider tokenProvider = new AzureAdTokenProvider(tokenCredentials);

                _context = new CloudMediaContext(amsCredentials.AmsRestApiEndpoint, tokenProvider);

                // find the Channel, Program and Asset
                channelName = (string)data.channelName;
                var channel = _context.Channels.Where(c => c.Name == channelName).FirstOrDefault();
                if (channel == null)
                {
                    log.Info("Channel not found");
                    return(req.CreateResponse(HttpStatusCode.BadRequest, new
                    {
                        error = "Channel not found"
                    }));
                }

                programName = (string)data.programName;
                var program = channel.Programs.Where(p => p.Name == programName).FirstOrDefault();
                if (program == null)
                {
                    log.Info("Program not found");
                    return(req.CreateResponse(HttpStatusCode.BadRequest, new
                    {
                        error = "Program not found"
                    }));
                }

                programState = program.State.ToString();
                programid    = program.Id;
                var asset = ManifestHelpers.GetAssetFromProgram(_context, programid);

                if (asset == null)
                {
                    log.Info($"Asset not found for program {programid}");
                    return(req.CreateResponse(HttpStatusCode.BadRequest, new
                    {
                        error = "Asset not found"
                    }));
                }

                log.Info($"Using asset Id : {asset.Id}");

                // Table storage to store and real the last timestamp processed
                // Retrieve the storage account from the connection string.
                CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials(amsCredentials.StorageAccountName, amsCredentials.StorageAccountKey), true);

                // Create the table client.
                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

                // Retrieve a reference to the table.
                CloudTable table = tableClient.GetTableReference("liveanalytics");

                // Create the table if it doesn't exist.

                if (!table.CreateIfNotExists())
                {
                    log.Info($"Table {table.Name} already exists");
                }
                else
                {
                    log.Info($"Table {table.Name} created");
                }

                var lastendtimeInTable = ManifestHelpers.RetrieveLastEndTime(table, programid);

                // Get the manifest data (timestamps)
                var assetmanifestdata = ManifestHelpers.GetManifestTimingData(_context, asset, log);
                if (assetmanifestdata.Error)
                {
                    return(req.CreateResponse(HttpStatusCode.InternalServerError, new { error = "Data cannot be read from program manifest." }));
                }

                log.Info("Timestamps: " + string.Join(",", assetmanifestdata.TimestampList.Select(n => n.ToString()).ToArray()));

                var livetime = TimeSpan.FromSeconds((double)assetmanifestdata.TimestampEndLastChunk / (double)assetmanifestdata.TimeScale);

                log.Info($"Livetime: {livetime}");

                starttime = ManifestHelpers.ReturnTimeSpanOnGOP(assetmanifestdata, livetime.Subtract(TimeSpan.FromSeconds(intervalsec)));
                log.Info($"Value starttime : {starttime}");

                if (lastendtimeInTable != null)
                {
                    lastProgramState = lastendtimeInTable.ProgramState;
                    log.Info($"Value ProgramState retrieved : {lastProgramState}");

                    var lastendtimeInTableValue = TimeSpan.Parse(lastendtimeInTable.LastEndTime);
                    log.Info($"Value lastendtimeInTable retrieved : {lastendtimeInTableValue}");

                    id = int.Parse(lastendtimeInTable.Id);
                    log.Info($"Value id retrieved : {id}");

                    if (lastendtimeInTableValue != null)
                    {
                        var delta = (livetime - lastendtimeInTableValue - TimeSpan.FromSeconds(intervalsec)).Duration();
                        log.Info($"Delta: {delta}");

                        //if (delta < (new TimeSpan(0, 0, 3*intervalsec))) // less than 3 times the normal duration (3*60s)
                        if (delta < (TimeSpan.FromSeconds(3 * intervalsec))) // less than 3 times the normal duration (3*60s)
                        {
                            starttime = lastendtimeInTableValue;
                            log.Info($"Value new starttime : {starttime}");
                        }
                    }
                }

                duration = livetime - starttime;
                log.Info($"Value duration: {duration}");
                if (duration == new TimeSpan(0)) // Duration is zero, this may happen sometimes !
                {
                    return(req.CreateResponse(HttpStatusCode.InternalServerError, new { error = "Stopping. Duration of subclip is zero." }));
                }

                // D:\home\site\wwwroot\Presets\LiveSubclip.json
                string ConfigurationSubclip = File.ReadAllText(Path.Combine(System.IO.Directory.GetParent(execContext.FunctionDirectory).FullName, "presets", "LiveSubclip.json")).Replace("0:00:00.000000", starttime.Subtract(TimeSpan.FromMilliseconds(100)).ToString()).Replace("0:00:30.000000", duration.Add(TimeSpan.FromMilliseconds(200)).ToString());

                int priority = 10;
                if (data.priority != null)
                {
                    priority = (int)data.priority;
                }

                // MES Subclipping TASK
                // Declare a new encoding job with the Standard encoder
                job = _context.Jobs.Create("Azure Function - Job for Live Analytics - " + programName, priority);
                // Get a media processor reference, and pass to it the name of the
                // processor to use for the specific task.
                IMediaProcessor processor = MediaServicesHelper.GetLatestMediaProcessorByName(_context, "Media Encoder Standard");

                // Change or modify the custom preset JSON used here.
                // string preset = File.ReadAllText("D:\home\site\wwwroot\Presets\H264 Multiple Bitrate 720p.json");

                // Create a task with the encoding details, using a string preset.
                // In this case "H264 Multiple Bitrate 720p" system defined preset is used.
                taskEncoding = job.Tasks.AddNew("Subclipping task",
                                                processor,
                                                ConfigurationSubclip,
                                                TaskOptions.None);

                // Specify the input asset to be encoded.
                taskEncoding.InputAssets.Add(asset);
                OutputMES = taskindex++;

                // Add an output asset to contain the results of the job.
                // This output is specified as AssetCreationOptions.None, which
                // means the output asset is not encrypted.
                var subclipasset = taskEncoding.OutputAssets.AddNew(asset.Name + " subclipped " + triggerStart, JobHelpers.OutputStorageFromParam(data.mesSubclip), AssetCreationOptions.None);

                log.Info($"Adding media analytics tasks");

                //new
                OutputIndex1            = JobHelpers.AddTask(execContext, _context, job, subclipasset, (data.indexV1 == null) ? (string)data.indexV1Language : ((string)data.indexV1.language ?? "English"), "Azure Media Indexer", "IndexerV1.xml", "English", ref taskindex, specifiedStorageAccountName: JobHelpers.OutputStorageFromParam(data.indexV1));
                OutputIndex2            = JobHelpers.AddTask(execContext, _context, job, subclipasset, (data.indexV2 == null) ? (string)data.indexV2Language : ((string)data.indexV2.language ?? "EnUs"), "Azure Media Indexer 2 Preview", "IndexerV2.json", "EnUs", ref taskindex, specifiedStorageAccountName: JobHelpers.OutputStorageFromParam(data.indexV2));
                OutputOCR               = JobHelpers.AddTask(execContext, _context, job, subclipasset, (data.ocr == null) ? (string)data.ocrLanguage : ((string)data.ocr.language ?? "AutoDetect"), "Azure Media OCR", "OCR.json", "AutoDetect", ref taskindex, specifiedStorageAccountName: JobHelpers.OutputStorageFromParam(data.ocr));
                OutputFaceDetection     = JobHelpers.AddTask(execContext, _context, job, subclipasset, (data.faceDetection == null) ? (string)data.faceDetectionMode : ((string)data.faceDetection.mode ?? "PerFaceEmotion"), "Azure Media Face Detector", "FaceDetection.json", "PerFaceEmotion", ref taskindex, specifiedStorageAccountName: JobHelpers.OutputStorageFromParam(data.faceDetection));
                OutputFaceRedaction     = JobHelpers.AddTask(execContext, _context, job, subclipasset, (data.faceRedaction == null) ? (string)data.faceRedactionMode : ((string)data.faceRedaction.mode ?? "comined"), "Azure Media Redactor", "FaceRedaction.json", "combined", ref taskindex, priority - 1, specifiedStorageAccountName: JobHelpers.OutputStorageFromParam(data.faceRedaction));
                OutputMotion            = JobHelpers.AddTask(execContext, _context, job, subclipasset, (data.motionDetection == null) ? (string)data.motionDetectionLevel : ((string)data.motionDetection.level ?? "medium"), "Azure Media Motion Detector", "MotionDetection.json", "medium", ref taskindex, priority - 1, specifiedStorageAccountName: JobHelpers.OutputStorageFromParam(data.motionDetection));
                OutputSummarization     = JobHelpers.AddTask(execContext, _context, job, subclipasset, (data.summarization == null) ? (string)data.summarizationDuration : ((string)data.summarization.duration ?? "0.0"), "Azure Media Video Thumbnails", "Summarization.json", "0.0", ref taskindex, specifiedStorageAccountName: JobHelpers.OutputStorageFromParam(data.summarization));
                OutputVideoAnnotation   = JobHelpers.AddTask(execContext, _context, job, subclipasset, (data.videoAnnotation != null) ? "1.0" : null, "Azure Media Video Annotator", "VideoAnnotation.json", "1.0", ref taskindex, specifiedStorageAccountName: JobHelpers.OutputStorageFromParam(data.videoAnnotation));
                OutputContentModeration = JobHelpers.AddTask(execContext, _context, job, subclipasset, (data.contentModeration != null) ? "2.0" : null, "Azure Media Content Moderator", "ContentModeration.json", "2.0", ref taskindex, specifiedStorageAccountName: JobHelpers.OutputStorageFromParam(data.contentModeration));

                // MES Thumbnails
                OutputMesThumbnails = JobHelpers.AddTask(execContext, _context, job, subclipasset, (data.mesThumbnails != null) ? ((string)data.mesThumbnails.Start ?? "{Best}") : null, "Media Encoder Standard", "MesThumbnails.json", "{Best}", ref taskindex, specifiedStorageAccountName: JobHelpers.OutputStorageFromParam(data.mesThumbnails));

                job.Submit();
                log.Info("Job Submitted");

                id++;
                ManifestHelpers.UpdateLastEndTime(table, starttime + duration, programid, id, program.State);

                log.Info($"Output MES index {OutputMES}");

                // Let store some data in altid of subclipped asset
                var sid = JobHelpers.ReturnId(job, OutputMES);
                log.Info($"SID {sid}");
                var subclipassetrefreshed = _context.Assets.Where(a => a.Id == sid).FirstOrDefault();
                log.Info($"subclipassetrefreshed ID {subclipassetrefreshed.Id}");
                subclipassetrefreshed.AlternateId = JsonConvert.SerializeObject(new ManifestHelpers.SubclipInfo()
                {
                    programId = programid, subclipStart = starttime, subclipDuration = duration
                });
                subclipassetrefreshed.Update();

                // Let store some data in altid of index assets
                var index1sid = JobHelpers.ReturnId(job, OutputIndex1);
                if (index1sid != null)
                {
                    var index1assetrefreshed = _context.Assets.Where(a => a.Id == index1sid).FirstOrDefault();
                    log.Info($"index1assetrefreshed ID {index1assetrefreshed.Id}");
                    index1assetrefreshed.AlternateId = JsonConvert.SerializeObject(new ManifestHelpers.SubclipInfo()
                    {
                        programId = programid, subclipStart = starttime, subclipDuration = duration
                    });
                    index1assetrefreshed.Update();
                }

                var index2sid = JobHelpers.ReturnId(job, OutputIndex2);
                if (index2sid != null)
                {
                    var index2assetrefreshed = _context.Assets.Where(a => a.Id == index2sid).FirstOrDefault();
                    log.Info($"index2assetrefreshed ID {index2assetrefreshed.Id}");
                    index2assetrefreshed.AlternateId = JsonConvert.SerializeObject(new ManifestHelpers.SubclipInfo()
                    {
                        programId = programid, subclipStart = starttime, subclipDuration = duration
                    });
                    index2assetrefreshed.Update();
                }

                // Get program URL
                var publishurlsmooth = MediaServicesHelper.GetValidOnDemandURI(_context, asset);

                if (publishurlsmooth != null)
                {
                    programUrl = publishurlsmooth.ToString();
                }

                NumberJobsQueue = _context.Jobs.Where(j => j.State == JobState.Queued).Count();
            }
            catch (Exception ex)
            {
                string message = ex.Message + ((ex.InnerException != null) ? Environment.NewLine + MediaServicesHelper.GetErrorMessage(ex) : "");
                log.Info($"ERROR: Exception {message}");
                return(req.CreateResponse(HttpStatusCode.InternalServerError, new { error = message }));
            }

            log.Info("Job Id: " + job.Id);
            log.Info("Output asset Id: " + ((OutputMES > -1) ? JobHelpers.ReturnId(job, OutputMES) : JobHelpers.ReturnId(job, OutputPremium)));

            return(req.CreateResponse(HttpStatusCode.OK, new
            {
                triggerStart = triggerStart,
                jobId = job.Id,
                subclip = new
                {
                    assetId = JobHelpers.ReturnId(job, OutputMES),
                    taskId = JobHelpers.ReturnTaskId(job, OutputMES),
                    start = starttime,
                    duration = duration,
                },
                mesThumbnails = new
                {
                    assetId = JobHelpers.ReturnId(job, OutputMesThumbnails),
                    taskId = JobHelpers.ReturnTaskId(job, OutputMesThumbnails)
                },
                indexV1 = new
                {
                    assetId = JobHelpers.ReturnId(job, OutputIndex1),
                    taskId = JobHelpers.ReturnTaskId(job, OutputIndex1),
                    language = (string)data.indexV1Language
                },
                indexV2 = new
                {
                    assetId = JobHelpers.ReturnId(job, OutputIndex2),
                    taskId = JobHelpers.ReturnTaskId(job, OutputIndex2),
                    language = (string)data.indexV2Language,
                },
                ocr = new
                {
                    assetId = JobHelpers.ReturnId(job, OutputOCR),
                    taskId = JobHelpers.ReturnTaskId(job, OutputOCR)
                },
                faceDetection = new
                {
                    assetId = JobHelpers.ReturnId(job, OutputFaceDetection),
                    taskId = JobHelpers.ReturnTaskId(job, OutputFaceDetection)
                },
                faceRedaction = new
                {
                    assetId = JobHelpers.ReturnId(job, OutputFaceRedaction),
                    taskId = JobHelpers.ReturnTaskId(job, OutputFaceRedaction)
                },
                motionDetection = new
                {
                    assetId = JobHelpers.ReturnId(job, OutputMotion),
                    taskId = JobHelpers.ReturnTaskId(job, OutputMotion)
                },
                summarization = new
                {
                    assetId = JobHelpers.ReturnId(job, OutputSummarization),
                    taskId = JobHelpers.ReturnTaskId(job, OutputSummarization)
                },
                videoAnnotation = new
                {
                    assetId = JobHelpers.ReturnId(job, OutputVideoAnnotation),
                    taskId = JobHelpers.ReturnTaskId(job, OutputVideoAnnotation)
                },
                contentModeration = new
                {
                    assetId = JobHelpers.ReturnId(job, OutputContentModeration),
                    taskId = JobHelpers.ReturnTaskId(job, OutputContentModeration)
                },

                channelName = channelName,
                programName = programName,
                programId = programid,
                programUrl = programUrl,
                programState = programState,
                programStateChanged = (lastProgramState != programState).ToString(),
                otherJobsQueue = NumberJobsQueue
            }));
        }
Exemplo n.º 7
0
        static void AzureStorageTableExamples()
        {
            // Getting configuration from the App.config file and get access to the CloudStorageAccount.
            // Azure access Key should is stored in the App.config
            String storageKeyValue = CloudConfigurationManager.GetSetting("AzureStorageAccount");

            // Just in case to check whether reading the correct value
            Console.WriteLine("Storage Account Key Used" + storageKeyValue);

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageKeyValue);

            // Create the table client.
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            // Retrieve a reference to the table.
            CloudTable table = tableClient.GetTableReference("tenant");

            table.CreateIfNotExists();

            // Lesson 1 Table Insert

            TenantEntity tenant1 = new TenantEntity("Neson", "De Jesus", "Canada");

            tenant1.Email       = "*****@*****.**";
            tenant1.PhoneNumber = "911-911-9111";

            TableOperation tOper = TableOperation.Insert(tenant1);

            // Lesson 2 Batch Insert
            TableBatchOperation batchInsertOperation = new TableBatchOperation();

            TenantEntity tenant2 = new TenantEntity("Vivek", "Menon", "USA");

            tenant2.Email       = "*****@*****.**";
            tenant2.PhoneNumber = "911-911-9111";

            batchInsertOperation.Insert(tenant2);

            TenantEntity tenant3 = new TenantEntity("Sanders", "John", "USA");

            tenant3.Email       = "*****@*****.**";
            tenant3.PhoneNumber = "911-911-9111";

            batchInsertOperation.Insert(tenant3);

            table.ExecuteBatch(batchInsertOperation);

            // Lession 3: Accesing the table data
            TableQuery <TenantEntity> query = new TableQuery <TenantEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey",
                                                                                                                       QueryComparisons.Equal, "USA"));

            foreach (TenantEntity tenant in table.ExecuteQuery(query))
            {
                Console.WriteLine("{0}, {1}, {2}, {3}", tenant.firstName, tenant.lastName, tenant.Email, tenant.PhoneNumber);
            }


            // Lesson 4: Multiple condition in where clause
            TableQuery <TenantEntity> queryMultipleWhereContidion = new TableQuery <TenantEntity>().Where(
                TableQuery.CombineFilters(
                    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "USA"),
                    TableOperators.And,
                    TableQuery.GenerateFilterCondition("lastName", QueryComparisons.Equal, "Sanders")));

            foreach (TenantEntity tenant in table.ExecuteQuery(queryMultipleWhereContidion))
            {
                Console.WriteLine("{0}, {1}, {2}, {3}", tenant.firstName, tenant.lastName, tenant.Email, tenant.PhoneNumber);
            }


            // Lesson 5: Single record retrieval
            TableOperation retrieveOperation = TableOperation.Retrieve <TenantEntity>("Sanders", "John");
            TableResult    retrievedResult   = table.Execute(retrieveOperation);

            if (retrievedResult.Result != null)
            {
                Console.WriteLine(((TenantEntity)retrievedResult.Result).PhoneNumber);
            }
            else
            {
                Console.WriteLine("The phone number could not be retrieved.");
            }
            Console.ReadLine();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Save Recent Activites emails to azure table
        /// </summary>
        public void GetRecentActivitiesEmailData()
        {
            Trace.TraceInformation("Worker Role RecentActivity start GetRecentActivitiesEmailData() {0}", DateTime.Now);

            try
            {
                List <int> objallcompany = objLeadNotifcationBusiness.GetAllActiveCompanies();
                foreach (int companyId in objallcompany)
                {
                    try
                    {
                        accountSetting = userBusiness.GetSendNotificationsActiveUsersId(companyId);
                    }
                    catch (Exception accountSettingExp)
                    {
                        hasError = true;
                        logdata.Append("\n");
                        logdata.Append(companyID + "," + " " + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + accountSettingExp.Message + ". Error Occured When Feching  User Account Setting Data");
                        continue;
                    }
                    try
                    {
                        foreach (var user in accountSetting)
                        {
                            WorkerRoleRecentActivity.CultureName = user.User.CultureInformation == null ? "en-US" : user.User.CultureInformation.CultureName;
                            WorkerRoleCommonFunctions.SetCurrentUserCulture();
                            WorkerRoleRecentActivity.UserId = user.UserId;
                            companyID = companyId;
                            WorkerRoleRecentActivity.TimeZoneOffSet = user.User.TimeZone == null ? "0" : user.User.TimeZone.offset.ToString();
                            int TotalRecords = 0;
                            List <SSP_GetRecentActivitesForEmailNotification_Result> RecentActivities = new List <SSP_GetRecentActivitesForEmailNotification_Result>();
                            try
                            {
                                RecentActivities = objLeadNotifcationBusiness.GetRecentActivitiesForNotification(ErucaCRM.Utility.ReadConfiguration.PageSize, companyId, user.UserId, ref TotalRecords);
                                AutoMapper.Mapper.Map(RecentActivities, RecentActivitiesModel);
                            }
                            catch (Exception exRecentActivities)
                            {
                                hasError = true;
                                logdata.Append("\n");
                                logdata.Append(companyID + "," + WorkerRoleRecentActivity.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + exRecentActivities.Message + ". Error Occured When Feching Recent Activites Data");
                                continue;
                            }

                            objmailhelper = new ErucaCRM.Utility.MailHelper();
                            if (RecentActivities.Count > 0)
                            {
                                maxLeadAuditId = RecentActivities.Max(x => x.LeadAuditId);
                            }
                            foreach (var homemodel in RecentActivitiesModel)
                            {
                                try
                                {
                                    MailBodyTemplat    = WorkerRoleCommonFunctions.GetGlobalizedLabel("EmailTemplates", "RecentActivityEmailBody", WorkerRoleRecentActivity.CultureName);
                                    mailSubjectTemplat = WorkerRoleCommonFunctions.GetGlobalizedLabel("EmailTemplates", "RecentActivityEmailSubject", WorkerRoleRecentActivity.CultureName);
                                    objmailhelper.Body = objmailhelper.Body + string.Format(MailBodyTemplat, ErucaCRM.Utility.ReadConfiguration.OwnerDetail + Convert.ToInt32(homemodel.CreatedBy).Encrypt(), ErucaCRM.Utility.ReadConfiguration.NoImage, homemodel.LeadAuditId, homemodel.ActivityText, homemodel.ActivityCreatedTime);
                                    if (objmailhelper.Subject == null)
                                    {
                                        objmailhelper.Subject = string.Format(mailSubjectTemplat, TotalRecords);
                                    }
                                    leadAuditIds.Add(homemodel.LeadAuditId);
                                }
                                catch (Exception expEmailTemplate)
                                {
                                    hasError = true;
                                    logdata.Append("\n");
                                    logdata.Append(companyID + "," + WorkerRoleRecentActivity.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + expEmailTemplate.Message + ". Error Occured When Reading Config File (OwnerDetail|NoImage|) || Reading Culture File.(EmailTemplates(RecentActivityEmailBody|RecentActivityEmailSubject|))");
                                }
                            }
                            if (RecentActivitiesModel.Count > 0)
                            {
                                try
                                {
                                    objmailhelper.Body = "<div style='width: 450px'> <div style='width:100%;text-align:center'><img src='" + ErucaCRM.Utility.ReadConfiguration.SiteUrl + ErucaCRM.Utility.ReadConfiguration.WebsiteLogoPath + "'></div>" + objmailhelper.Body;

                                    if (TotalRecords > ErucaCRM.Utility.ReadConfiguration.PageSize)
                                    {
                                        objmailhelper.Body = objmailhelper.Body + " <div style='text-align: right; margin: 15px 0 0 0;'><a href='" + ErucaCRM.Utility.ReadConfiguration.PopUrl + "' style='text-decoration:none;background: none repeat scroll 0 0 #0798bc; width:300px;color: #fff; font-size: 9px; border: 1px solid #8db6e4; border-radius: 3px; cursor: pointer; margin: 14px 5px 13px; padding: 1px;'>" + WorkerRoleCommonFunctions.GetGlobalizedLabel("DashBoard", "ViewAll", WorkerRoleRecentActivity.CultureName) + "</a></div></div>";
                                    }
                                    //send email
                                    objmailhelper.ToAddress     = user.User.EmailId;
                                    objmailhelper.RecipientName = user.User.FirstName + " " + user.User.LastName;
                                    //objmailhelper.SendMailMessage(objmailhelper.ToAddress, objmailhelper.Subject, objmailhelper.Body);

                                    // Retrieve the storage account from the connection string.
                                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                                        CloudConfigurationManager.GetSetting("StorageConnectionString"));
                                    // Create the table client.
                                    CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
                                    // Create the table if it doesn't exist.
                                    CloudTable table = tableClient.GetTableReference("Message");
                                    table.CreateIfNotExists();
                                    // Create a new customer entity.

                                    Message message = new Message();
                                    message.ToAddress      = objmailhelper.ToAddress;
                                    message.Subject        = objmailhelper.Subject;
                                    message.Body           = objmailhelper.Body;
                                    message.ReciepientName = objmailhelper.RecipientName;
                                    var sendEmailRow = new SendEmail
                                    {
                                        PartitionKey     = message.ReciepientName,
                                        RowKey           = message.ToAddress,
                                        EmailAddress     = message.ToAddress,
                                        EmailSent        = false,
                                        MessageBody      = message.Body,
                                        ScheduledDate    = DateTime.Now,
                                        FromEmailAddress = ErucaCRM.Utility.ReadConfiguration.EmailForScheduler,
                                        SubjectLine      = message.Subject,
                                    };

                                    try
                                    {
                                        TableOperation insertOperation = TableOperation.InsertOrReplace(sendEmailRow);
                                        table.Execute(insertOperation);
                                        Trace.TraceInformation("Worker Role RecentActivity saved data in message table {0}", DateTime.Now);
                                    }
                                    catch (Exception ex)
                                    {
                                        string err = "Error creating SendEmail row:  " + ex.Message;
                                        if (ex.InnerException != null)
                                        {
                                            err += " Inner Exception: " + ex.InnerException;
                                        }
                                        Trace.TraceError(err);
                                    }

                                    string queueMessageString =
                                        sendEmailRow.PartitionKey + "," +
                                        sendEmailRow.RowKey + ",";
                                    // Create the queue client.
                                    CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
                                    // Retrieve a reference to a queue.
                                    CloudQueue queue = queueClient.GetQueueReference("azuremailqueue");
                                    // Create the queue if it doesn't already exist.
                                    queue.CreateIfNotExists();
                                    var queueMessage = new CloudQueueMessage(queueMessageString);
                                    // Create a message and add it to the queue.
                                    CloudQueueMessage cloudMessage = new CloudQueueMessage("azuremailqueue");
                                    queue.AddMessage(queueMessage);
                                    Trace.TraceInformation("Worker Role RecentActivity saved data in queue table {0}", DateTime.Now);
                                    userBusiness.UpdateUserNotification(WorkerRoleRecentActivity.UserId, maxLeadAuditId);

                                    logdata.Append("\n");
                                    logdata.Append(companyID + "," + WorkerRoleRecentActivity.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Success.ToString() + "," + objmailhelper.Subject);
                                }
                                catch (System.Net.Mail.SmtpException expEmailSend)
                                {
                                    hasError = true;
                                    logdata.Append("\n");
                                    logdata.Append(companyID + "," + WorkerRoleRecentActivity.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + expEmailSend.Message + ". Error Occured When Sending Email || Reading Config File File(PopUrl|SiteUrl|WebsiteLogoPath|PageSize).");
                                }
                                catch (Exception expEmailSend)
                                {
                                    hasError = true;
                                    logdata.Append("\n");
                                    logdata.Append(companyID + "," + WorkerRoleRecentActivity.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + expEmailSend.Message + ". Error Occured When Sending Email || Reading Config File File(PopUrl|SiteUrl|WebsiteLogoPath|PageSize).");
                                }
                            }
                        }
                    }
                    catch (Exception exeption)
                    {
                        hasError = true;
                        logdata.Append("\n");
                        logdata.Append(companyID + "," + WorkerRoleRecentActivity.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + exeption.Message);
                    }
                }
                SaveLogData();
            }
            catch (Exception exep)
            {
                logdata.Append("\n");
                logdata.Append("" + "," + "" + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + exep.Message + ". Error Occur When Feching All Company Data.Please Check Network Releated Information.");
                hasError = true;
                SaveLogData();
            }
        }
Exemplo n.º 9
0
 public void CreateTable()
 {
     tableClient = storageAccount.CreateCloudTableClient();
     chatTable   = tableClient.GetTableReference(TABLENAME);
     chatTable.CreateIfNotExists();
 }
Exemplo n.º 10
0
 public bool CreateTable <T>() where T : ITableEntity, new()
 {
     table = tableClient.GetTableReference(typeof(T).Name);
     return(table.CreateIfNotExists());
 }
Exemplo n.º 11
0
        /// <summary>
        /// Run a bunch of core Table operations. Each operation is run ~100 times to measure latency.
        /// You can swap the endpoint and compare with regular Azure Table storage.
        /// </summary>
        /// <param name="tableClient">The Azure Table storage client</param>
        /// <param name="numIterations">Number of iterations</param>
        public void Run(CloudTableClient tableClient, int numIterations)
        {
            Console.WriteLine("\n");
            Console.WriteLine("Creating Table if it doesn't exist...");

            CloudTable table = tableClient.GetTableReference("People");

            table.DeleteIfExists();
            table.CreateIfNotExists();

            List <CustomerEntity> items = new List <CustomerEntity>();
            Stopwatch             watch = new Stopwatch();

            Console.WriteLine("\n");
            Console.WriteLine("Running inserts: ");
            for (int i = 0; i < numIterations; i++)
            {
                watch.Start();

                CustomerEntity item = new CustomerEntity()
                {
                    PartitionKey = Guid.NewGuid().ToString(),
                    RowKey       = Guid.NewGuid().ToString(),
                    Email        = $"{GetRandomString(6)}@contoso.com",
                    PhoneNumber  = "425-555-0102",
                    Bio          = GetRandomString(1000)
                };

                TableOperation insertOperation = TableOperation.Insert(item);
                table.Execute(insertOperation);
                double latencyInMs = watch.Elapsed.TotalMilliseconds;

                Console.Write($"\r\tInsert #{i + 1} completed in {latencyInMs} ms.");
                items.Add(item);

                watch.Reset();
            }

            Console.WriteLine("\n");
            Console.WriteLine("Running retrieves: ");

            for (int i = 0; i < numIterations; i++)
            {
                watch.Start();

                TableOperation retrieveOperation = TableOperation.Retrieve <CustomerEntity>(items[i].PartitionKey, items[i].RowKey);
                table.Execute(retrieveOperation);
                double latencyInMs = watch.Elapsed.TotalMilliseconds;

                Console.Write($"\r\tRetrieve #{i + 1} completed in {latencyInMs} ms");

                watch.Reset();
            }

            Console.WriteLine("\n");
            Console.WriteLine("Running replace: ");


            for (int i = 0; i < numIterations; i++)
            {
                watch.Start();

                // Same latency as inserts, p99 < 15ms, and p50 < 6ms
                items[i].PhoneNumber = "425-555-5555";
                TableOperation replaceOperation = TableOperation.Replace(items[i]);
                table.Execute(replaceOperation);

                double latencyInMs = watch.Elapsed.TotalMilliseconds;
                Console.Write($"\r\tReplace #{i + 1} completed in {latencyInMs} ms");

                watch.Reset();
            }
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            CloudStorageAccount storedAccount = CloudStorageAccount.Parse
                                                    (CloudConfigurationManager.GetSetting("StorageConnectionString"));
            CloudTableClient tableClient = storedAccount.CreateCloudTableClient();
            CloudTable       table       = tableClient.GetTableReference("customers");

            table.CreateIfNotExists();
            Console.WriteLine("Table customers is ready!");

            //Insert
            //CustomerEntity customer1 = new CustomerEntity("AP", "A01");
            //customer1.LastName = "Mark";
            //customer1.FirstName = "wines";
            //customer1.Email = "*****@*****.**";
            //customer1.PhoneNumber = "9100945142";


            //TableOperation insertOperation =  TableOperation.Insert(customer1);
            //table.Execute(insertOperation);
            //Console.WriteLine("Row Added!");

            //TableBatchOperation batchOperation = new TableBatchOperation();
            //CustomerEntity customer1 = new CustomerEntity("MH", "A01");
            //customer1.LastName = "Mark";
            //customer1.FirstName = "wines";
            //customer1.Email = "*****@*****.**";
            //customer1.PhoneNumber = "9100945142";

            //CustomerEntity customer2 = new CustomerEntity("MH", "A02");
            //customer2.LastName = "Mark";
            //customer2.FirstName = "wines";
            //customer2.Email = "*****@*****.**";
            //customer2.PhoneNumber = "9100945142";


            //CustomerEntity customer3 = new CustomerEntity("MH", "A03");
            //customer3.LastName = "Mark";
            //customer3.FirstName = "wines";
            //customer3.Email = "*****@*****.**";
            //customer3.PhoneNumber = "9100945142";

            //CustomerEntity customer4 = new CustomerEntity("MH", "A04");
            //customer4.LastName = "Mark";
            //customer4.FirstName = "wines";
            //customer4.Email = "*****@*****.**";
            //customer4.PhoneNumber = "9100945142";


            //batchOperation.Insert(customer1);
            //batchOperation.Insert(customer2);
            //batchOperation.Insert(customer3);
            //batchOperation.Insert(customer4);

            //table.ExecuteBatch(batchOperation);

            TableQuery <CustomerEntity> query = new TableQuery <CustomerEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "MH"));

            foreach (var item in table.ExecuteQuery(query))
            {
                Console.WriteLine($"{ item.FirstName }{item.LastName}{item.PhoneNumber}");
            }
            Console.WriteLine("Completed");
            Console.ReadLine();
        }
Exemplo n.º 13
0
 private void initTable()
 {
     myTableClient = this.storageAccount.CreateCloudTableClient();
     myTable       = myTableClient.GetTableReference(tableName);
     myTable.CreateIfNotExists();
 }
 public TableSample()
 {
     tableClient   = storageAccount.CreateCloudTableClient();
     customerTable = tableClient.GetTableReference(TABLENAME);
     customerTable.CreateIfNotExists();
 }
Exemplo n.º 15
0
        void Initialize()
        {
            CloudTable table = GetTable(TableName);

            table.CreateIfNotExists();
        }
Exemplo n.º 16
0
 public ActivityAzureLogger(CloudStorageAccount account)
 {
     tableClient   = account.CreateCloudTableClient();
     activityTable = tableClient.GetTableReference("ClientActivity");
     activityTable.CreateIfNotExists();
 }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            CloudTableClient tableClient = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudTableClient();
            CloudTable       table       = tableClient.GetTableReference("roster");

            // Ensure that the table is created.
            table.CreateIfNotExists();

            // Create 3 Employee instances.
            Employee first = new Employee
            {
                PartitionKey   = "IT",
                RowKey         = "ibahena",
                YearsAtCompany = 7
            };
            Employee second = new Employee
            {
                PartitionKey   = "HR",
                RowKey         = "rreeves",
                YearsAtCompany = 12
            };
            Employee third = new Employee
            {
                PartitionKey   = "HR",
                RowKey         = "rromani",
                YearsAtCompany = 3
            };

            // Insert the employee with the IT partition key to the table.
            // POST
            TableOperation insertOperation = TableOperation.InsertOrReplace(first);

            table.Execute(insertOperation);

            // Batch insert the employees with the HR partition key to the table.
            // Batch operations can be used to insert multiple entities into an Azure Storage table.
            // The entities must all have the same PartitionKey in order to be inserted as a single batch.
            // POST
            TableBatchOperation batchOperation = new TableBatchOperation();

            batchOperation.InsertOrReplace(second);
            batchOperation.InsertOrReplace(third);
            table.ExecuteBatch(batchOperation);

            // GET
            // Query the table for employees with a partition key equal to HR.
            TableQuery <Employee> query = new TableQuery <Employee>()
                                          .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "HR"));

            Console.WriteLine("HR Employees\n");
            foreach (Employee hrEmployee in table.ExecuteQuery <Employee>(query))
            {
                Console.WriteLine(hrEmployee);
            }

            // GET
            // Retrieve the single employee with a partition key of IT, and a row key of ibahena.
            Console.WriteLine("\n\n\n\nIT Employee\n");
            TableOperation retrieveOperation = TableOperation.Retrieve <Employee>("IT", "ibahena");
            TableResult    result            = table.Execute(retrieveOperation);
            Employee       itEmployee        = result.Result as Employee;

            Console.WriteLine(itEmployee);
        }
Exemplo n.º 18
0
        public void ProfileStorageAccess()
        {
            CloudStorageAccount cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;

            #region Blob

            //Blobs
            CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();

            CloudBlobContainer cloudBlobContainer = blobClient.GetContainerReference("blobcontainer");
            cloudBlobContainer.CreateIfNotExists();

            ICloudBlob cloudBlob = cloudBlobContainer.GetBlockBlobReference("testblob");

            byte[] data = { 1, 2, 3 };

            using (TimeMeasure.Measure("blob write"))
            {
                cloudBlob.UploadFromByteArray(data, 0, 3);
            }

            #endregion

            #region Queue

            CloudQueueClient queueClient = cloudStorageAccount.CreateCloudQueueClient();

            //Queues
            CloudQueue cloudQueue = queueClient.GetQueueReference("test-queue");
            cloudQueue.CreateIfNotExists();

            using (TimeMeasure.Measure("queue write"))
            {
                cloudQueue.AddMessage(new CloudQueueMessage("testing123"));
            }

            CloudTableClient tableClient = cloudStorageAccount.CreateCloudTableClient();

            #endregion

            #region Table

            //Tables
            CloudTable cloudTable = tableClient.GetTableReference("testtable");
            cloudTable.CreateIfNotExists();

            ITableEntity tableEntity = new DynamicTableEntity
            {
                PartitionKey = "pkey",
                Properties   = new Dictionary <string, EntityProperty> {
                    { "name", new EntityProperty("chris") }
                },
                RowKey = "row1",
            };

            TableOperation operation = TableOperation.InsertOrMerge(tableEntity);

            using (TimeMeasure.Measure("table entity write"))
            {
                cloudTable.Execute(operation);
            };

            #endregion
        }
 public AzureTableContext()
 {
     client = this.StorageAccount.CreateCloudTableClient();
     UserTokenCacheTable = client.GetTableReference("tokenCache");
     UserTokenCacheTable.CreateIfNotExists();
 }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
            CloudTableClient    tableClient    = storageAccount.CreateCloudTableClient();
            CloudTable          table          = tableClient.GetTableReference("customers");

            table.CreateIfNotExists();
            Console.WriteLine("Table customers is ready!");

            ////Insert
            //CustomerEntity customer1 = new CustomerEntity("AP", "A01");
            //customer1.FirstName = "James";
            //customer1.LastName= "Mark";
            //customer1.Email = "*****@*****.**";
            //customer1.PhoneNumber = "9820001010";

            //TableOperation insertOperation = TableOperation.Insert(customer1);
            //table.Execute(insertOperation);
            //Console.WriteLine("Row added!");

            ////Bulk insert
            //TableBatchOperation batchOperation = new TableBatchOperation();

            //CustomerEntity customer1 = new CustomerEntity("MH", "A02");
            //customer1.FirstName = "Sarah";
            //customer1.LastName = "Lee";
            //customer1.Email = "*****@*****.**";
            //customer1.PhoneNumber = "9820001011";

            //CustomerEntity customer2 = new CustomerEntity("MH", "A03");
            //customer2.FirstName = "Simon";
            //customer2.LastName = "Jack";
            //customer2.Email = "*****@*****.**";
            //customer2.PhoneNumber = "9820001012";

            //CustomerEntity customer3 = new CustomerEntity("MH", "A04");
            //customer3.FirstName = "Sim";
            //customer3.LastName = "Yu";
            //customer3.Email = "*****@*****.**";
            //customer3.PhoneNumber = "9820001013";

            //CustomerEntity customer4 = new CustomerEntity("MH", "A05");
            //customer4.FirstName = "Dan";
            //customer4.LastName = "Jones";
            //customer4.Email = "*****@*****.**";
            //customer4.PhoneNumber = "9820001014";

            //batchOperation.Insert(customer1);
            //batchOperation.Insert(customer2);
            //batchOperation.Insert(customer3);
            //batchOperation.Insert(customer4);

            //table.ExecuteBatch(batchOperation);
            //Console.WriteLine("Batch of rows added!");

            TableQuery <CustomerEntity> query = new TableQuery <CustomerEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "MH"));

            foreach (CustomerEntity entity in table.ExecuteQuery(query))
            {
                Console.WriteLine("{0}, {1}\t{2}\t{3}\t{4}\t{5}", entity.PartitionKey, entity.RowKey, entity.FirstName, entity.LastName, entity.Email, entity.PhoneNumber);
            }
        }
Exemplo n.º 21
0
        public static void Main(string[] args)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("ConnectionString"));

            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();//storage table section
            CloudTable       table       = tableClient.GetTableReference("class");

            #region

            //table.Delete();
            //table.DeleteIfExists();

            Console.WriteLine("Table has been deleted or removed.All info has been deleted.");

            #endregion

            #region Info of table

            table.CreateIfNotExists();

            var tableNames = tableClient.ListTables();// all tables name

            foreach (CloudTable item in tableNames)
            {
                Console.WriteLine(item.Name);
            }

            #endregion

            #region Insert data

            Teacher teacher = new Teacher("001", "Teachers")
            {
                Name       = "Ricardo Celis",
                Assignment = "Programmer"
            };

            Teacher teacher2 = new Teacher("002", "Teachers")
            {
                Name       = "Carlos Paredes",
                Assignment = "Tester"
            };

            TableOperation insertData  = TableOperation.Insert(teacher);
            TableOperation insertData2 = TableOperation.Insert(teacher2);

            //TODO: Check batch operation
            table.Execute(insertData);
            table.Execute(insertData2);

            Console.WriteLine("Isnert has been process succesfully");

            #endregion

            #region Read data

            TableQuery <Teacher> query = new TableQuery <Teacher>().Where(TableQuery.GenerateFilterCondition("Partition Key", QueryComparisons.GreaterThan, "000"));

            foreach (Teacher item in table.ExecuteQuery(query))
            {
                Console.WriteLine("{0},  {1}\t{2}\t{3}", item.PartitionKey, item.RowKey, item.Name, item.Assignment);
            }

            Console.WriteLine("Excecution succesfully");

            #endregion

            #region Update data

            TableOperation updateData = TableOperation.Retrieve <Teacher>("002[Partition Key]", "Teachers");

            TableResult result = table.Execute(updateData);

            Teacher updateEntity = (Teacher)result.Result;

            if (updateEntity != null)
            {
                updateEntity.Name = "Diseño audiovisual";
                TableOperation updateOperation = TableOperation.Replace(updateEntity);
                table.Execute(updateOperation);
                Console.WriteLine("Entity updated");
            }
            else
            {
                Console.WriteLine("Entity not found");
            }

            #endregion

            #region Delete data

            TableOperation deleteData = TableOperation.Retrieve <Teacher>("002[Partition Key]", "Teachers");

            TableResult resultDelete = table.Execute(updateData);

            Teacher deleteEntity = (Teacher)result.Result;

            if (updateEntity != null)
            {
                TableOperation deleteOperation = TableOperation.Delete(deleteEntity);
                table.Execute(deleteOperation);
                Console.WriteLine("Entity deleted");
            }
            else
            {
                Console.WriteLine("Entity not found");
            }

            #endregion

            Console.ReadLine();
        }
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            try
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=[name];AccountKey=[key]");
                CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();
                CloudQueue          queue          = queueClient.GetQueueReference("myqueue");
                CloudTableClient    tableClient    = storageAccount.CreateCloudTableClient();
                CloudTable          table          = tableClient.GetTableReference("mytable");

                // Create the queue if it doesn't already exist
                queue.CreateIfNotExists();

                // Create the table if it doesn't exist.
                table.CreateIfNotExists();

                // TODO: Replace the following with your own logic.
                while (!cancellationToken.IsCancellationRequested)
                {
                    // Get the next message
                    CloudQueueMessage retrievedMessage = queue.GetMessage();

                    if (retrievedMessage != null)
                    {
                        var messages = new StringBuilder("Worker received: " + retrievedMessage.AsString);
                        messages.AppendLine();

                        // read the latest messages from the table
                        TableOperation retrieveOperation = TableOperation.Retrieve <MyMessages>("Partition0", "Row0");

                        // Execute the retrieve operation.
                        TableResult retrievedResult = table.Execute(retrieveOperation);

                        MyMessages myMessages = retrievedResult.Result == null
                                              ? new MyMessages {
                            PartitionKey = "Partition0", RowKey = "Row0", LastUpdated = DateTime.Now
                        }
                                              : (MyMessages)retrievedResult.Result;


                        messages.AppendLine(myMessages.Messages);

                        var filename = RoleEnvironment.IsEmulated
                                     ? @"c:\windows\system32\cmd.exe"
                                     : @"d:\windows\system32\cmd.exe";

                        var processStartInfo = new ProcessStartInfo()
                        {
                            Arguments = "/c echo \"test message from a process on the worker vm\"",
                            FileName  = filename,
                            RedirectStandardOutput = true,
                            UseShellExecute        = false
                        };

                        var process = Process.Start(processStartInfo);

                        using (var streamReader = new StreamReader(process.StandardOutput.BaseStream))
                        {
                            messages.AppendLine(streamReader.ReadToEnd() + " at " + DateTime.Now.ToString() + " on " + RoleEnvironment.CurrentRoleInstance);
                        }

                        // replace the messages
                        myMessages.Messages    = messages.ToString();
                        myMessages.LastUpdated = DateTime.Now;

                        // Create the Replace TableOperation.
                        TableOperation replaceOperation = TableOperation.InsertOrReplace(myMessages);

                        // Execute the operation.
                        var result = table.Execute(replaceOperation);

                        //Process the message in less than 30 seconds, and then delete the message
                        queue.DeleteMessage(retrievedMessage);


                        Trace.TraceInformation("Updated myMessage");
                    }

                    Trace.TraceInformation("Working");
                    await Task.Delay(1000);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Worker failed with " + ex.Message);
            }
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            CloudStorageAccount storedAccount = CloudStorageAccount.Parse
                                                    (CloudConfigurationManager.GetSetting("DefaultEndpointsProtocol=https;AccountName=simplilearnstg5aa;AccountKey=U4NJL7RMnHZSN/UO6C3ExGbnZsSIQmFO0wO2dFDOtp/hlBsMlfaWfctIGBDUYAGm+2z1keO5mKuRz04Rsu2FFQ==;EndpointSuffix=core.windows.net"));
            CloudTableClient tableClient = storedAccount.CreateCloudTableClient();
            CloudTable       table       = tableClient.GetTableReference("customers");

            table.CreateIfNotExists();
            Console.WriteLine("Table customers is ready!");

            //Insert
            //CustomerEntity customer1 = new CustomerEntity("AP", "A01");
            //customer1.LastName = "Mark";
            //customer1.FirstName = "wines";
            //customer1.Email = "*****@*****.**";
            //customer1.PhoneNumber = "9100945142";


            //TableOperation insertOperation =  TableOperation.Insert(customer1);
            //table.Execute(insertOperation);
            //Console.WriteLine("Row Added!");

            //TableBatchOperation batchOperation = new TableBatchOperation();
            //CustomerEntity customer1 = new CustomerEntity("MH", "A01");
            //customer1.LastName = "Mark";
            //customer1.FirstName = "wines";
            //customer1.Email = "*****@*****.**";
            //customer1.PhoneNumber = "9100945142";

            //CustomerEntity customer2 = new CustomerEntity("MH", "A02");
            //customer2.LastName = "Mark";
            //customer2.FirstName = "wines";
            //customer2.Email = "*****@*****.**";
            //customer2.PhoneNumber = "9100945142";


            //CustomerEntity customer3 = new CustomerEntity("MH", "A03");
            //customer3.LastName = "Mark";
            //customer3.FirstName = "wines";
            //customer3.Email = "*****@*****.**";
            //customer3.PhoneNumber = "9100945142";

            //CustomerEntity customer4 = new CustomerEntity("MH", "A04");
            //customer4.LastName = "Mark";
            //customer4.FirstName = "wines";
            //customer4.Email = "*****@*****.**";
            //customer4.PhoneNumber = "9100945142";


            //batchOperation.Insert(customer1);
            //batchOperation.Insert(customer2);
            //batchOperation.Insert(customer3);
            //batchOperation.Insert(customer4);

            //table.ExecuteBatch(batchOperation);

            TableQuery <CustomerEntity> query = new TableQuery <CustomerEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "MH"));

            foreach (var item in table.ExecuteQuery(query))
            {
                Console.WriteLine($"{ item.FirstName }{item.LastName}{item.PhoneNumber}");
            }
            Console.WriteLine("Completed");
            Console.ReadLine();
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            // Parse the connection string and return a reference to the storage account.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Create the table client.
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            // Retrieve a reference to the table.
            CloudTable table = tableClient.GetTableReference("people");

            // Create the table if it doesn't exist.
            table.CreateIfNotExists();


            // Create a new customer entity.
            CustomerEntity customer1 = new CustomerEntity("Harp", "Walter");

            customer1.Email       = "*****@*****.**";
            customer1.PhoneNumber = "01283 628459";

            // Create the TableOperation object that inserts the customer entity.
            TableOperation insertOperation = TableOperation.Insert(customer1);

            // Execute the insert operation.
            table.Execute(insertOperation);
            Console.WriteLine("Inserted one entity");
            Console.ReadLine();

            // Create the batch operation.
            TableBatchOperation batchOperation = new TableBatchOperation();

            // Create a customer entity and add it to the table.
            CustomerEntity customer2 = new CustomerEntity("Smith", "Jeff");

            customer2.Email       = "*****@*****.**";
            customer2.PhoneNumber = "425-555-0104";

            // Create another customer entity and add it to the table.
            CustomerEntity customer3 = new CustomerEntity("Smith", "Ben");

            customer3.Email = "*****@*****.**";

            // Add both customer entities to the batch insert operation.
            batchOperation.Insert(customer2);
            batchOperation.Insert(customer3);

            // Execute the batch operation.
            table.ExecuteBatch(batchOperation);
            Console.WriteLine("Inserted multiple entities with the batch operation");
            Console.ReadLine();



            Console.WriteLine("Starting query of Smith ...");
            //Query the partition
            // Construct the query operation for all customer entities where PartitionKey="Smith".
            TableQuery <CustomerEntity> query = new TableQuery <CustomerEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Smith"));

            // Print the fields for each customer.
            foreach (CustomerEntity entity in table.ExecuteQuery(query))
            {
                Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey,
                                  entity.Email, entity.PhoneNumber);
            }
            Console.ReadLine();


            //Update an object
            // Create a retrieve operation that takes a customer entity.
            TableOperation retrieveOperation = TableOperation.Retrieve <CustomerEntity>("Smith", "Jeff");

            // Execute the operation.
            TableResult retrievedResult = table.Execute(retrieveOperation);

            // Assign the result to a CustomerEntity object.
            CustomerEntity updateEntity = (CustomerEntity)retrievedResult.Result;

            if (updateEntity != null)
            {
                // Change the phone number.
                updateEntity.PhoneNumber = "01332 167832";

                // Create the Replace TableOperation.
                TableOperation updateOperation = TableOperation.Replace(updateEntity);

                // Execute the operation.
                table.Execute(updateOperation);

                Console.WriteLine("Entity updated.");
                Console.ReadLine();
            }

            else
            {
                Console.WriteLine("Entity could not be retrieved.");
            }
            Console.ReadLine();
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            string connectionString = "";

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            CloudTable table = tableClient.GetTableReference("Empleados");

            table.CreateIfNotExists();

            Console.Write("Cual es tu nombre? ");
            string nombre = Console.ReadLine();

            Console.WriteLine("");
            Console.Write("Cual es tu apellido paterno? ");
            string apaterno = Console.ReadLine();

            Console.WriteLine("");
            Console.Write("Cual es tu apellido materno? ");
            string amaterno = Console.ReadLine();

            Console.WriteLine("");
            Console.Write("Cual es tu correo? ");
            string correo = Console.ReadLine();

            Console.WriteLine("");
            Console.Write("Donde vives? ");
            string localidad = Console.ReadLine();

            //added this line
            //CreaMensaje(table, new Empleado(nombre, apaterno, correo, localidad.ToUpper()));

            CreaMensaje(table,
                        new Empleado
            {
                Nombre       = nombre,
                Apaterno     = apaterno,
                Amaterno     = amaterno,
                RowKey       = correo,
                PartitionKey = localidad.ToUpper()
            });
            //added this line

            Console.WriteLine("Entidad creada");

            //Table service returns a maximum of 1000 entities in a single call to it.
            //If there're more than 1000 entities available in your table, it returns a continuation token which can be used to fetch next set of entities

            TableContinuationToken token = null;
            var entities = new List <Empleado>();

            do
            {
                var queryResult = table.ExecuteQuerySegmented(new TableQuery <Empleado>(), token);
                entities.AddRange(queryResult.Results);
                token = queryResult.ContinuationToken;
            } while (token != null);


            foreach (var item in entities)
            {
                Console.WriteLine(item.Nombre);
            }


            Console.ReadKey();
        }
Exemplo n.º 26
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var message = await result;

            try
            {
                EventEntity oneEventEntity = new EventEntity();
                bool        foundEvent     = false;
                int         option         = Convert.ToInt32(message.Text);

                string oneEvent;
                //Check the option selected exists for the event
                if (eventDict.TryGetValue(option, out oneEvent))
                {
                    cacheOption    = option;
                    oneEventEntity = JsonConvert.DeserializeObject <EventEntity>(oneEvent);
                    foundEvent     = true;
                }
                else //Option is not selected / cannot be found
                {
                    //however if dialog is run for second times, then it uses the cache option to gather event details
                    if (eventDict.TryGetValue(cacheOption, out oneEvent))
                    {
                        oneEventEntity = JsonConvert.DeserializeObject <EventEntity>(oneEvent);
                        foundEvent     = true;
                    }

                    // Got an Action Submit (Dialog run for second time; action taken for adaptative card buttons)
                    dynamic value      = message.Value;
                    string  submitType = value.Type.ToString();
                    switch (submitType)
                    {
                    case "SaveEditSurvey":
                        SaveEditSurvey(context, message.Value, oneEventEntity);

                        await context.PostAsync("Your event's survey has been successfully saved!");

                        context.Done(this);
                        return;

                    case "DeleteEvent":
                        await DeleteEventCardAsync(context);

                        return;

                    case "YesDeleteEvent":
                        var        storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureWebJobsStorage"]);
                        var        tableClient    = storageAccount.CreateCloudTableClient();
                        CloudTable cloudTable     = tableClient.GetTableReference("Event");
                        cloudTable.CreateIfNotExists();
                        cloudTable.Execute(TableOperation.Delete(oneEventEntity));

                        await context.PostAsync("Your event has been successfully deleted!");

                        context.Done(this);
                        return;

                    case "NoDeleteEvent":
                        await context.PostAsync("Okayy, talk to me again if you need assistance!");

                        context.Done(this);
                        return;
                    }
                    await context.PostAsync("Your option is out of range!  Please enter again or type \"exit\" to exit the conversation.");
                }

                //Event found
                if (foundEvent)
                {
                    var eventDetail = "";
                    eventDetail += "Event Name: " + oneEventEntity.EventName + "\n\n";
                    eventDetail += "Event Date: " + oneEventEntity.EventStartDate + "\n\n";
                    eventDetail += "Attendance Code 1: " + oneEventEntity.AttendanceCode1 + "\n\n";
                    eventDetail += "Attendance Code 2: " + oneEventEntity.AttendanceCode2 + "\n\n";
                    eventDetail += "Survey Code: " + oneEventEntity.RowKey + "\n\n";

                    //Adaptive Card starts from here
                    await ShowEventCardAsync(context, eventDetail, oneEventEntity);
                }
            }
            catch (Exception)
            {
                await context.PostAsync("It seems like your option is not an number. Please enter again or type \"exit\" to exit the conversation.");
            }
        }
Exemplo n.º 27
0
        public override void Run()
        {
            while (true)
            {
                Thread.Sleep(500);
                Trace.TraceInformation("Working");

                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                    ConfigurationManager.AppSettings["StorageConnectionString"]);
                CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
                CloudQueue       queue       = queueClient.GetQueueReference("urls");
                queue.CreateIfNotExists();
                CloudQueue rootQueue = queueClient.GetQueueReference("rooturls");
                rootQueue.CreateIfNotExists();
                CloudQueue commandQueue = queueClient.GetQueueReference("commands");
                commandQueue.CreateIfNotExists();
                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
                CloudTable       table       = tableClient.GetTableReference("results");
                table.CreateIfNotExists();
                CloudTable outputTable = tableClient.GetTableReference("output");
                outputTable.CreateIfNotExists();
                CloudQueueMessage currentUrl = queue.GetMessage();
                CloudQueueMessage command    = commandQueue.GetMessage();
                CloudQueueMessage baseSite   = rootQueue.GetMessage();
                if (command != null)
                {
                    if (command.AsString == "update")
                    {
                        OutputEntity   update   = new OutputEntity(status, urlCrawled, queueCount, tableCount, lastTen);
                        TableOperation insertOp = TableOperation.InsertOrMerge(update);
                        outputTable.Execute(insertOp);
                    }

                    else if (command.AsString == "stop")
                    {
                        queue.Clear();
                        rootQueue.Clear();
                        commandQueue.Clear();
                        table.Delete();
                        visitedLinks.Clear();
                        disallowList.Clear();
                        siteMaps.Clear();
                        lastTen.Clear();
                        queueCount = 0;
                        tableCount = 0;
                        urlCrawled = 0;
                        currentUrl = null;
                        baseSite   = null;
                    }
                }

                if (baseSite != null)
                {
                    if (baseSite.AsString.EndsWith("robots.txt"))
                    {
                        string       rootUrl      = baseSite.AsString;
                        WebRequest   getDomain    = WebRequest.Create(rootUrl);
                        Stream       domainStream = getDomain.GetResponse().GetResponseStream();
                        StreamReader robots       = new StreamReader(domainStream);
                        String       line;
                        while ((line = robots.ReadLine()) != null)
                        {
                            if (line.StartsWith("Disallow:"))
                            {
                                disallowList.Add(line.Replace("Disallow: ", ""));
                            }
                            else if (line.StartsWith("Sitemap:"))
                            {
                                siteMaps.Add(line.Replace("Sitemap: ", ""));
                            }
                        }
                        foreach (string map in siteMaps)
                        {
                            WebRequest   crawlMap   = WebRequest.Create(map);
                            Stream       urlStream  = crawlMap.GetResponse().GetResponseStream();
                            StreamReader readUrl    = new StreamReader(urlStream);
                            XmlDocument  urlContent = new XmlDocument();
                            urlContent.Load(readUrl);
                            XmlNodeList nodes = urlContent.DocumentElement.ChildNodes;
                            foreach (XmlNode node in nodes)
                            {
                                Boolean valid = true;
                                if (node.Name == "sitemap")
                                {
                                    foreach (XmlNode item in node.ChildNodes)
                                    {
                                        if (item.Name == "loc")
                                        {
                                            foreach (string rule in disallowList)
                                            {
                                                if (node.Name.Contains(rule))
                                                {
                                                    valid = false;
                                                    break;
                                                }
                                            }
                                            if (valid != false)
                                            {
                                                string   itemDate = item.NextSibling.InnerText;
                                                DateTime date     = XmlConvert.ToDateTime(itemDate);
                                                if (DateTime.Now.Date <= date.AddMonths(3))
                                                {
                                                    CloudQueueMessage message = new CloudQueueMessage(item.InnerText.Trim());
                                                    queue.AddMessage(message);
                                                    queueCount++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    rootQueue.DeleteMessage(baseSite);
                }
                else if (currentUrl != null)
                {
                    if (currentUrl.AsString.EndsWith(".xml"))
                    {
                        WebRequest   crawlXml   = WebRequest.Create(currentUrl.AsString);
                        Stream       urlStream  = crawlXml.GetResponse().GetResponseStream();
                        StreamReader readUrl    = new StreamReader(urlStream);
                        XmlDocument  urlContent = new XmlDocument();
                        urlContent.Load(readUrl);
                        XmlNodeList nodes = urlContent.DocumentElement.ChildNodes;
                        foreach (XmlNode node in nodes)
                        {
                            Boolean valid = true;
                            if (node.Name == "url")
                            {
                                foreach (XmlNode item in node.ChildNodes)
                                {
                                    if (item.Name == "loc")
                                    {
                                        foreach (string rule in disallowList)
                                        {
                                            if (node.Name.Contains(rule))
                                            {
                                                valid = false;
                                                break;
                                            }
                                        }
                                        if (valid != false)
                                        {
                                            if (item.NextSibling.Name.Equals("lastmod"))
                                            {
                                                string itemDate = item.NextSibling.InnerText;

                                                CloudQueueMessage message = new CloudQueueMessage(item.InnerText);
                                                queue.AddMessage(message);
                                                queueCount++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!visitedLinks.Contains(currentUrl.AsString))
                        {
                            HttpWebRequest htmlPage = (HttpWebRequest)HttpWebRequest.Create(currentUrl.AsString);
                            Stream         html     = htmlPage.GetResponse().GetResponseStream();
                            StreamReader   getHtml  = new StreamReader(html);
                            urlCrawled++;
                            string data = "";
                            string line;
                            while ((line = getHtml.ReadLine()) != null)
                            {
                                data += line;
                            }
                            HtmlDocument page = new HtmlDocument();
                            page.LoadHtml(data);
                            HtmlNodeCollection links    = page.DocumentNode.SelectNodes("//a[@href]");
                            List <String>      newLinks = new List <String>();
                            if (links != null)
                            {
                                foreach (HtmlNode link in links)
                                {
                                    string item = link.GetAttributeValue("href", "");
                                    if (item.StartsWith("http://www.cnn.com") || (item.StartsWith("http://www.sportsillustrated.cnn.com") && item.Contains("/basketball/nba")))
                                    {
                                        newLinks.Add(item);
                                    }
                                }
                                bool valid = true;
                                foreach (string potential in newLinks)
                                {
                                    foreach (string rule in disallowList)
                                    {
                                        if (potential.Contains(rule))
                                        {
                                            valid = false;
                                            break;
                                        }
                                    }
                                    if (valid == true && !potential.Contains("disqus_thread"))
                                    {
                                        CloudQueueMessage toCrawl = new CloudQueueMessage(potential);
                                        queue.AddMessage(toCrawl);
                                        queueCount++;
                                    }
                                    valid = true;
                                }
                            }
                            string   title      = page.DocumentNode.SelectSingleNode("//head/title").InnerText;
                            Regex    r          = new Regex("[^a-zA-Z.-]");
                            string   tempUrl    = currentUrl.AsString;
                            string[] titleWords = title.Split(' ');
                            foreach (string word in titleWords)
                            {
                                string      cleanWord  = r.Replace(word, "");
                                CrawlEntity addToTable = new CrawlEntity(cleanWord.ToLower(), title, tempUrl);
                                if (addToTable.Title.Length > 0)
                                {
                                    TableOperation insert = TableOperation.InsertOrReplace(addToTable);
                                    table.Execute(insert);
                                    tableCount++;
                                    lastTen.Add(currentUrl.AsString);
                                    if (lastTen.Count > 0)
                                    {
                                        lastTen.RemoveAt(0);
                                    }
                                }
                                visitedLinks.Add(currentUrl.AsString);
                            }
                        }
                    }
                    queue.DeleteMessage(currentUrl);
                    queueCount--;
                }
            }
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            //#region Insert
            //Console.Write("Digite o nome do aluno");
            //string nome = Console.ReadLine();

            //Console.Write("Digite o nome do email");
            //string email = Console.ReadLine();

            //Console.Write("Digite o nome do celular");
            //string celular = Console.ReadLine();

            //Console.Write("Digite o curso");
            //string curso = Console.ReadLine();

            //Console.Write("Digite o nome do RM");
            //string rm = Console.ReadLine();

            //Aluno aluno = new Aluno("Alunos", rm)
            //{
            //    Celular = celular,
            //    Nome = nome,
            //    Email = email,
            //    Curso = curso
            //};

            //CloudStorageAccount account = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=fiap11net2;AccountKey=yXW/qtVwDvzSPX3hwiZ7pdhe1RYg5TsT8GBmsWXG8eXmEuplRnLrLEsPTE6BaNfgVYoOq7uFELouYFuI9wpzKQ==;EndpointSuffix=core.windows.net");

            //CloudTableClient table = account.CreateCloudTableClient();
            //CloudTable tbAlunos = table.GetTableReference("AlunosFIAP");
            //tbAlunos.CreateIfNotExists();

            //TableOperation operation = TableOperation.Insert(aluno);
            //tbAlunos.Execute(operation);

            //Console.WriteLine("fim");
            //Console.Read();
            //#endregion

            #region Select
            //CloudStorageAccount account = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=fiap11net2;AccountKey=yXW/qtVwDvzSPX3hwiZ7pdhe1RYg5TsT8GBmsWXG8eXmEuplRnLrLEsPTE6BaNfgVYoOq7uFELouYFuI9wpzKQ==;EndpointSuffix=core.windows.net");

            //CloudTableClient table = account.CreateCloudTableClient();
            //CloudTable tbAlunos = table.GetTableReference("AlunosFIAP");
            //tbAlunos.CreateIfNotExists();

            //TableQuery<Aluno> query = new TableQuery<Aluno>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "alunos"));

            //List<Aluno> result = tbAlunos.ExecuteQuery(query).ToList();

            /////TableOperation.Retrieve<Aluno>("alunos", "RM31948");
            ////TableResult result = tbAlunos.Execute(retrieve);

            ////List<Aluno> aluno = result.Result as List<Aluno>;

            //foreach (var item in result)
            //{
            //    Console.WriteLine($"Nome: {item.Nome}");
            //    Console.WriteLine($"Celular: {item.Celular}");
            //    Console.WriteLine($"Email: {item.Email}");
            //}


            //Console.WriteLine("fim");
            //Console.Read();
            #endregion

            #region Delete
            CloudStorageAccount account = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=fiap11net2;AccountKey=yXW/qtVwDvzSPX3hwiZ7pdhe1RYg5TsT8GBmsWXG8eXmEuplRnLrLEsPTE6BaNfgVYoOq7uFELouYFuI9wpzKQ==;EndpointSuffix=core.windows.net");

            CloudTableClient table    = account.CreateCloudTableClient();
            CloudTable       tbAlunos = table.GetTableReference("AlunosFIAP");
            tbAlunos.CreateIfNotExists();

            var         operation = TableOperation.Retrieve <Aluno>("alunos", "teste");
            TableResult result    = tbAlunos.Execute(operation);

            Aluno alunoExcluir = result.Result as Aluno;

            TableOperation delete = TableOperation.Delete(alunoExcluir);

            tbAlunos.Execute(delete);

            #endregion
        }
Exemplo n.º 29
0
 /// <summary>
 /// Cloud a azure storage table if not exists.
 /// </summary>
 /// <param name="table">Cloud table object</param>
 /// <param name="requestOptions">Table request options</param>
 /// <param name="operationContext">Operation context</param>
 /// <returns>True if table was created; otherwise, false.</returns>
 public bool CreateTableIfNotExists(CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext)
 {
     return(table.CreateIfNotExists(requestOptions, operationContext));
 }
Exemplo n.º 30
0
        private async Task RegisterUser(IDialogContext context, IAwaitable <object> result)
        {
            var activity = await result as Activity;
            var cS       = CloudConfigurationManager.GetSetting("StorageConnectionString");
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(cS);
            CloudTableClient    tableClient    = storageAccount.CreateCloudTableClient();
            CloudTable          table          = tableClient.GetTableReference("usertable");

            table.CreateIfNotExists();
            var            user = new Users(activity.From.Id, activity.From.Name, activity.ChannelId);
            TableOperation retrieveOperation = TableOperation.Retrieve <Users>(activity.ChannelId.ToLower(), activity.From.Id.ToLower());
            TableResult    retrievedResult   = table.Execute(retrieveOperation);

            if (activity.Text == "1")
            {
                try
                {
                    if (retrievedResult.Result == null)
                    {
                        TableOperation insertOperation = TableOperation.Insert(user);

                        table.Execute(insertOperation);

                        await context.PostAsync($"Hello, Nice to meet you. I have registered you to our lunch menu program, you will receive notification at 1 PM daily on working days to choose from menu. Please press 2 to unregister from the application.");
                    }
                    else
                    {
                        await context.PostAsync("you have alreaddy been registered to launch bot" + activity.Recipient.Id + activity.Recipient.Name);
                    }
                }
                catch (Exception ex)
                {
                    await context.PostAsync(ex.Message);
                }
                context.Wait(MessageReceivedAsync);
            }
            else if (activity.Text == "2")
            {
                try
                {
                    if (retrievedResult.Result != null)
                    {
                        Users          deleteEntity    = (Users)retrievedResult.Result;
                        TableOperation deleteOperation = TableOperation.Delete(deleteEntity);

                        // Execute the operation.
                        table.Execute(deleteOperation);

                        await context.PostAsync($"You have sucessfully unregistered from lunch bot.");
                    }
                    else
                    {
                        await context.PostAsync("you have not been registered to launch bot. Please register first.");
                    }
                }
                catch (Exception ex)
                {
                    await context.PostAsync(ex.Message);
                }
                context.Wait(MessageReceivedAsync);
            }
            else
            {
                context.Wait(MessageReceivedAsync);
            }
        }
 public void MyTestInitialize()
 {
     CloudTableClient tableClient = GenerateCloudTableClient();
     currentTable = tableClient.GetTableReference(GenerateRandomTableName());
     currentTable.CreateIfNotExists();
 }
Exemplo n.º 32
0
        static void Main(string[] args)
        {
            //Customers customer1 = new Customers("Ivan", "Stepanov");
            //customer1.Email = "*****@*****.**";

            //Customers customer2 = new Customers("Petro", "Stepanov");
            //customer2.Email = "*****@*****.**";



            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnections"));

            CloudTableClient client = storageAccount.CreateCloudTableClient();

            CloudTable table = client.GetTableReference("tereshchenko");

            table.CreateIfNotExists();

            TableBatchOperation batch = new TableBatchOperation();

            //batch.Insert(customer1);
            //batch.Insert(customer2);

            //table.ExecuteBatch(batch);


            //SELECT

            TableQuery <Customers> query = new TableQuery <Customers>().Where(
                //query builder
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Melnik")

                );



            TableQuery <Customers> queryOR = new TableQuery <Customers>().Where(
                CombineFilterOR(TableQuery.GenerateFilterCondition("PartionKey", QueryComparisons.Equal, "Melnik"), TableQuery.GenerateFilterCondition("PartionKey", QueryComparisons.Equal, "Stepanov"))
                );

            var xxx = table.ExecuteQuery(queryOR);

            foreach (Customers customer in table.ExecuteQuery(queryOR))
            {
                Console.WriteLine(customer.PartitionKey);
                Console.WriteLine(customer.RowKey);
                Console.WriteLine(customer.Email);
                Console.WriteLine("----------------------------");
            }


            //get 1 Entity
            TableOperation getOneOperation = TableOperation.Retrieve <Customers>("Melnik", "Ivan");
            TableResult    result          = table.Execute(getOneOperation);

            if (result != null)
            {
                Customers cr = (Customers)(result).Result;
                Console.WriteLine("---------Retrieve-------------");
                Console.WriteLine($"{cr.PartitionKey} {cr.RowKey} {cr.Email} {cr.Timestamp}");

                //UPDATE

                cr.Email = "UPDATED EMAIL";
                TableOperation updateOper = TableOperation.InsertOrReplace(cr);
                table.Execute(updateOper);

                TableOperation daleteOper = TableOperation.Delete(cr);
                table.Execute(daleteOper);
            }

            foreach (Customers customer in table.ExecuteQuery(query))
            {
                Console.WriteLine(customer.PartitionKey);
                Console.WriteLine(customer.RowKey);
                Console.WriteLine(customer.Email);
                Console.WriteLine("----------------------------");
            }

            Console.ReadLine();
        }