Example #1
0
		/// <summary>The method to delink record</summary>
		/// <param name="relatedRecordId">long?</param>
		/// <param name="headerInstance">Instance of HeaderMap</param>
		/// <returns>Instance of APIResponse<ActionHandler></returns>
		public APIResponse<ActionHandler> DelinkRecord(long? relatedRecordId, HeaderMap headerInstance)
		{
			CommonAPIHandler handlerInstance=new CommonAPIHandler();

			string apiPath="";

			apiPath=string.Concat(apiPath, "/crm/v2/");

			apiPath=string.Concat(apiPath,  this.moduleAPIName.ToString());

			apiPath=string.Concat(apiPath, "/");

			apiPath=string.Concat(apiPath,  this.recordId.ToString());

			apiPath=string.Concat(apiPath, "/");

			apiPath=string.Concat(apiPath,  this.relatedListAPIName.ToString());

			apiPath=string.Concat(apiPath, "/");

			apiPath=string.Concat(apiPath, relatedRecordId.ToString());

			handlerInstance.APIPath=apiPath;

			handlerInstance.HttpMethod=Constants.REQUEST_METHOD_DELETE;

			handlerInstance.CategoryMethod=Constants.REQUEST_METHOD_DELETE;

			handlerInstance.Header=headerInstance;

			return handlerInstance.APICall<ActionHandler>(typeof(ActionHandler), "application/json");


		}
Example #2
0
		/// <summary>The method to get related records</summary>
		/// <param name="paramInstance">Instance of ParameterMap</param>
		/// <param name="headerInstance">Instance of HeaderMap</param>
		/// <returns>Instance of APIResponse<ResponseHandler></returns>
		public APIResponse<ResponseHandler> GetRelatedRecords(ParameterMap paramInstance, HeaderMap headerInstance)
		{
			CommonAPIHandler handlerInstance=new CommonAPIHandler();

			string apiPath="";

			apiPath=string.Concat(apiPath, "/crm/v2/");

			apiPath=string.Concat(apiPath,  this.moduleAPIName.ToString());

			apiPath=string.Concat(apiPath, "/");

			apiPath=string.Concat(apiPath,  this.recordId.ToString());

			apiPath=string.Concat(apiPath, "/");

			apiPath=string.Concat(apiPath,  this.relatedListAPIName.ToString());

			handlerInstance.APIPath=apiPath;

			handlerInstance.HttpMethod=Constants.REQUEST_METHOD_GET;

			handlerInstance.CategoryMethod=Constants.REQUEST_CATEGORY_READ;

			handlerInstance.Param=paramInstance;

			handlerInstance.Header=headerInstance;

			Utility.GetRelatedLists( this.relatedListAPIName,  this.moduleAPIName, handlerInstance);

			return handlerInstance.APICall<ResponseHandler>(typeof(ResponseHandler), "application/json");


		}
Example #3
0
        public static string PostBytes(string URI, byte[] Data, HeaderMap Headers = null)
        {
            WebClient client = new WebClient();

            FillHeaders(client, Headers);

            return(client.Encoding.GetString(client.UploadData(URI, Data)));
        }
Example #4
0
        public static string PostString(string URI, string Data = "", HeaderMap Headers = null)
        {
            WebClient client = new WebClient();

            FillHeaders(client, Headers);

            return(client.UploadString(URI, Data));
        }
Example #5
0
        public static string Get(string URI, HeaderMap Headers = null)
        {
            WebClient client = new WebClient();

            FillHeaders(client, Headers);

            return(client.DownloadString(URI));
        }
Example #6
0
        public static string Post(string URI, HeaderMap Headers = null, ParameterMap Parameters = null)
        {
            WebClient client = new WebClient();

            FillHeaders(client, Headers);

            NameValueCollection parameters = BuildParameters(Parameters);

            return(client.Encoding.GetString(client.UploadValues(URI, "POST", parameters)));
        }
Example #7
0
        private static void FillHeaders(WebClient Client, HeaderMap Headers)
        {
            if (Headers == null)
            {
                return;
            }

            HeaderMap.Enumerator it = Headers.GetEnumerator();
            while (it.MoveNext())
            {
                Client.Headers.Add(it.Current.Key, it.Current.Value);
            }
        }
