public void WhenExecutingTheReplyCommand_ThenNavigatesToComposeEmailViewWithId()
        {
            var email = new EmailDocument();

            EmailDocument[] emails = new EmailDocument[] { email };

            var emailServiceMock = new Mock <IEmailService>();
            var asyncResultMock  = new Mock <IAsyncResult>();

            emailServiceMock
            .Setup(svc => svc.GetEmailDocumentsAsync())
            .Returns(Task.FromResult(emails.AsEnumerable()));

            Mock <IRegionManager> regionManagerMock = new Mock <IRegionManager>();

            regionManagerMock.Setup(x => x.RequestNavigate(RegionNames.MainContentRegion, @"ComposeEmailView?ReplyTo=" + email.Id.ToString("N")))
            .Verifiable();

            var viewModel = new TestInboxViewModel(emailServiceMock.Object, regionManagerMock.Object, emails);

            Assert.IsFalse(viewModel.Messages.IsEmpty);

            viewModel.Messages.MoveCurrentToFirst();

            viewModel.ReplyMessageCommand.Execute(null);

            regionManagerMock.VerifyAll();
        }
        public void WhenExecutingTheReplyCommand_ThenNavigatesToComposeEmailViewWithId()
        {
            var email = new EmailDocument();

            var           emailServiceMock = new Mock <IEmailService>();
            AsyncCallback callback         = null;
            var           asyncResultMock  = new Mock <IAsyncResult>();

            emailServiceMock
            .Setup(svc => svc.BeginGetEmailDocuments(It.IsAny <AsyncCallback>(), null))
            .Callback <AsyncCallback, object>((ac, o) => callback = ac)
            .Returns(asyncResultMock.Object);
            emailServiceMock
            .Setup(svc => svc.EndGetEmailDocuments(asyncResultMock.Object))
            .Returns(new[] { email });

            Mock <IRegionManager> regionManagerMock = new Mock <IRegionManager>();

            regionManagerMock.Setup(x => x.RequestNavigate(RegionNames.MainContentRegion, @"ComposeEmailView?ReplyTo=" + email.Id.ToString("N")))
            .Verifiable();

            EmailDocument[] emails    = new EmailDocument[] { email };
            var             viewModel = new TestInboxViewModel(emailServiceMock.Object, regionManagerMock.Object, emails);

            Assert.IsFalse(viewModel.Messages.IsEmpty);

            viewModel.Messages.MoveCurrentToFirst();

            viewModel.ReplyMessageCommand.Execute(null);

            regionManagerMock.VerifyAll();
        }
        public static void Run()
        {
            // ExStart:1
            EmailApi   emailApi   = new EmailApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);
            StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            String fileName = "email_test.eml";
            String storage  = "";
            String folder   = "";

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

                // Invoke Aspose.Email Cloud SDK API to get message properties
                EmailDocument apiResponse = emailApi.GetDocument(fileName, storage, folder);

                if (apiResponse != null)
                {
                    foreach (EmailProperty emailProperty in apiResponse.DocumentProperties.List)
                    {
                        Console.WriteLine("Property Name :: " + emailProperty.Name);
                        Console.WriteLine("Property Value :: " + emailProperty.Value);
                    }
                    Console.WriteLine("Retrieve Message Properties, Done!");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
            // ExEnd:1
        }
Exemplo n.º 4
0
        public void WhenNavigatedTo_ThenRequestsEmailFromService()
        {
            var email = new EmailDocument();

            var emailServiceMock = new Mock <IEmailService>();

            emailServiceMock
            .Setup(svc => svc.GetEmailDocument(email.Id))
            .Returns(email)
            .Verifiable();

            var viewModel = new EmailViewModel(emailServiceMock.Object);

            var notified = false;

            viewModel.PropertyChanged += (s, o) => notified = o.PropertyName == "Email";

            NavigationContext context = new NavigationContext(new Mock <IRegionNavigationService>().Object, new Uri("location", UriKind.Relative));

            context.Parameters.Add("EmailId", email.Id);

            ((INavigationAware)viewModel).OnNavigatedTo(context);

            Assert.IsTrue(notified);
            emailServiceMock.VerifyAll();
        }
Exemplo n.º 5
0
        public static Func <bool> SetupGetEmails(Mock <IEmailService> serviceMock, IEnumerable <EmailDocument> result)
        {
            var           asyncResultMock = new Mock <IAsyncResult>();
            AsyncCallback callback        = null;

            serviceMock
            .Setup(svc => svc.BeginGetEmailDocuments(It.IsAny <AsyncCallback>(), null))
            .Callback <AsyncCallback, object>((ac, o) => callback = ac)
            .Returns(asyncResultMock.Object);
            var email = new EmailDocument {
            };

            serviceMock
            .Setup(svc => svc.EndGetEmailDocuments(asyncResultMock.Object))
            .Returns(result);

            return(() =>
            {
                if (callback == null)
                {
                    return false;
                }

                callback(asyncResultMock.Object);
                return true;
            });
        }
Exemplo n.º 6
0
        public void WhenAskedCanNavigateForDifferentQuery_ThenReturnsFalse()
        {
            var email = new EmailDocument();

            var emailServiceMock = new Mock <IEmailService>();

            emailServiceMock
            .Setup(svc => svc.GetEmailDocument(email.Id))
            .Returns(email)
            .Verifiable();

            var viewModel = new EmailViewModel(emailServiceMock.Object);

            NavigationContext context = new NavigationContext(new Mock <IRegionNavigationService>().Object, new Uri("location", UriKind.Relative));

            context.Parameters.Add("EmailId", email.Id);

            ((INavigationAware)viewModel).OnNavigatedTo(context);

            context = new NavigationContext(new Mock <IRegionNavigationService>().Object, new Uri("location", UriKind.Relative));
            context.Parameters.Add("EmailId", new Guid());

            bool canNavigate =
                ((INavigationAware)viewModel).IsNavigationTarget(context);

            Assert.IsFalse(canNavigate);
        }
