Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public void Execute(IList <IReportRow> rows)
        {
            List <int> incId            = new List <int>();
            List <int> incVinId         = new List <int>();
            int        parentIncidentId = 0;// This will store Internal Incident ID when user delete Incident_VIN record

            foreach (IReportRow row in rows)
            {
                IList <IReportCell> cells = row.Cells;

                foreach (IReportCell cell in cells)
                {
                    // This condition is for parent report
                    if (cell.Name == "Internal_Incident_ID")
                    {
                        incId.Add(Convert.ToInt32(cell.Value));
                        break;
                    }
                    /* Below 2 check is for sub report */
                    if (cell.Name == "Incident_VIN_ID")
                    {
                        incVinId.Add(Convert.ToInt32(cell.Value));
                    }
                    if (cell.Name == "Parent_Incident")//meaning.. Incident ID mapped to Incident_VIN record
                    {
                        parentIncidentId = Convert.ToInt32(cell.Value);
                    }
                }
            }
            //If Incident ID exist
            if (incId != null && incId.Count > 0)
            {
                DialogResult result = MessageBox.Show("Are you sure you want to delete selected SR(s)?", "Confirmation", MessageBoxButtons.YesNoCancel);
                if (result == DialogResult.Yes)
                {
                    RightNowConnectService.GetService().DeleteInternalIncident(incId);
                    _globalContext.AutomationContext.CurrentWorkspace.ExecuteEditorCommand(RightNow.AddIns.Common.EditorCommand.Save);
                }
            }
            //If incident_Vin id exist
            if (incVinId != null && incVinId.Count > 0)
            {
                DialogResult result = MessageBox.Show("Are you sure you want to delete selected VIN(s)?", "Confirmation", MessageBoxButtons.YesNoCancel);
                if (result == DialogResult.Yes)
                {
                    RightNowConnectService.GetService().DeleteIncidentVIN(incVinId);
                    //If user has deleted all VIN of affected SR, then delete Internal incident too
                    RightNowConnectService.GetService().IncidentVinCountForInternalInc(parentIncidentId);
                    _globalContext.AutomationContext.CurrentWorkspace.ExecuteEditorCommand(RightNow.AddIns.Common.EditorCommand.Save);
                }
            }
        }
        public static RightNowConnectService GetService()
        {
            if (_rightnowConnectService != null)
            {
                return(_rightnowConnectService);
            }

            try
            {
                lock (_sync)
                {
                    if (_rightnowConnectService == null)
                    {
                        // Initialize client with current interface soap url
                        string          url      = ReportCommandAddIn._globalContext.GetInterfaceServiceUrl(ConnectServiceType.Soap);
                        EndpointAddress endpoint = new EndpointAddress(url);

                        BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
                        binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

                        // Optional depending upon use cases
                        binding.MaxReceivedMessageSize = 1024 * 1024;
                        binding.MaxBufferSize          = 1024 * 1024;
                        binding.MessageEncoding        = WSMessageEncoding.Mtom;

                        _rightNowClient = new RightNowSyncPortClient(binding, endpoint);

                        BindingElementCollection elements = _rightNowClient.Endpoint.Binding.CreateBindingElements();
                        elements.Find <SecurityBindingElement>().IncludeTimestamp = false;
                        _rightNowClient.Endpoint.Binding = new CustomBinding(elements);
                        ReportCommandAddIn._globalContext.PrepareConnectSession(_rightNowClient.ChannelFactory);

                        _rightnowConnectService = new RightNowConnectService();
                    }
                }
            }
            catch (Exception e)
            {
                _rightnowConnectService = null;
                MessageBox.Show(e.Message);
            }
            return(_rightnowConnectService);
        }