Example #8
0
        private void ParseAndUpload(string fileContents)
        {
            //Convert the string to the individual entries
            //Handles both Unix and Windows new lines
            List <string> entries = new List <string>(fileContents.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries));

            //Excel defaults to outputting rows of all commas so this handles that
            //This strips all rows that have only commas
            Regex r = new Regex(@"[^\\,]");

            entries.RemoveAll(e => !r.IsMatch(e));

            //Pull out the header to its own list and extract key data
            //Convert to using a map stored with indicies so everything can be remapped

            var header = new List <string>(entries[0].Split(','));

            entries.RemoveAt(0);

            //Strip whitespace from all fields in header
            for (int i = 0; i < header.Count; i++)
            {
                header[i] = string.Concat(header[i].Where(c => !char.IsWhiteSpace(c)));
            }

            var template = TemplateDal.GetCurrentTemplate();

            foreach (string entry in entries)
            {
                //Removes commas from fields that are enclosed in quotes
                string result = Regex.Replace(entry, @",(?=[^""]*""(?:[^""]*""[^""]*"")*[^""]*$)", String.Empty);

                //Removes quotes from within fields
                result = result.Replace("\"", "");
                List <string> data     = new List <string>(result.Split(','));
                var           tempCase = HeaderMap.MapToCase(header, data);
                tempCase.id          = Guid.NewGuid().ToString();
                tempCase.Status      = CaseStatus.Available.ToString();
                tempCase.Template    = template;
                tempCase.UpdatedOn   = DateTime.Now;
                tempCase.RecordAudit = new List <Tuple <string, DateTime, Dictionary <string, string> > >();
                CaseDal.UploadCase(tempCase);
                //Used to handle two jurisidictions getting to work on two seperate documents for the same case
                if (tempCase.Jurisdiction != tempCase.Data["ResidentJurisdiction"])
                {
                    tempCase.Jurisdiction = tempCase.Data["ResidentJurisdiction"];
                    tempCase.id           = Guid.NewGuid().ToString();
                    CaseDal.UploadCase(tempCase);
                }
            }
        }
Example #9
0
        /// <summary>
        /// This method to add an API request header.
        /// </summary>
        /// <typeparam name="T">A T containing the specified method type.</typeparam>
        /// <param name="headerInstance">A Header instance the API request header.</param>
        /// <param name="headerValue">A T containing the API request header value.</param>
        public void AddHeader <T>(Header <T> headerInstance, T headerValue)
        {
            if (headerValue == null)
            {
                return;
            }

            if (header == null)
            {
                header = new HeaderMap();
            }

            header.Add(headerInstance, headerValue);
        }
Example #10
0
        /// <summary>The method to get modules</summary>
        /// <param name="headerInstance">Instance of HeaderMap</param>
        /// <returns>Instance of APIResponse<ResponseHandler></returns>
        public APIResponse <ResponseHandler> GetModules(HeaderMap headerInstance)
        {
            CommonAPIHandler handlerInstance = new CommonAPIHandler();

            string apiPath = "";

            apiPath = string.Concat(apiPath, "/crm/v2.1/settings/modules");

            handlerInstance.APIPath = apiPath;

            handlerInstance.HttpMethod = Constants.REQUEST_METHOD_GET;

            handlerInstance.CategoryMethod = Constants.REQUEST_CATEGORY_READ;

            handlerInstance.Header = headerInstance;

            return(handlerInstance.APICall <ResponseHandler>(typeof(ResponseHandler), "application/json"));
        }
Example #11
0
        /// <summary>The method to get user</summary>
        /// <param name="id">long?</param>
        /// <param name="headerInstance">Instance of HeaderMap</param>
        /// <returns>Instance of APIResponse<ResponseHandler></returns>
        public APIResponse <ResponseHandler> GetUser(long?id, HeaderMap headerInstance)
        {
            CommonAPIHandler handlerInstance = new CommonAPIHandler();

            string apiPath = "";

            apiPath = string.Concat(apiPath, "/crm/v2/users/");

            apiPath = string.Concat(apiPath, id.ToString());

            handlerInstance.APIPath = apiPath;

            handlerInstance.HttpMethod = Constants.REQUEST_METHOD_GET;

            handlerInstance.CategoryMethod = Constants.REQUEST_CATEGORY_READ;

            handlerInstance.Header = headerInstance;

            return(handlerInstance.APICall <ResponseHandler>(typeof(ResponseHandler), "application/json"));
        }