Exemplo n.º 7
0
        void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
        {
            // todo: 09 - Email OnNavigatedTo : Accessing navigation context.
            // When this view model is navigated to it gains access to the
            // NavigationContext to determine if we are composing a new email
            // or replying to an existing one.
            //
            // The navigation context offers the context information through
            // the Parameters property that is a string/value dictionairy
            // built from the navigation Uri.
            //
            // In this example, we look for the 'ReplyTo' value to
            // determine if we are replying to an email and, if so,
            // retrieving it's relevant information from the email service
            // to pre-populate response values.
            //
            var emailDocument = new EmailDocument();

            var parameters = navigationContext.Parameters;

            var  replyTo = parameters[ReplyToParameterKey];
            Guid replyToId;

            if (replyTo != null && Guid.TryParse(replyTo, out replyToId))
            {
                var replyToEmail = _emailService.GetEmailDocument(replyToId);
                if (replyToEmail != null)
                {
                    emailDocument.To      = replyToEmail.From;
                    emailDocument.Subject = "RE: " + replyToEmail.Subject;

                    emailDocument.Text =
                        Environment.NewLine +
                        replyToEmail.Text
                        .Split(Environment.NewLine.ToCharArray())
                        .Select(l => l.Length > 0 ? ">> " + l : l)
                        .Aggregate((l1, l2) => l1 + Environment.NewLine + l2);
                }
            }
            else
            {
                var to = parameters[ToParameterKey];
                if (to != null)
                {
                    emailDocument.To = to;
                }
            }

            EmailDocument = emailDocument;

            // todo: 10 - Email OnNaviatedTo : Capture the navigation service journal
            // You can capture the navigation service or navigation service journal
            // to navigate the region you're placed in without having to expressly
            // know which region to navigate.
            //
            // This is useful if you need to navigate 'back' at some point after this
            // view model closes.
            _navigationJournal = navigationContext.NavigationService.Journal;
        }
Exemplo n.º 8
0
        public void WhenExecutingTheReplyCommand_ThenNavigatesToComposeEmailViewWithId()
        {
            var email = new EmailDocument();

            var           emailServiceMock = new Mock <IEmailService>();
            AsyncCallback callback         = null;
            var           asyncResultMock  = new Mock <IAsyncResult>();

            emailServiceMock
            .Setup(svc => svc.BeginGetEmailDocuments(It.IsAny <AsyncCallback>(), null))
            .Callback <AsyncCallback, object>((ac, o) => callback = ac)
            .Returns(asyncResultMock.Object);
            emailServiceMock
            .Setup(svc => svc.EndGetEmailDocuments(asyncResultMock.Object))
            .Returns(new[] { email });

            Mock <IRegion> regionMock = new Mock <IRegion>();

            regionMock
            .Setup(x => x.RequestNavigate(new Uri(@"ComposeEmailView?ReplyTo=" + email.Id.ToString("N"), UriKind.Relative), It.IsAny <Action <NavigationResult> >()))
            .Callback <Uri, Action <NavigationResult> >((s, c) => c(new NavigationResult(null, true)))
            .Verifiable();

            Mock <IRegionManager> regionManagerMock = new Mock <IRegionManager>();

            regionManagerMock.Setup(x => x.Regions.ContainsRegionWithName(RegionNames.MainContentRegion)).Returns(true);
            regionManagerMock.Setup(x => x.Regions[RegionNames.MainContentRegion]).Returns(regionMock.Object);

            var viewModel = new InboxViewModel(emailServiceMock.Object, regionManagerMock.Object);

            EnqueueConditional(() => callback != null);

            EnqueueCallback(
                () =>
            {
                callback(asyncResultMock.Object);
            });

            EnqueueConditional(
                () =>
            {
                return(!viewModel.Messages.IsEmpty);
            });

            EnqueueCallback(
                () =>
            {
                viewModel.Messages.MoveCurrentToFirst();

                viewModel.ReplyMessageCommand.Execute(null);

                regionMock.VerifyAll();
            });

            EnqueueTestComplete();
        }
Exemplo n.º 9
0
        private void OpenMessage(EmailDocument document)
        {
            // todo: 04 - Open Email: Navigating to a view in a region with context
            // When navigating, you can also supply context so the target view or
            // viewmodel can orient their data to something appropriate.  In this case,
            // we've chosen to pass the email id in a name/value pair using and handmade Uri.
            //
            // The EmailViewModel retrieves this context by implementing the INavigationAware
            // interface.
            //
            NavigationParameters parameters = new NavigationParameters();

            parameters.Add(EmailIdKey, document.Id.ToString("N"));

            this.regionManager.RequestNavigate(RegionNames.MainContentRegion, new Uri(EmailViewKey + parameters, UriKind.Relative));
        }
        public void WhenExecutingTheOpenCommand_ThenNavigatesToEmailView()
        {
            var email = new EmailDocument();

            var emailServiceMock = new Mock <IEmailService>();

            Mock <IRegionManager> regionManagerMock = new Mock <IRegionManager>();

            regionManagerMock.Setup(x => x.RequestNavigate(RegionNames.MainContentRegion, new Uri(@"EmailView?EmailId=" + email.Id.ToString("N"), UriKind.Relative))).Verifiable();

            var viewModel = new InboxViewModel(emailServiceMock.Object, regionManagerMock.Object);

            viewModel.OpenMessageCommand.Execute(email);

            regionManagerMock.VerifyAll();
        }
