Ejemplo n.º 1
0
        public HttpResponseMessage Put(int id, [FromBody] TextReplace textreplace)
        {
            try
            {
                using (ghostDBEntities entities = new ghostDBEntities())
                {
                    var entity = entities.TextReplaces.FirstOrDefault(e => e.idTextReplace.Equals(id));

                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Artist with id '" + id.ToString() + "' not found."));
                    }
                    else
                    {
                        entity.OldText = textreplace.OldText;
                        entity.NewText = textreplace.NewText;
                        entities.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        public static void Run()
        {
            // ExStart:1
            PdfApi     pdfApi     = new PdfApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);
            StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            String      fileName   = "sample-input.pdf";
            int         pageNumber = 1;
            String      storage    = "";
            String      folder     = "";
            TextReplace body       = new TextReplace();

            body.OldValue = "Sample PDF";
            body.NewValue = "Sample Aspose PDF";

            try
            {
                // Upload source file to aspose cloud storage
                storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName));

                // Invoke Aspose.PDF Cloud SDK API to replace text in a pdf page
                PageTextReplaceResponse apiResponse = pdfApi.PostPageReplaceText(fileName, pageNumber, storage, folder, body);

                if (apiResponse != null && apiResponse.Status.Equals("OK"))
                {
                    Console.WriteLine("Replace Text in a PDF Page, Done!");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
            // ExEnd:1
        }
Ejemplo n.º 3
0
        public string RequestPasswordChange([FromUri] PasswordChange obj)
        {
            //1. create a password change request
            var user = appRepository.ChangePasswordRequest(obj.Email);

            //2. send a request emailmessage
            ITextReplace replace = new TextReplace();

            if (!string.IsNullOrEmpty(user.Name))
            {
                replace.Add("%name%", user.Name);
            }
            else
            {
                replace.Add("%name%", "");
            }

            replace.Add("%epost%", user.Email.Trim());
            if (user.ChangePasswordRequest != null)
            {
                replace.Add("%url%", string.Format(obj.Url + "changepassword.html?key={0}", user.ChangePasswordRequest.Value));
            }
            string body = replace.ReplaceFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates", "ChangePassword.html"));

            MailService smtp   = new MailService("http://communicationservice.woxion.com/MailService.asmx");
            bool        result = smtp.Send("Projektplaneraren", "*****@*****.**", user.Email.Trim(), null, "Ändra lösenord", body);

            return("Request Created");
        }
Ejemplo n.º 4
0
        public void PostPageTextReplaceTest()
        {
            var rect            = new Rectangle(100, 100, 300, 300);
            var textReplace     = new TextReplace("market", "m_a_r_k_e_t", false, Rect: rect);
            var textReplaceList = new TextReplaceListRequest(new List <TextReplace> {
                textReplace
            },
                                                             StartIndex: 0, CountReplace: 0);

            var response = PdfApi.PostPageTextReplace(Name, 1, textReplaceList, folder: TempFolder);

            Assert.That(response.Code, Is.EqualTo(200));
        }
        public void PostPageTextReplaceTest()
        {
            var rect            = new Rectangle(100, 100, 300, 300);
            var textReplace     = new TextReplace("market", "m_a_r_k_e_t", false, Rect: rect);
            var textReplaceList = new TextReplaceListRequest(new List <TextReplace> {
                textReplace
            },
                                                             StartIndex: 0, CountReplace: 0);

            var response = api.PostPageTextReplace(Name, 1, textReplaceList, folder: FolderName);

            Console.WriteLine(response);
        }
        public void PostDocumentTextReplaceExample()
        {
            //ExStart: PostDocumentTextReplaceExample
            var rect            = new Rectangle(100, 100, 300, 300);
            var textReplace     = new TextReplace("market", "m_a_r_k_e_t", false, Rect: rect);
            var textReplaceList = new TextReplaceListRequest(new List <TextReplace> {
                textReplace
            },
                                                             StartIndex: 0, CountReplace: 0);

            var response = api.PostDocumentTextReplace(Name, textReplaceList, folder: FolderName);

            Console.WriteLine(response);
            //ExEnd: PostDocumentTextReplaceExample
        }
        public void Pdf_TextReplace_Tests()
        {
            try
            {
                storageService.File.CopyFile(Utils.CloudStorage_Input_Folder + "/pdf-sample.pdf", Utils.CloudStorage_Output_Folder + "/pdf-textReplace.pdf");

                TextReplace textReplace = new TextReplace("Aspose", "Aspose Pty Ltd.", true);
                DocumentReplaceTextResponse documentReplaceTextResponse = pdfService.TextReplace.ReplaceText("pdf-textReplace.pdf", Utils.CloudStorage_Output_Folder, textReplace);

                storageService.File.DownloadFile(Utils.CloudStorage_Output_Folder + "/pdf-textReplace.pdf", Utils.Local_Output_Path + "/pdf-textReplace.pdf");

                //------------------------------

                storageService.File.CopyFile(Utils.CloudStorage_Input_Folder + "/pdf-sample.pdf", Utils.CloudStorage_Output_Folder + "/pdf-textReplace2.pdf");

                TextReplace             textReplace2            = new TextReplace("Aspose", "Aspose Pty Ltd.", true);
                PageReplaceTextResponse pageTextReplaceResponse = pdfService.TextReplace.ReplaceText("pdf-textReplace2.pdf", 1, Utils.CloudStorage_Output_Folder, textReplace2);

                storageService.File.DownloadFile(Utils.CloudStorage_Output_Folder + "/pdf-textReplace2.pdf", Utils.Local_Output_Path + "/pdf-textReplace2.pdf");

                //========================================

                storageService.File.CopyFile(Utils.CloudStorage_Input_Folder + "/pdf-sample.pdf", Utils.CloudStorage_Output_Folder + "/pdf-textReplaceList.pdf");

                TextReplaceList textReplaceList = new TextReplaceList();
                textReplaceList.TextReplaces.Add(new TextReplace("Aspose", "Aspose Pty Ltd.", true));
                textReplaceList.TextReplaces.Add(new TextReplace("MS Office", "Microsoft Office", true));

                DocumentReplaceTextResponse textReplaceResponse = pdfService.TextReplace.ReplaceTextList("pdf-textReplaceList.pdf", Utils.CloudStorage_Output_Folder, textReplaceList);

                storageService.File.DownloadFile(Utils.CloudStorage_Output_Folder + "/pdf-textReplaceList.pdf", Utils.Local_Output_Path + "/pdf-textReplaceList.pdf");

                //-------------------------------------------------

                storageService.File.CopyFile(Utils.CloudStorage_Input_Folder + "/pdf-sample.pdf", Utils.CloudStorage_Output_Folder + "/pdf-textReplaceList2.pdf");

                TextReplaceList textReplaceList2 = new TextReplaceList();
                textReplaceList2.TextReplaces.Add(new TextReplace("Aspose", "Aspose Pty Ltd.", true));
                textReplaceList2.TextReplaces.Add(new TextReplace("MS Office", "Microsoft Office", true));
                PageReplaceTextResponse pageTextReplaceResponse2 = pdfService.TextReplace.ReplaceTextList("pdf-textReplaceList2.pdf", 1, Utils.CloudStorage_Output_Folder, textReplaceList2);

                storageService.File.DownloadFile(Utils.CloudStorage_Output_Folder + "/pdf-textReplaceList2.pdf", Utils.Local_Output_Path + "/pdf-textReplaceList2.pdf");
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        public static void Run()
        {
            // ExStart:1
            PdfApi     pdfApi     = new PdfApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);
            StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            String fileName = "sample-input.pdf";
            String storage  = "";
            String folder   = "";

            TextReplaceListRequest body = new TextReplaceListRequest();

            TextReplace tr1 = new TextReplace();

            tr1.OldValue = "Sample";
            tr1.NewValue = "Aspose Sample";

            TextReplace tr2 = new TextReplace();

            tr2.OldValue = "PDF";
            tr2.NewValue = "PDF Document";

            body.TextReplaces = new List <TextReplace> {
                tr1, tr2
            };

            try
            {
                // Upload source file to aspose cloud storage
                storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName));

                // Invoke Aspose.PDF Cloud SDK API to replace multiple text in PDF
                DocumentTextReplaceResponse apiResponse = pdfApi.PostDocumentReplaceTextList(fileName, storage, folder, body);

                if (apiResponse != null && apiResponse.Status.Equals("OK"))
                {
                    Console.WriteLine("Replace Multiple Texts in a PDF, Done!");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
            // ExEnd:1
        }
Ejemplo n.º 9
0
        public HttpResponseMessage Post([FromBody] TextReplace textreplace)
        {
            try
            {
                using (ghostDBEntities entities = new ghostDBEntities())
                {
                    entities.TextReplaces.Add(textreplace);
                    entities.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, textreplace);
                    message.Headers.Location = new Uri(Request.RequestUri + textreplace.idTextReplace.ToString());
                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Ejemplo n.º 10
0
        public string Mail()
        {
            string email = "*****@*****.**";

            //2. send a request emailmessage
            ITextReplace replace = new TextReplace();

            replace.Add("%name%", "Claes-Philip");
            replace.Add("%username%", email);
            replace.Add("%yammer%", true ? "Aktivt" : "Inaktivt");
            //replace.Add("%url%", string.Format("http://projectplanner.azurewebsites.net/changepassword.html?key={0}", "mykey"));
            replace.Add("%url%", string.Format("http://projektplaneraren.se/changepassword.html?key={0}", "mykey"));
            string body = replace.ReplaceFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates", "ChangePassword.html"));

            MailService smtp   = new MailService("http://communicationservice.woxion.com/MailService.asmx");
            bool        result = smtp.Send("Projektplaneraren", "*****@*****.**", email, null, "Ändra lösenord", body);

            return("Request Created");
        }
Ejemplo n.º 11
0
        public MemberModel CreateProjectMember(MemberModel memberModel)
        {
            // Mapp to backend model
            var member = new ProjectMember();

            if (memberModel != null)
            {
                member = ApplicationMapper.MapProjectMember(memberModel);
            }
            // Create P.Member
            bool memberExists;
            bool userExists;
            ProjectMemberView pmv = projectRepository.CreateProjectMember(member, out memberExists, out userExists);

            //If the member is a new member
            if (!userExists)
            {
                if (!string.IsNullOrEmpty(pmv.UserEmail))
                {
                    ITextReplace replace = new TextReplace();
                    //replace.Add("%name%", pmv.UserName);
                    replace.Add("%username%", pmv.UserEmail.Trim());
                    string body = replace.ReplaceFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates", "NewUser.html"));
                    // TODO replace with setting
                    MailService smtp   = new MailService("http://communicationservice.woxion.com/MailService.asmx");
                    bool        result = smtp.Send("Projektplaneraren", "*****@*****.**", pmv.UserEmail.Trim(), null, "Projektplaneraren", body);
                }
                else
                {
                    throw new Exception("Could not send new member email. Email is null or empty.");
                }
            }

            MemberModel createMemberModel = ApplicationMapper.MapProjectMemberView(pmv);

            createMemberModel.memberExists = memberExists;
            createMemberModel.MemberRoles  = memberModel.MemberRoles;
            return(createMemberModel);
        }
Ejemplo n.º 12
0
        public HttpResponseMessage Register(NewUser user)
        {
            try
            {
                var password = string.Empty;
                var status   = RegisterUserStatus.Undefined;
                appRepository.CreateUser(user.Email, user.Name, out password, out status);

                if (status == RegisterUserStatus.Ok)
                {
                    ITextReplace replace = new TextReplace();
                    //replace.Add("%name%", pmv.UserName);
                    replace.Add("%username%", user.Email.Trim());
                    replace.Add("%password%", password);
                    string body = replace.ReplaceFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates", "RegisterUser.html"));
                    // TODO replace with setting
                    MailService smtp = new MailService("http://communicationservice.woxion.com/MailService.asmx");
                    //bool result = smtp.Send("Projektplaneraren", "*****@*****.**", user.Email.Trim(), null, "Projektplaneraren", body);
                    bool result = smtp.Send("Projektplaneraren", "*****@*****.**", "*****@*****.**", null, "Projektplaneraren", body);
                }

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ObjectContent <object>(new
                    {
                        IsRegistered = status == RegisterUserStatus.Ok,
                        Status = status.ToString()
                                 //Password = password
                                 //IsAuthenticated = IdentityContext.Current.IsAuthenticated,
                                 //User = IdentityContext.Current.JsonUser,
                    }, Configuration.Formatters.JsonFormatter)
                });
            }
            catch (Exception ex)
            {
                log.Error("Error while register new user. " + ex);
                throw ex;
            }
        }