Example #12
0
        /// <summary>The method to upload file</summary>
        /// <param name="request">Instance of FileBodyWrapper</param>
        /// <param name="headerInstance">Instance of HeaderMap</param>
        /// <returns>Instance of APIResponse<ActionResponse></returns>
        public APIResponse <ActionResponse> UploadFile(FileBodyWrapper request, HeaderMap headerInstance)
        {
            CommonAPIHandler handlerInstance = new CommonAPIHandler();

            string apiPath = "";

            apiPath = string.Concat(apiPath, "https://content.zohoapis.com/crm/v2/upload");

            handlerInstance.APIPath = apiPath;

            handlerInstance.HttpMethod = Constants.REQUEST_METHOD_POST;

            handlerInstance.CategoryMethod = Constants.REQUEST_CATEGORY_CREATE;

            handlerInstance.ContentType = "multipart/form-data";

            handlerInstance.Request = request;

            handlerInstance.MandatoryChecker = true;

            handlerInstance.Header = headerInstance;

            return(handlerInstance.APICall <ActionResponse>(typeof(ActionResponse), "application/json"));
        }
Example #13
0
        /// <summary>
        /// This method is used to upload a CSV file in ZIP format for bulk write API. The response contains the file_id.
        /// Use this ID while making the bulk write request.
        /// </summary>
        /// <param name="orgID">The unique ID (zgid) of your organization obtained through the Organization API.</param>
        /// <param name="absoluteFilePath">The absoluteFilePath of the zip file you want to upload.</param>
        public static void UploadFile(string orgID, string absoluteFilePath)
        {
            //example
            //string absoluteFilePath = "/Users/user_name/Documents/Leads.zip";
            //string orgID = "673573045";

            //Get instance of BulkWriteOperations Class
            BulkWriteOperations bulkWriteOperations = new BulkWriteOperations();

            //Get instance of FileBodyWrapper class that will contain the request file
            FileBodyWrapper fileBodyWrapper = new FileBodyWrapper();

            //Get instance of StreamWrapper class that takes absolute path of the file to be attached as parameter
            StreamWrapper streamWrapper = new StreamWrapper(absoluteFilePath);

            //FileInfo fileInfo = new FileInfo(absoluteFilePath);

            //Get instance of StreamWrapper class that takes file name and stream of the file to be attached as parameter
            //StreamWrapper streamWrapper = new StreamWrapper(fileInfo.Name, fileInfo.OpenRead());

            //Set file to the FileBodyWrapper instance
            fileBodyWrapper.File = streamWrapper;

            //Get instance of HeaderMap Class
            HeaderMap headerInstance = new HeaderMap();

            //To indicate that this a bulk write operation
            headerInstance.Add(UploadFileHeader.FEATURE, "bulk-write");

            headerInstance.Add(UploadFileHeader.X_CRM_ORG, orgID);

            //Call uploadFile method that takes FileBodyWrapper instance and headerInstance as parameter
            APIResponse <ActionResponse> response = bulkWriteOperations.UploadFile(fileBodyWrapper, headerInstance);

            if (response != null)
            {
                //Get the status code from response
                Console.WriteLine("Status Code: " + response.StatusCode);

                //Check if expected response is received
                if (response.IsExpected)
                {
                    //Get object from response
                    ActionResponse actionResponse = response.Object;

                    //Check if the request is successful
                    if (actionResponse is SuccessResponse)
                    {
                        //Get the received SuccessResponse instance
                        SuccessResponse successResponse = (SuccessResponse)actionResponse;

                        //Get the Status
                        Console.WriteLine("Status: " + successResponse.Status.Value);

                        //Get the Code
                        Console.WriteLine("Code: " + successResponse.Code.Value);

                        Console.WriteLine("Details: ");

                        //Get the details map
                        foreach (KeyValuePair <string, object> entry in successResponse.Details)
                        {
                            //Get each value in the map
                            Console.WriteLine(entry.Key + " : " + JsonConvert.SerializeObject(entry.Value));
                        }

                        //Get the Message
                        Console.WriteLine("Message: " + successResponse.Message.Value);
                    }
                    //Check if the request returned an exception
                    else if (actionResponse is APIException)
                    {
                        //Get the received APIException instance
                        APIException exception = (APIException)actionResponse;

                        if (exception.Status != null)
                        {
                            //Get the Status
                            Console.WriteLine("Status: " + exception.Status.Value);
                        }

                        if (exception.Code != null)
                        {
                            //Get the Code
                            Console.WriteLine("Code: " + exception.Code.Value);
                        }

                        if (exception.Message != null)
                        {
                            //Get the Message
                            Console.WriteLine("Message: " + exception.Message.Value);
                        }

                        Console.WriteLine("Details: ");

                        if (exception.Details != null)
                        {
                            //Get the details map
                            foreach (KeyValuePair <string, object> entry in exception.Details)
                            {
                                //Get each value in the map
                                Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value));
                            }
                        }

                        if (exception.ErrorMessage != null)
                        {
                            //Get the ErrorMessage
                            Console.WriteLine("ErrorMessage: " + exception.ErrorMessage.Value);
                        }

                        //Get the ErrorCode
                        Console.WriteLine("ErrorCode: " + exception.ErrorCode);

                        if (exception.XError != null)
                        {
                            //Get the XError
                            Console.WriteLine("XError: " + exception.XError.Value);
                        }

                        if (exception.Info != null)
                        {
                            //Get the Info
                            Console.WriteLine("Info: " + exception.Info.Value);
                        }

                        if (exception.XInfo != null)
                        {
                            //Get the XInfo
                            Console.WriteLine("XInfo: " + exception.XInfo.Value);
                        }

                        //Get the HttpStatus
                        Console.WriteLine("HttpStatus: " + exception.HttpStatus);
                    }
                }
                else
                { //If response is not as expected
                    //Get model object from response
                    Model responseObject = response.Model;

                    //Get the response object's class
                    Type type = responseObject.GetType();

                    //Get all declared fields of the response class
                    Console.WriteLine("Type is: {0}", type.Name);

                    PropertyInfo[] props = type.GetProperties();

                    Console.WriteLine("Properties (N = {0}):", props.Length);

                    foreach (var prop in props)
                    {
                        if (prop.GetIndexParameters().Length == 0)
                        {
                            Console.WriteLine("{0} ({1}) : {2}", prop.Name, prop.PropertyType.Name, prop.GetValue(responseObject));
                        }
                        else
                        {
                            Console.WriteLine("{0} ({1}) : <Indexed>", prop.Name, prop.PropertyType.Name);
                        }
                    }
                }
            }
        }