Exemplo n.º 11
0
        void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
        {
            // todo: 15 - Orient to the right context
            //
            // When this view model is navigated to, it gathers the
            // requested EmailId from the navigation context's parameters.
            //
            // It also captures the navigation Journal so it
            // can offer a 'go back' command.
            var emailId = GetRequestedEmailId(navigationContext);

            if (emailId.HasValue)
            {
                this.Email = this.emailService.GetEmailDocument(emailId.Value);
            }

            this.navigationJournal = navigationContext.NavigationService.Journal;
        }
Exemplo n.º 12
0
        private Document GetDocument(Emails.CustomerEmailsRow row, Token lastToken, NorthwindConfig config)
        {
            EmailDocument doc;
            string        id;

            id = row.ID.ToString();

            doc    = new EmailDocument();
            doc.Id = id;

            if (lastToken.InitRequest)
            {
                doc.LogState = LogState.Created;
            }

            else if (row.IsCreateIDNull() || row.IsModifyIDNull() ||
                     row.IsCreateUserNull() || row.IsModifyUserNull())
            {
                doc.LogState = LogState.Created;
            }

            else if ((row.CreateID > lastToken.SequenceNumber) &&
                     (row.CreateUser != config.CrmUser))
            {
                doc.LogState = LogState.Created;
            }

            else if ((row.CreateID == lastToken.SequenceNumber) &&
                     (row.CreateUser != config.CrmUser) &&
                     (id.CompareTo(lastToken.Id.Id) > 0))
            {
                doc.LogState = LogState.Created;
            }
            else if ((row.ModifyID >= lastToken.SequenceNumber) && (row.ModifyUser != config.CrmUser))
            {
                doc.LogState = LogState.Updated;
            }

            doc.emailaddress.Value = row.IsEmailNull() ? null : row.Email;

            doc.type.Value = Constants.DefaultValues.Email.Type;

            return(doc);
        }
Exemplo n.º 13
0
        private void OpenMessage(EmailDocument document)
        {
            // todo: 04 - Open Email: Navigating to a view in a region with context
            // When navigating, you can also supply context so the target view or
            // viewmodel can orient their data to something appropriate.  In this case,
            // we've chosen to pass the email id in a name/value pair as part of the Uri.
            //
            // The EmailViewModel retrieves this context by implementing the INavigationAware
            // interface.
            //
            var builder = new StringBuilder();

            builder.Append(EmailViewKey);
            var query = new UriQuery();

            query.Add(EmailIdKey, document.Id.ToString("N"));
            builder.Append(query);
            this.regionManager.RequestNavigate(RegionNames.MainContentRegion, new Uri(builder.ToString(), UriKind.Relative));
        }
Exemplo n.º 14
0
        public void WhenAskedCanNavigateForDifferentQuery_ThenReturnsFalse()
        {
            var email = new EmailDocument();

            var emailServiceMock = new Mock <IEmailService>();

            emailServiceMock
            .Setup(svc => svc.GetEmailDocument(email.Id))
            .Returns(email)
            .Verifiable();

            var viewModel = new EmailViewModel(emailServiceMock.Object);

            ((INavigationAware)viewModel).OnNavigatedTo(new NavigationContext(new Mock <IRegionNavigationService>().Object, new Uri("location?EmailId=" + email.Id.ToString("N"), UriKind.Relative)));

            bool canNavigate =
                ((INavigationAware)viewModel).IsNavigationTarget(new NavigationContext(new Mock <IRegionNavigationService>().Object, new Uri("location?EmailId=" + Guid.NewGuid().ToString("N"), UriKind.Relative)));

            Assert.IsFalse(canNavigate);
        }
Exemplo n.º 15
0
        public void WhenNavigatedToWithAReplyToQueryParameter_ThenRepliesToTheAppropriateMessage()
        {
            var replyToEmail = new EmailDocument {
                From = "*****@*****.**", To = "", Subject = "", Text = ""
            };

            var emailServiceMock = new Mock <IEmailService>();

            emailServiceMock
            .Setup(svc => svc.GetEmailDocument(replyToEmail.Id))
            .Returns(replyToEmail);

            var viewModel = new ComposeEmailViewModel(emailServiceMock.Object);
            var uriQuery  = new UriQuery();

            uriQuery.Add("ReplyTo", replyToEmail.Id.ToString("N"));
            ((INavigationAware)viewModel).OnNavigatedTo(new NavigationContext(new Mock <IRegionNavigationService>().Object, new Uri("" + uriQuery.ToString(), UriKind.Relative)));

            Assert.AreEqual("*****@*****.**", viewModel.EmailDocument.To);
        }
Exemplo n.º 16
0
        public void WhenEmailsAreReturned_ThenViewModelIsPopulated()
        {
            var asyncResultMock = new Mock <IAsyncResult>();

            var           emailServiceMock = new Mock <IEmailService>(MockBehavior.Strict);
            AsyncCallback callback         = null;

            emailServiceMock
            .Setup(svc => svc.BeginGetEmailDocuments(It.IsAny <AsyncCallback>(), null))
            .Callback <AsyncCallback, object>((ac, o) => callback = ac)
            .Returns(asyncResultMock.Object);
            var email = new EmailDocument {
            };

            emailServiceMock
            .Setup(svc => svc.EndGetEmailDocuments(asyncResultMock.Object))
            .Returns(new[] { email });


            var viewModel = new InboxViewModel(emailServiceMock.Object, new Mock <IRegionManager>().Object);

            this.EnqueueConditional(() => callback != null);

            this.EnqueueCallback(
                () =>
            {
                callback(asyncResultMock.Object);
            });

            this.EnqueueCallback(
                () =>
            {
                CollectionAssert.AreEqual(new[] { email }, viewModel.Messages.Cast <EmailDocument>().ToArray());
                emailServiceMock.VerifyAll();
            });

            this.EnqueueTestComplete();
        }
