public void Download_Test()
            {
                //Arrange
                //load the user
                UserBean user = _bundledocsApi.Users.Me();

                //find a brief to load
                Brief parentBrief = user.Briefs.Where(k => k.PartitionKey == user.RowKey).FirstOrDefault();

                //load the brief
                BriefBean loadedBrief = _bundledocsApi.Bundles.Get(parentBrief.PartitionKey, parentBrief.RowKey);

                //load the brief documents
                BriefDocument documentToDownload = _bundledocsApi.Bundles.Tree(loadedBrief.PartitionKey, loadedBrief.RowKey).Where(k => k.Type == "HEADER").FirstOrDefault().Children.Where(k => k.Type == "DOCUMENT").FirstOrDefault();

                //Act
                //download the document
                Stream myStream = _bundledocsApi.Documents.Download(documentToDownload.PartitionKey, documentToDownload.RowKey);

                //write the downloaded bundle to disk
                byte[] myFile      = myStream.ReadToEnd();
                string newFilePath = $@"{App.Default.TempFolder}{Guid.NewGuid().ToString("n")}.pdf";

                File.WriteAllBytes(newFilePath, myFile);

                //Assert
                Assert.IsTrue(File.Exists(newFilePath));

                //open the downloaded bundle
                Process.Start(newFilePath);
            }
Ejemplo n.º 2
0
        private void Save(Brief entity)
        {
            entity.Name        = Name;
            entity.SortId      = SortId;
            entity.Status      = Status;
            entity.PostDate    = PostDate;
            entity.Content     = Content;
            entity.AFile1      = AFile1;
            entity.AFile1Name  = AFile1Name;
            entity.IsUrl       = IsUrl;
            entity.AUrl        = AUrl;
            entity.AYear       = AYear;
            entity.MainCode    = MainCode;
            entity.MainName    = MainName;
            entity.AdminCode   = AdminCode;
            entity.AdminName   = AdminName;
            entity.ServiceCode = ServiceCode;
            entity.ServiceName = ServiceName;

            if (entity.BriefId == 0)
            {
                m_FTISService.CreateBrief(entity);
            }
            else
            {
                m_FTISService.UpdateBrief(entity);
            }

            LoadEntity(entity.BriefId);
        }
            public void Create_Test()
            {
                //Arrange
                bool expected = true;
                bool actual   = false;

                //load the user
                UserBean user = _bundledocsApi.Users.Me();

                //find a brief to load
                Brief briefToLoad = user.Briefs.Where(k => k.PartitionKey == user.RowKey).FirstOrDefault();

                //load the brief
                BriefBean loadedBrief = _bundledocsApi.Bundles.Get(briefToLoad.PartitionKey, briefToLoad.RowKey);

                //load the brief documents
                IList <BriefDocument> briefDocuments = _bundledocsApi.Bundles.Tree(loadedBrief.PartitionKey, loadedBrief.RowKey);

                //find a section to upload a document into
                BriefDocument uploadLocation = briefDocuments.Where(k => k.Type == "HEADER").FirstOrDefault();

                //Act
                bool isSuccess = _bundledocsApi.Documents.Create(uploadLocation, App.Default.UploadFileLocation);

                //listen to the events back from the server to verify the document is uploaded and processed successfully
                actual = _bundledocsApi.Events.WaitForUploadToComplete(uploadLocation.ForeignKey);

                //Assert
                Assert.AreEqual(expected, actual);
            }
            public void Download_Test()
            {
                //Arrange
                //load the user
                UserBean user = _bundledocsApi.Users.Me();

                //find a brief to load
                Brief parentBrief = user.Briefs.Where(k => k.PartitionKey == user.RowKey).FirstOrDefault();

                //load the brief
                BriefBean loadedBrief = _bundledocsApi.Bundles.Get(parentBrief.PartitionKey, parentBrief.RowKey);

                //load the brief receipts
                IList <BriefReceipt> briefReceipts = _bundledocsApi.Bundles.Receipts(loadedBrief.PartitionKey, loadedBrief.RowKey);

                //load the latest brief receipt
                BriefReceipt briefReceiptToDownload = briefReceipts.FirstOrDefault();

                //download the brief receipt
                Stream briefReceiptStream = _bundledocsApi.Receipts.Download(briefReceiptToDownload.PartitionKey, briefReceiptToDownload.RowKey);

                //write the downloaded stream to disk
                byte[] myFile      = briefReceiptStream.ReadToEnd();
                string newFilePath = $@"{App.Default.TempFolder}{Guid.NewGuid().ToString("n")}.pdf";

                File.WriteAllBytes(newFilePath, myFile);

                //Assert
                Assert.IsTrue(File.Exists(newFilePath));

                //open the downloaded bundle
                Process.Start(newFilePath);
            }
            public void Rename_Test()
            {
                //Arrange
                string expected = Guid.NewGuid().ToString("n");
                string actual   = String.Empty;

                //Arrange
                //load the user
                UserBean user = _bundledocsApi.Users.Me();

                //choose a brief
                Brief brief = user.Briefs.Where(k => k.PartitionKey == user.RowKey).FirstOrDefault();

                //load the brief
                BriefBean loadedBrief = _bundledocsApi.Bundles.Get(brief.PartitionKey, brief.RowKey);

                //load the brief documents
                BriefDocument sectionToRename = _bundledocsApi.Bundles.Tree(loadedBrief.PartitionKey, loadedBrief.RowKey).Where(k => k.Type == "HEADER").FirstOrDefault();

                //Act
                //rename the section
                BriefDocument renamedSection = _bundledocsApi.Sections.Rename(sectionToRename.PartitionKey, sectionToRename.RowKey, expected);

                actual = renamedSection.Description;

                //Assert
                Assert.AreEqual(expected, actual);
            }
            public void Download_Test()
            {
                //Arange
                //load the user
                UserBean user = _bundledocsApi.Users.Me();

                //find a brief to load
                Brief briefToLoad = user.Briefs.Where(k => k.PartitionKey == user.RowKey).FirstOrDefault();

                //load the brief
                BriefBean loadedBrief = _bundledocsApi.Bundles.Get(briefToLoad.PartitionKey, briefToLoad.RowKey);

                //Act
                //Download the bundle
                Stream myStream = _bundledocsApi.Bundles.Download(loadedBrief.PartitionKey, loadedBrief.RowKey);

                //write the downloaded bundle to disk
                byte[] myFile      = myStream.ReadToEnd();
                string newFilePath = $@"{App.Default.TempFolder}{Guid.NewGuid().ToString("n")}.pdf";

                File.WriteAllBytes(newFilePath, myFile);

                //Assert
                Assert.IsTrue(File.Exists(newFilePath));

                //open the downloaded bundle
                Process.Start(newFilePath);
            }
            public void Rename_Test()
            {
                //Arrange
                string expected = Guid.NewGuid().ToString("n");

                //Arrange
                //load the user
                UserBean user = _bundledocsApi.Users.Me();

                //choose a brief
                Brief brief = user.Briefs.Where(k => k.PartitionKey == user.RowKey).FirstOrDefault();

                //load the brief
                BriefBean loadedBrief = _bundledocsApi.Bundles.Get(brief.PartitionKey, brief.RowKey);

                //load the brief documents
                BriefDocument documentToRename = _bundledocsApi.Bundles.Tree(loadedBrief.PartitionKey, loadedBrief.RowKey).Where(k => k.Type == "HEADER").FirstOrDefault().Children.Where(k => k.Type == "DOCUMENT").FirstOrDefault();

                //Act
                //rename the section
                BriefDocument renamedDocument = _bundledocsApi.Documents.Rename(documentToRename.PartitionKey, documentToRename.RowKey, expected);

                //Assert
                Assert.AreEqual(expected, renamedDocument.Description);
            }