Example #14
0
        private static List <string> GetModules(string header)
        {
            List <string> apiNames = new List <string>();

            HeaderMap headerMap = new HeaderMap();

            if (header != null)
            {
                DateTimeOffset headerValue = DateTimeOffset.FromUnixTimeMilliseconds(Convert.ToInt64(header));

                DateTimeOffset targetTime = TimeZoneInfo.ConvertTime(headerValue, TimeZoneInfo.Local);

                headerMap.Add(GetModulesHeader.IF_MODIFIED_SINCE, targetTime);
            }

            APIResponse <Com.Zoho.Crm.API.Modules.ResponseHandler> response = new ModulesOperations().GetModules(headerMap);

            if (response != null)
            {
                if (new List <int>()
                {
                    Constants.NO_CONTENT_STATUS_CODE, Constants.NOT_MODIFIED_STATUS_CODE
                }.Contains(response.StatusCode))
                {
                    return(apiNames);
                }

                // Check if expected response is received
                if (response.IsExpected)
                {
                    Com.Zoho.Crm.API.Modules.ResponseHandler responseObject = response.Object;

                    if (responseObject is Com.Zoho.Crm.API.Modules.ResponseWrapper)
                    {
                        List <Module> modules = ((Com.Zoho.Crm.API.Modules.ResponseWrapper)responseObject).Modules;

                        foreach (Module module in modules)
                        {
                            if (module.APISupported != null && (bool)module.APISupported)
                            {
                                apiNames.Add(module.APIName);
                            }
                        }
                    }
                    else if (responseObject is Com.Zoho.Crm.API.Modules.APIException)
                    {
                        Com.Zoho.Crm.API.Modules.APIException exception = (Com.Zoho.Crm.API.Modules.APIException)responseObject;

                        JObject errorResponse = new JObject();

                        errorResponse.Add(Constants.CODE, exception.Code.Value);

                        errorResponse.Add(Constants.STATUS, exception.Status.Value);

                        errorResponse.Add(Constants.MESSAGE, exception.Message.Value);

                        throw new SDKException(Constants.API_EXCEPTION, errorResponse);
                    }
                }
            }

            return(apiNames);
        }