Exemplo n.º 17
0
        public void WhenExecutingTheOpenCommand_ThenNavigatesToEmailView()
        {
            var email = new EmailDocument();

            var emailServiceMock = new Mock <IEmailService>();

            Mock <IRegion> regionMock = new Mock <IRegion>();

            regionMock
            .Setup(x => x.RequestNavigate(new Uri(@"EmailView?EmailId=" + email.Id.ToString("N"), UriKind.Relative), It.IsAny <Action <NavigationResult> >()))
            .Callback <Uri, Action <NavigationResult> >((s, c) => c(new NavigationResult(null, true)))
            .Verifiable();

            Mock <IRegionManager> regionManagerMock = new Mock <IRegionManager>();

            regionManagerMock.Setup(x => x.Regions.ContainsRegionWithName(RegionNames.MainContentRegion)).Returns(true);
            regionManagerMock.Setup(x => x.Regions[RegionNames.MainContentRegion]).Returns(regionMock.Object);

            var viewModel = new InboxViewModel(emailServiceMock.Object, regionManagerMock.Object);

            viewModel.OpenMessageCommand.Execute(email);

            regionMock.VerifyAll();
        }
Exemplo n.º 18
0
        /* Update */
        public override void Update(Document doc, NorthwindConfig config, ref List <TransactionResult> result)
        {
            List <TransactionResult> transactionResult = new List <TransactionResult>();
            EmailDocument            emailDocument     = doc as EmailDocument;

            #region check input values

            if (emailDocument == null)
            {
                result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_DocumentTypeNotSupported));
                return;
            }

            // check id
            #endregion

            CustomerEmailsTableAdapter tableAdapter;


            Emails emailsDataset = new Emails();
            Emails.CustomerEmailsRow emailsRow;
            tableAdapter = new CustomerEmailsTableAdapter();
            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                connection.Open();
                tableAdapter.Connection = connection;
                int recordCount = tableAdapter.FillBy(emailsDataset.CustomerEmails, Convert.ToInt32(emailDocument.Id));
                if (recordCount == 0)
                {
                    doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, "Category does not exists");
                    return;
                }
                emailsRow = (Emails.CustomerEmailsRow)emailsDataset.CustomerEmails.Rows[0];

                try
                {
                    if (emailDocument.emailaddress.IsNull)
                    {
                        emailsRow.SetEmailNull();
                    }
                    else
                    {
                        emailsRow.Email = (string)emailDocument.emailaddress.Value;
                    }

                    emailsRow.ModifyID   = config.SequenceNumber;
                    emailsRow.ModifyUser = config.CrmUser;
                }
                catch (Exception e)
                {
                    emailDocument.Id = "";
#warning Check error message
                    result.Add(emailDocument.SetTransactionStatus(TransactionStatus.UnRecoverableError, e.ToString()));
                    return;
                }

                tableAdapter            = new CustomerEmailsTableAdapter();
                tableAdapter.Connection = connection;

                tableAdapter.Update(emailsDataset.CustomerEmails);
            }
        }
Exemplo n.º 19
0
        /* Add */
        public override void Add(Document doc, NorthwindConfig config, ref List <TransactionResult> result)
        {
            List <TransactionResult> transactionResult = new List <TransactionResult>();

            // cast the given document to an email document
            // return if fails
            EmailDocument emailDocument = doc as EmailDocument;

            if (emailDocument == null)
            {
                result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_DocumentTypeNotSupported));
                return;
            }

            CustomerEmailsTableAdapter tableAdapter;
            Emails emailsDataset = new Emails();

            Emails.CustomerEmailsRow emailRow = emailsDataset.CustomerEmails.NewCustomerEmailsRow();

            #region fill dataset from document

            try
            {
                if (emailDocument.emailaddress.IsNull)
                {
                    emailRow.SetEmailNull();
                }
                else
                {
                    emailRow.Email = (string)emailDocument.emailaddress.Value;
                }

                emailRow.CreateID   = config.SequenceNumber;
                emailRow.CreateUser = config.CrmUser;

                emailRow.ModifyID   = config.SequenceNumber;
                emailRow.ModifyUser = config.CrmUser;
            }
            catch (Exception e)
            {
                emailDocument.Id = "";
#warning Check error message
                result.Add(emailDocument.SetTransactionStatus(TransactionStatus.UnRecoverableError, e.ToString()));
                return;
            }

            #endregion

            #region Get the ID of the new row and set it to the document

            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                connection.Open();


                tableAdapter            = new CustomerEmailsTableAdapter();
                tableAdapter.Connection = connection;


                emailsDataset.CustomerEmails.AddCustomerEmailsRow(emailRow);
                tableAdapter.Update(emailsDataset.CustomerEmails);
                OleDbCommand Cmd    = new OleDbCommand("SELECT @@IDENTITY", connection);
                object       lastid = Cmd.ExecuteScalar();
                emailDocument.Id = ((int)lastid).ToString();
            }

            #endregion
        }
