コード例 #1
0
        public HttpResponseMessage GetModulesDetails()
        {
            var sessionId = "0";

            try
            {
                sessionId = SuiteWrapper.Login().GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.Message.ToString()));
            }
            try
            {
                var req = new SuiteAPI.ReadEntryListRequest();
                req.SessionId  = sessionId;
                req.ModuleName = "Contacts";
                req.MethodName = "get_module_fields";
                var list = SuiteWrapper.GetModuleList <CMSModels.ModuleDetails>(req).GetAwaiter().GetResult();
                return(Request.CreateResponse(HttpStatusCode.OK, list));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message.ToString()));
            }
        }
コード例 #2
0
        //Path: /api/Contact/PullContacts
        public HttpResponseMessage PullContacts()
        {
            // Trace Log
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called PullClientData");
            var sessionId = "0";

            try
            {
                sessionId = SuiteWrapper.Login().GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while generating session id is " + ex.ToString());
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.Message.ToString()));
            }

            try
            {
                List <string> vs = new List <string>();
                vs.Add("id");

                var req = new SuiteAPI.ReadEntryListRequest();
                req.SessionId             = sessionId;
                req.MethodName            = "get_entry_list";
                req.ModuleName            = "Contacts";
                req.LinkNameToFieldsArray = new Dictionary <string, object>()
                {
                    { "name", "contacts_add1_addresses_1" },
                    { "value", vs }
                };
                PropertyInfo[] props = typeof(PullContact).GetProperties();
                req.SelectFields = SuiteAPI.SuiteWrapper.GetFieldList(props);
                var list         = SuiteWrapper.GetList <PullContact>(req).GetAwaiter().GetResult();
                var pullResponse = PullResponseWithoutPagination <PullContact> .pullResponse(list);


                SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pullResponse));
                return(Request.CreateResponse(HttpStatusCode.OK, pullResponse));
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while pulling data is : " + ex.ToString());
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message.ToString()));
            }
        }