Example #15
0
        /// <summary>The method to update record using external id</summary>
        /// <param name="externalFieldValue">string</param>
        /// <param name="moduleAPIName">string</param>
        /// <param name="request">Instance of BodyWrapper</param>
        /// <param name="headerInstance">Instance of HeaderMap</param>
        /// <returns>Instance of APIResponse<ActionHandler></returns>
        public APIResponse <ActionHandler> UpdateRecordUsingExternalId(string externalFieldValue, string moduleAPIName, BodyWrapper request, HeaderMap headerInstance)
        {
            CommonAPIHandler handlerInstance = new CommonAPIHandler();

            string apiPath = "";

            apiPath = string.Concat(apiPath, "/crm/v2.1/");

            apiPath = string.Concat(apiPath, moduleAPIName.ToString());

            apiPath = string.Concat(apiPath, "/");

            apiPath = string.Concat(apiPath, externalFieldValue.ToString());

            handlerInstance.APIPath = apiPath;

            handlerInstance.HttpMethod = Constants.REQUEST_METHOD_PUT;

            handlerInstance.CategoryMethod = Constants.REQUEST_CATEGORY_UPDATE;

            handlerInstance.ContentType = "application/json";

            handlerInstance.Request = request;

            handlerInstance.Header = headerInstance;

            handlerInstance.ModuleAPIName = moduleAPIName;

            Utility.GetFields(moduleAPIName, handlerInstance);

            return(handlerInstance.APICall <ActionHandler>(typeof(ActionHandler), "application/json"));
        }
Example #16
0
		/// <summary>The method to update related record</summary>
		/// <param name="relatedRecordId">long?</param>
		/// <param name="request">Instance of BodyWrapper</param>
		/// <param name="headerInstance">Instance of HeaderMap</param>
		/// <returns>Instance of APIResponse<ActionHandler></returns>
		public APIResponse<ActionHandler> UpdateRelatedRecord(long? relatedRecordId, BodyWrapper request, HeaderMap headerInstance)
		{
			CommonAPIHandler handlerInstance=new CommonAPIHandler();

			string apiPath="";

			apiPath=string.Concat(apiPath, "/crm/v2/");

			apiPath=string.Concat(apiPath,  this.moduleAPIName.ToString());

			apiPath=string.Concat(apiPath, "/");

			apiPath=string.Concat(apiPath,  this.recordId.ToString());

			apiPath=string.Concat(apiPath, "/");

			apiPath=string.Concat(apiPath,  this.relatedListAPIName.ToString());

			apiPath=string.Concat(apiPath, "/");

			apiPath=string.Concat(apiPath, relatedRecordId.ToString());

			handlerInstance.APIPath=apiPath;

			handlerInstance.HttpMethod=Constants.REQUEST_METHOD_PUT;

			handlerInstance.CategoryMethod=Constants.REQUEST_CATEGORY_UPDATE;

			handlerInstance.ContentType="application/json";

			handlerInstance.Request=request;

			handlerInstance.Header=headerInstance;

			Utility.GetRelatedLists( this.relatedListAPIName,  this.moduleAPIName, handlerInstance);

			return handlerInstance.APICall<ActionHandler>(typeof(ActionHandler), "application/json");


		}
Example #17
0
        /// <summary>The method to get related record using external id</summary>
        /// <param name="externalFieldValue">string</param>
        /// <param name="externalValue">string</param>
        /// <param name="headerInstance">Instance of HeaderMap</param>
        /// <returns>Instance of APIResponse<ResponseHandler></returns>
        public APIResponse <ResponseHandler> GetRelatedRecordUsingExternalId(string externalFieldValue, string externalValue, HeaderMap headerInstance)
        {
            CommonAPIHandler handlerInstance = new CommonAPIHandler();

            string apiPath = "";

            apiPath = string.Concat(apiPath, "/crm/v2.1/");

            apiPath = string.Concat(apiPath, this.moduleAPIName.ToString());

            apiPath = string.Concat(apiPath, "/");

            apiPath = string.Concat(apiPath, externalValue.ToString());

            apiPath = string.Concat(apiPath, "/");

            apiPath = string.Concat(apiPath, this.relatedListAPIName.ToString());

            apiPath = string.Concat(apiPath, "/");

            apiPath = string.Concat(apiPath, externalFieldValue.ToString());

            handlerInstance.APIPath = apiPath;

            handlerInstance.HttpMethod = Constants.REQUEST_METHOD_GET;

            handlerInstance.CategoryMethod = Constants.REQUEST_CATEGORY_READ;

            handlerInstance.AddHeader(new Header <string>("X-EXTERNAL", "com.zoho.crm.api.RelatedRecords.GetRelatedRecordUsingExternalIDHeader"), this.xExternal);

            handlerInstance.Header = headerInstance;

            Utility.GetRelatedLists(this.relatedListAPIName, this.moduleAPIName, handlerInstance);

            return(handlerInstance.APICall <ResponseHandler>(typeof(ResponseHandler), "application/json"));
        }