Exemplo n.º 20
0
        public void TestPutCreateNewEmail()
        {
            EmailApi   target     = new EmailApi(APIKEY, APPSID, BASEPATH);
            StorageApi storageApi = new StorageApi(APIKEY, APPSID, BASEPATH);

            string name    = "email_test.eml";
            string storage = null;
            string folder  = null;

            EmailDocument body = new EmailDocument();

            EmailProperties emailProperties = new EmailProperties();

            System.Collections.Generic.List <Link> links             = new System.Collections.Generic.List <Link> {
            };
            System.Collections.Generic.List <EmailProperty> empProps = new System.Collections.Generic.List <EmailProperty> {
            };


            Link link = new Link();

            link.Href  = "http://api.aspose.com/v1.1/pdf/";
            link.Rel   = "self";
            link.Title = "NewField";
            link.Type  = "link";
            links.Add(link);


            EmailProperty emailBody = new EmailProperty();
            EmailProperty emailTo   = new EmailProperty();
            EmailProperty emailFrom = new EmailProperty();

            emailBody.Name  = "Body";
            emailBody.Value = "This is the Body";
            emailBody.Link  = link;
            empProps.Add(emailBody);

            emailTo.Name  = "To";
            emailTo.Value = "*****@*****.**";
            emailTo.Link  = link;
            empProps.Add(emailTo);

            emailFrom.Name  = "From";
            emailFrom.Value = "*****@*****.**";
            emailFrom.Link  = link;
            empProps.Add(emailFrom);


            emailProperties.List = empProps;
            emailProperties.Link = link;

            body.DocumentProperties = emailProperties;
            body.Links = links;

            storageApi.PutCreate(name, null, null, System.IO.File.ReadAllBytes("\\temp\\email\\resources\\" + name));

            EmailDocumentResponse actual;

            actual = target.PutCreateNewEmail(name, storage, folder, body);

            Assert.AreEqual("200", actual.Code);
            Assert.IsInstanceOfType(new EmailDocumentResponse(), actual.GetType());
        }
        public TradingAccountFeedEntry GetTransformedPayload(AccountDocument document)
        {
            TradingAccountFeedEntry entry = new TradingAccountFeedEntry();

            entry.customerSupplierFlag = GetSupplierFlag(document.customerSupplierFlag);
            entry.active = true;

            entry.deleted      = false;
            entry.deliveryRule = false;

            entry.name = (document.name.IsNull) ? null : document.name.Value.ToString();

            #region addresses
            int adressCount = document.addresses.documents.Count;
            entry.postalAddresses    = new PostalAddressFeed();
            entry.postalAddresses.Id = GetSDataId(document.Id) + "/" + SupportedResourceKinds.postalAddresses.ToString();
            for (int index = 0; index < adressCount; index++)
            {
                AddressDocument        address           = document.addresses.documents[index] as AddressDocument;
                PostalAddressFeedEntry postalAdressEntry = _postalAdressTransformation.GetTransformedPayload(address);
                if (postalAdressEntry != null)
                {
                    entry.postalAddresses.Entries.Add(postalAdressEntry);
                }
            }
            #endregion

            #region emails
            int emailsCount = document.emails.documents.Count;
            entry.emails = new EmailFeed();
            for (int index = 0; index < emailsCount; index++)
            {
                EmailDocument  email      = document.emails.documents[index] as EmailDocument;
                EmailFeedEntry emailEntry = _emailAdressTransformation.GetTransformedPayload(email);
                entry.emails.Entries.Add(emailEntry);
            }
            #endregion


            #region phones
            int phonesCount = document.phones.documents.Count;
            entry.phones = new PhoneNumberFeed();
            for (int index = 0; index < phonesCount; index++)
            {
                PhoneDocument        phone            = document.phones.documents[index] as PhoneDocument;
                PhoneNumberFeedEntry phoneNumberEntry = _phoneNumberTransformation.GetTransformedPayload(phone);
                if (phoneNumberEntry != null)
                {
                    entry.phones.Entries.Add(phoneNumberEntry);
                }
            }
            #endregion

            #region contacts
            int contactsCount = document.people.documents.Count;
            entry.contacts = new ContactFeed();
            for (int index = 0; index < contactsCount; index++)
            {
                PersonDocument   person       = document.people.documents[index] as PersonDocument;
                ContactFeedEntry contactEntry = _contactTransformation.GetTransformedPayload(person);
                if (contactEntry != null)
                {
                    entry.contacts.Entries.Add(contactEntry);
                }
            }
            #endregion

            entry.currency = _config.CurrencyCode;
            SetCommonProperties(document, entry.name, entry);
            return(entry);
        }