Ejemplo n.º 8
0
 public static async Task UpdateBrief(this AppDbContext db, Brief brief)
 {
     if (await brief.Validate(db))
     {
         db.Briefs.Update(brief);
         await db.SaveChangesAsync();
     }
 }
            public void Receipts_Test()
            {
                //Arange
                //load the user
                UserBean user = _bundledocsApi.Users.Me();

                //find a brief to load
                Brief briefToLoad = user.Briefs.Where(k => k.PartitionKey == user.RowKey).FirstOrDefault();

                //load the brief
                BriefBean loadedBrief = _bundledocsApi.Bundles.Get(briefToLoad.PartitionKey, briefToLoad.RowKey);

                //Act
                //load the brief receipts
                List <BriefReceipt> briefReceipts = _bundledocsApi.Bundles.Receipts(loadedBrief.PartitionKey, loadedBrief.RowKey);

                //Assert
                Assert.IsTrue(briefReceipts.Count >= 0);
            }
Ejemplo n.º 10
0
        public static async Task <bool> Validate(this Brief brief, AppDbContext db)
        {
            if (string.IsNullOrEmpty(brief.Name))
            {
                throw new AppException("A brief must have a name", ExceptionType.Validation);
            }

            var check = await db.Briefs
                        .FirstOrDefaultAsync(x =>
                                             x.Id != brief.Id &&
                                             x.Name.ToLower() == brief.Name.ToLower()
                                             );

            if (check != null)
            {
                throw new AppException("The provided brief already exists", ExceptionType.Validation);
            }

            return(true);
        }
