public void NewBatchWorkItemParametersTest()
        {
            // Setup cmdlet without the required parameters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
            cmdlet.BatchContext = context;
            
            Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());

            cmdlet.Name = "testWorkItem";

            // Don't go to the service on an AddWorkItem call
            YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
            {
                if (request is AddWorkItemRequest)
                {
                    AddWorkItemResponse response = new AddWorkItemResponse();
                    Task<object> task = Task<object>.Factory.StartNew(() => { return response; });
                    return task;
                }
                return null;
            });
            cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

            // Verify no exceptions when required parameters are set
            cmdlet.ExecuteCmdlet();
        }
Пример #2
0
        public void NewBatchWorkItemParametersTest()
        {
            // Setup cmdlet without the required parameters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;

            Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet());

            cmdlet.Name = "testWorkItem";

            // Don't go to the service on an AddWorkItem call
            YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
            {
                if (request is AddWorkItemRequest)
                {
                    AddWorkItemResponse response = new AddWorkItemResponse();
                    Task <object> task           = Task <object> .Factory.StartNew(() => { return(response); });
                    return(task);
                }
                return(null);
            });

            cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>()
            {
                interceptor
            };

            // Verify no exceptions when required parameters are set
            cmdlet.ExecuteCmdlet();
        }
Пример #3
0
        protected override async Task <SendResult> Send(IWin32Window Owner, Output Output, ImageData ImageData)
        {
            try
            {
                HttpBindingBase binding;
                if (Output.Url.StartsWith("https", StringComparison.InvariantCultureIgnoreCase))
                {
                    binding = new BasicHttpsBinding();
                }
                else
                {
                    binding = new BasicHttpBinding();
                }
                binding.MaxBufferSize          = int.MaxValue;
                binding.MaxReceivedMessageSize = int.MaxValue;

                WorkItemSoapClient informUp = new WorkItemSoapClient(binding, new EndpointAddress(Output.Url + "/Services/WorkItem.asmx"));


                string fileName = AttributeHelper.ReplaceAttributes(Output.FileName, ImageData);


                // Show send window
                Send send = new Send(Output.Url, Output.LastItemType, Output.LastItemID, fileName);

                var sendOwnerHelper = new System.Windows.Interop.WindowInteropHelper(send);
                sendOwnerHelper.Owner = Owner.Handle;

                if (!send.ShowDialog() == true)
                {
                    return(new SendResult(Result.Canceled));
                }


                string userName            = Output.UserName;
                string password            = Output.Password;
                bool   showLogin           = string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password);
                bool   rememberCredentials = false;

                while (true)
                {
                    if (showLogin)
                    {
                        // Show credentials window
                        Credentials credentials = new Credentials(Output.Url, userName, password, rememberCredentials);

                        var credentialsOwnerHelper = new System.Windows.Interop.WindowInteropHelper(credentials);
                        credentialsOwnerHelper.Owner = Owner.Handle;

                        if (credentials.ShowDialog() != true)
                        {
                            return(new SendResult(Result.Canceled));
                        }

                        userName            = credentials.UserName;
                        password            = credentials.Password;
                        rememberCredentials = credentials.Remember;
                    }

                    string itemType = null;
                    int    itemID;

                    if (send.CreateNewItem)
                    {
                        itemType = send.ItemType;

                        AddWorkItemResponse addWorkItemResult = await informUp.AddWorkItemAsync(userName, password, send.ItemType, send.ItemTitle, send.Description);

                        if (!int.TryParse(addWorkItemResult.Body.AddWorkItemResult, out itemID))
                        {
                            if (addWorkItemResult.Body.AddWorkItemResult.Equals("Login or Password is incorrect", StringComparison.InvariantCultureIgnoreCase))
                            {
                                showLogin = true;
                                continue;
                            }
                            else
                            {
                                return(new SendResult(Result.Failed, addWorkItemResult.Body.AddWorkItemResult));
                            }
                        }
                    }
                    else
                    {
                        itemType = Output.LastItemType;
                        itemID   = send.ItemID;
                    }

                    IFileFormat fileFormat = FileHelper.GetFileFormat(Output.FileFormatID);

                    string fullFileName = String.Format("{0}.{1}", send.FileName, fileFormat.FileExtension);
                    byte[] fileBytes    = FileHelper.GetFileBytes(Output.FileFormatID, ImageData);

                    UploadFileResponse uploadFileResult = await informUp.UploadFileAsync(userName, password, fileBytes, fullFileName, itemID);

                    if (!uploadFileResult.Body.UploadFileResult.Equals("OK", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(new SendResult(Result.Failed, uploadFileResult.ToString()));
                    }


                    // Open item in browser
                    if (Output.OpenItemInBrowser)
                    {
                        WebHelper.OpenUrl(String.Format("{0}/Main.aspx?ID={1}&Window=PopupItem", Output.Url, itemID));
                    }

                    return(new SendResult(Result.Success,
                                          new Output(Output.Name,
                                                     Output.Url,
                                                     (rememberCredentials) ? userName : Output.UserName,
                                                     (rememberCredentials) ? password : Output.Password,
                                                     Output.FileName,
                                                     Output.FileFormatID,
                                                     Output.OpenItemInBrowser,
                                                     itemType,
                                                     itemID)));
                }
            }
            catch (Exception ex)
            {
                return(new SendResult(Result.Failed, ex.Message));
            }
        }