Exemplo n.º 22
0
        void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
        {
            // todo: 09 - Email OnNavigatedTo : Accessing navigation context.
            // When this view model is navigated to it gains access to the
            // NavigationContext to determine if we are composing a new email
            // or replying to an existing one.
            //
            // The navigation context offers the context information through
            // the Parameters property that is a string/value dictionary
            // built using the NavigationParameters class.
            //
            // In this example, we look for the 'ReplyTo' value to
            // determine if we are replying to an email and, if so,
            // retrieving it's relevant information from the email service
            // to pre-populate response values.
            //
            var emailDocument = new EmailDocument();

            var parameters = navigationContext.Parameters;

            object replyTo;

            if (parameters.TryGetValue(ReplyToParameterKey, out replyTo))
            {
                Guid replyToId;
                if (replyTo is Guid)
                {
                    replyToId = (Guid)replyTo;
                }
                else
                {
                    replyToId = Guid.Parse(replyTo.ToString());
                }

                var replyToEmail = this.emailService.GetEmailDocument(replyToId);
                if (replyToEmail != null)
                {
                    emailDocument.To      = replyToEmail.From;
                    emailDocument.Subject = Resources.ResponseMessagePrefix + replyToEmail.Subject;

                    emailDocument.Text =
                        Environment.NewLine +
                        replyToEmail.Text
                        .Split(Environment.NewLine.ToCharArray())
                        .Select(l => l.Length > 0 ? Resources.ResponseLinePrefix + l : l)
                        .Aggregate((l1, l2) => l1 + Environment.NewLine + l2);
                }
            }
            else
            {
                object to;
                if (parameters.TryGetValue(ToParameterKey, out to))
                {
                    emailDocument.To = to.ToString();
                }
            }

            this.EmailDocument = emailDocument;

            // todo: 10 - Email OnNaviatedTo : Capture the navigation service journal
            // You can capture the navigation service or navigation service journal
            // to navigate the region you're placed in without having to expressly
            // know which region to navigate.
            //
            // This is useful if you need to navigate 'back' at some point after this
            // view model closes.
            this.navigationJournal = navigationContext.NavigationService.Journal;
        }
        public AccountDocument GetTransformedDocument(TradingAccountFeedEntry feedEntry)
        {
            AccountDocument accountDocument = new AccountDocument();

            #region Postal adresses
            accountDocument.addresses = new AddressDocumentCollection();

            if (feedEntry.postalAddresses != null && feedEntry.postalAddresses != null)
            {
                foreach (PostalAddressFeedEntry postalAdressEntry in feedEntry.postalAddresses.Entries)
                {
                    AddressDocument address = _postalAdressTransformation.GetTransformedDocument(postalAdressEntry);
                    accountDocument.addresses.Add(address);
                }
            }

            bool hasMainAdress = false;
            for (int index = 0; index < accountDocument.addresses.documents.Count; index++)
            {
                AddressDocument address = accountDocument.addresses.documents[index] as AddressDocument;
                if ((address.primaryaddress.Value != null) && (address.primaryaddress.Value.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)))
                {
                    hasMainAdress = true;
                }
            }
            if ((!hasMainAdress) && (accountDocument.addresses.documents.Count > 0))
            {
                AddressDocument address = accountDocument.addresses.documents[0] as AddressDocument;
                address.primaryaddress.Value = "true";
            }

            #endregion postal adresses

            if (GuidIsNullOrEmpty(feedEntry.UUID))
            {
                accountDocument.Id = feedEntry.Key;
            }
            else
            {
                accountDocument.CrmId = feedEntry.UUID.ToString();
                accountDocument.Id    = GetLocalId(feedEntry.UUID);
            }

            if (feedEntry.IsPropertyChanged("currency"))
            {
                accountDocument.currencyid.Value = feedEntry.currency;
            }


            #region emails
            accountDocument.emails = new EmailsDocumentCollection();
            if (feedEntry.emails != null)
            {
                foreach (EmailFeedEntry emailEntry in feedEntry.emails.Entries)
                {
                    EmailDocument emailDocument = _emailAdressTransformation.GetTransformedDocument(emailEntry);
                    accountDocument.emails.Add(emailDocument);
                }
            }
            #endregion

            if (feedEntry.IsPropertyChanged("name"))
            {
                accountDocument.name.Value = feedEntry.name;
            }

            // ????? document.onhold

            #region contacts
            accountDocument.people = new PeopleDocumentCollection();
            if (feedEntry.contacts != null)
            {
                foreach (ContactFeedEntry contact in feedEntry.contacts.Entries)
                {
                    PersonDocument person = _contactTransformation.GetTransformedDocument(contact);
                    accountDocument.people.Add(person);
                }
            }
            bool hasMainPerson = false;
            for (int index = 0; index < accountDocument.people.documents.Count; index++)
            {
                PersonDocument person = accountDocument.people.documents[index] as PersonDocument;
                if ((person.primaryperson.Value != null) && (person.primaryperson.Value.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)))
                {
                    hasMainPerson = true;
                }
            }
            if ((!hasMainPerson) && (accountDocument.people.documents.Count > 0))
            {
                PersonDocument person = accountDocument.people.documents[0] as PersonDocument;
                person.primaryperson.Value = "true";
            }
            #endregion

            #region phones
            accountDocument.phones = new PhonesDocumentCollection();
            if (feedEntry.phones != null)
            {
                foreach (PhoneNumberFeedEntry phoneNumberPayload in feedEntry.phones.Entries)
                {
                    PhoneDocument phone = _phoneNumberTransformation.GetTransformedDocument(phoneNumberPayload);
                    accountDocument.phones.Add(phone);
                }
            }
            #endregion

            if (feedEntry.IsPropertyChanged("customerSupplierFlag"))
            {
                accountDocument.customerSupplierFlag.Value = Enum.GetName(typeof(supplierFlagenum), feedEntry.customerSupplierFlag);
            }

            return(accountDocument);
        }