Ejemplo n.º 11
0
        public ActionResult SetSort(string entityId, string sortValue)
        {
            AjaxResult    result = new AjaxResult(AjaxResultStatus.Success, string.Empty);
            StringBuilder sbMsg  = new StringBuilder();

            try
            {
                Brief entity = m_FTISService.GetBriefById(Convert.ToInt32(entityId));
                entity.SortId = int.Parse(sortValue);
                m_FTISService.UpdateBrief(entity);
            }
            catch (Exception ex)
            {
                result.ErrorCode = AjaxResultStatus.Fail;
                sbMsg.AppendFormat(ex.Message + "<br/>");
            }

            result.Message = sbMsg.ToString();
            return(this.Json(result));
        }
Ejemplo n.º 12
0
        public ActionResult Delete(int id)
        {
            AjaxResult result = new AjaxResult();

            try
            {
                Brief entity = m_FTISService.GetBriefById(id);

                m_FTISService.DeleteBrief(entity);

                result.ErrorCode = AjaxResultStatus.Success;
                result.Message   = string.Format("{0}刪除成功", entity.Name);
            }
            catch (Exception ex)
            {
                result.ErrorCode = AjaxResultStatus.Exception;
                result.Message   = ex.Message;
            }

            return(this.Json(result));
        }
            public void Generate_Test()
            {
                //Arrange
                //load the user
                UserBean user = _bundledocsApi.Users.Me();

                //find a brief to load
                Brief briefToLoad = user.Briefs.Where(k => k.PartitionKey == user.RowKey && !String.IsNullOrEmpty(k.PdfFilePath)).FirstOrDefault();

                //load the brief
                BriefBean loadedBrief = _bundledocsApi.Bundles.Get(briefToLoad.PartitionKey, briefToLoad.RowKey);

                //Act
                //generate the bundle
                OAuthApiMessage generateMessage = _bundledocsApi.Bundles.Generate(loadedBrief.PartitionKey, loadedBrief.RowKey, loadedBrief);

                //listen to the events back from the server to verify the brief is processed and generated successfully
                bool generateComplete = _bundledocsApi.Events.WaitForGenerateToComplete(briefToLoad.RowKey);

                //Assert
                Assert.IsTrue(generateComplete);
            }
            public void Delete_Test()
            {
                //Arrange
                //load the user
                UserBean user = _bundledocsApi.Users.Me();

                //choose a brief
                Brief brief = user.Briefs.Where(k => k.PartitionKey == user.RowKey).FirstOrDefault();

                //load the brief
                BriefBean loadedBrief = _bundledocsApi.Bundles.Get(brief.PartitionKey, brief.RowKey);

                //load the brief documents
                BriefDocument documentToDelete = _bundledocsApi.Bundles.Tree(loadedBrief.PartitionKey, loadedBrief.RowKey).Where(k => k.Type == "HEADER").FirstOrDefault().Children.Where(k => k.Type == "DOCUMENT").FirstOrDefault();

                //Act
                //delete the document
                BriefDocument deletedDocument = _bundledocsApi.Documents.Delete(documentToDelete.PartitionKey, documentToDelete.RowKey);

                //Assert
                Assert.AreEqual(documentToDelete.RowKey, deletedDocument.RowKey);
            }
Ejemplo n.º 15
0
 protected void LoadEntity(Brief entity)
 {
     if (entity != null)
     {
         EntityId    = entity.BriefId;
         Name        = entity.Name;
         SortId      = entity.SortId;
         Status      = entity.Status;
         PostDate    = entity.PostDate;
         Content     = entity.Content;
         AFile1      = entity.AFile1;
         AFile1Name  = entity.AFile1Name;
         IsUrl       = entity.IsUrl;
         AUrl        = entity.AUrl;
         AYear       = entity.AYear;
         MainCode    = entity.MainCode;
         MainName    = entity.MainName;
         AdminCode   = entity.AdminCode;
         AdminName   = entity.AdminName;
         ServiceCode = entity.ServiceCode;
         ServiceName = entity.ServiceName;
     }
 }
            public void Create_Test()
            {
                //Arrange
                string expected = Guid.NewGuid().ToString("n");
                string actual   = String.Empty;

                //load the user
                UserBean user = _bundledocsApi.Users.Me();

                //choose a brief
                Brief brief = user.Briefs.Where(k => k.PartitionKey == user.RowKey).FirstOrDefault();

                //load the brief
                BriefBean loadedBrief = _bundledocsApi.Bundles.Get(brief.PartitionKey, brief.RowKey);

                //Act
                BriefDocument newSection = _bundledocsApi.Sections.Create(loadedBrief.PartitionKey, loadedBrief.RowKey, expected);

                actual = newSection.Description;

                //Assert
                Assert.AreEqual(expected, actual);
            }