コード例 #3
0
        public HttpResponseMessage PullMasterData(string methodName, string lastSyncDate = null, int?nextOffSet = null, bool deleted = false)
        {
            // Trace Log
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'PullMasterData' with request : MethodName-" + methodName + " and nextOffSet=" + nextOffSet);
            var sessionId = "0";

            try
            {
                sessionId = SuiteWrapper.Login().GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while generating session id is " + ex.ToString());
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.Message.ToString()));
            }

            var query = string.Empty;
            var req   = new SuiteAPI.ReadEntryListRequest();

            req.SessionId  = sessionId;
            req.MethodName = "get_entry_list";
            req.MaxResults = SuiteWrapper.maxPullResults;
            req.Deleted    = deleted;
            if (nextOffSet != null && nextOffSet > 0)
            {
                req.Offset = nextOffSet;
            }
            int v = (req.Deleted) ? 1 : 0;

            try
            {
                if (methodName == "Artists")
                {
                    req.ModuleName = "A1_Artists";
                    PropertyInfo[] props = typeof(PullArtist).GetProperties();
                    req.SelectFields = SuiteAPI.SuiteWrapper.GetFieldList(props);
                    query            = "A1_Artists.deleted=" + Convert.ToInt32((req.Deleted) ? 1 : 0) + " ";
                    if (!string.IsNullOrEmpty(lastSyncDate))
                    {
                        req.Query = query + "and A1_Artists.date_modified >='" + lastSyncDate + "'";
                    }
                    else
                    {
                        req.Query = query;
                    }
                    var list         = SuiteWrapper.GetList <PullArtist>(req).GetAwaiter().GetResult();
                    var pullResponse = PullResponse <PullArtist> .pullResponse(list, methodName, deleted, lastSyncDate);

                    SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pullResponse));

                    return(Request.CreateResponse(HttpStatusCode.OK, pullResponse));
                }
                else if (methodName == "Auctions")
                {
                    req.ModuleName = "AC1_Auction_Calendar";
                    PropertyInfo[] props = typeof(PullAuctionCalendar).GetProperties();
                    query = "AC1_Auction_Calendar.deleted=" + Convert.ToInt32((req.Deleted) ? 1 : 0) + " ";
                    if (!string.IsNullOrEmpty(lastSyncDate))
                    {
                        req.Query = query + "and AC1_Auction_Calendar.date_modified >='" + lastSyncDate + "'";
                    }
                    else
                    {
                        req.Query = query;
                    }
                    var list         = SuiteWrapper.GetList <PullAuctionCalendar>(req).GetAwaiter().GetResult();
                    var pullResponse = PullResponse <PullAuctionCalendar> .pullResponse(list, methodName, deleted, lastSyncDate);

                    SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pullResponse));

                    return(Request.CreateResponse(HttpStatusCode.OK, pullResponse));
                }
                else if (methodName == "Symbols")
                {
                    req.ModuleName = "Sym1_Symbols";
                    PropertyInfo[] props = typeof(PullSymbols).GetProperties();
                    req.SelectFields = SuiteAPI.SuiteWrapper.GetFieldList(props);
                    query            = "Sym1_Symbols.deleted=" + Convert.ToInt32((req.Deleted) ? 1 : 0) + " ";
                    if (!string.IsNullOrEmpty(lastSyncDate))
                    {
                        req.Query = query + "and Sym1_Symbols.date_modified >='" + lastSyncDate + "'";
                    }
                    else
                    {
                        req.Query = query;
                    }
                    var list         = SuiteWrapper.GetList <PullSymbols>(req).GetAwaiter().GetResult();
                    var pullResponse = PullResponse <PullSymbols> .pullResponse(list, methodName, deleted, lastSyncDate);

                    SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pullResponse));

                    return(Request.CreateResponse(HttpStatusCode.OK, pullResponse));
                }
                else if (methodName == "Locations")
                {
                    req.ModuleName = "loc_Location";
                    PropertyInfo[] props = typeof(PullLocation).GetProperties();
                    req.SelectFields = SuiteAPI.SuiteWrapper.GetFieldList(props);
                    query            = "loc_Location.deleted=" + Convert.ToInt32((req.Deleted) ? 1 : 0) + " ";
                    if (!string.IsNullOrEmpty(lastSyncDate))
                    {
                        req.Query = query + "and loc_Location.date_modified >='" + lastSyncDate + "'";
                    }
                    else
                    {
                        req.Query = query;
                    }
                    var list         = SuiteWrapper.GetList <PullLocation>(req).GetAwaiter().GetResult();
                    var pullResponse = PullResponse <PullLocation> .pullResponse(list, methodName, deleted, lastSyncDate);

                    SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pullResponse));

                    return(Request.CreateResponse(HttpStatusCode.OK, pullResponse));
                }
                else if (methodName == "Categories")
                {
                    req.ModuleName = "Cat1_Categories";
                    PropertyInfo[] props = typeof(PullCategories).GetProperties();
                    req.SelectFields = SuiteAPI.SuiteWrapper.GetFieldList(props);
                    query            = "Cat1_Categories.deleted=" + Convert.ToInt32((req.Deleted) ? 1 : 0) + " ";
                    if (!string.IsNullOrEmpty(lastSyncDate))
                    {
                        req.Query = query + "and Cat1_Categories.date_modified >='" + lastSyncDate + "'";
                    }
                    else
                    {
                        req.Query = query;
                    }
                    var list         = SuiteWrapper.GetList <PullCategories>(req).GetAwaiter().GetResult();
                    var pullResponse = PullResponse <PullCategories> .pullResponse(list, methodName, deleted, lastSyncDate);

                    SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pullResponse));

                    return(Request.CreateResponse(HttpStatusCode.OK, pullResponse));
                }
                else
                {
                    SuiteWrapper.WriteTraceLog("Invalid Pull request method name : " + methodName);
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Method name '" + methodName + "' not found."));
                }
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while pulling the data is " + ex.ToString());
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message.ToString()));
            }
        }