Example #18
0
        /// <summary>The method to delete record</summary>
        /// <param name="id">long?</param>
        /// <param name="moduleAPIName">string</param>
        /// <param name="paramInstance">Instance of ParameterMap</param>
        /// <param name="headerInstance">Instance of HeaderMap</param>
        /// <returns>Instance of APIResponse<ActionHandler></returns>
        public APIResponse <ActionHandler> DeleteRecord(long?id, string moduleAPIName, ParameterMap paramInstance, HeaderMap headerInstance)
        {
            CommonAPIHandler handlerInstance = new CommonAPIHandler();

            string apiPath = "";

            apiPath = string.Concat(apiPath, "/crm/v2/");

            apiPath = string.Concat(apiPath, moduleAPIName.ToString());

            apiPath = string.Concat(apiPath, "/");

            apiPath = string.Concat(apiPath, id.ToString());

            handlerInstance.APIPath = apiPath;

            handlerInstance.HttpMethod = Constants.REQUEST_METHOD_DELETE;

            handlerInstance.CategoryMethod = Constants.REQUEST_METHOD_DELETE;

            handlerInstance.Param = paramInstance;

            handlerInstance.Header = headerInstance;

            return(handlerInstance.APICall <ActionHandler>(typeof(ActionHandler), "application/json"));
        }
Example #19
0
        /// <summary>The method to search records</summary>
        /// <param name="moduleAPIName">string</param>
        /// <param name="paramInstance">Instance of ParameterMap</param>
        /// <param name="headerInstance">Instance of HeaderMap</param>
        /// <returns>Instance of APIResponse<ResponseHandler></returns>
        public APIResponse <ResponseHandler> SearchRecords(string moduleAPIName, ParameterMap paramInstance, HeaderMap headerInstance)
        {
            CommonAPIHandler handlerInstance = new CommonAPIHandler();

            string apiPath = "";

            apiPath = string.Concat(apiPath, "/crm/v2/");

            apiPath = string.Concat(apiPath, moduleAPIName.ToString());

            apiPath = string.Concat(apiPath, "/search");

            handlerInstance.APIPath = apiPath;

            handlerInstance.HttpMethod = Constants.REQUEST_METHOD_GET;

            handlerInstance.CategoryMethod = Constants.REQUEST_CATEGORY_READ;

            handlerInstance.Param = paramInstance;

            handlerInstance.Header = headerInstance;

            Utility.GetFields(moduleAPIName);

            handlerInstance.ModuleAPIName = moduleAPIName;

            return(handlerInstance.APICall <ResponseHandler>(typeof(ResponseHandler), "application/json"));
        }
Example #20
0
 /**
  * 添加请求头
  *
  * @param key a {@link java.lang.String} object.
  * @param value a {@link java.lang.String} object.
  */
 public void AddHeader(string key, string value)
 {
     HeaderMap.Add(key, value, AddChoice.Update);
 }
Example #21
0
 public HearderPage(IWebDriver webDriver) : base(webDriver)
 {
     _driver    = webDriver;
     _headerMap = new HeaderMap(_driver);
     _rand      = new Random();
 }