Exemplo n.º 24
0
        public TradingAccountPayload GetTransformedPayload(AccountDocument document, out List <SyncFeedEntryLink> links)
        {
            links = new List <SyncFeedEntryLink>();
            TradingAccountPayload payload        = new TradingAccountPayload();
            tradingAccounttype    tradingAccount = new tradingAccounttype();

            tradingAccount.accountingType       = tradingAccountAccountingTypeenum.Unknown;
            tradingAccount.customerSupplierFlag = (document.customerSupplierFlag.IsNull) ? null : document.customerSupplierFlag.Value.ToString();
            tradingAccount.active = true;
            //tradingAccount.postalAddresses = new postalAddresstype[0]();
            //tradingAccount.contacts = new contacttype[0]();
            //tradingAccount.phones = new phoneNumbertype[0]();
            tradingAccount.deleted         = false;
            tradingAccount.deliveryContact = null;
            tradingAccount.deliveryMethod  = null;
            tradingAccount.deliveryRule    = false;
            //tradingAccount.emails = new emailtype[0]();
            tradingAccount.applicationID = document.Id;
            payload.SyncUuid             = GetUuid(document.Id, document.CrmId);
            payload.LocalID      = document.Id;
            tradingAccount.uuid  = payload.SyncUuid.ToString();
            tradingAccount.label = SupportedResourceKinds.tradingAccounts.ToString();
            tradingAccount.name  = (document.name.IsNull) ? null : document.name.Value.ToString();


            //Many more things should set to default values


            // adresses
            int adressCount = document.addresses.documents.Count;

            tradingAccount.postalAddresses = new postalAddresstype[adressCount];
            for (int index = 0; index < adressCount; index++)
            {
                List <SyncFeedEntryLink> addressLinks;
                AddressDocument          address = document.addresses.documents[index] as AddressDocument;
                PostalAddressPayload     postalAdressPayload;
                postalAdressPayload = _postalAdressTransformation.GetTransformedPayload(address, out addressLinks);
                tradingAccount.postalAddresses[index] = postalAdressPayload.PostalAddresstype;
                links.Add(SyncFeedEntryLink.CreateRelatedLink(
                              Common.ResourceKindHelpers.GetSingleResourceUrl(
                                  _context.DatasetLink, SupportedResourceKinds.postalAddresses.ToString(), postalAdressPayload.LocalID),
                              "postalAddresses",
                              "postalAddresses[" + index.ToString() + "]",
                              postalAdressPayload.SyncUuid.ToString()));
            }

            //emails
            int emailsCount = document.emails.documents.Count;

            tradingAccount.emails = new emailtype[emailsCount];
            for (int index = 0; index < emailsCount; index++)
            {
                List <SyncFeedEntryLink> emailLinks;
                EmailDocument            email = document.emails.documents[index] as EmailDocument;
                EmailPayload             EmailPayload;
                EmailPayload = _emailAdressTransformation.GetTransformedPayload(email, out emailLinks);
                tradingAccount.emails[index] = EmailPayload.Emailtype;

                links.Add(SyncFeedEntryLink.CreateRelatedLink(
                              Common.ResourceKindHelpers.GetSingleResourceUrl(
                                  _context.DatasetLink, SupportedResourceKinds.emails.ToString(), EmailPayload.LocalID),
                              "emails",
                              "emails[" + index.ToString() + "]",
                              EmailPayload.SyncUuid.ToString()));
            }


            //phones
            int phonesCount = document.phones.documents.Count;

            tradingAccount.phones = new phoneNumbertype[phonesCount];
            for (int index = 0; index < phonesCount; index++)
            {
                List <SyncFeedEntryLink> phoneLinks;
                PhoneDocument            phone = document.phones.documents[index] as PhoneDocument;
                PhoneNumberPayload       phoneNumberPayload;
                phoneNumberPayload           = _phoneNumberTransformation.GetTransformedPayload(phone, out phoneLinks);
                tradingAccount.phones[index] = phoneNumberPayload.PhoneNumbertype;

                links.Add(SyncFeedEntryLink.CreateRelatedLink(
                              Common.ResourceKindHelpers.GetSingleResourceUrl(
                                  _context.DatasetLink, SupportedResourceKinds.phoneNumbers.ToString(), phoneNumberPayload.LocalID),
                              "phones",
                              "phones[" + index.ToString() + "]",
                              phoneNumberPayload.SyncUuid.ToString()));
            }

            //contacts
            int contactsCount = document.people.documents.Count;

            tradingAccount.contacts = new contacttype[contactsCount];
            for (int index = 0; index < contactsCount; index++)
            {
                List <SyncFeedEntryLink> contactLinks;
                PersonDocument           person = document.people.documents[index] as PersonDocument;
                ContactPayload           contactPayload;
                contactPayload = _contactTransformation.GetTransformedPayload(person, out contactLinks);
                tradingAccount.contacts[index] = contactPayload.Contacttype;
                links.Add(SyncFeedEntryLink.CreateRelatedLink(
                              Common.ResourceKindHelpers.GetSingleResourceUrl(
                                  _context.DatasetLink, SupportedResourceKinds.contacts.ToString(), contactPayload.LocalID),
                              "contacts",
                              "contacts[" + index.ToString() + "]",
                              contactPayload.SyncUuid.ToString()));
            }


            payload.TradingAccount = tradingAccount;

            SyncFeedEntryLink selfLink = SyncFeedEntryLink.CreateSelfLink(String.Format("{0}{1}('{2}')", _datasetLink, SupportedResourceKinds.tradingAccounts, document.Id));

            links.Add(selfLink);
            return(payload);
        }
