Ejemplo n.º 1
0
        public Asset SerialNumberValidation(string serialNum, string orgId, int _logIncidentId = 0, int _logContactId = 0)
        {
            // can reuse SRURL, service username and password, is all the same 
            if (String.IsNullOrWhiteSpace(SRURL) || String.IsNullOrWhiteSpace(SRServiceUsername) || String.IsNullOrWhiteSpace(SRServicePassword))
            {
                throw new Exception("Provider's InitForAsset not run.");
            }

            string request, response, logMessage, logNote;

            ASSETSVC.AssetManagementPortClient client = new ASSETSVC.AssetManagementPortClient(binding, addr);
            MyEndpointBehavior eBehavior = new MyEndpointBehavior();
            client.Endpoint.Behaviors.Add(eBehavior);
            if (SRServiceTimeout > 0)
                client.InnerChannel.OperationTimeout = TimeSpan.FromMilliseconds(SRServiceTimeout);

            Asset retval = null;

            ASSETSVC.AssetManagementQueryPage_Input ip = new ASSETSVC.AssetManagementQueryPage_Input();

            ip.ListOfAsset_Management_Io = new ASSETSVC.ListOfAsset_Management_IoQuery();
            ip.ListOfAsset_Management_Io.AssetMgmtAsset = new ASSETSVC.AssetMgmtAssetQuery();


            ip.ListOfAsset_Management_Io.AssetMgmtAsset.SerialNumber = new ASSETSVC.queryType();
            ip.ListOfAsset_Management_Io.AssetMgmtAsset.SerialNumber.Value = "='" + serialNum + "'";

            ip.ListOfAsset_Management_Io.AssetMgmtAsset.OrganizationId = new ASSETSVC.queryType();
            ip.ListOfAsset_Management_Io.AssetMgmtAsset.OrganizationId.Value = "='" + orgId + "'";

            ip.ListOfAsset_Management_Io.AssetMgmtAsset.Id= new ASSETSVC.queryType();
            ip.ListOfAsset_Management_Io.AssetMgmtAsset.Id.Value = String.Empty;

            ip.ListOfAsset_Management_Io.AssetMgmtAsset.ProductId = new ASSETSVC.queryType();
            ip.ListOfAsset_Management_Io.AssetMgmtAsset.ProductId.Value = String.Empty;

            ip.ListOfAsset_Management_Io.AssetMgmtAsset.ProductName = new ASSETSVC.queryType();
            ip.ListOfAsset_Management_Io.AssetMgmtAsset.ProductName.Value = String.Empty;

            ip.LOVLanguageMode = "LIC";
            ip.ViewMode = "All";
            Stopwatch stopwatch = new Stopwatch();
            ASSETSVC.AssetManagementQueryPage_Output opList;
            try
            {
                using (new OperationContextScope(client.InnerChannel))
                {
                    MessageHeader usrMsgHdr = MessageHeader.CreateHeader("UsernameToken", "http://siebel.com/webservices", SRServiceUsername);
                    OperationContext.Current.OutgoingMessageHeaders.Add(usrMsgHdr);
                    MessageHeader pwdMsgHdr = MessageHeader.CreateHeader("PasswordText", "http://siebel.com/webservices", SRServicePassword);
                    OperationContext.Current.OutgoingMessageHeaders.Add(pwdMsgHdr);
                    stopwatch.Start();
                    opList = client.AssetManagementQueryPage(ip);
                    stopwatch.Stop();
                    request = eBehavior.msgInspector.reqPayload;
                    response = eBehavior.msgInspector.resPayload;
                }

                ASSETSVC.AssetMgmtAssetData[] assets = opList.ListOfAsset_Management_Io.AssetMgmtAsset;
                if (assets == null)
                {
                    retval = null;

                    logMessage = "Request of serial number validation (Failure). Serial Number = " + serialNum + "; Account Org ID = " + orgId;
                    logNote = "Request Payload: " + request;
                    log.NoticeLog(_logIncidentId, _logContactId, logMessage, logNote);

                    logMessage = "Response of serial number validation (Failure). Serial Number = " + serialNum + "; Account Org ID = " + orgId;
                    logNote = "Response Payload: " + response;
                    log.NoticeLog(_logIncidentId, _logContactId, logMessage, logNote, (int)stopwatch.ElapsedMilliseconds);
                }
                else
                {
                    ASSETSVC.AssetMgmtAssetData asset = assets[0];
                    retval = new Asset();
                    retval.AssetID = asset.Id;
                    retval.SerialNumber = asset.SerialNumber;
                    retval.AccountOrgID = asset.AccountOrgId;
                    retval.ProductID = asset.ProductId;
                    retval.ProductName = asset.ProductName;

                    logMessage = "Request of serial number validation (Success). Serial Number = " + serialNum + "; Account Org ID = " + orgId;
                    logNote = "Request Payload: " + request;
                    log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote);

                    logMessage = "Response of serial number validation (Success). Serial Number = " + serialNum + "; Account Org ID = " + orgId;
                    logNote = "Response Payload: " + response;
                    log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote, (int)stopwatch.ElapsedMilliseconds);
                }
            }
            catch (Exception ex)
            {

                request = eBehavior.msgInspector.reqPayload;
                response = eBehavior.msgInspector.resPayload;

                retval = new Asset();
                retval.ErrorMessage = "There has been an error communicating with Siebel. Please check log for detail.";
                logMessage = "Request of serial number validation (Failure). Serial Number = " + serialNum + "; Account Org ID = " + orgId + "; Error: " + ex.Message;
                logNote = "Request Payload: " + request;
                log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote);

                logMessage = "Response of serial number validation (Failure). Serial Number = " + serialNum + "; Account Org ID = " + orgId + "; Error: " + ex.Message;
                logNote = "Response Payload: " + response;
                log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote);

                handleSiebelException(ex, "Lookup Service Request", _logIncidentId, _logContactId);
            }
            

            return retval;
        }