Example #22
0
        /// <summary>The method to delete record using external id</summary>
        /// <param name="externalFieldValue">string</param>
        /// <param name="moduleAPIName">string</param>
        /// <param name="paramInstance">Instance of ParameterMap</param>
        /// <param name="headerInstance">Instance of HeaderMap</param>
        /// <returns>Instance of APIResponse<ActionHandler></returns>
        public APIResponse <ActionHandler> DeleteRecordUsingExternalId(string externalFieldValue, string moduleAPIName, ParameterMap paramInstance, HeaderMap headerInstance)
        {
            CommonAPIHandler handlerInstance = new CommonAPIHandler();

            string apiPath = "";

            apiPath = string.Concat(apiPath, "/crm/v2.1/");

            apiPath = string.Concat(apiPath, moduleAPIName.ToString());

            apiPath = string.Concat(apiPath, "/");

            apiPath = string.Concat(apiPath, externalFieldValue.ToString());

            handlerInstance.APIPath = apiPath;

            handlerInstance.HttpMethod = Constants.REQUEST_METHOD_DELETE;

            handlerInstance.CategoryMethod = Constants.REQUEST_METHOD_DELETE;

            handlerInstance.Param = paramInstance;

            handlerInstance.Header = headerInstance;

            Utility.GetFields(moduleAPIName, handlerInstance);

            return(handlerInstance.APICall <ActionHandler>(typeof(ActionHandler), "application/json"));
        }
Example #23
0
        /// <summary>The method to upsert records</summary>
        /// <param name="moduleAPIName">string</param>
        /// <param name="request">Instance of BodyWrapper</param>
        /// <param name="headerInstance">Instance of HeaderMap</param>
        /// <returns>Instance of APIResponse<ActionHandler></returns>
        public APIResponse <ActionHandler> UpsertRecords(string moduleAPIName, BodyWrapper request, HeaderMap headerInstance)
        {
            CommonAPIHandler handlerInstance = new CommonAPIHandler();

            string apiPath = "";

            apiPath = string.Concat(apiPath, "/crm/v2/");

            apiPath = string.Concat(apiPath, moduleAPIName.ToString());

            apiPath = string.Concat(apiPath, "/upsert");

            handlerInstance.APIPath = apiPath;

            handlerInstance.HttpMethod = Constants.REQUEST_METHOD_POST;

            handlerInstance.CategoryMethod = Constants.REQUEST_CATEGORY_ACTION;

            handlerInstance.ContentType = "application/json";

            handlerInstance.Request = request;

            handlerInstance.Header = headerInstance;

            Utility.GetFields(moduleAPIName);

            handlerInstance.ModuleAPIName = moduleAPIName;

            return(handlerInstance.APICall <ActionHandler>(typeof(ActionHandler), "application/json"));
        }
        public Dimensions ReadDimensions(Stream byteStream)
        {
            byteStream.Seek(0, SeekOrigin.Begin);

            List <HashNode <FileType> > relevantHashNodes = new List <HashNode <FileType> >();

            while (InternalFileType == FileType.UNKNOWN)
            {
                int readByte = byteStream.ReadByte();

                if (readByte == -1)
                {
                    throw new HeaderNotFoundException("Header not found in stream.");
                }

                HashNode <FileType> hashNode;
                for (int i = 0; i < relevantHashNodes.Count; i++)
                {
                    hashNode = relevantHashNodes[i].GetFirstKey((byte)readByte);
                    if (hashNode != null)
                    {
                        if (hashNode.HasValue)
                        {
                            InternalFileType = hashNode.Value;
                            break;
                        }
                        else
                        {
                            relevantHashNodes[i] = hashNode;
                        }
                    }
                    else
                    {
                        relevantHashNodes.RemoveAt(i);
                        i--;
                    }
                }
                hashNode = HeaderMap.GetFirstKey((byte)readByte);
                if (hashNode != null)
                {
                    relevantHashNodes.Add(hashNode);
                }
            }

            Dimensions dimensions = Dimensions.None;

            switch (InternalFileType)
            {
            case FileType.PNG:
                dimensions = ReadPngDimensions(byteStream);
                break;

            case FileType.JPG:
                dimensions = ReadJpgDimensions(byteStream);
                break;

            default:
                Console.WriteLine("Found currently unsupported filetype");
                break;
            }

            EndOfMetadataIndex = byteStream.Position;

            if (byteStream.ReadByte() == -1)
            {
                throw new HeaderNotFoundException("Header only partially present in stream.");
            }

            if (dimensions.Width < 0 || dimensions.Height < 0)
            {
                Console.WriteLine("Bad negative value found - Width: " + dimensions.Width + " Height: " + dimensions.Height);
            }

            return(dimensions);
        }