Ejemplo n.º 17
0
        public ActionResult MultiDelete(string allId)
        {
            AjaxResult    result = new AjaxResult(AjaxResultStatus.Success, string.Empty);
            StringBuilder sbMsg  = new StringBuilder();

            string[] ids = allId.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string id in ids)
            {
                try
                {
                    Brief entity = m_FTISService.GetBriefById(Convert.ToInt32(id));
                    m_FTISService.DeleteBrief(entity);
                }
                catch (Exception ex)
                {
                    result.ErrorCode = AjaxResultStatus.Fail;
                    sbMsg.AppendFormat(ex.Message + "<br/>");
                }
            }

            result.Message = sbMsg.ToString();
            return(this.Json(result));
        }
Ejemplo n.º 18
0
 public static async Task RemoveBrief(this AppDbContext db, Brief brief)
 {
     db.Briefs.Remove(brief);
     await db.SaveChangesAsync();
 }
Ejemplo n.º 19
0
        public void Update()
        {
            Brief entity = m_FTISService.GetBriefById(EntityId);

            Save(entity);
        }
Ejemplo n.º 20
0
        public void Insert()
        {
            Brief entity = new Brief();

            Save(entity);
        }
Ejemplo n.º 21
0
        protected void LoadEntity(int id)
        {
            Brief entity = m_FTISService.GetBriefById(id);

            LoadEntity(entity);
        }
Ejemplo n.º 22
0
 private static void AddDomainSpecificCommands(Machine machine)
 {
     machine.Context.AddWord10("say", "Speak given string", s => speech.Say(s));
     machine.Context.AddWord20("phrase", "Add phrase to speech recognition grammar; bind to Brief expression (`phrase 'hello [say \"hi there\"]`)", (p, b) => speechCommands.Add(p, b));
     machine.Context.AddWord00("speechreco", "Start speech recognition, after having added `phrase` bindings (`reco`)", () => speech.SetGrammar(Speech.Choices(speechCommands.Select(kv => Speech.Phrase(kv.Key, Brief.Print(kv.Value))).ToArray())));
     machine.Context.AddWord20("window", "Show window in foreground by process name; optionally maximized (`window \"Skype\" true`)", (n, m) => Windows.ShowWindow(n, m));
     machine.Context.AddWord10("key", "Send key to forground app (`key '^{q}`)", k => Windows.SendKey(k));
     machine.Context.AddWord20("config", "Set configuration value (`config 'port 80`)", (k, v) => config[k] = v is IEnumerable <Word>?Brief.Print(v) : v.ToString());
     machine.Context.AddWord00("faces-train", "Create and train faces in Azure Cognitive Services (`faces-train \"myfaces/\")`", () => faces.TrainFaces());
     machine.Context.AddWord10("faces-reco", "Recognize faces in given image file (`faces-reco \"test.jpg\"`)", f => faces.RecoFaces((string)f, true));
     machine.Context.AddWord20("faces-watch", "Begin watching given directory and children for face images [debug mode optional] (`faces-watch \"c:/test\"` true)", (dir, debug) => WatchFaces(dir, debug, machine));
     machine.Context.AddWord10("nav", "Send relay to given place (`nav \"booth\"`)", p => Goto(p, config["relayQueueName"]));
     machine.Context.AddWord10("tour", "Send relay to given places (`tour [\"booth\",\"foo\",\"bar\"]`)", p => Wander(((IEnumerable <Word>)p).Reverse().Select(n => n.ToString()), config["relayQueueName"]));
     machine.Context.AddWord00("stop", "Stop relay by canceling previous task (`stop`)", () => Stop(config["relayQueueId"], false));
     machine.Context.AddWord00("cancel", "Cancel current task (`cancel`)", () => Stop(config["relayQueueId"], true));
 }
Ejemplo n.º 23
0
 public OAuthApiMessage Generate(string partitionKey, string rowKey, Brief generateBriefBean)
 {
     return(_bundles.BundlesGenerateBundle(_authorizationHeader, partitionKey, rowKey, BriefBean.FromBrief(generateBriefBean))?.Messages.FirstOrDefault());
 }
Ejemplo n.º 24
0
 public static BriefBean FromBrief(Brief selectedBundle)
 {
     return(JsonConvert.DeserializeObject <BriefBean>(JsonConvert.SerializeObject(selectedBundle)));
 }
Ejemplo n.º 25
0
 public async Task ToggleBriefDeleted([FromBody] Brief brief) =>
 await db.Authorize(provider, async db => await db.ToggleBriefDeleted(brief));
Ejemplo n.º 26
0
 public async Task RemoveBrief([FromBody] Brief brief) =>
 await db.Authorize(provider, async db => await db.RemoveBrief(brief));
Ejemplo n.º 27
0
 public static async Task ToggleBriefDeleted(this AppDbContext db, Brief brief)
 {
     db.Briefs.Attach(brief);
     brief.IsDeleted = !brief.IsDeleted;
     await db.SaveChangesAsync();
 }