Ejemplo n.º 2
0
        public Dictionary<string, string> LookupAssetDetail(IList<string> columns, string serialNum, string orgId, int _logIncidentId = 0, int _logContactId = 0)
        {
            // can reuse SRURL, service username and password, is all the same 
            if (String.IsNullOrWhiteSpace(SRURL) || String.IsNullOrWhiteSpace(SRServiceUsername) || String.IsNullOrWhiteSpace(SRServicePassword))
            {
                throw new Exception("Provider's InitForAsset not run.");
            }
            string request, response, logMessage, logNote;

            ASSETSVC.AssetManagementPortClient client = new ASSETSVC.AssetManagementPortClient(binding, addr);
            MyEndpointBehavior eBehavior = new MyEndpointBehavior();
            client.Endpoint.Behaviors.Add(eBehavior);
            if (SRServiceTimeout > 0)
                client.InnerChannel.OperationTimeout = TimeSpan.FromMilliseconds(SRServiceTimeout);

            ASSETSVC.AssetManagementQueryPage_Input ip = new ASSETSVC.AssetManagementQueryPage_Input();

            ip.ListOfAsset_Management_Io = new ASSETSVC.ListOfAsset_Management_IoQuery();
            ip.ListOfAsset_Management_Io.AssetMgmtAsset = new ASSETSVC.AssetMgmtAssetQuery();

            foreach (PropertyInfo propertyInfo in ip.ListOfAsset_Management_Io.AssetMgmtAsset.GetType().GetProperties())
            {
                foreach (string column in columns)
                {
                    if (propertyInfo.Name == column.Split('.')[1])
                    {
                        if (propertyInfo.PropertyType == typeof(ASSETSVC.queryType))
                        {
                            ASSETSVC.queryType queryType = new ASSETSVC.queryType();
                            propertyInfo.SetValue(ip.ListOfAsset_Management_Io.AssetMgmtAsset, queryType, null);
                        }
                        break;
                    }
                }
            }

            ip.ListOfAsset_Management_Io.AssetMgmtAsset.SerialNumber = new ASSETSVC.queryType();
            ip.ListOfAsset_Management_Io.AssetMgmtAsset.SerialNumber.Value = "='" + serialNum + "'";

            ip.ListOfAsset_Management_Io.AssetMgmtAsset.OrganizationId = new ASSETSVC.queryType();
            ip.ListOfAsset_Management_Io.AssetMgmtAsset.OrganizationId.Value = "='" + orgId + "'";

            ip.LOVLanguageMode = "LIC";
            ip.ViewMode = "All";

            ASSETSVC.AssetManagementQueryPage_Output opList;
            Stopwatch stopwatch = new Stopwatch();
            try
            {
                using (new OperationContextScope(client.InnerChannel))
                {
                    MessageHeader usrMsgHdr = MessageHeader.CreateHeader("UsernameToken", "http://siebel.com/webservices", SRServiceUsername);
                    OperationContext.Current.OutgoingMessageHeaders.Add(usrMsgHdr);
                    MessageHeader pwdMsgHdr = MessageHeader.CreateHeader("PasswordText", "http://siebel.com/webservices", SRServicePassword);
                    OperationContext.Current.OutgoingMessageHeaders.Add(pwdMsgHdr);
                    stopwatch.Start();
                    opList = client.AssetManagementQueryPage(ip);
                    stopwatch.Stop();
                    request = eBehavior.msgInspector.reqPayload;
                    logMessage = "Request of asset (Success). Siebel serialNum = " + serialNum + ", orgId = " + orgId;
                    logNote = "Request Payload: " + request;
                    log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote);
                    response = eBehavior.msgInspector.resPayload;
                    logMessage = "Response of asset (Success). Siebel serialNum = " + serialNum + ", orgId = " + orgId;
                    logNote = "Response Payload: " + response;
                    log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote, (int)stopwatch.ElapsedMilliseconds);
                }
            }
            catch (Exception ex)
            {
                request = eBehavior.msgInspector.reqPayload;
                logMessage = "Request of asset (Failure). Siebel serialNum = " + serialNum + ", orgId = " + orgId;
                logNote = "Request Payload: " + request;
                log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote);
                response = eBehavior.msgInspector.resPayload;
                logMessage = "Response of asset (Failure). Siebel serialNum = " + serialNum + ", orgId = " + orgId;
                logNote = "Response Payload: " + response;
                log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote);
                handleSiebelException(ex, "client.AssetManagementQueryPage(ip)");
                throw ex;
            }

            if (opList.ListOfAsset_Management_Io.AssetMgmtAsset == null)
            {
                return null;
            }

            Dictionary<string, string> dictDetail = new Dictionary<string, string>();

            ASSETSVC.AssetMgmtAssetData assetData = opList.ListOfAsset_Management_Io.AssetMgmtAsset[0];
            foreach (PropertyInfo propertyInfo in assetData.GetType().GetProperties())
            {
                Object propVal = assetData.GetType().GetProperty(propertyInfo.Name).GetValue(assetData, null);
                dictAddProperty(propertyInfo, propVal, ref dictDetail);
            }

            return dictDetail;
        }