Exemplo n.º 25
0
        public AccountDocument GetTransformedDocument(TradingAccountPayload payload, List <SyncFeedEntryLink> links)
        {
            AccountDocument    document       = new AccountDocument();
            tradingAccounttype tradingAccount = payload.TradingAccount;

            document.addresses = new AddressDocumentCollection();
            if (tradingAccount.postalAddresses != null && tradingAccount.postalAddresses != null)
            {
                foreach (postalAddresstype postalAddress in tradingAccount.postalAddresses)
                {
                    PostalAddressPayload postalAdressPayload = new PostalAddressPayload();
                    postalAdressPayload.PostalAddresstype = postalAddress;
                    postalAdressPayload.SyncUuid          = StringToGuid(postalAddress.uuid);
                    AddressDocument address = _postalAdressTransformation.GetTransformedDocument(postalAdressPayload, Helper.ReducePayloadPath(links));
                    document.addresses.Add(address);
                }
            }
            bool hasMainAdress = false;

            for (int index = 0; index < document.addresses.documents.Count; index++)
            {
                AddressDocument address = document.addresses.documents[index] as AddressDocument;
                if ((address.primaryaddress.Value != null) && (address.primaryaddress.Value.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)))
                {
                    hasMainAdress = true;
                }
            }
            if ((!hasMainAdress) && (document.addresses.documents.Count > 0))
            {
                AddressDocument address = document.addresses.documents[0] as AddressDocument;
                address.primaryaddress.Value = "true";
            }
            if (String.IsNullOrEmpty(payload.LocalID))
            {
                document.CrmId = payload.SyncUuid.ToString();//
                document.Id    = GetLocalId(payload.SyncUuid);
            }
            else
            {
                document.Id = payload.LocalID;
            }
            document.currencyid.Value = tradingAccount.currency;
            document.emails           = new EmailsDocumentCollection();
            if (tradingAccount.emails != null && tradingAccount.emails != null)
            {
                foreach (emailtype email in tradingAccount.emails)
                {
                    EmailPayload emailPayload = new EmailPayload();
                    emailPayload.Emailtype = email;
                    emailPayload.SyncUuid  = StringToGuid(email.uuid);
                    EmailDocument emailDocument = _emailAdressTransformation.GetTransformedDocument(emailPayload, Helper.ReducePayloadPath(links));
                    document.emails.Add(emailDocument);
                }
            }
            document.name.Value = tradingAccount.name;
            // ????? document.onhold
            document.people = new PeopleDocumentCollection();
            if (tradingAccount.contacts != null && tradingAccount.contacts != null)
            {
                foreach (contacttype contact in tradingAccount.contacts)
                {
                    ContactPayload contactPayload = new ContactPayload();
                    contactPayload.Contacttype = contact;
                    contactPayload.SyncUuid    = StringToGuid(contact.uuid);
                    PersonDocument person = _contactTransformation.GetTransformedDocument(contactPayload, Helper.ReducePayloadPath(links));
                    document.people.Add(person);
                }
            }
            bool hasMainPerson = false;

            for (int index = 0; index < document.people.documents.Count; index++)
            {
                PersonDocument person = document.people.documents[index] as PersonDocument;
                if ((person.primaryperson.Value != null) && (person.primaryperson.Value.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)))
                {
                    hasMainPerson = true;
                }
            }
            if ((!hasMainPerson) && (document.people.documents.Count > 0))
            {
                PersonDocument person = document.people.documents[0] as PersonDocument;
                person.primaryperson.Value = "true";
            }

            document.phones = new PhonesDocumentCollection();
            if (tradingAccount.phones != null && tradingAccount.phones != null)
            {
                foreach (phoneNumbertype phoneNumber in tradingAccount.phones)
                {
                    PhoneNumberPayload phoneNumberPayload = new PhoneNumberPayload();
                    phoneNumberPayload.PhoneNumbertype = phoneNumber;
                    //phoneNumberPayload.SyncUuid = GetUuid(phoneNumber.applicationID);
                    PhoneDocument phone = _phoneNumberTransformation.GetTransformedDocument(phoneNumberPayload, Helper.ReducePayloadPath(links));
                    document.phones.Add(phone);
                }
            }
            document.customerSupplierFlag.Value = tradingAccount.customerSupplierFlag;
            return(document);
        }
Exemplo n.º 26
0
        public static void Run()
        {
            // ExStart:1
            EmailApi   emailApi   = new EmailApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);
            StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            String name     = "email_test";
            String fileName = name + ".eml";
            String storage  = "";
            String folder   = "";

            EmailDocument body = new EmailDocument();

            EmailProperties emailProperties = new EmailProperties();

            System.Collections.Generic.List <Link> links             = new System.Collections.Generic.List <Link> {
            };
            System.Collections.Generic.List <EmailProperty> empProps = new System.Collections.Generic.List <EmailProperty> {
            };


            Link link = new Link();

            link.Href  = "http://api.aspose.com/v1.1/pdf/";
            link.Rel   = "self";
            link.Title = "NewField";
            link.Type  = "link";
            links.Add(link);


            EmailProperty emailBody = new EmailProperty();
            EmailProperty emailTo   = new EmailProperty();
            EmailProperty emailFrom = new EmailProperty();

            emailBody.Name  = "Body";
            emailBody.Value = "This is the Body";
            emailBody.Link  = link;
            empProps.Add(emailBody);

            emailTo.Name  = "To";
            emailTo.Value = "*****@*****.**";
            emailTo.Link  = link;
            empProps.Add(emailTo);

            emailFrom.Name  = "From";
            emailFrom.Value = "*****@*****.**";
            emailFrom.Link  = link;
            empProps.Add(emailFrom);


            emailProperties.List = empProps;
            emailProperties.Link = link;

            body.DocumentProperties = emailProperties;
            body.Links = links;

            try
            {
                // Invoke Aspose.Email Cloud SDK API to add new email
                EmailDocumentResponse apiResponse = emailApi.PutCreateNewEmail(fileName, storage, folder, body);

                if (apiResponse != null)
                {
                    Com.Aspose.Storage.Model.ResponseMessage storageRes = storageApi.GetDownload(fileName, null, null);
                    System.IO.File.WriteAllBytes(Common.GetDataDir() + fileName, storageRes.ResponseStream);
                    Console.WriteLine("Add New Email, Done!");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
            // ExEnd:1
        }